@@ -19,17 +19,15 @@ const SYSTEM_MAP = {
1919
2020export default function TimePlugin ( options ) {
2121 return function install ( openmct ) {
22- var TODAY_BOUNDS = {
22+ const TODAY_BOUNDS = {
2323 start : moment . utc ( ) . startOf ( 'day' ) . valueOf ( ) ,
2424 end : moment . utc ( ) . endOf ( 'day' ) . valueOf ( )
2525 } ;
26-
27- var solFormat = new MSLSolFormat ( openmct ) ;
28- var lmstFormat = new LMSTFormat ( openmct ) ;
29- var nowLST = solFormat . format ( moment . utc ( ) ) ;
30- var sol = Number ( / S O L - ( \d + ) M / . exec ( nowLST ) [ 1 ] ) ;
31-
32- var BOUNDS_MAP = {
26+ const solFormat = new MSLSolFormat ( openmct ) ;
27+ const lmstFormat = new LMSTFormat ( openmct ) ;
28+ const nowLST = solFormat . format ( moment . utc ( ) ) ;
29+ const sol = Number ( / S O L - ( \d + ) M / . exec ( nowLST ) [ 1 ] ) ;
30+ const BOUNDS_MAP = {
3331 ert : TODAY_BOUNDS ,
3432 scet : TODAY_BOUNDS ,
3533 sclk : {
@@ -51,7 +49,7 @@ export default function TimePlugin(options) {
5149 }
5250
5351 if ( options . lmstEpoch ) {
54- var lmstFormatWithEpoch = new LMSTFormat ( options . lmstEpoch ) ;
52+ const lmstFormatWithEpoch = new LMSTFormat ( options . lmstEpoch ) ;
5553
5654 BOUNDS_MAP . lmst = {
5755 start : lmstFormatWithEpoch . parse ( 'SOL-' + sol ) ,
@@ -61,74 +59,105 @@ export default function TimePlugin(options) {
6159
6260 install . ladClocks = { } ;
6361 install . timeSystems = options . timeSystems ;
62+
6463 let useUTCClock = false ;
6564 let menuOptions = [ ] ;
6665
67-
6866 options . timeSystems . forEach ( function ( timeSystem ) {
69- const key = timeSystem . key || timeSystem ;
67+ const key = timeSystem . key ?? timeSystem ;
7068
7169 if ( ! SYSTEM_MAP [ key ] ) {
7270 console . error ( 'Invalid timeSystem specified: ' + key ) ;
71+
7372 return ;
7473 }
7574
7675 const system = new SYSTEM_MAP [ key ] ( options . utcFormat ) ;
77- openmct . time . addTimeSystem ( system ) ;
78-
7976 const systemOptions = {
8077 timeSystem : system . key ,
81- bounds : BOUNDS_MAP [ key ]
78+ name : 'fixed'
8279 } ;
8380
84- if ( timeSystem . presets ) {
85- systemOptions . presets = timeSystem . presets ;
81+ openmct . time . addTimeSystem ( system ) ;
82+
83+ if ( timeSystem . modeSettings ?. fixed ?. bounds ) {
84+ systemOptions . bounds = timeSystem . modeSettings . fixed . bounds ;
85+ } else {
86+ systemOptions . bounds = BOUNDS_MAP [ key ] ;
87+ }
88+
89+ if ( timeSystem . modeSettings ?. fixed ?. presets ) {
90+ systemOptions . presets = timeSystem . modeSettings . fixed . presets ;
8691 }
92+
8793 if ( timeSystem . limit ) {
8894 systemOptions . limit = timeSystem . limit ;
8995 }
96+
9097 if ( options . records ) {
9198 systemOptions . records = options . records ;
9299 }
93100
94101 menuOptions . push ( systemOptions ) ;
95102
103+ const DEFAULT_OFFSET_CONFIG = {
104+ start : - 30 * 60 * 1000 ,
105+ end : 5 * 60 * 1000
106+ }
107+
96108 if ( options . allowRealtime && system . isUTCBased ) {
109+ let offsetConfig = DEFAULT_OFFSET_CONFIG ;
110+ let presetConfig = [ ] ;
111+
112+ if ( timeSystem . modeSettings ?. realtime ?. clockOffsets ) {
113+ offsetConfig = timeSystem . modeSettings . realtime . clockOffsets
114+ }
115+
116+ if ( timeSystem . modeSettings ?. realtime ?. presets ) {
117+ presetConfig = timeSystem . modeSettings . realtime . presets
118+ }
119+
97120 useUTCClock = true ;
98121 menuOptions . push ( {
122+ name :'realtime' ,
99123 timeSystem : system . key ,
100124 clock : 'utc.local' ,
101- clockOffsets : {
102- start : - 30 * 60 * 1000 ,
103- end : 5 * 60 * 1000
104- }
125+ clockOffsets : offsetConfig ,
126+ presets : presetConfig
105127 } ) ;
106128 }
129+
107130 if ( options . allowRealtime && options . allowLAD ) {
108- var ladClock = new LADClock ( key ) ;
131+ const ladClock = new LADClock ( key ) ;
132+ let offsetConfig = DEFAULT_OFFSET_CONFIG ;
133+
134+ if ( timeSystem . modeSettings ?. lad ?. clockOffsets ) {
135+ offsetConfig = timeSystem . modeSettings . lad . clockOffsets
136+ }
137+
109138 install . ladClocks [ key ] = ladClock ;
110139 openmct . time . addClock ( ladClock ) ;
111140 menuOptions . push ( {
112141 timeSystem : system . key ,
113142 clock : ladClock . key ,
114- clockOffsets : {
115- start : - 30 * 60 * 1000 ,
116- end : 5 * 60 * 1000
117- }
143+ clockOffsets : offsetConfig ,
118144 } ) ;
119145 }
120146 } ) ;
147+
121148 if ( options . defaultMode ) {
122- let matchingConfigIndex = menuOptions . findIndex ( menuOption =>
123- menuOption . clock === options . defaultMode ) ;
149+ const isFixedMode = options . defaultMode === 'fixed' ;
150+ const matchingConfigIndex = menuOptions . findIndex (
151+ ( menuOption ) => isFixedMode ? ! menuOption . clock : menuOption . clock === options . defaultMode
152+ ) ;
124153
125154 if ( matchingConfigIndex !== - 1 ) {
126- let matchingConfig = menuOptions [ matchingConfigIndex ] ;
155+ const matchingConfig = menuOptions [ matchingConfigIndex ] ;
156+
127157 menuOptions . splice ( matchingConfigIndex , 1 ) ;
128158 menuOptions . unshift ( matchingConfig ) ;
129159 } else {
130- console . warn ( `Default mode '${ options . defaultMode } ' specified in configuration could not be applied.
131- Are LAD or realtime enabled? Does the defaultMode contain a typo?` ) ;
160+ console . warn ( `Default mode '${ options . defaultMode } ' specified in configuration could not be applied. Are LAD or realtime enabled? Does the defaultMode contain a typo?` ) ;
132161 }
133162 }
134163
0 commit comments