43
43
44
44
<script>
45
45
import raf from 'utils/raf';
46
+ import throttle from '../../../utils/throttle';
46
47
47
48
const moment = require('moment-timezone');
48
49
const momentDurationFormatSetup = require('moment-duration-format');
50
+ const refreshRateSeconds = 2;
49
51
50
52
momentDurationFormatSetup(moment);
51
53
@@ -68,38 +70,21 @@ export default {
68
70
};
69
71
},
70
72
computed: {
71
- relativeTimestamp() {
72
- let relativeTimestamp;
73
- if (this.configuration && this.configuration.timestamp) {
74
- relativeTimestamp = moment(this.configuration.timestamp).toDate();
75
- } else if (this.configuration && this.configuration.timestamp === undefined) {
76
- relativeTimestamp = undefined;
73
+ timeDelta() {
74
+ if (this.configuration.pausedTime) {
75
+ return Date.parse(this.configuration.pausedTime) - this.startTimeMs;
76
+ } else {
77
+ return this.lastTimestamp - this.startTimeMs;
77
78
}
78
-
79
- return relativeTimestamp;
80
79
},
81
- timeDelta () {
82
- return this.lastTimestamp - this.relativeTimestamp ;
80
+ startTimeMs () {
81
+ return Date.parse( this.configuration.timestamp) ;
83
82
},
84
83
timeTextValue() {
85
- if (isNaN(this.timeDelta)) {
86
- return null;
87
- }
88
-
89
84
const toWholeSeconds = Math.abs(Math.floor(this.timeDelta / 1000) * 1000);
90
85
91
86
return moment.duration(toWholeSeconds, 'ms').format(this.format, { trim: false });
92
87
},
93
- pausedTime() {
94
- let pausedTime;
95
- if (this.configuration && this.configuration.pausedTime) {
96
- pausedTime = moment(this.configuration.pausedTime).toDate();
97
- } else if (this.configuration && this.configuration.pausedTime === undefined) {
98
- pausedTime = undefined;
99
- }
100
-
101
- return pausedTime;
102
- },
103
88
timerState() {
104
89
let timerState = 'started';
105
90
if (this.configuration && this.configuration.timerState) {
@@ -179,20 +164,17 @@ export default {
179
164
}
180
165
},
181
166
mounted() {
182
- this.unobserve = this.openmct.objects.observe(
183
- this.domainObject,
184
- 'configuration',
185
- (configuration) => {
186
- this.configuration = configuration;
187
- }
188
- );
167
+ this.unobserve = this.openmct.objects.observe(this.domainObject, '*', (domainObject) => {
168
+ this.configuration = domainObject.configuration;
169
+ });
189
170
this.$nextTick(() => {
190
171
if (!this.configuration?.timerState) {
191
172
const timerAction = !this.relativeTimestamp ? 'stop' : 'start';
192
173
this.triggerAction(`timer.${timerAction}`);
193
174
}
194
175
195
176
this.handleTick = raf(this.handleTick);
177
+ this.refreshTimerObject = throttle(this.refreshTimerObject, refreshRateSeconds * 1000);
196
178
this.openmct.time.on('tick', this.handleTick);
197
179
198
180
this.viewActionsCollection = this.openmct.actions.getActionsCollection(
@@ -210,15 +192,11 @@ export default {
210
192
},
211
193
methods: {
212
194
handleTick() {
213
- const isTimerRunning = !['paused', 'stopped'].includes(this.timerState);
214
-
215
- if (isTimerRunning) {
216
- this.lastTimestamp = new Date(this.openmct.time.now());
217
- }
218
-
219
- if (this.timerState === 'paused' && !this.lastTimestamp) {
220
- this.lastTimestamp = this.pausedTime;
221
- }
195
+ this.lastTimestamp = new Date(this.openmct.time.now());
196
+ this.refreshTimerObject();
197
+ },
198
+ refreshTimerObject() {
199
+ this.openmct.objects.refresh(this.domainObject);
222
200
},
223
201
restartTimer() {
224
202
this.triggerAction('timer.restart');
0 commit comments