[Time Conductor] #933 Fixed code style errors

This commit is contained in:
Henry
2016-09-06 10:04:29 -07:00
parent c6eaa3d528
commit 7af5875dd5
21 changed files with 124 additions and 113 deletions

View File

@ -65,19 +65,31 @@ define([
* Licensed
*/
return [
[".SSS", function(m) { return m.milliseconds(); }],
[":ss", function(m) { return m.seconds(); }],
["HH:mm", function(m) { return m.minutes(); }],
["HH", function(m) { return m.hours(); }],
[".SSS", function (m) {
return m.milliseconds();
}],
[":ss", function (m) {
return m.seconds();
}],
["HH:mm", function (m) {
return m.minutes();
}],
["HH", function (m) {
return m.hours();
}],
["ddd DD", function (m) {
return m.days() &&
m.date() !== 1;
}],
["MMM DD", function(m) { return m.date() !== 1; }],
["MMM DD", function (m) {
return m.date() !== 1;
}],
["MMMM", function (m) {
return m.month();
}],
["YYYY", function() { return true; }]
["YYYY", function () {
return true;
}]
].filter(function (row) {
return row[1](momentified);
})[0][0];

View File

@ -35,7 +35,6 @@ define([], function () {
* @type {TimeSystemMetadata}
*/
this.metadata = undefined;
this._tickSources = [];
}
/**

View File

@ -30,13 +30,13 @@ define(['./NumberFormat'], function (NumberFormat) {
it("The format function takes a string and produces a number", function () {
var text = format.format(1);
expect(text).toBe("1");
expect(typeof(text)).toBe("string");
expect(typeof text).toBe("string");
});
it("The parse function takes a string and produces a number", function () {
var number = format.parse("1");
expect(number).toBe(1);
expect(typeof(number)).toBe("number");
expect(typeof number).toBe("number");
});
it("validates that the input is a number", function () {

View File

@ -126,7 +126,8 @@ define(
TimeConductorController.prototype.setFormFromMode = function (mode) {
this.$scope.modeModel.selectedKey = mode;
//Synchronize scope with time system on mode
this.$scope.timeSystemModel.options = this.conductorViewService.availableTimeSystems()
this.$scope.timeSystemModel.options =
this.conductorViewService.availableTimeSystems()
.map(function (t) {
return t.metadata;
});

View File

@ -33,12 +33,12 @@ define(
function TimeConductorMode(metadata, conductor, timeSystems) {
this.conductor = conductor;
this._metadata = metadata;
this._deltas = undefined;
this._tickSource = undefined;
this._tickSourceUnlisten = undefined;
this._timeSystems = timeSystems;
this._availableTickSources = undefined;
this.mdata = metadata;
this.dlts = undefined;
this.source = undefined;
this.sourceUnlisten = undefined;
this.systems = timeSystems;
this.availableSources = undefined;
this.changeTimeSystem = this.changeTimeSystem.bind(this);
this.tick = this.tick.bind(this);
@ -52,9 +52,9 @@ define(
if (metadata.key === 'fixed') {
//Fixed automatically supports all time systems
this._availableTimeSystems = timeSystems;
this.availableSystems = timeSystems;
} else {
this._availableTimeSystems = timeSystems.filter(function (timeSystem) {
this.availableSystems = timeSystems.filter(function (timeSystem) {
//Only include time systems that have tick sources that
// support the current mode
return timeSystem.tickSources().some(function (tickSource) {
@ -86,10 +86,10 @@ define(
this.deltas(defaults.deltas);
// Tick sources are mode-specific, so restrict tick sources to only those supported by the current mode.
var key = this._metadata.key;
var key = this.mdata.key;
var tickSources = timeSystem.tickSources();
if (tickSources) {
this._availableTickSources = tickSources.filter(function (source){
this.availableSources = tickSources.filter(function (source) {
return source.metadata.mode === key;
});
}
@ -102,11 +102,11 @@ define(
* @returns {ModeMetadata}
*/
TimeConductorMode.prototype.metadata = function () {
return this._metadata;
return this.mdata;
};
TimeConductorMode.prototype.availableTimeSystems = function () {
return this._availableTimeSystems;
return this.availableSystems;
};
/**
@ -115,7 +115,7 @@ define(
* @returns {Array.<T>}
*/
TimeConductorMode.prototype.availableTickSources = function (timeSystem) {
return this._availableTickSources;
return this.availableSources;
};
/**
@ -126,26 +126,26 @@ define(
*/
TimeConductorMode.prototype.tickSource = function (tickSource) {
if (arguments.length > 0) {
if (this._tickSourceUnlisten) {
this._tickSourceUnlisten();
if (this.sourceUnlisten) {
this.sourceUnlisten();
}
this._tickSource = tickSource;
this.source = tickSource;
if (tickSource) {
this._tickSourceUnlisten = tickSource.listen(this.tick);
this.sourceUnlisten = tickSource.listen(this.tick);
//Now following a tick source
this.conductor.follow(true);
} else {
this.conductor.follow(false);
}
}
return this._tickSource;
return this.source;
};
TimeConductorMode.prototype.destroy = function () {
this.conductor.off('timeSystem', this.changeTimeSystem);
if (this._tickSourceUnlisten) {
this._tickSourceUnlisten();
if (this.sourceUnlisten) {
this.sourceUnlisten();
}
};
@ -179,21 +179,21 @@ define(
if (arguments.length !== 0) {
var oldEnd = this.conductor.bounds().end;
if (this._deltas && this._deltas.end !== undefined){
if (this.dlts && this.dlts.end !== undefined) {
//Calculate the previous raw end value (without delta)
oldEnd = oldEnd - this._deltas.end;
oldEnd = oldEnd - this.dlts.end;
}
this._deltas = deltas;
this.dlts = deltas;
var newBounds = {
start: oldEnd - this._deltas.start,
end: oldEnd + this._deltas.end
start: oldEnd - this.dlts.start,
end: oldEnd + this.dlts.end
};
this.conductor.bounds(newBounds);
}
return this._deltas;
return this.dlts;
};
return TimeConductorMode;

View File

@ -36,13 +36,12 @@ define(
* @constructor
*/
function TimeConductorViewService(conductor, timeSystems) {
this._timeSystems = timeSystems.map(
function (timeSystemConstructor) {
this.systems = timeSystems.map(function (timeSystemConstructor) {
return timeSystemConstructor();
});
this._conductor = conductor;
this._mode = undefined;
this.conductor = conductor;
this.currentMode = undefined;
/**
* @typedef {object} ModeMetadata
@ -53,7 +52,7 @@ define(
* @property {string} name A longer name for the mode
* @property {string} description A description of the mode
*/
this._availableModes = {
this.availModes = {
'fixed': {
key: 'fixed',
cssclass: 'icon-calendar',
@ -70,7 +69,7 @@ define(
}
var timeSystemsForMode = function (sourceType) {
return this._timeSystems.filter(hasTickSource.bind(this, sourceType));
return this.systems.filter(hasTickSource.bind(this, sourceType));
}.bind(this);
//Only show 'real-time mode' if appropriate time systems available
@ -82,7 +81,7 @@ define(
name: 'Real-time Mode',
description: 'Monitor real-time streaming data as it comes in. The Time Conductor and displays will automatically advance themselves based on a UTC clock.'
};
this._availableModes[realtimeMode.key] = realtimeMode;
this.availModes[realtimeMode.key] = realtimeMode;
}
//Only show 'LAD mode' if appropriate time systems available
@ -94,7 +93,7 @@ define(
name: 'LAD Mode',
description: 'Latest Available Data mode monitors real-time streaming data as it comes in. The Time Conductor and displays will only advance when data becomes available.'
};
this._availableModes[ladMode.key] = ladMode;
this.availModes[ladMode.key] = ladMode;
}
}
@ -125,23 +124,23 @@ define(
}
if (arguments.length === 1) {
var timeSystem = this._conductor.timeSystem();
var timeSystem = this.conductor.timeSystem();
var modes = this.availableModes();
var modeMetaData = modes[newModeKey];
if (this._mode) {
this._mode.destroy();
if (this.currentMode) {
this.currentMode.destroy();
}
this._mode = new TimeConductorMode(modeMetaData, this._conductor, this._timeSystems);
this.currentMode = new TimeConductorMode(modeMetaData, this.conductor, this.systems);
// If no time system set on time conductor, or the currently selected time system is not available in
// the new mode, default to first available time system
if (!timeSystem || !contains(this._mode.availableTimeSystems(), timeSystem)) {
timeSystem = this._mode.availableTimeSystems()[0];
this._conductor.timeSystem(timeSystem, timeSystem.defaults().bounds);
if (!timeSystem || !contains(this.currentMode.availableTimeSystems(), timeSystem)) {
timeSystem = this.currentMode.availableTimeSystems()[0];
this.conductor.timeSystem(timeSystem, timeSystem.defaults().bounds);
}
}
return this._mode ? this._mode.metadata().key : undefined;
return this.currentMode ? this.currentMode.metadata().key : undefined;
};
/**
@ -176,7 +175,7 @@ define(
*/
TimeConductorViewService.prototype.deltas = function () {
//Deltas stored on mode. Use .apply to preserve arguments
return this._mode.deltas.apply(this._mode, arguments);
return this.currentMode.deltas.apply(this.currentMode, arguments);
};
/**
@ -187,7 +186,7 @@ define(
* @returns {ModeMetadata[]}
*/
TimeConductorViewService.prototype.availableModes = function () {
return this._availableModes;
return this.availModes;
};
/**
@ -195,7 +194,7 @@ define(
* mode. Time systems and tick sources are mode dependent
*/
TimeConductorViewService.prototype.availableTimeSystems = function () {
return this._mode.availableTimeSystems();
return this.currentMode.availableTimeSystems();
};
return TimeConductorViewService;

View File

@ -133,7 +133,7 @@ define(['./TimeConductorViewService'], function (TimeConductorViewService) {
]);
viewService = new TimeConductorViewService(mockTimeConductor, mockTimeSystems);
viewService._mode = oldMode;
viewService.currentMode = oldMode;
viewService.mode('fixed');
expect(oldMode.destroy).toHaveBeenCalled();
});

View File

@ -46,14 +46,14 @@ define([
'cssclass': 'icon-clock'
};
this._formats = ['utc'];
this._tickSources = [new LocalClock($timeout, DEFAULT_PERIOD)];
this.fmts = ['utc'];
this.sources = [new LocalClock($timeout, DEFAULT_PERIOD)];
}
UTCTimeSystem.prototype = Object.create(TimeSystem.prototype);
UTCTimeSystem.prototype.formats = function () {
return this._formats;
return this.fmts;
};
UTCTimeSystem.prototype.deltaFormat = function () {
@ -61,7 +61,7 @@ define([
};
UTCTimeSystem.prototype.tickSources = function () {
return this._tickSources;
return this.sources;
};
UTCTimeSystem.prototype.defaults = function (key) {