77 faHourglassHalf ,
88} from "@fortawesome/free-solid-svg-icons" ;
99import { html , nothing , render , LitElement } from "lit" ;
10+ import { default as objectPath } from "object-path" ;
1011
1112import styleSheet from "./notification.css" ;
1213import { AddonBase , addUtmParameters , getLinkWithFilename } from "./utils" ;
@@ -135,7 +136,7 @@ export class NotificationElement extends LitElement {
135136 this . config = config ;
136137
137138 if (
138- this . config . addons . external_version_warning . enabled &&
139+ this . config . addons . notifications . enabled &&
139140 this . config . versions . current . type === "external"
140141 ) {
141142 this . urls = {
@@ -150,7 +151,11 @@ export class NotificationElement extends LitElement {
150151 }
151152
152153 if (
153- config . addons . non_latest_version_warning . enabled &&
154+ objectPath . get (
155+ this . config ,
156+ "addons.notifications.show_on_latest" ,
157+ false ,
158+ ) &&
154159 config . projects . current . versioning_scheme !==
155160 "single_version_without_translations" &&
156161 config . versions . current . type !== "external"
@@ -189,16 +194,42 @@ export class NotificationElement extends LitElement {
189194 return nothing ;
190195 }
191196
197+ if ( ! this . config . addons . notifications . enabled ) {
198+ return nothing ;
199+ }
200+
192201 if ( this . config . versions . current . type === "external" ) {
193- if ( this . config . addons . external_version_warning . enabled ) {
202+ if (
203+ objectPath . get (
204+ this . config ,
205+ "addons.notifications.show_on_external" ,
206+ false ,
207+ )
208+ ) {
194209 return this . renderExternalVersionWarning ( ) ;
195210 }
196- } else if (
197- this . config . addons . non_latest_version_warning . enabled &&
198- ( this . readingLatestVersion || this . stableVersionAvailable )
211+ }
212+
213+ if (
214+ this . readingLatestVersion &&
215+ this . stableVersionAvailable &&
216+ objectPath . get ( this . config , "addons.notifications.show_on_latest" , false )
199217 ) {
200- return this . renderStableLatestVersionWarning ( ) ;
218+ return this . renderLatestVersionWarning ( ) ;
201219 }
220+
221+ if (
222+ ! this . readingStableVersion &&
223+ this . stableVersionAvailable &&
224+ objectPath . get (
225+ this . config ,
226+ "addons.notifications.show_on_non_stable" ,
227+ false ,
228+ )
229+ ) {
230+ return this . renderStableVersionWarning ( ) ;
231+ }
232+
202233 return nothing ;
203234 }
204235
@@ -247,56 +278,51 @@ export class NotificationElement extends LitElement {
247278 }
248279 }
249280
250- renderStableLatestVersionWarning ( ) {
251- library . add ( faHourglassHalf ) ;
281+ renderLatestVersionWarning ( ) {
252282 library . add ( faFlask ) ;
253- if ( this . readingLatestVersion && this . stableVersionAvailable ) {
254- const iconFlask = icon ( faFlask , {
255- classes : [ "header" , "icon" ] ,
256- } ) ;
257-
258- return html `
259- < div >
260- ${ iconFlask . node [ 0 ] }
261- < div class ="title ">
262- This is the < span > latest development version</ span >
263- ${ this . renderCloseButton ( ) }
264- </ div >
265- < div class ="content ">
266- Some features may not yet be available in the published stable
267- version. Read the
268- < a href ="${ this . urls . stable } "
269- > stable version of this documentation</ a
270- > .
271- </ div >
272- </ div >
273- ` ;
274- }
283+ const iconFlask = icon ( faFlask , {
284+ classes : [ "header" , "icon" ] ,
285+ } ) ;
275286
276- if ( ! this . readingStableVersion && this . stableVersionAvailable ) {
277- const iconHourglassHalf = icon ( faHourglassHalf , {
278- classes : [ "header" , "icon" ] ,
279- } ) ;
280-
281- return html `
282- < div >
283- ${ iconHourglassHalf . node [ 0 ] }
284- < div class ="title ">
285- This < em > may</ em > be an
286- < span > old version of this documentation</ span >
287- ${ this . renderCloseButton ( ) }
288- </ div >
289- < div class ="content ">
290- You may be reading an old version of this documentation. Read the
291- < a href ="${ this . urls . stable } "
292- > latest stable version of this documentation</ a
293- > .
294- </ div >
287+ return html `
288+ < div >
289+ ${ iconFlask . node [ 0 ] }
290+ < div class ="title ">
291+ This is the < span > latest development version</ span >
292+ ${ this . renderCloseButton ( ) }
295293 </ div >
296- ` ;
297- }
294+ < div class ="content ">
295+ Some features may not yet be available in the published stable
296+ version. Read the
297+ < a href ="${ this . urls . stable } "> stable version of this documentation</ a
298+ > .
299+ </ div >
300+ </ div >
301+ ` ;
302+ }
298303
299- return nothing ;
304+ renderStableVersionWarning ( ) {
305+ library . add ( faHourglassHalf ) ;
306+ const iconHourglassHalf = icon ( faHourglassHalf , {
307+ classes : [ "header" , "icon" ] ,
308+ } ) ;
309+
310+ return html `
311+ < div >
312+ ${ iconHourglassHalf . node [ 0 ] }
313+ < div class ="title ">
314+ This < em > may</ em > be an
315+ < span > old version of this documentation</ span >
316+ ${ this . renderCloseButton ( ) }
317+ </ div >
318+ < div class ="content ">
319+ You may be reading an old version of this documentation. Read the
320+ < a href ="${ this . urls . stable } "
321+ > latest stable version of this documentation</ a
322+ > .
323+ </ div >
324+ </ div >
325+ ` ;
300326 }
301327
302328 renderExternalVersionWarning ( ) {
@@ -376,6 +402,7 @@ export class NotificationElement extends LitElement {
376402export class NotificationAddon extends AddonBase {
377403 static jsonValidationURI =
378404 "http://v1.schemas.readthedocs.org/addons.notifications.json" ;
405+ static addonEnabledPath = "addons.notifications.enabled" ;
379406 static addonName = "Notification" ;
380407
381408 constructor ( config ) {
@@ -393,24 +420,6 @@ export class NotificationAddon extends AddonBase {
393420 elem . loadConfig ( config ) ;
394421 }
395422 }
396-
397- /**
398- * Test if addon is enabled in the configuration
399- *
400- * @param {Object } config - Addon configuration object
401- */
402- static isEnabled ( config ) {
403- if ( ! super . isConfigValid ( config ) ) {
404- return false ;
405- }
406-
407- return (
408- ( config . addons . external_version_warning . enabled === true &&
409- config . versions . current . type === "external" ) ||
410- ( config . addons . non_latest_version_warning . enabled === true &&
411- config . versions . current . type !== "external" )
412- ) ;
413- }
414423}
415424
416425customElements . define ( "readthedocs-notification" , NotificationElement ) ;
0 commit comments