@@ -21,6 +21,7 @@ import '@anypoint-web-components/anypoint-button/anypoint-button.js';
2121import '@polymer/paper-toast/paper-toast.js' ;
2222import '@api-components/api-console-ext-comm/api-console-ext-comm.js' ;
2323import attributionTpl from './attribution-template.js' ;
24+ import { close } from '@advanced-rest-client/arc-icons/ArcIcons.js' ;
2425
2526export const isChrome = / C h r o m e / . test ( navigator . userAgent ) && / G o o g l e I n c / . test ( navigator . vendor ) ;
2627/**
@@ -127,6 +128,25 @@ export class ApiConsole extends AmfHelperMixin(LitElement) {
127128 max-width: var(--api-console-main-max-width, 1600px);
128129 }
129130
131+ .extension-banner {
132+ align-items: center;
133+ display: none;
134+ border-bottom: 1px var(--api-console-extension-banner-border-bottom-color, rgba(0,0,0,0.12)) solid;
135+ border-top: 1px var(--api-console-extension-banner-border-bottom-color, rgba(0,0,0,0.12)) solid;
136+ margin-bottom: 12px;
137+ box-sizing: border-box;
138+ color: var(--api-console-extension-banner-color, rgba(0,0,0,0.54));
139+ }
140+
141+ .extension-banner[active] {
142+ display: flex;
143+ flex-direction: row;
144+ }
145+
146+ .extension-banner {
147+ max-width: var(--api-console-main-max-width, 1600px);
148+ }
149+
130150 .method-title {
131151 flex: 1;
132152 font-size: var(--arc-font-headline-font-size);
@@ -150,6 +170,13 @@ export class ApiConsole extends AmfHelperMixin(LitElement) {
150170 overflow: auto;
151171 height: 100%;
152172 }
173+
174+ .icon {
175+ fill: currentColor;
176+ width: 24px;
177+ height: 24px;
178+ display: block;
179+ }
153180 ` ;
154181 }
155182
@@ -161,7 +188,29 @@ export class ApiConsole extends AmfHelperMixin(LitElement) {
161188 }
162189 }
163190
164- _bannerMessage ( ) { }
191+ _bannerMessage ( ) {
192+ if ( ! this . allowExtensionBanner ) {
193+ return '' ;
194+ }
195+ return html `
196+ < div class ="extension-banner " ?active ="${ this . _extensionBannerActive } ">
197+ < p >
198+ For better experience install API console extension.
199+ Get it from < a target ="_blank "
200+ class ="store-link "
201+ href ="https://chrome.google.com/webstore/detail/olkpohecoakpkpinafnpppponcfojioa "
202+ >
203+ Chrome Web Store
204+ </ a >
205+ </ p >
206+ < anypoint-icon-button
207+ aria-label ="Activate to close the message "
208+ @click ="${ this . dismissExtensionBanner } "
209+ >
210+ < span class ="icon "> ${ close } </ span >
211+ </ anypoint-icon-button >
212+ </ div > ` ;
213+ }
165214
166215 _getRequestTemplate ( ) {
167216 const {
@@ -245,7 +294,7 @@ export class ApiConsole extends AmfHelperMixin(LitElement) {
245294 .redirectUri ="${ redirectUri } "
246295 .scrollTarget ="${ scrollTarget } "
247296 @api-navigation-selection-changed ="${ this . _apiNavigationOcurred } "
248- @tryit-requested =" ${ this . _tryitHandler } " > </ api-documentation > ` ;
297+ > </ api-documentation > ` ;
249298 }
250299
251300 _navigationTemplate ( ) {
@@ -294,7 +343,7 @@ export class ApiConsole extends AmfHelperMixin(LitElement) {
294343 */
295344 _helpersTemplate ( ) {
296345 return html `< paper-toast class ="error-toast " id ="apiLoadErrorToast "> </ paper-toast >
297- < api-console-ext-comm @has- extension-changed ="${ this . _hasExtensionHandler } "> </ api-console-ext-comm >
346+ < api-console-ext-comm @api-console- extension-installed ="${ this . _hasExtensionHandler } "> </ api-console-ext-comm >
298347 ` ;
299348 }
300349
@@ -503,6 +552,20 @@ export class ApiConsole extends AmfHelperMixin(LitElement) {
503552 } ;
504553 }
505554
555+ get allowExtensionBanner ( ) {
556+ return this . _allowExtensionBanner ;
557+ }
558+
559+ set allowExtensionBanner ( value ) {
560+ const old = this . _allowExtensionBanner ;
561+ /* istanbul ignore if */
562+ if ( old === value ) {
563+ return ;
564+ }
565+ this . _allowExtensionBanner = value ;
566+ this . _allowExtensionBannerChanged ( value ) ;
567+ }
568+
506569 get selectedShape ( ) {
507570 return this . _selectedShape ;
508571 }
@@ -653,16 +716,18 @@ export class ApiConsole extends AmfHelperMixin(LitElement) {
653716 return ;
654717 }
655718 this . amf = data ;
719+ this . dispatchEvent ( new CustomEvent ( 'model-load-success' ) ) ;
656720 }
657721 /**
658722 * Called by `_modelLocationChanged` when error occurred when getting API data.
659723 * @param {Error } error
660724 */
661725 _apiLoadErrorHandler ( error ) {
662- const message = ' Unable to load API model data. ' + ( error . message ? error . message : '' ) ;
726+ const message = ` Unable to load API model data. ${ error . message || '' } ` ;
663727 const toast = this . shadowRoot . querySelector ( '#apiLoadErrorToast' ) ;
664728 toast . text = message ;
665729 toast . opened = true ;
730+ this . dispatchEvent ( new CustomEvent ( 'model-load-error' ) ) ;
666731 }
667732 /**
668733 * Handler for the `tryit-requested` event. Sets current screen to
@@ -731,12 +796,6 @@ export class ApiConsole extends AmfHelperMixin(LitElement) {
731796 composed : true
732797 } ) ) ;
733798 }
734-
735- _hasCorsExtensionChanged ( value ) {
736- if ( value && this . _extensionBannerActive ) {
737- this . _extensionBannerActive = false ;
738- }
739- }
740799 /**
741800 * Computes method name for not-wide view, where the request panel
742801 * has close button.
@@ -770,12 +829,24 @@ export class ApiConsole extends AmfHelperMixin(LitElement) {
770829 }
771830
772831 _hasExtensionHandler ( e ) {
773- this . _hasApicCorsExtension = e . detail . value ;
774- this . _hasCorsExtensionChanged ( e . detail . value ) ;
832+ this . _hasApicCorsExtension = true ;
833+ this . _extensionBannerActive = false ;
775834 }
776835
777836 _closeDrawer ( ) {
778837 this . navigationOpened = false ;
779838 this . dispatchEvent ( new CustomEvent ( 'navigation-close' ) ) ;
780839 }
840+
841+ /**
842+ * Controls behavior if the extension banner.
843+ * @param {Boolean } value Current value of `allowExtensionBanner` property
844+ */
845+ _allowExtensionBannerChanged ( value ) {
846+ if ( ! value && this . _extensionBannerActive ) {
847+ this . _extensionBannerActive = false ;
848+ } else if ( value && ! this . _hasApicCorsExtension ) {
849+ this . _extensionBannerActive = true ;
850+ }
851+ }
781852}
0 commit comments