1
- define ( [ './summary-widget.html' , '@braintree/sanitize-url' ] , function (
2
- summaryWidgetTemplate ,
3
- urlSanitizeLib
4
- ) {
5
- const WIDGET_ICON_CLASS = 'c-sw__icon js-sw__icon' ;
1
+ import * as urlSanitizeLib from '@braintree/sanitize-url' ;
6
2
7
- function SummaryWidgetView ( domainObject , openmct ) {
3
+ const WIDGET_ICON_CLASS = 'c-sw__icon js-sw__icon' ;
4
+
5
+ class SummaryWidgetView {
6
+ #createSummaryWidgetTemplate( ) {
7
+ const anchor = document . createElement ( 'a' ) ;
8
+ anchor . classList . add (
9
+ 't-summary-widget' ,
10
+ 'c-summary-widget' ,
11
+ 'js-sw' ,
12
+ 'u-links' ,
13
+ 'u-fills-container'
14
+ ) ;
15
+
16
+ const widgetIcon = document . createElement ( 'div' ) ;
17
+ widgetIcon . id = 'widgetIcon' ;
18
+ widgetIcon . classList . add ( 'c-sw__icon' , 'js-sw__icon' ) ;
19
+ anchor . appendChild ( widgetIcon ) ;
20
+
21
+ const widgetLabel = document . createElement ( 'div' ) ;
22
+ widgetLabel . id = 'widgetLabel' ;
23
+ widgetLabel . classList . add ( 'c-sw__label' , 'js-sw__label' ) ;
24
+ widgetLabel . textContent = 'Loading...' ;
25
+ anchor . appendChild ( widgetLabel ) ;
26
+
27
+ return anchor ;
28
+ }
29
+
30
+ constructor ( domainObject , openmct ) {
8
31
this . openmct = openmct ;
9
32
this . domainObject = domainObject ;
10
33
this . hasUpdated = false ;
11
34
this . render = this . render . bind ( this ) ;
12
35
}
13
36
14
- SummaryWidgetView . prototype . updateState = function ( datum ) {
37
+ updateState ( datum ) {
15
38
this . hasUpdated = true ;
16
39
this . widget . style . color = datum . textColor ;
17
40
this . widget . style . backgroundColor = datum . backgroundColor ;
18
41
this . widget . style . borderColor = datum . borderColor ;
19
42
this . widget . title = datum . message ;
20
43
this . label . title = datum . message ;
21
- this . label . innerHTML = datum . ruleLabel ;
44
+ this . label . textContent = datum . ruleLabel ;
22
45
this . icon . className = WIDGET_ICON_CLASS + ' ' + datum . icon ;
23
- } ;
46
+ }
24
47
25
- SummaryWidgetView . prototype . render = function ( ) {
48
+ render ( ) {
26
49
if ( this . unsubscribe ) {
27
50
this . unsubscribe ( ) ;
28
51
}
29
52
30
53
this . hasUpdated = false ;
31
54
32
- this . container . innerHTML = summaryWidgetTemplate ;
55
+ const anchor = this . #createSummaryWidgetTemplate( ) ;
56
+ this . container . appendChild ( anchor ) ;
57
+
33
58
this . widget = this . container . querySelector ( 'a' ) ;
34
59
this . icon = this . container . querySelector ( '#widgetIcon' ) ;
35
60
this . label = this . container . querySelector ( '.js-sw__label' ) ;
@@ -49,33 +74,32 @@ define(['./summary-widget.html', '@braintree/sanitize-url'], function (
49
74
50
75
const renderTracker = { } ;
51
76
this . renderTracker = renderTracker ;
77
+
52
78
this . openmct . telemetry
53
79
. request ( this . domainObject , {
54
80
strategy : 'latest' ,
55
81
size : 1
56
82
} )
57
- . then (
58
- function ( results ) {
59
- if (
60
- this . destroyed ||
61
- this . hasUpdated ||
62
- this . renderTracker !== renderTracker ||
63
- results . length === 0
64
- ) {
65
- return ;
66
- }
67
-
68
- this . updateState ( results [ results . length - 1 ] ) ;
69
- } . bind ( this )
70
- ) ;
83
+ . then ( ( results ) => {
84
+ if (
85
+ this . destroyed ||
86
+ this . hasUpdated ||
87
+ this . renderTracker !== renderTracker ||
88
+ results . length === 0
89
+ ) {
90
+ return ;
91
+ }
92
+
93
+ this . updateState ( results [ results . length - 1 ] ) ;
94
+ } ) ;
71
95
72
96
this . unsubscribe = this . openmct . telemetry . subscribe (
73
97
this . domainObject ,
74
98
this . updateState . bind ( this )
75
99
) ;
76
- } ;
100
+ }
77
101
78
- SummaryWidgetView . prototype . show = function ( container ) {
102
+ show ( container ) {
79
103
this . container = container ;
80
104
this . render ( ) ;
81
105
this . removeMutationListener = this . openmct . objects . observe (
@@ -84,14 +108,14 @@ define(['./summary-widget.html', '@braintree/sanitize-url'], function (
84
108
this . onMutation . bind ( this )
85
109
) ;
86
110
this . openmct . time . on ( 'timeSystem' , this . render ) ;
87
- } ;
111
+ }
88
112
89
- SummaryWidgetView . prototype . onMutation = function ( domainObject ) {
113
+ onMutation ( domainObject ) {
90
114
this . domainObject = domainObject ;
91
115
this . render ( ) ;
92
- } ;
116
+ }
93
117
94
- SummaryWidgetView . prototype . destroy = function ( container ) {
118
+ destroy ( ) {
95
119
this . unsubscribe ( ) ;
96
120
this . removeMutationListener ( ) ;
97
121
this . openmct . time . off ( 'timeSystem' , this . render ) ;
@@ -100,7 +124,7 @@ define(['./summary-widget.html', '@braintree/sanitize-url'], function (
100
124
delete this . label ;
101
125
delete this . openmct ;
102
126
delete this . domainObject ;
103
- } ;
127
+ }
128
+ }
104
129
105
- return SummaryWidgetView ;
106
- } ) ;
130
+ export default SummaryWidgetView ;
0 commit comments