@@ -32,17 +32,31 @@ define(
32
32
this . $scope = $scope ;
33
33
this . $timeout = $timeout ;
34
34
this . conductor = conductor ;
35
+ this . endDelta = 0 ;
35
36
36
- $scope . formModel = { } ;
37
- $scope . modeSelector = {
38
- value : 'fixed'
37
+ this . changing = {
38
+ 'start' : false ,
39
+ 'startDelta' : false ,
40
+ 'end' : false ,
41
+ 'endDelta' : false
39
42
} ;
40
43
44
+ $scope . formModel = { } ;
45
+
41
46
conductor . on ( 'bounds' , function ( bounds ) {
42
- $scope . formModel = {
43
- start : bounds . start ,
44
- end : bounds . end
45
- } ;
47
+ if ( ! self . changing [ 'start' ] ) {
48
+ $scope . formModel . start = bounds . start ;
49
+ }
50
+ if ( ! self . changing [ 'end' ] ) {
51
+ $scope . formModel . end = bounds . end ;
52
+ }
53
+ if ( ! self . changing [ 'startDelta' ] ) {
54
+ $scope . formModel . startDelta = bounds . end - bounds . start ;
55
+ }
56
+
57
+ if ( ! self . changing [ 'endDelta' ] ) {
58
+ $scope . formModel . endDelta = 0 ;
59
+ }
46
60
} ) ;
47
61
48
62
conductor . on ( 'follow' , function ( follow ) {
@@ -89,6 +103,7 @@ define(
89
103
var now = Math . ceil ( Date . now ( ) / 1000 ) * 1000 ;
90
104
//Set the time conductor to some default
91
105
this . conductor . bounds ( { start : now - SIX_HOURS , end : now } ) ;
106
+
92
107
this . $scope . modeModel . selected = 'fixed' ;
93
108
this . conductor . follow ( false ) ;
94
109
} ;
@@ -111,19 +126,46 @@ define(
111
126
}
112
127
} ;
113
128
129
+ TimeConductorController . prototype . validateStartDelta = function ( startDelta ) {
130
+ return startDelta > 0 ;
131
+ } ;
132
+
133
+ TimeConductorController . prototype . validateEndDelta = function ( endDelta ) {
134
+ return endDelta >= 0 ;
135
+ } ;
136
+
137
+ TimeConductorController . prototype . validateDeltas = function ( formModel ) {
138
+ // Validate that start Delta is some non-zero value, and that end
139
+ // delta is zero or positive (ie. 'now' or some time in the future).
140
+ return this . validateStartDelta ( formModel . startDelta ) && this . validateEndDelta ( formModel . endDelta ) ;
141
+ } ;
142
+
143
+ TimeConductorController . prototype . updateDeltasFromForm = function ( formModel ) {
144
+
145
+ if ( this . validateDeltas ( formModel ) ) {
146
+ var oldBounds = this . conductor . bounds ( ) ,
147
+ newBounds = {
148
+ start : oldBounds . end - formModel . startDelta ,
149
+ end : oldBounds . end + formModel . endDelta
150
+ } ;
151
+ this . conductor . bounds ( newBounds ) ;
152
+ }
153
+ } ;
154
+
114
155
TimeConductorController . prototype . switchMode = function ( newMode ) {
115
156
if ( this . mode ) {
116
157
this . mode ( ) ;
117
158
}
118
- this . mode = TimeConductorController . modes [ newMode ] . call ( this , this . conductor ) ;
159
+ this . mode = TimeConductorController . modes [ newMode ] . call ( this ) ;
119
160
} ;
120
161
121
162
TimeConductorController . modes = {
122
- 'fixed' : function ( conductor ) {
123
- conductor . follow ( false ) ;
163
+ 'fixed' : function ( ) {
164
+ this . conductor . follow ( false ) ;
124
165
} ,
125
- 'realtime' : function ( conductor ) {
166
+ 'realtime' : function ( ) {
126
167
var tickInterval = 1000 ;
168
+ var conductor = this . conductor ;
127
169
var $timeout = this . $timeout ;
128
170
var timeoutPromise = $timeout ( tick , tickInterval ) ;
129
171
@@ -144,7 +186,7 @@ define(
144
186
} ,
145
187
'latest' : function ( conductor ) {
146
188
//Don't know what to do here yet...
147
- conductor . follow ( true ) ;
189
+ this . conductor . follow ( true ) ;
148
190
}
149
191
} ;
150
192
0 commit comments