Skip to content

Commit

Permalink
Time Conductor state retained on navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Aug 3, 2016
1 parent 34c62ba commit b9c4110
Show file tree
Hide file tree
Showing 12 changed files with 133 additions and 85 deletions.
6 changes: 3 additions & 3 deletions platform/features/conductor-v2/compatibility/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ define([
"key": "conductorService",
"implementation": ConductorService,
"depends": [
"timeConductor"
"timeConductorService"
]
}
],
"representers": [
{
"implementation": ConductorRepresenter,
"depends": [
"timeConductor"
"timeConductorService"
]
}
],
Expand All @@ -57,7 +57,7 @@ define([
"provides": "telemetryService",
"implementation": ConductorTelemetryDecorator,
"depends": [
"timeConductor"
"timeConductorService"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ define(
* @constructor
*/
function ConductorRepresenter(
conductor,
conductorService,
scope,
element
) {
this.conductor = conductor;
this.conductor = conductorService.conductor();
this.scope = scope;
this.element = element;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ define([

) {

function Conductor(timeConductor) {
this.timeConductor = timeConductor;
function Conductor(timeConductorService) {
this.timeConductor = timeConductorService.conductor();
}

Conductor.prototype.displayStart = function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ define(
* the service which exposes the global time conductor
* @param {TelemetryService} telemetryService the decorated service
*/
function ConductorTelemetryDecorator(conductor, telemetryService) {
this.conductor = conductor;
function ConductorTelemetryDecorator(conductorService, telemetryService) {
this.conductor = conductorService.conductor();
this.telemetryService = telemetryService;

this.amendRequests = ConductorTelemetryDecorator.prototype.amendRequests.bind(this);
Expand Down
12 changes: 6 additions & 6 deletions platform/features/conductor-v2/conductor/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
*****************************************************************************/

define([
"./src/TimeConductor",
"./src/ui/TimeConductorService",
"./src/ui/TimeConductorController",
"./src/ui/MCTConductorAxis",
"text!./res/templates/time-conductor.html",
"text!./res/templates/mode-selector/mode-selector.html",
"text!./res/templates/mode-selector/mode-menu.html",
'legacyRegistry'
], function (
TimeConductor,
TimeConductorService,
TimeConductorController,
MCTConductorAxis,
timeConductorTemplate,
Expand All @@ -42,8 +42,8 @@ define([
"extensions": {
"services": [
{
"key": "timeConductor",
"implementation": TimeConductor
"key": "timeConductorService",
"implementation": TimeConductorService
}
],
"controllers": [
Expand All @@ -52,7 +52,7 @@ define([
"implementation": TimeConductorController,
"depends": [
"$scope",
"timeConductor",
"timeConductorService",
"timeSystems[]"
]
}
Expand All @@ -62,7 +62,7 @@ define([
"key": "mctConductorAxis",
"implementation": MCTConductorAxis,
"depends": [
"timeConductor",
"timeConductorService",
"formatService"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
class="holder flex-elem menus-up time-system"
structure="{
text: timeSystemModel.selected.metadata.name,
click: tcController.selectTimeSystem,
click: tcController.selectTimeSystemByKey,
options: timeSystemModel.options
}">
</mct-control>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ define(
* labelled 'ticks'. It requires 'start' and 'end' integer values to
* be specified as attributes.
*/
function MCTConductorAxis(conductor, formatService) {
function MCTConductorAxis(conductorService, formatService) {
var conductor = conductorService.conductor();

function link(scope, element, attrs, ngModelController) {
var target = element[0].firstChild,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ define(
],
function (FixedMode, FollowMode, TimeConductorValidation) {

function TimeConductorController($scope, conductor, timeSystems) {
function TimeConductorController($scope, conductorService, timeSystems) {

var self = this;

Expand All @@ -39,7 +39,14 @@ define(
self[key] = self[key].bind(self);
});

this.conductor = conductor;
this.conductorService = conductorService;
this.conductor = conductorService.conductor();

this.conductor.on('bounds', this.setBounds);
this.conductor.on('follow', function (follow){
$scope.followMode = follow;
});

// Construct the provided time system definitions
this._timeSystems = timeSystems.map(function (timeSystemConstructor){
return timeSystemConstructor();
Expand All @@ -61,7 +68,7 @@ define(
label: 'Real-time',
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.'
}
};
}

//Only show 'real-time mode' if a clock source is available
Expand All @@ -71,66 +78,54 @@ define(
label: 'LAD',
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.selectedMode = undefined;

this.validation = new TimeConductorValidation(conductor);
this.validation = new TimeConductorValidation(this.conductor);
this.$scope = $scope;
this.initializeScope($scope);

conductor.on('bounds', this.setBounds);
conductor.on('follow', function (follow){
$scope.followMode = follow;
});

//Set the time conductor mode to the first one in the list,
// effectively initializing the time conductor
this.setMode('fixed');
}
/*
Set time Conductor bounds in the form
*/
$scope.formModel = this.conductor.bounds();

/**
* @private
*/
TimeConductorController.prototype.initializeScope = function ($scope) {
var self = this;
/*
Represents the various time system options, and the currently
selected time system in the view. Additionally holds the
default format from the selected time system for convenience
of access from the template.
Represents the various time system options, and the currently
selected time system in the view. Additionally holds the
default format from the selected time system for convenience
of access from the template.
*/
$scope.timeSystemModel = {
selected: undefined,
format: undefined,
options: []
};
$scope.timeSystemModel = {};
if (this.conductor.timeSystem()) {
$scope.timeSystemModel.selected = this.conductor.timeSystem();
$scope.timeSystemModel.format = this.conductor.timeSystem().formats()[0];
}

/*
Represents the various modes, and the currently
selected mode in the view
*/
$scope.modeModel = {
selectedKey: undefined,
options: this.modes
};
/*
Time Conductor bounds in the form
*/
$scope.formModel = {
start: 0,
end: 0
};

var mode = conductorService.mode();
if (mode) {
$scope.modeModel.selectedKey = mode.key();
var deltas = mode.deltas && mode.deltas();
if (deltas) {
$scope.formModel.startDelta = deltas.start;
$scope.formModel.endDelta = deltas.end;
}
} else {
// Default to fixed mode
this.setMode('fixed');
}

$scope.$watch('modeModel.selectedKey', this.setMode);
$scope.$watch('timeSystem', this.setTimeSystem);

$scope.$on('$destroy', function() {
if (self.selectedMode) {
self.selectedMode.destroy();
}
});
};
}

/**
* Called when the bounds change in the time conductor. Synchronizes
Expand Down Expand Up @@ -165,7 +160,7 @@ define(
* @see TimeConductorMode
*/
TimeConductorController.prototype.updateDeltasFromForm = function (formModel) {
var mode = this.selectedMode,
var mode = this.conductorService.mode(),
deltas = mode.deltas();

if (deltas !== undefined && this.validation.validateDeltas(formModel)) {
Expand Down Expand Up @@ -193,37 +188,39 @@ define(
* Change the selected Time Conductor mode. This will call destroy
* and initialization functions on the relevant modes, setting
* default values for bound and deltas in the form.
* @param newMode
* @param oldMode
* @param newModeKey
* @param oldModeKey
*/
TimeConductorController.prototype.setMode = function (newMode, oldMode) {
if (newMode !== oldMode) {
this.$scope.modeModel.selectedKey = newMode;
TimeConductorController.prototype.setMode = function (newModeKey, oldModeKey) {
if (newModeKey !== oldModeKey) {
var newMode = undefined;
this.$scope.modeModel.selectedKey = newModeKey;

if (this.selectedMode) {
this.selectedMode.destroy();
if (this.conductorService.mode()) {
this.conductorService.mode().destroy();
}
switch (newMode) {

switch (newModeKey) {
case 'fixed':
this.selectedMode = new FixedMode(this.conductor, this._timeSystems);
newMode = new FixedMode(this.conductor, this._timeSystems, newModeKey);
break;
case 'realtime':
// Filter time systems to only those with clock tick
// sources
this.selectedMode = new FollowMode(this.conductor, this.timeSystemsForSourceType('clock'));
newMode = new FollowMode(this.conductor, this.timeSystemsForSourceType('clock'), newModeKey);
break;
case 'latest':
// Filter time systems to only those with data tick
// sources
this.selectedMode = new FollowMode(this.conductor, this.timeSystemsForSourceType('data'));
newMode = new FollowMode(this.conductor, this.timeSystemsForSourceType('data'), newModeKey);
break;
}
this.selectedMode.initialize();

var timeSystem = this.selectedMode.selectedTimeSystem();
newMode.initialize();
this.conductorService.mode(newMode);
var timeSystem = newMode.selectedTimeSystem();

//Synchronize scope with time system on mode
this.$scope.timeSystemModel.options = this.selectedMode.timeSystems().map(function (timeSystem) {
this.$scope.timeSystemModel.options = newMode.timeSystems().map(function (timeSystem) {
return timeSystem.metadata;
});

Expand Down Expand Up @@ -257,7 +254,7 @@ define(
* @param key
* @see TimeConductorController#setTimeSystem
*/
TimeConductorController.prototype.selectTimeSystem = function(key){
TimeConductorController.prototype.selectTimeSystemByKey = function(key){
var selected = this._timeSystems.find(function (timeSystem){
return timeSystem.metadata.key === key;
});
Expand All @@ -273,7 +270,7 @@ define(
if (newTimeSystem && newTimeSystem !== this.$scope.timeSystemModel.selected) {
this.$scope.timeSystemModel.selected = newTimeSystem;
this.$scope.timeSystemModel.format = newTimeSystem.formats()[0];
var mode = this.selectedMode;
var mode = this.conductorService.mode();
mode.selectedTimeSystem(newTimeSystem);
this.setDeltasFromTimeSystem(newTimeSystem);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*****************************************************************************
* 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(
['../TimeConductor'],
function (TimeConductor) {

function TimeConductorService() {
this._conductor = new TimeConductor();
this._mode = undefined;
}

TimeConductorService.prototype.mode = function (mode) {
if (arguments.length === 1) {
this._mode = mode;
}
return this._mode;
};

TimeConductorService.prototype.conductor = function () {
return this._conductor;
};

return TimeConductorService;
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ define(
* @param timeSystems
* @constructor
*/
function FixedMode(conductor, timeSystems) {
TimeConductorMode.call(this, conductor, timeSystems);
function FixedMode(conductor, timeSystems, key) {
TimeConductorMode.call(this, conductor, timeSystems, key);
}

FixedMode.prototype = Object.create(TimeConductorMode.prototype);
Expand Down
Loading

0 comments on commit b9c4110

Please sign in to comment.