Skip to content

Commit

Permalink
Support deltaFormat on timeSystems
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Aug 4, 2016
1 parent 9007522 commit f844495
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 8 deletions.
4 changes: 4 additions & 0 deletions example/localTimeSystem/src/LocalTimeSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ define([
return this._formats;
};

LocalTimeSystem.prototype.deltaFormat = function () {
return 'duration';
};

LocalTimeSystem.prototype.tickSources = function () {
return this._tickSources;
};
Expand Down
8 changes: 8 additions & 0 deletions platform/features/conductor-v2/conductor/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define([
"./src/ui/TimeConductorService",
"./src/ui/TimeConductorController",
"./src/ui/MCTConductorAxis",
"./src/ui/NumberFormat",
"text!./res/templates/time-conductor.html",
"text!./res/templates/mode-selector/mode-selector.html",
"text!./res/templates/mode-selector/mode-menu.html",
Expand All @@ -32,6 +33,7 @@ define([
TimeConductorService,
TimeConductorController,
MCTConductorAxis,
NumberFormat,
timeConductorTemplate,
modeSelectorTemplate,
modeMenuTemplate,
Expand Down Expand Up @@ -99,6 +101,12 @@ define([
"key": "mode-menu",
"template": modeMenuTemplate
}
],
"formats": [
{
"key": "number",
"implementation": NumberFormat
}
]
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
-
<mct-control key="'datetime-field'"
structure="{
format: 'duration',
format: timeSystemModel.deltaFormat,
validate: tcController.validation.validateStartDelta
}"
ng-model="formModel"
Expand Down Expand Up @@ -62,7 +62,7 @@
+
<mct-control key="'datetime-field'"
structure="{
format: 'duration',
format: timeSystemModel.deltaFormat,
validate: tcController.validation.validateEndDelta
}"
ng-model="formModel"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ define([], function () {
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
* are event generators that can be used to advance the time conductor
Expand Down
57 changes: 57 additions & 0 deletions platform/features/conductor-v2/conductor/src/ui/NumberFormat.js
Original file line number Diff line number Diff line change
@@ -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;
});
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ define(
var mode = this.conductorService.mode(),
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
mode.deltas({start: formModel.startDelta, end: formModel.endDelta});
mode.deltas({start: parseFloat(formModel.startDelta), end: parseFloat(formModel.endDelta)});
}
};

Expand Down Expand Up @@ -270,6 +270,7 @@ define(
if (newTimeSystem && newTimeSystem !== this.$scope.timeSystemModel.selected) {
this.$scope.timeSystemModel.selected = newTimeSystem;
this.$scope.timeSystemModel.format = newTimeSystem.formats()[0];
this.$scope.timeSystemModel.deltaFormat = newTimeSystem.deltaFormat();
var mode = this.conductorService.mode();
mode.selectedTimeSystem(newTimeSystem);
this.setDeltasFromTimeSystem(newTimeSystem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ define(
};

TimeConductorValidation.prototype.validateStartDelta = function (startDelta) {
return startDelta > 0;
return !isNaN(startDelta) && startDelta > 0;
};

TimeConductorValidation.prototype.validateEndDelta = function (endDelta) {
return endDelta >= 0;
return !isNaN(endDelta) && endDelta >= 0;
};

/**
Expand All @@ -68,10 +68,10 @@ define(
* @param formModel
* @returns {*}
*/
TimeConductorValidation.prototype.validateDeltas = function (formModel) {
TimeConductorValidation.prototype.validateDeltas = function (startDelta, endDelta) {
// 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).
return this.validateStartDelta(formModel.startDelta) && this.validateEndDelta(formModel.endDelta);
return this.validateStartDelta(startDelta) && this.validateEndDelta(endDelta);
};

return TimeConductorValidation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ define([
return this._formats;
};

UTCTimeSystem.prototype.deltaFormat = function () {
return 'duration';
};

UTCTimeSystem.prototype.tickSources = function () {
return this._tickSources;
};
Expand Down
1 change: 1 addition & 0 deletions platform/forms/res/templates/controls/textfield.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<input type="text"
ng-required="ngRequired"
ng-model="ngModel[field]"
ng-blur="ngBlur()"
ng-pattern="ngPattern"
size="{{structure.size}}"
name="mctControl">
Expand Down

0 comments on commit f844495

Please sign in to comment.