[Time Conductor] Remove queryStart, queryEnd

...per feedback from code review, nasa/openmctweb#104
This commit is contained in:
Victor Woeltjen 2015-10-02 16:05:23 -07:00
parent 1ca2b769d9
commit dd83816035
5 changed files with 19 additions and 76 deletions

View File

@ -60,40 +60,24 @@ define(
this.$compile = $compile;
}
// Combine start/end times into a single object
function bounds(start, end) {
return { start: start, end: end };
}
// Update the time conductor from the scope
function wireScope(conductor, conductorScope, repScope) {
function updateConductorOuter() {
conductor.queryStart(conductorScope.conductor.outer.start);
conductor.queryEnd(conductorScope.conductor.outer.end);
repScope.$broadcast(
'telemetry:query:bounds',
bounds(conductor.queryStart(), conductor.queryEnd())
);
// Combine start/end times into a single object
function bounds(start, end) {
return {
start: conductor.displayStart(),
end: conductor.displayEnd()
};
}
function updateConductorInner() {
conductor.displayStart(conductorScope.conductor.inner.start);
conductor.displayEnd(conductorScope.conductor.inner.end);
repScope.$broadcast(
'telemetry:display:bounds',
bounds(conductor.displayStart(), conductor.displayEnd())
);
repScope.$broadcast('telemetry:display:bounds', bounds());
}
conductorScope.conductor = {
outer: bounds(conductor.queryStart(), conductor.queryEnd()),
inner: bounds(conductor.displayStart(), conductor.displayEnd())
};
conductorScope.conductor = { outer: bounds(), inner: bounds() };
conductorScope
.$watch('conductor.outer.start', updateConductorOuter);
conductorScope
.$watch('conductor.outer.end', updateConductorOuter);
conductorScope
.$watch('conductor.inner.start', updateConductorInner);
conductorScope
@ -103,8 +87,7 @@ define(
}
ConductorRepresenter.prototype.conductorScope = function (s) {
return (this.cScope = arguments.length > 0 ?
s : this.cScope);
return (this.cScope = arguments.length > 0 ? s : this.cScope);
};
// Handle a specific representation of a specific domain object

View File

@ -41,35 +41,9 @@ define(
* @param {number} end the initial end time
*/
function TimeConductor(start, end) {
this.inner = { start: start, end: end };
this.outer = { start: start, end: end };
this.range = { start: start, end: end };
}
/**
* Get or set (if called with an argument) the start time for queries.
* @param {number} [value] the start time to set
* @returns {number} the start time
*/
TimeConductor.prototype.queryStart = function (value) {
if (arguments.length > 0) {
this.outer.start = value;
}
return this.outer.start;
};
/**
* Get or set (if called with an argument) the end time for queries.
* @param {number} [value] the end time to set
* @returns {number} the end time
*/
TimeConductor.prototype.queryEnd = function (value) {
if (arguments.length > 0) {
this.outer.end = value;
}
return this.outer.end;
};
/**
* Get or set (if called with an argument) the start time for displays.
* @param {number} [value] the start time to set
@ -77,9 +51,9 @@ define(
*/
TimeConductor.prototype.displayStart = function (value) {
if (arguments.length > 0) {
this.inner.start = value;
this.range.start = value;
}
return this.inner.start;
return this.range.start;
};
/**
@ -89,9 +63,9 @@ define(
*/
TimeConductor.prototype.displayEnd = function (value) {
if (arguments.length > 0) {
this.inner.end = value;
this.range.end = value;
}
return this.inner.end;
return this.range.end;
};
return TimeConductor;

View File

@ -77,7 +77,7 @@ define(
mockElement = jasmine.createSpyObj('element', ELEMENT_METHODS);
mockConductor = jasmine.createSpyObj(
'conductor',
[ 'queryStart', 'queryEnd', 'displayStart', 'displayEnd' ]
[ 'displayStart', 'displayEnd' ]
);
mockCompiledTemplate = jasmine.createSpy('template');
mockNewScope = jasmine.createSpyObj('newScope', SCOPE_METHODS);
@ -127,15 +127,13 @@ define(
});
it("exposes conductor state in scope", function () {
mockConductor.queryStart.andReturn(42);
mockConductor.queryEnd.andReturn(12321);
mockConductor.displayStart.andReturn(1977);
mockConductor.displayEnd.andReturn(1984);
representer.represent(testViews[0], {});
expect(mockNewScope.conductor).toEqual({
inner: { start: 1977, end: 1984 },
outer: { start: 42, end: 12321 }
outer: { start: 1977, end: 1984 }
});
});
@ -154,12 +152,6 @@ define(
fireWatch(mockNewScope, 'conductor.inner.end', testState.inner.end);
expect(mockConductor.displayEnd).toHaveBeenCalledWith(1984);
fireWatch(mockNewScope, 'conductor.outer.start', testState.outer.start);
expect(mockConductor.queryStart).toHaveBeenCalledWith(-1977);
fireWatch(mockNewScope, 'conductor.outer.end', testState.outer.end);
expect(mockConductor.queryEnd).toHaveBeenCalledWith(12321);
});
});

View File

@ -43,9 +43,9 @@ define(
it("initializes a time conductor around the current time", function () {
var conductor = conductorService.getConductor();
expect(conductor.queryStart() <= TEST_NOW).toBeTruthy();
expect(conductor.queryEnd() >= TEST_NOW).toBeTruthy();
expect(conductor.queryEnd() > conductor.queryStart())
expect(conductor.displayStart() <= TEST_NOW).toBeTruthy();
expect(conductor.displayEnd() >= TEST_NOW).toBeTruthy();
expect(conductor.displayEnd() > conductor.displayStart())
.toBeTruthy();
});

View File

@ -41,19 +41,13 @@ define(
});
it("provides accessors for query/display start/end times", function () {
expect(conductor.queryStart()).toEqual(testStart);
expect(conductor.queryEnd()).toEqual(testEnd);
expect(conductor.displayStart()).toEqual(testStart);
expect(conductor.displayEnd()).toEqual(testEnd);
});
it("provides setters for query/display start/end times", function () {
expect(conductor.queryStart(1)).toEqual(1);
expect(conductor.queryEnd(2)).toEqual(2);
expect(conductor.displayStart(3)).toEqual(3);
expect(conductor.displayEnd(4)).toEqual(4);
expect(conductor.queryStart()).toEqual(1);
expect(conductor.queryEnd()).toEqual(2);
expect(conductor.displayStart()).toEqual(3);
expect(conductor.displayEnd()).toEqual(4);
});