[Time Conductor] Maintain domain state

Maintain domain state in the time conductor; add a default list of
domains to choose from.
This commit is contained in:
Victor Woeltjen 2015-09-23 16:53:12 -07:00
parent 0b0cee3afb
commit 5d5a7c26c5
3 changed files with 46 additions and 5 deletions

View File

@ -18,7 +18,17 @@
{ {
"key": "conductorService", "key": "conductorService",
"implementation": "ConductorService.js", "implementation": "ConductorService.js",
"depends": [ "now" ] "depends": [ "now", "TIME_CONDUCTOR_DOMAINS" ]
}
],
"contants": [
{
"key": "TIME_CONDUCTOR_DOMAINS",
"value": [
{ "key": "time", "name": "Time" },
{ "key": "yesterday", "name": "Yesterday" }
],
"comment": "Placeholder; to be replaced by inspection of available domains."
} }
] ]
} }

View File

@ -39,12 +39,15 @@ define(
* @param {Function} now a function which returns the current time * @param {Function} now a function which returns the current time
* as a UNIX timestamp, in milliseconds * as a UNIX timestamp, in milliseconds
*/ */
function ConductorService(now) { function ConductorService(now, domains) {
var initialEnd = var initialEnd =
Math.ceil(now() / SIX_HOURS_IN_MS) * SIX_HOURS_IN_MS; Math.ceil(now() / SIX_HOURS_IN_MS) * SIX_HOURS_IN_MS;
this.conductor = this.conductor = new TimeConductor(
new TimeConductor(initialEnd - ONE_DAY_IN_MS, initialEnd); initialEnd - ONE_DAY_IN_MS,
initialEnd,
domains
);
} }
/** /**

View File

@ -40,9 +40,11 @@ define(
* @param {number} start the initial start time * @param {number} start the initial start time
* @param {number} end the initial end time * @param {number} end the initial end time
*/ */
function TimeConductor(start, end) { function TimeConductor(start, end, domains) {
this.inner = { start: start, end: end }; this.inner = { start: start, end: end };
this.outer = { start: start, end: end }; this.outer = { start: start, end: end };
this.domains = domains;
this.domain = domains[0];
} }
/** /**
@ -94,6 +96,32 @@ define(
return this.inner.end; return this.inner.end;
}; };
/**
* Get available domain options which can be used to bound time
* selection.
* @returns {TelemetryDomain[]} available domains
*/
TimeConductor.prototype.domainOptions = function () {
return this.domains;
};
/**
* Get or set (if called with an argument) the active domain.
* @param {string} [key] the key identifying the domain choice
* @returns {TelemetryDomain} the active telemetry domain
*/
TimeConductor.prototype.activeDomain = function (key) {
var i;
if (arguments.length > 0) {
for (i = 0; i < this.domains.length; i += 1) {
if (this.domains[i].key === key) {
this.domain = this.domains[i];
}
}
}
return this.domain;
};
return TimeConductor; return TimeConductor;
} }
); );