7
7
faHourglassHalf ,
8
8
} from "@fortawesome/free-solid-svg-icons" ;
9
9
import { html , nothing , render , LitElement } from "lit" ;
10
+ import { default as objectPath } from "object-path" ;
10
11
11
12
import styleSheet from "./notification.css" ;
12
13
import { AddonBase , addUtmParameters , getLinkWithFilename } from "./utils" ;
@@ -135,7 +136,7 @@ export class NotificationElement extends LitElement {
135
136
this . config = config ;
136
137
137
138
if (
138
- this . config . addons . external_version_warning . enabled &&
139
+ this . config . addons . notifications . enabled &&
139
140
this . config . versions . current . type === "external"
140
141
) {
141
142
this . urls = {
@@ -150,7 +151,7 @@ export class NotificationElement extends LitElement {
150
151
}
151
152
152
153
if (
153
- config . addons . non_latest_version_warning . enabled &&
154
+ config . addons . notifications . show_on_latest &&
154
155
config . projects . current . versioning_scheme !==
155
156
"single_version_without_translations" &&
156
157
config . versions . current . type !== "external"
@@ -189,16 +190,42 @@ export class NotificationElement extends LitElement {
189
190
return nothing ;
190
191
}
191
192
193
+ if ( ! this . config . addons . notifications . enabled ) {
194
+ return nothing ;
195
+ }
196
+
192
197
if ( this . config . versions . current . type === "external" ) {
193
- if ( this . config . addons . external_version_warning . enabled ) {
198
+ if (
199
+ objectPath . get (
200
+ this . config ,
201
+ "addons.notifications.show_on_external" ,
202
+ false ,
203
+ )
204
+ ) {
194
205
return this . renderExternalVersionWarning ( ) ;
195
206
}
196
- } else if (
197
- this . config . addons . non_latest_version_warning . enabled &&
198
- ( this . readingLatestVersion || this . stableVersionAvailable )
207
+ }
208
+
209
+ if (
210
+ this . readingLatestVersion &&
211
+ this . stableVersionAvailable &&
212
+ objectPath . get ( this . config , "addons.notifications.show_on_latest" , false )
199
213
) {
200
- return this . renderStableLatestVersionWarning ( ) ;
214
+ return this . renderLatestVersionWarning ( ) ;
201
215
}
216
+
217
+ if (
218
+ ! this . readingStableVersion &&
219
+ this . stableVersionAvailable &&
220
+ objectPath . get (
221
+ this . config ,
222
+ "addons.notifications.show_on_non_stable" ,
223
+ false ,
224
+ )
225
+ ) {
226
+ return this . renderStableVersionWarning ( ) ;
227
+ }
228
+
202
229
return nothing ;
203
230
}
204
231
@@ -247,56 +274,51 @@ export class NotificationElement extends LitElement {
247
274
}
248
275
}
249
276
250
- renderStableLatestVersionWarning ( ) {
251
- library . add ( faHourglassHalf ) ;
277
+ renderLatestVersionWarning ( ) {
252
278
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
- }
279
+ const iconFlask = icon ( faFlask , {
280
+ classes : [ "header" , "icon" ] ,
281
+ } ) ;
275
282
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 >
283
+ return html `
284
+ < div >
285
+ ${ iconFlask . node [ 0 ] }
286
+ < div class ="title ">
287
+ This is the < span > latest development version</ span >
288
+ ${ this . renderCloseButton ( ) }
295
289
</ div >
296
- ` ;
297
- }
290
+ < div class ="content ">
291
+ Some features may not yet be available in the published stable
292
+ version. Read the
293
+ < a href ="${ this . urls . stable } "> stable version of this documentation</ a
294
+ > .
295
+ </ div >
296
+ </ div >
297
+ ` ;
298
+ }
298
299
299
- return nothing ;
300
+ renderStableVersionWarning ( ) {
301
+ library . add ( faHourglassHalf ) ;
302
+ const iconHourglassHalf = icon ( faHourglassHalf , {
303
+ classes : [ "header" , "icon" ] ,
304
+ } ) ;
305
+
306
+ return html `
307
+ < div >
308
+ ${ iconHourglassHalf . node [ 0 ] }
309
+ < div class ="title ">
310
+ This < em > may</ em > be an
311
+ < span > old version of this documentation</ span >
312
+ ${ this . renderCloseButton ( ) }
313
+ </ div >
314
+ < div class ="content ">
315
+ You may be reading an old version of this documentation. Read the
316
+ < a href ="${ this . urls . stable } "
317
+ > latest stable version of this documentation</ a
318
+ > .
319
+ </ div >
320
+ </ div >
321
+ ` ;
300
322
}
301
323
302
324
renderExternalVersionWarning ( ) {
@@ -376,6 +398,7 @@ export class NotificationElement extends LitElement {
376
398
export class NotificationAddon extends AddonBase {
377
399
static jsonValidationURI =
378
400
"http://v1.schemas.readthedocs.org/addons.notifications.json" ;
401
+ static addonEnabledPath = "addons.notifications.enabled" ;
379
402
static addonName = "Notification" ;
380
403
381
404
constructor ( config ) {
@@ -393,24 +416,6 @@ export class NotificationAddon extends AddonBase {
393
416
elem . loadConfig ( config ) ;
394
417
}
395
418
}
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
- }
414
419
}
415
420
416
421
customElements . define ( "readthedocs-notification" , NotificationElement ) ;
0 commit comments