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,11 @@ export class NotificationElement extends LitElement {
150
151
}
151
152
152
153
if (
153
- config . addons . non_latest_version_warning . enabled &&
154
+ objectPath . get (
155
+ this . config ,
156
+ "addons.notifications.show_on_latest" ,
157
+ false ,
158
+ ) &&
154
159
config . projects . current . versioning_scheme !==
155
160
"single_version_without_translations" &&
156
161
config . versions . current . type !== "external"
@@ -189,16 +194,42 @@ export class NotificationElement extends LitElement {
189
194
return nothing ;
190
195
}
191
196
197
+ if ( ! this . config . addons . notifications . enabled ) {
198
+ return nothing ;
199
+ }
200
+
192
201
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
+ ) {
194
209
return this . renderExternalVersionWarning ( ) ;
195
210
}
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 )
199
217
) {
200
- return this . renderStableLatestVersionWarning ( ) ;
218
+ return this . renderLatestVersionWarning ( ) ;
201
219
}
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
+
202
233
return nothing ;
203
234
}
204
235
@@ -247,56 +278,51 @@ export class NotificationElement extends LitElement {
247
278
}
248
279
}
249
280
250
- renderStableLatestVersionWarning ( ) {
251
- library . add ( faHourglassHalf ) ;
281
+ renderLatestVersionWarning ( ) {
252
282
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
+ } ) ;
275
286
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 ( ) }
295
293
</ 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
+ }
298
303
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
+ ` ;
300
326
}
301
327
302
328
renderExternalVersionWarning ( ) {
@@ -376,6 +402,7 @@ export class NotificationElement extends LitElement {
376
402
export class NotificationAddon extends AddonBase {
377
403
static jsonValidationURI =
378
404
"http://v1.schemas.readthedocs.org/addons.notifications.json" ;
405
+ static addonEnabledPath = "addons.notifications.enabled" ;
379
406
static addonName = "Notification" ;
380
407
381
408
constructor ( config ) {
@@ -393,24 +420,6 @@ export class NotificationAddon extends AddonBase {
393
420
elem . loadConfig ( config ) ;
394
421
}
395
422
}
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
423
}
415
424
416
425
customElements . define ( "readthedocs-notification" , NotificationElement ) ;
0 commit comments