mirror of
https://github.com/nasa/openmct.git
synced 2025-06-22 00:57:11 +00:00
[Clocks/Timers] Update remaining classes
Complete code style changes for Clocks/Timers.
This commit is contained in:
@ -28,32 +28,40 @@ define(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicator that displays the current UTC time in the status area.
|
* Indicator that displays the current UTC time in the status area.
|
||||||
* @implements Indicator
|
* @implements {Indicator}
|
||||||
|
* @memberof platform/features/clock
|
||||||
|
* @param {platform/features/clock.TickerService} tickerService
|
||||||
|
* a service used to align behavior with clock ticks
|
||||||
|
* @param {string} indicatorFormat format string for timestamps
|
||||||
|
* shown in this indicator
|
||||||
*/
|
*/
|
||||||
function ClockIndicator(tickerService, CLOCK_INDICATOR_FORMAT) {
|
function ClockIndicator(tickerService, indicatorFormat) {
|
||||||
var text = "";
|
var self = this;
|
||||||
|
|
||||||
|
this.text = "";
|
||||||
|
|
||||||
tickerService.listen(function (timestamp) {
|
tickerService.listen(function (timestamp) {
|
||||||
text = moment.utc(timestamp).format(CLOCK_INDICATOR_FORMAT) + " UTC";
|
self.text = moment.utc(timestamp)
|
||||||
|
.format(indicatorFormat) + " UTC";
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
|
||||||
getGlyph: function () {
|
|
||||||
return "C";
|
|
||||||
},
|
|
||||||
getGlyphClass: function () {
|
|
||||||
return "";
|
|
||||||
},
|
|
||||||
getText: function () {
|
|
||||||
return text;
|
|
||||||
},
|
|
||||||
getDescription: function () {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ClockIndicator.prototype.getGlyph = function () {
|
||||||
|
return "C";
|
||||||
|
};
|
||||||
|
|
||||||
|
ClockIndicator.prototype.getGlyphClass = function () {
|
||||||
|
return "";
|
||||||
|
};
|
||||||
|
|
||||||
|
ClockIndicator.prototype.getText = function () {
|
||||||
|
return this.text;
|
||||||
|
};
|
||||||
|
|
||||||
|
ClockIndicator.prototype.getDescription = function () {
|
||||||
|
return "";
|
||||||
|
};
|
||||||
|
|
||||||
return ClockIndicator;
|
return ClockIndicator;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -30,23 +30,23 @@ define(
|
|||||||
* Calls functions every second, as close to the actual second
|
* Calls functions every second, as close to the actual second
|
||||||
* tick as is feasible.
|
* tick as is feasible.
|
||||||
* @constructor
|
* @constructor
|
||||||
|
* @memberof platform/features/clock
|
||||||
* @param $timeout Angular's $timeout
|
* @param $timeout Angular's $timeout
|
||||||
* @param {Function} now function to provide the current time in ms
|
* @param {Function} now function to provide the current time in ms
|
||||||
*/
|
*/
|
||||||
function TickerService($timeout, now) {
|
function TickerService($timeout, now) {
|
||||||
var callbacks = [],
|
var self = this;
|
||||||
last = now() - 1000;
|
|
||||||
|
|
||||||
function tick() {
|
function tick() {
|
||||||
var timestamp = now(),
|
var timestamp = now(),
|
||||||
millis = timestamp % 1000;
|
millis = timestamp % 1000;
|
||||||
|
|
||||||
// Only update callbacks if a second has actually passed.
|
// Only update callbacks if a second has actually passed.
|
||||||
if (timestamp >= last + 1000) {
|
if (timestamp >= self.last + 1000) {
|
||||||
callbacks.forEach(function (callback) {
|
self.callbacks.forEach(function (callback) {
|
||||||
callback(timestamp);
|
callback(timestamp);
|
||||||
});
|
});
|
||||||
last = timestamp - millis;
|
self.last = timestamp - millis;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to update at exactly the next second
|
// Try to update at exactly the next second
|
||||||
@ -55,35 +55,35 @@ define(
|
|||||||
|
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
return {
|
this.callbacks = [];
|
||||||
/**
|
this.last = now() - 1000;
|
||||||
* Listen for clock ticks. The provided callback will
|
|
||||||
* be invoked with the current timestamp (in milliseconds
|
|
||||||
* since Jan 1 1970) at regular intervals, as near to the
|
|
||||||
* second boundary as possible.
|
|
||||||
*
|
|
||||||
* @method listen
|
|
||||||
* @name TickerService#listen
|
|
||||||
* @param {Function} callback callback to invoke
|
|
||||||
* @returns {Function} a function to unregister this listener
|
|
||||||
*/
|
|
||||||
listen: function (callback) {
|
|
||||||
callbacks.push(callback);
|
|
||||||
|
|
||||||
// Provide immediate feedback
|
|
||||||
callback(last);
|
|
||||||
|
|
||||||
// Provide a deregistration function
|
|
||||||
return function () {
|
|
||||||
callbacks = callbacks.filter(function (cb) {
|
|
||||||
return cb !== callback;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Listen for clock ticks. The provided callback will
|
||||||
|
* be invoked with the current timestamp (in milliseconds
|
||||||
|
* since Jan 1 1970) at regular intervals, as near to the
|
||||||
|
* second boundary as possible.
|
||||||
|
*
|
||||||
|
* @param {Function} callback callback to invoke
|
||||||
|
* @returns {Function} a function to unregister this listener
|
||||||
|
*/
|
||||||
|
TickerService.prototype.listen = function (callback) {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
self.callbacks.push(callback);
|
||||||
|
|
||||||
|
// Provide immediate feedback
|
||||||
|
callback(this.last);
|
||||||
|
|
||||||
|
// Provide a deregistration function
|
||||||
|
return function () {
|
||||||
|
self.callbacks = self.callbacks.filter(function (cb) {
|
||||||
|
return cb !== callback;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
return TickerService;
|
return TickerService;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
Reference in New Issue
Block a user