Merged mode-specific defaults, with some refactoring

This commit is contained in:
Henry 2016-08-03 19:57:03 -07:00
commit 6b482d487b
8 changed files with 47 additions and 17 deletions

View File

@ -38,16 +38,6 @@ define(['../../../platform/features/conductor-v2/conductor/src/timeSystems/Local
}
LADTickSource.prototype = Object.create(LocalClock.prototype);
LADTickSource.prototype.tick = function () {
console.log('data tick');
var now = Date.now();
this.listeners.forEach(function (listener){
listener(now);
});
this.timeoutHandle = this.$timeout(this.tick.bind(this), this.period);
};
LADTickSource.prototype.type = function () {
return 'data';
};

View File

@ -26,6 +26,7 @@ define([
'./LADTickSource'
], function (TimeSystem, LocalClock, LADTickSource) {
var FIFTEEN_MINUTES = 15 * 60 * 1000,
THIRTY_MINUTES = 30 * 60 * 1000,
DEFAULT_PERIOD = 1000;
/**
@ -71,8 +72,16 @@ define([
{
key: 'local-default',
name: 'Local 12 hour time system defaults',
mode: 'fixed',
deltas: {start: FIFTEEN_MINUTES, end: 0},
bounds: {start: now - FIFTEEN_MINUTES, end: now}
},
{
key: 'local-default',
name: 'Local 12 hour time system defaults',
mode: 'follow',
deltas: {start: THIRTY_MINUTES, end: 0},
bounds: {start: now - THIRTY_MINUTES, end: now}
}
];
};

View File

@ -54,7 +54,6 @@ define(['./TickSource'], function (TickSource) {
};
LocalClock.prototype.tick = function () {
console.log('clock tick');
var now = Date.now();
this.listeners.forEach(function (listener){
listener(now);

View File

@ -253,8 +253,8 @@ define(
/**
* @private
*/
TimeConductorController.prototype.setDeltasFromTimeSystem = function (timeSystem) {
var defaults = timeSystem.defaults()[0];
TimeConductorController.prototype.setDeltasFromMode = function (mode) {
var defaults = mode.defaults();
var deltas = defaults.deltas;
/*
@ -295,7 +295,7 @@ define(
this.$scope.timeSystemModel.deltaFormat = newTimeSystem.deltaFormat();
var mode = this.conductorService.mode();
mode.timeSystem(newTimeSystem);
this.setDeltasFromTimeSystem(newTimeSystem);
this.setDeltasFromMode(mode);
// If current mode supports ticking, set an appropriate tick
// source from the new time system

View File

@ -43,6 +43,16 @@ define(
this.conductor.follow(false);
};
FixedMode.prototype.defaults = function () {
var timeSystem = this.timeSystem();
if (timeSystem){
return timeSystem.defaults().filter(function (d) {
return d.mode === 'fixed';
})[0];
}
};
/**
* Defines behavior to occur when selected time system changes. In
* this case, sets default bounds on the time conductor.
@ -53,7 +63,7 @@ define(
TimeConductorMode.prototype.timeSystem.apply(this, arguments);
if (timeSystem) {
var defaults = timeSystem.defaults()[0];
var defaults = this.defaults();
var bounds = {
start: defaults.bounds.start,

View File

@ -64,7 +64,7 @@ define(
* Get or set tick source. Setting tick source will also start
* listening to it and unlisten from any existing tick source
* @param tickSource
* @returns {undefined|*}
* @returns {TickSource}
*/
FollowMode.prototype.tickSource = function (tickSource) {
if (tickSource) {
@ -77,6 +77,16 @@ define(
return this._tickSource;
};
FollowMode.prototype.defaults = function () {
var timeSystem = this.timeSystem();
if (timeSystem){
return timeSystem.defaults().filter(function (d) {
return d.mode === 'follow';
})[0];
}
};
/**
* On time system change, default the bounds values in the time
* conductor, using the deltas associated with this mode.
@ -87,7 +97,7 @@ define(
TimeConductorMode.prototype.timeSystem.apply(this, arguments);
if (timeSystem) {
var defaults = timeSystem.defaults()[0];
var defaults = this.defaults();
if (arguments.length > 0) {
var bounds = {

View File

@ -62,6 +62,10 @@ define(
return this._key;
};
TimeConductorMode.prototype.defaults = function () {
throw new Error("Not implemented");
};
TimeConductorMode.prototype.destroy = function () {
};

View File

@ -70,6 +70,14 @@ define([
{
key: 'utc-default',
name: 'UTC time system defaults',
mode: 'follow',
deltas: {start: FIFTEEN_MINUTES, end: 0},
bounds: {start: now - FIFTEEN_MINUTES, end: now}
},
{
key: 'utc-default',
name: 'UTC time system defaults',
mode: 'fixed',
deltas: {start: FIFTEEN_MINUTES, end: 0},
bounds: {start: now - FIFTEEN_MINUTES, end: now}
}