Select appropriate tick source based on mode

This commit is contained in:
Henry 2016-08-03 19:34:31 -07:00
parent 579233ade9
commit f96f78ff79
5 changed files with 97 additions and 19 deletions

View File

@ -0,0 +1,56 @@
/*****************************************************************************
* Open MCT Web, Copyright (c) 2014-2015, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* Open MCT Web includes source code licensed under additional open source
* licenses. See the Open Source Licenses file (LICENSES.md) included with
* this source code distribution or the Licensing information page available
* at runtime from the About dialog for additional information.
*****************************************************************************/
define(['../../../platform/features/conductor-v2/conductor/src/timeSystems/LocalClock'], function (LocalClock) {
/**
* @implements TickSource
* @constructor
*/
function LADTickSource ($timeout, period) {
LocalClock.call(this, $timeout, period);
this.metadata = {
key: 'test-lad',
cssclass: 'icon-clock',
label: 'Latest Available Data',
name: 'Latest available data',
description: 'Monitor real-time streaming data as it comes in. The Time Conductor and displays will automatically advance themselves based on a UTC clock.'
};
}
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';
};
return LADTickSource;
});

View File

@ -22,8 +22,9 @@
define([ define([
'../../../platform/features/conductor-v2/conductor/src/timeSystems/TimeSystem', '../../../platform/features/conductor-v2/conductor/src/timeSystems/TimeSystem',
'../../../platform/features/conductor-v2/conductor/src/timeSystems/LocalClock' '../../../platform/features/conductor-v2/conductor/src/timeSystems/LocalClock',
], function (TimeSystem, LocalClock) { './LADTickSource'
], function (TimeSystem, LocalClock, LADTickSource) {
var FIFTEEN_MINUTES = 15 * 60 * 1000, var FIFTEEN_MINUTES = 15 * 60 * 1000,
DEFAULT_PERIOD = 1000; DEFAULT_PERIOD = 1000;
@ -47,7 +48,7 @@ define([
}; };
this._formats = ['local-format']; this._formats = ['local-format'];
this._tickSources = [new LocalClock($timeout, DEFAULT_PERIOD)]; this._tickSources = [new LocalClock($timeout, DEFAULT_PERIOD), new LADTickSource($timeout, DEFAULT_PERIOD)];
} }
LocalTimeSystem.prototype = Object.create(TimeSystem.prototype); LocalTimeSystem.prototype = Object.create(TimeSystem.prototype);

View File

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

View File

@ -67,6 +67,7 @@ define(
cssclass: 'icon-clock', cssclass: 'icon-clock',
label: 'Real-time', label: 'Real-time',
name: 'Real-time Mode', name: 'Real-time Mode',
tickSourceType: 'clock',
description: 'Monitor real-time streaming data as it comes in. The Time Conductor and displays will automatically advance themselves based on a UTC clock.' description: 'Monitor real-time streaming data as it comes in. The Time Conductor and displays will automatically advance themselves based on a UTC clock.'
}; };
} }
@ -77,6 +78,7 @@ define(
cssclass: 'icon-database', cssclass: 'icon-database',
label: 'LAD', label: 'LAD',
name: 'LAD Mode', name: 'LAD Mode',
tickSourceType: 'data',
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.' 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.'
}; };
} }
@ -185,6 +187,12 @@ define(
} }
}; };
TimeConductorController.prototype.selectTickSource = function (timeSystem, sourceType) {
return timeSystem.tickSources().filter(function (source){
return source.type() === sourceType;
})[0];
}
/** /**
* Change the selected Time Conductor mode. This will call destroy * Change the selected Time Conductor mode. This will call destroy
* and initialization functions on the relevant modes, setting * and initialization functions on the relevant modes, setting
@ -197,6 +205,7 @@ define(
var newMode = undefined; var newMode = undefined;
var timeSystems = []; var timeSystems = [];
var timeSystem = undefined; var timeSystem = undefined;
var tickSourceType = this.modes[newModeKey].tickSourceType;
this.$scope.modeModel.selectedKey = newModeKey; this.$scope.modeModel.selectedKey = newModeKey;
@ -210,19 +219,23 @@ define(
timeSystem = timeSystems[0]; timeSystem = timeSystems[0];
newMode = new FixedMode(this.conductor, timeSystem, newModeKey); newMode = new FixedMode(this.conductor, timeSystem, newModeKey);
break; break;
case 'realtime': case 'realtime':
// Filter time systems to only those with clock tick // Filter time systems to only those with clock tick
// sources // sources
timeSystems = this.timeSystemsForSourceType('clock'); timeSystems = this.timeSystemsForSourceType(tickSourceType);
timeSystem = timeSystems[0]; timeSystem = timeSystems[0];
newMode = new FollowMode(this.conductor, timeSystem, newModeKey); newMode = new FollowMode(this.conductor, timeSystem, newModeKey);
newMode.tickSource(this.selectTickSource(timeSystem, tickSourceType));
break; break;
case 'latest': case 'latest':
// Filter time systems to only those with data tick // Filter time systems to only those with data tick
// sources // sources
timeSystems = this.timeSystemsForSourceType('data'); timeSystems = this.timeSystemsForSourceType(tickSourceType);
timeSystem = timeSystems[0]; timeSystem = timeSystems[0];
newMode = new FollowMode(this.conductor, timeSystem, newModeKey); newMode = new FollowMode(this.conductor, timeSystem, newModeKey);
newMode.tickSource(this.selectTickSource(timeSystem, tickSourceType));
break; break;
} }
newMode.initialize(); newMode.initialize();
@ -283,6 +296,13 @@ define(
var mode = this.conductorService.mode(); var mode = this.conductorService.mode();
mode.timeSystem(newTimeSystem); mode.timeSystem(newTimeSystem);
this.setDeltasFromTimeSystem(newTimeSystem); this.setDeltasFromTimeSystem(newTimeSystem);
// If current mode supports ticking, set an appropriate tick
// source from the new time system
if (mode.tickSource) {
var tickSourceType = this.modes[mode.key()].tickSourceType;
mode.tickSource(this.selectTickSource(newTimeSystem, tickSourceType));
}
} }
}; };

View File

@ -37,6 +37,8 @@ define(
TimeConductorMode.call(this, conductor, timeSystem, key); TimeConductorMode.call(this, conductor, timeSystem, key);
this._deltas = undefined; this._deltas = undefined;
this._tickSource = undefined;
this._tickSourceUnlisten = undefined;
} }
FollowMode.prototype = Object.create(TimeConductorMode.prototype); FollowMode.prototype = Object.create(TimeConductorMode.prototype);
@ -59,16 +61,20 @@ define(
}; };
/** /**
* @private * Get or set tick source. Setting tick source will also start
* listening to it and unlisten from any existing tick source
* @param tickSource * @param tickSource
* @returns {undefined|*}
*/ */
FollowMode.prototype.listenToTickSource = function () { FollowMode.prototype.tickSource = function (tickSource) {
if (this._timeSystem) { if (tickSource) {
var tickSource = this._timeSystem.tickSources()[0]; if (this._tickSourceUnlisten) {
if (tickSource) { this._tickSourceUnlisten();
this.tickSourceUnlisten = tickSource.listen(this.tick.bind(this));
} }
this._tickSource = tickSource;
this._tickSourceUnlisten = tickSource.listen(this.tick.bind(this));
} }
return this._tickSource;
}; };
/** /**
@ -81,10 +87,6 @@ define(
TimeConductorMode.prototype.timeSystem.apply(this, arguments); TimeConductorMode.prototype.timeSystem.apply(this, arguments);
if (timeSystem) { if (timeSystem) {
if (this.tickSourceUnlisten) {
this.tickSourceUnlisten();
}
var defaults = timeSystem.defaults()[0]; var defaults = timeSystem.defaults()[0];
if (arguments.length > 0) { if (arguments.length > 0) {
@ -100,8 +102,6 @@ define(
} }
this.conductor.timeSystem(timeSystem, bounds); this.conductor.timeSystem(timeSystem, bounds);
this.listenToTickSource();
} }
} }
return this._timeSystem; return this._timeSystem;
@ -139,8 +139,8 @@ define(
* Stop listening to tick sources * Stop listening to tick sources
*/ */
FollowMode.prototype.destroy = function () { FollowMode.prototype.destroy = function () {
if (this.tickSourceUnlisten) { if (this._tickSourceUnlisten) {
this.tickSourceUnlisten(); this._tickSourceUnlisten();
} }
}; };