diff --git a/index.html b/index.html index 6e769611a7..b8758fb052 100644 --- a/index.html +++ b/index.html @@ -39,6 +39,7 @@ openmct.install(openmct.plugins.LocalStorage()); openmct.install(openmct.plugins.Espresso()); openmct.install(openmct.plugins.Generator()); + openmct.install(openmct.plugins.UTCTimeSystem()); openmct.start(); }); diff --git a/openmct.js b/openmct.js index 68151008cd..c3df199f4b 100644 --- a/openmct.js +++ b/openmct.js @@ -84,5 +84,11 @@ define([ return new Main().run(defaultRegistry); }); + // For now, install conductor by default + openmct.install(openmct.plugins.Conductor({ + showConductor: false + })); + + return openmct; }); diff --git a/platform/features/conductor/core/bundle.js b/platform/features/conductor/core/bundle.js index b458b2b4ed..e99e54d22b 100644 --- a/platform/features/conductor/core/bundle.js +++ b/platform/features/conductor/core/bundle.js @@ -70,8 +70,9 @@ define([ "$location", "openmct", "timeConductorViewService", - "timeSystems[]", - "formatService" + "formatService", + "DEFAULT_TIMECONDUCTOR_MODE", + "SHOW_TIMECONDUCTOR" ] }, { @@ -150,6 +151,13 @@ define([ "link": "https://github.com/d3/d3/blob/master/LICENSE" } ], + "constants": [ + { + "key": "DEFAULT_TIMECONDUCTOR_MODE", + "value": "realtime", + "priority": "fallback" + } + ], "formats": [ { "key": "number", diff --git a/platform/features/conductor/core/res/templates/time-conductor.html b/platform/features/conductor/core/res/templates/time-conductor.html index de1b5c2326..6d9c34b069 100644 --- a/platform/features/conductor/core/res/templates/time-conductor.html +++ b/platform/features/conductor/core/res/templates/time-conductor.html @@ -1,8 +1,7 @@
- + ng-class="{'status-panning': tcController.panning}" ng-show="showTimeConductor">
diff --git a/platform/features/conductor/core/src/ui/TimeConductorController.js b/platform/features/conductor/core/src/ui/TimeConductorController.js index 5b600de3e2..da75dddb92 100644 --- a/platform/features/conductor/core/src/ui/TimeConductorController.js +++ b/platform/features/conductor/core/src/ui/TimeConductorController.js @@ -40,7 +40,16 @@ define( * @memberof platform.features.conductor * @constructor */ - function TimeConductorController($scope, $window, $location, openmct, conductorViewService, timeSystems, formatService) { + function TimeConductorController( + $scope, + $window, + $location, + openmct, + conductorViewService, + formatService, + DEFAULT_MODE, + SHOW_TIMECONDUCTOR + ) { var self = this; @@ -60,10 +69,14 @@ define( this.validation = new TimeConductorValidation(this.conductor); this.formatService = formatService; + //Check if the default mode defined is actually available + if (this.modes[DEFAULT_MODE] === undefined) { + DEFAULT_MODE = 'fixed'; + } + this.DEFAULT_MODE = DEFAULT_MODE; + // Construct the provided time system definitions - this.timeSystems = timeSystems.map(function (timeSystemConstructor) { - return timeSystemConstructor(); - }); + this.timeSystems = conductorViewService.systems; this.initializeScope(); var searchParams = JSON.parse(JSON.stringify(this.$location.search())); @@ -94,6 +107,8 @@ define( //Respond to any subsequent conductor changes this.conductor.on('bounds', this.changeBounds); this.conductor.on('timeSystem', this.changeTimeSystem); + + this.$scope.showTimeConductor = SHOW_TIMECONDUCTOR; } /** @@ -139,7 +154,7 @@ define( //Set mode from url if changed if (searchParams[SEARCH.MODE] === undefined || searchParams[SEARCH.MODE] !== this.$scope.modeModel.selectedKey) { - this.setMode(searchParams[SEARCH.MODE] || "fixed"); + this.setMode(searchParams[SEARCH.MODE] || this.DEFAULT_MODE); } if (searchParams[SEARCH.TIME_SYSTEM] && diff --git a/platform/features/conductor/core/src/ui/TimeConductorControllerSpec.js b/platform/features/conductor/core/src/ui/TimeConductorControllerSpec.js index 9606205cfc..1ea5fa1b29 100644 --- a/platform/features/conductor/core/src/ui/TimeConductorControllerSpec.js +++ b/platform/features/conductor/core/src/ui/TimeConductorControllerSpec.js @@ -130,8 +130,10 @@ define(['./TimeConductorController'], function (TimeConductorController) { mockLocation, {conductor: mockTimeConductor}, mockConductorViewService, - mockTimeSystems, - mockFormatService + mockFormatService, + 'fixed', + true + ); tsListener = getListener(mockTimeConductor.on, "timeSystem"); @@ -244,7 +246,6 @@ define(['./TimeConductorController'], function (TimeConductorController) { var ts1Metadata; var ts2Metadata; var ts3Metadata; - var mockTimeSystemConstructors; beforeEach(function () { mode = "realtime"; @@ -276,11 +277,7 @@ define(['./TimeConductorController'], function (TimeConductorController) { ]; //Wrap in mock constructors - mockTimeSystemConstructors = mockTimeSystems.map(function (mockTimeSystem) { - return function () { - return mockTimeSystem; - }; - }); + mockConductorViewService.systems = mockTimeSystems; controller = new TimeConductorController( mockScope, @@ -288,8 +285,9 @@ define(['./TimeConductorController'], function (TimeConductorController) { mockLocation, {conductor: mockTimeConductor}, mockConductorViewService, - mockTimeSystemConstructors, - mockFormatService + mockFormatService, + "fixed", + true ); }); @@ -434,12 +432,7 @@ define(['./TimeConductorController'], function (TimeConductorController) { } }; - mockTimeSystems.push(function () { - return timeSystem; - }); - mockTimeSystems.push(function () { - return otherTimeSystem; - }); + mockConductorViewService.systems = [timeSystem, otherTimeSystem]; urlBounds = { start: 100, @@ -467,8 +460,9 @@ define(['./TimeConductorController'], function (TimeConductorController) { mockLocation, {conductor: mockTimeConductor}, mockConductorViewService, - mockTimeSystems, - mockFormatService + mockFormatService, + "fixed", + true ); spyOn(controller, "setMode"); diff --git a/platform/features/conductor/utcTimeSystem/bundle.js b/platform/features/conductor/utcTimeSystem/bundle.js index 5db4bd968f..3cd29cf438 100644 --- a/platform/features/conductor/utcTimeSystem/bundle.js +++ b/platform/features/conductor/utcTimeSystem/bundle.js @@ -34,23 +34,7 @@ define([ "implementation": UTCTimeSystem, "depends": ["$timeout"] } - ], - "runs": [ - { - "implementation": function (openmct, $timeout) { - // Temporary shim to initialize the time conductor to - // something - if (!openmct.conductor.timeSystem()) { - var utcTimeSystem = new UTCTimeSystem($timeout); - - openmct.conductor.timeSystem(utcTimeSystem, utcTimeSystem.defaults().bounds); - } - }, - "depends": ["openmct", "$timeout"], - "priority": "fallback" - } ] } }); - }); diff --git a/platform/features/conductor/utcTimeSystem/src/UTCTimeSystem.js b/platform/features/conductor/utcTimeSystem/src/UTCTimeSystem.js index a933761eac..422c356512 100644 --- a/platform/features/conductor/utcTimeSystem/src/UTCTimeSystem.js +++ b/platform/features/conductor/utcTimeSystem/src/UTCTimeSystem.js @@ -48,6 +48,7 @@ define([ this.fmts = ['utc']; this.sources = [new LocalClock($timeout, DEFAULT_PERIOD)]; + this.defaultValues = undefined; } UTCTimeSystem.prototype = Object.create(TimeSystem.prototype); @@ -64,18 +65,25 @@ define([ return this.sources; }; - UTCTimeSystem.prototype.defaults = function () { - var now = Math.ceil(Date.now() / 1000) * 1000; - var ONE_MINUTE = 60 * 1 * 1000; - var FIFTY_YEARS = 50 * 365 * 24 * 60 * 60 * 1000; + UTCTimeSystem.prototype.defaults = function (defaults) { + if (arguments.length > 0) { + this.defaultValues = defaults; + } - return { - key: 'utc-default', - name: 'UTC time system defaults', - deltas: {start: FIFTEEN_MINUTES, end: 0}, - bounds: {start: now - FIFTEEN_MINUTES, end: now}, - zoom: {min: FIFTY_YEARS, max: ONE_MINUTE} - }; + if (this.defaultValues === undefined) { + var now = Math.ceil(Date.now() / 1000) * 1000; + var ONE_MINUTE = 60 * 1 * 1000; + var FIFTY_YEARS = 50 * 365 * 24 * 60 * 60 * 1000; + + this.defaultValues = { + key: 'utc-default', + name: 'UTC time system defaults', + deltas: {start: FIFTEEN_MINUTES, end: 0}, + bounds: {start: now - FIFTEEN_MINUTES, end: now}, + zoom: {min: FIFTY_YEARS, max: ONE_MINUTE} + }; + } + return this.defaultValues; }; return UTCTimeSystem; diff --git a/src/plugins/plugins.js b/src/plugins/plugins.js index 11e5bcfc16..428a7015a5 100644 --- a/src/plugins/plugins.js +++ b/src/plugins/plugins.js @@ -55,6 +55,59 @@ define([ }; }; + var conductorInstalled = false; + + plugins.Conductor = function (options) { + if (!options) { + options = {}; + } + + function applyDefaults(openmct, timeConductorViewService) { + var defaults = {}; + var timeSystem = timeConductorViewService.systems.find(function (ts) { + return ts.metadata.key === options.defaultTimeSystem; + }); + if (timeSystem !== undefined) { + defaults = timeSystem.defaults(); + + if (options.defaultTimespan !== undefined) { + defaults.deltas.start = options.defaultTimespan; + defaults.bounds.start = defaults.bounds.end - options.defaultTimespan; + timeSystem.defaults(defaults); + } + + openmct.conductor.timeSystem(timeSystem, defaults.bounds); + } + } + + return function (openmct) { + openmct.legacyExtension('constants', { + key: 'DEFAULT_TIMECONDUCTOR_MODE', + value: options.showConductor ? 'fixed' : 'realtime', + priority: conductorInstalled ? 'mandatory' : 'fallback' + }); + if (options.showConductor !== undefined) { + openmct.legacyExtension('constants', { + key: 'SHOW_TIMECONDUCTOR', + value: options.showConductor, + priority: conductorInstalled ? 'mandatory' : 'fallback' + }); + } + if (options.defaultTimeSystem !== undefined || options.defaultTimespan !== undefined) { + openmct.legacyExtension('runs', { + implementation: applyDefaults, + depends: ["openmct", "timeConductorViewService"] + }); + } + + if (!conductorInstalled) { + openmct.legacyRegistry.enable('platform/features/conductor/core'); + openmct.legacyRegistry.enable('platform/features/conductor/compatibility'); + } + conductorInstalled = true; + }; + }; + plugins.CouchDB = function (url) { return function (openmct) { if (url) {