Support deltaFormat on timeSystems

This commit is contained in:
Henry 2016-08-03 17:40:37 -07:00
parent 900752208f
commit f844495cc1
9 changed files with 100 additions and 8 deletions

View File

@ -56,6 +56,10 @@ define([
return this._formats; return this._formats;
}; };
LocalTimeSystem.prototype.deltaFormat = function () {
return 'duration';
};
LocalTimeSystem.prototype.tickSources = function () { LocalTimeSystem.prototype.tickSources = function () {
return this._tickSources; return this._tickSources;
}; };

View File

@ -24,6 +24,7 @@ define([
"./src/ui/TimeConductorService", "./src/ui/TimeConductorService",
"./src/ui/TimeConductorController", "./src/ui/TimeConductorController",
"./src/ui/MCTConductorAxis", "./src/ui/MCTConductorAxis",
"./src/ui/NumberFormat",
"text!./res/templates/time-conductor.html", "text!./res/templates/time-conductor.html",
"text!./res/templates/mode-selector/mode-selector.html", "text!./res/templates/mode-selector/mode-selector.html",
"text!./res/templates/mode-selector/mode-menu.html", "text!./res/templates/mode-selector/mode-menu.html",
@ -32,6 +33,7 @@ define([
TimeConductorService, TimeConductorService,
TimeConductorController, TimeConductorController,
MCTConductorAxis, MCTConductorAxis,
NumberFormat,
timeConductorTemplate, timeConductorTemplate,
modeSelectorTemplate, modeSelectorTemplate,
modeMenuTemplate, modeMenuTemplate,
@ -99,6 +101,12 @@ define([
"key": "mode-menu", "key": "mode-menu",
"template": modeMenuTemplate "template": modeMenuTemplate
} }
],
"formats": [
{
"key": "number",
"implementation": NumberFormat
}
] ]
} }
}); });

View File

@ -31,7 +31,7 @@
- -
<mct-control key="'datetime-field'" <mct-control key="'datetime-field'"
structure="{ structure="{
format: 'duration', format: timeSystemModel.deltaFormat,
validate: tcController.validation.validateStartDelta validate: tcController.validation.validateStartDelta
}" }"
ng-model="formModel" ng-model="formModel"
@ -62,7 +62,7 @@
+ +
<mct-control key="'datetime-field'" <mct-control key="'datetime-field'"
structure="{ structure="{
format: 'duration', format: timeSystemModel.deltaFormat,
validate: tcController.validation.validateEndDelta validate: tcController.validation.validateEndDelta
}" }"
ng-model="formModel" ng-model="formModel"

View File

@ -48,6 +48,23 @@ define([], function () {
throw new Error('Not implemented'); throw new Error('Not implemented');
}; };
/**
* @typedef DeltaFormat
* @property {string} type the type of MctControl used to represent this
* field. Typically 'datetime-field' for UTC based dates, or 'textfield'
* otherwise
* @property {string} [format] An optional field specifying the
* Format to use for delta fields in this time system.
*/
/**
* Specifies a format for deltas in this time system.
*
* @returns {DeltaFormat} a delta format specifier
*/
TimeSystem.prototype.deltaFormat = function () {
throw new Error('Not implemented');
};
/** /**
* Returns the tick sources supported by this time system. Tick sources * Returns the tick sources supported by this time system. Tick sources
* are event generators that can be used to advance the time conductor * are event generators that can be used to advance the time conductor

View File

@ -0,0 +1,57 @@
/*****************************************************************************
* Open MCT, Copyright (c) 2014-2016, United States Government
* as represented by the Administrator of the National Aeronautics and Space
* Administration. All rights reserved.
*
* Open MCT 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 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([
'moment'
], function (
moment
) {
/**
* Formatter for basic numbers. Provides basic support for non-UTC
* numbering systems
*
* @implements {Format}
* @constructor
* @memberof platform/commonUI/formats
*/
function NumberFormat() {
}
NumberFormat.prototype.format = function (value) {
if (isNaN(value)){
return '';
} else {
return '' + value;
}
};
NumberFormat.prototype.parse = function (text) {
return parseFloat(text);
};
NumberFormat.prototype.validate = function (text) {
return !isNaN(text);
};
return NumberFormat;
});

