[Timer] Updated Timer UI to indicate playing or paused state
Removed PauseCheck & TimeOfPause from properties, Removed duplicate functionality Resume class , replaced peeking restart at 0 button with persistent play/pause button
This commit is contained in:
@@ -50,15 +50,26 @@ define(
|
||||
now = this.now;
|
||||
|
||||
function setTimestamp(model) {
|
||||
model.timestamp = now();
|
||||
//if we are resuming
|
||||
if (model.pausedTime) {
|
||||
var timeShift = now() - model.pausedTime;
|
||||
model.timestamp = model.timestamp + timeShift;
|
||||
} else {
|
||||
model.timestamp = now();
|
||||
}
|
||||
}
|
||||
|
||||
function setPaused(model) {
|
||||
model.paused = false;
|
||||
function setTimerState(model) {
|
||||
model.timerState = 'play';
|
||||
}
|
||||
|
||||
function setPausedTime(model) {
|
||||
model.pausedTime = undefined;
|
||||
}
|
||||
|
||||
return domainObject.useCapability('mutation', setTimestamp) &&
|
||||
domainObject.useCapability('mutation', setPaused);
|
||||
domainObject.useCapability('mutation', setTimerState) &&
|
||||
domainObject.useCapability('mutation', setPausedTime);
|
||||
};
|
||||
|
||||
return AbstractTimerAction;
|
||||
|
||||
@@ -25,10 +25,10 @@ define(
|
||||
function (AbstractTimerAction) {
|
||||
|
||||
/**
|
||||
* Implements the "Start" action for timers.
|
||||
* Implements the "Pause" action for timers.
|
||||
*
|
||||
* Sets the reference timestamp in a timer to the current
|
||||
* time, such that it begins counting up.
|
||||
* Sets the reference pausedTime in a timer to the current
|
||||
* time, such that it stops counting up.
|
||||
*
|
||||
* @extends {platform/features/clock.AbstractTimerAction}
|
||||
* @implements {Action}
|
||||
@@ -51,25 +51,26 @@ define(
|
||||
{};
|
||||
|
||||
|
||||
// We show this variant for timers which do not yet have
|
||||
// a target time.
|
||||
// We show this variant for timers which have
|
||||
// a target time, or is in a playing state.
|
||||
return model.type === 'timer' &&
|
||||
model.timestamp !== undefined && !model.paused;
|
||||
(model.timestamp !== undefined ||
|
||||
model.timerState === 'play');
|
||||
};
|
||||
|
||||
PauseTimerAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject,
|
||||
now = this.now;
|
||||
|
||||
function setPaused(model) {
|
||||
model.paused = true;
|
||||
function setTimerState(model) {
|
||||
model.timerState = 'pause';
|
||||
}
|
||||
|
||||
function setPausedTime(model) {
|
||||
model.pausedTime = now();
|
||||
}
|
||||
|
||||
return domainObject.useCapability('mutation', setPaused) &&
|
||||
return domainObject.useCapability('mutation', setTimerState) &&
|
||||
domainObject.useCapability('mutation', setPausedTime);
|
||||
};
|
||||
|
||||
|
||||
@@ -53,7 +53,8 @@ define(
|
||||
// We show this variant for timers which already have
|
||||
// a target time.
|
||||
return model.type === 'timer' &&
|
||||
model.timestamp !== undefined;
|
||||
(model.timestamp !== undefined ||
|
||||
model.timerState !== undefined);
|
||||
};
|
||||
|
||||
return RestartTimerAction;
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/*****************************************************************************
|
||||
* Open MCT, Copyright (c) 2009-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(
|
||||
['./AbstractTimerAction'],
|
||||
function (AbstractTimerAction) {
|
||||
|
||||
/**
|
||||
* Implements the "Start" action for timers.
|
||||
*
|
||||
* Sets the reference timestamp in a timer to the current
|
||||
* time, such that it begins counting up.
|
||||
*
|
||||
* @extends {platform/features/clock.AbstractTimerAction}
|
||||
* @implements {Action}
|
||||
* @memberof platform/features/clock
|
||||
* @constructor
|
||||
* @param {Function} now a function which returns the current
|
||||
* time (typically wrapping `Date.now`)
|
||||
* @param {ActionContext} context the context for this action
|
||||
*/
|
||||
function ResumeTimerAction(now, context) {
|
||||
AbstractTimerAction.apply(this, [now, context]);
|
||||
}
|
||||
|
||||
ResumeTimerAction.prototype =
|
||||
Object.create(AbstractTimerAction.prototype);
|
||||
|
||||
ResumeTimerAction.appliesTo = function (context) {
|
||||
var model =
|
||||
(context.domainObject && context.domainObject.getModel()) ||
|
||||
{};
|
||||
|
||||
|
||||
// We show this variant for timers which do not yet have
|
||||
// a target time.
|
||||
return model.type === 'timer' &&
|
||||
model.timestamp !== undefined &&
|
||||
model.paused;
|
||||
};
|
||||
|
||||
ResumeTimerAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject,
|
||||
now = this.now;
|
||||
|
||||
function setPaused(model) {
|
||||
model.paused = false;
|
||||
}
|
||||
|
||||
function setTimestamp(model) {
|
||||
var timeShift = now() - model.pausedTime;
|
||||
model.timestamp = model.timestamp + timeShift;
|
||||
}
|
||||
|
||||
function setPausedTime(model) {
|
||||
model.pausedTime = undefined;
|
||||
}
|
||||
|
||||
return domainObject.useCapability('mutation', setPaused) &&
|
||||
domainObject.useCapability('mutation', setTimestamp) &&
|
||||
domainObject.useCapability('mutation', setPausedTime);
|
||||
};
|
||||
|
||||
return ResumeTimerAction;
|
||||
}
|
||||
);
|
||||
@@ -53,7 +53,8 @@ define(
|
||||
// We show this variant for timers which do not yet have
|
||||
// a target time.
|
||||
return model.type === 'timer' &&
|
||||
model.timestamp === undefined;
|
||||
(model.timestamp === undefined ||
|
||||
model.timerState !== 'play');
|
||||
};
|
||||
|
||||
return StartTimerAction;
|
||||
|
||||
@@ -25,10 +25,10 @@ define(
|
||||
function (AbstractTimerAction) {
|
||||
|
||||
/**
|
||||
* Implements the "Start" action for timers.
|
||||
* Implements the "Stop" action for timers.
|
||||
*
|
||||
* Sets the reference timestamp in a timer to the current
|
||||
* time, such that it begins counting up.
|
||||
* Sets the reference timestamp in a timer undefined,
|
||||
* such that it is reset and makes no movements.
|
||||
*
|
||||
* @extends {platform/features/clock.AbstractTimerAction}
|
||||
* @implements {Action}
|
||||
@@ -54,7 +54,8 @@ define(
|
||||
// We show this variant for timers which do not yet have
|
||||
// a target time.
|
||||
return model.type === 'timer' &&
|
||||
model.timestamp !== undefined;
|
||||
(model.timestamp !== undefined ||
|
||||
model.timerState !== undefined);
|
||||
};
|
||||
|
||||
StopTimerAction.prototype.perform = function () {
|
||||
@@ -64,12 +65,17 @@ define(
|
||||
model.timestamp = undefined;
|
||||
}
|
||||
|
||||
function setPaused(model) {
|
||||
model.paused = false;
|
||||
function setTimerState(model) {
|
||||
model.timerState = undefined;
|
||||
}
|
||||
|
||||
function setPausedTime(model) {
|
||||
model.pausedTime = undefined;
|
||||
}
|
||||
|
||||
return domainObject.useCapability('mutation', setTimestamp) &&
|
||||
domainObject.useCapability('mutation', setPaused);
|
||||
domainObject.useCapability('mutation', setTimerState) &&
|
||||
domainObject.useCapability('mutation', setPausedTime);
|
||||
};
|
||||
|
||||
return StopTimerAction;
|
||||
|
||||
@@ -42,6 +42,7 @@ define(
|
||||
active = true,
|
||||
relativeTimestamp,
|
||||
lastTimestamp,
|
||||
relativeTimerState,
|
||||
self = this;
|
||||
|
||||
function update() {
|
||||
@@ -68,24 +69,34 @@ define(
|
||||
relativeTimestamp = timestamp;
|
||||
}
|
||||
|
||||
function updateTimerState(timerState) {
|
||||
relativeTimerState = timerState;
|
||||
}
|
||||
|
||||
function isPaused() {
|
||||
return relativeTimerState === 'pause';
|
||||
}
|
||||
|
||||
function updateObject(domainObject) {
|
||||
var model = domainObject.getModel(),
|
||||
timestamp = model.timestamp,
|
||||
formatKey = model.timerFormat,
|
||||
timerState = model.timerState,
|
||||
actionCapability = domainObject.getCapability('action'),
|
||||
actionKey = (timestamp === undefined) ?
|
||||
'timer.start' : 'timer.restart';
|
||||
actionKey = (timerState !== 'play') ?
|
||||
'timer.start' : 'timer.pause';
|
||||
|
||||
self.paused = model.paused;
|
||||
self.timerState = model.timerState;
|
||||
self.pausedTime = model.pausedTime;
|
||||
|
||||
//if paused on startup show last known position
|
||||
if (self.paused && !lastTimestamp){
|
||||
lastTimestamp = self.pausedTime;
|
||||
}
|
||||
|
||||
updateFormat(formatKey);
|
||||
updateTimestamp(timestamp);
|
||||
updateTimerState(timerState);
|
||||
|
||||
//if paused on startup show last known position
|
||||
if (isPaused() && !lastTimestamp) {
|
||||
lastTimestamp = self.pausedTime;
|
||||
}
|
||||
|
||||
self.relevantAction = actionCapability &&
|
||||
actionCapability.getActions(actionKey)[0];
|
||||
@@ -107,7 +118,7 @@ define(
|
||||
var lastSign = self.signValue,
|
||||
lastText = self.textValue;
|
||||
|
||||
if (!self.paused) {
|
||||
if (!isPaused()) {
|
||||
lastTimestamp = now();
|
||||
update();
|
||||
}
|
||||
@@ -141,7 +152,7 @@ define(
|
||||
|
||||
/**
|
||||
* Get the CSS class to display the right icon
|
||||
* for the start/restart button.
|
||||
* for the start/pause button.
|
||||
* @returns {string} cssclass to display
|
||||
*/
|
||||
TimerController.prototype.buttonCssClass = function () {
|
||||
@@ -150,7 +161,7 @@ define(
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the text to show for the start/restart button
|
||||
* Get the text to show for the start/pause button
|
||||
* (e.g. in a tooltip)
|
||||
* @returns {string} name of the action
|
||||
*/
|
||||
@@ -161,7 +172,7 @@ define(
|
||||
|
||||
|
||||
/**
|
||||
* Perform the action associated with the start/restart button.
|
||||
* Perform the action associated with the start/pause button.
|
||||
*/
|
||||
TimerController.prototype.clickButton = function () {
|
||||
if (this.relevantAction) {
|
||||
|
||||
Reference in New Issue
Block a user