View File

@ -163,9 +163,9 @@ define(
var mode = this.conductorService.mode(), var mode = this.conductorService.mode(),
deltas = mode.deltas(); deltas = mode.deltas();
if (deltas !== undefined && this.validation.validateDeltas(formModel)) { if (deltas !== undefined && this.validation.validateDeltas(formModel.startDelta, formModel.endDelta)) {
//Sychronize deltas between form and mode //Sychronize deltas between form and mode
mode.deltas({start: formModel.startDelta, end: formModel.endDelta}); mode.deltas({start: parseFloat(formModel.startDelta), end: parseFloat(formModel.endDelta)});
} }
}; };
@ -270,6 +270,7 @@ define(
if (newTimeSystem && newTimeSystem !== this.$scope.timeSystemModel.selected) { if (newTimeSystem && newTimeSystem !== this.$scope.timeSystemModel.selected) {
this.$scope.timeSystemModel.selected = newTimeSystem; this.$scope.timeSystemModel.selected = newTimeSystem;
this.$scope.timeSystemModel.format = newTimeSystem.formats()[0]; this.$scope.timeSystemModel.format = newTimeSystem.formats()[0];
this.$scope.timeSystemModel.deltaFormat = newTimeSystem.deltaFormat();
var mode = this.conductorService.mode(); var mode = this.conductorService.mode();
mode.selectedTimeSystem(newTimeSystem); mode.selectedTimeSystem(newTimeSystem);
this.setDeltasFromTimeSystem(newTimeSystem); this.setDeltasFromTimeSystem(newTimeSystem);

View File

@ -54,11 +54,11 @@ define(
}; };
TimeConductorValidation.prototype.validateStartDelta = function (startDelta) { TimeConductorValidation.prototype.validateStartDelta = function (startDelta) {
return startDelta > 0; return !isNaN(startDelta) && startDelta > 0;
}; };
TimeConductorValidation.prototype.validateEndDelta = function (endDelta) { TimeConductorValidation.prototype.validateEndDelta = function (endDelta) {
return endDelta >= 0; return !isNaN(endDelta) && endDelta >= 0;
}; };
/** /**
@ -68,10 +68,10 @@ define(
* @param formModel * @param formModel
* @returns {*} * @returns {*}
*/ */
TimeConductorValidation.prototype.validateDeltas = function (formModel) { TimeConductorValidation.prototype.validateDeltas = function (startDelta, endDelta) {
// Validate that start Delta is some non-zero value, and that end // Validate that start Delta is some non-zero value, and that end
// delta is zero or positive (ie. 'now' or some time in the future). // delta is zero or positive (ie. 'now' or some time in the future).
return this.validateStartDelta(formModel.startDelta) && this.validateEndDelta(formModel.endDelta); return this.validateStartDelta(startDelta) && this.validateEndDelta(endDelta);
}; };
return TimeConductorValidation; return TimeConductorValidation;

View File

@ -56,6 +56,10 @@ define([
return this._formats; return this._formats;
}; };
UTCTimeSystem.prototype.deltaFormat = function () {
return 'duration';
};
UTCTimeSystem.prototype.tickSources = function () { UTCTimeSystem.prototype.tickSources = function () {
return this._tickSources; return this._tickSources;
}; };

View File

@ -24,6 +24,7 @@
<input type="text" <input type="text"
ng-required="ngRequired" ng-required="ngRequired"
ng-model="ngModel[field]" ng-model="ngModel[field]"
ng-blur="ngBlur()"
ng-pattern="ngPattern" ng-pattern="ngPattern"
size="{{structure.size}}" size="{{structure.size}}"
name="mctControl"> name="mctControl">