Skip to content

Commit 05b6503

Browse files
author
William Becker
committed
Events were not being sorted - it was only working because they were being sent from the server in the correct order.
1 parent 4ab2dcc commit 05b6503

File tree

2 files changed

+18
-19
lines changed

2 files changed

+18
-19
lines changed

public/js/collections/event_locations.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ define([
7575
handleResults: function (results) {
7676
this.queryPending = false;
7777
results = this.combineEventsAtTheSamePlace(_.cloneDeep(results));
78-
7978
var oldResultsAsKeys = _.map(this.lastResults, this.makeKey, this);
8079
var newResultsAsKeys = _.map(results, this.makeKey, this);
80+
8181
var toRemove = _.difference(oldResultsAsKeys, newResultsAsKeys);
8282
var toRender = _.difference(newResultsAsKeys, oldResultsAsKeys);
8383

@@ -111,7 +111,7 @@ define([
111111
location.sort(function (a, b) {
112112
a = new Date(a.start_date).getTime();
113113
b = new Date(b.start_date).getTime();
114-
return (a - b) / Math.abs(a - b);
114+
return a > b ? 1 : (a === b ? 0 : -1);
115115
});
116116
});
117117
return locations;

test/webapp/collections/event_locations.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ define(
9595
]
9696
);
9797
});
98-
it("should sort things right - the order looks wrong below");
9998
it("should sort the events within the location by the date of the start_time", function () {
10099
var result = this.events.combineEventsAtTheSamePlace([{
101100
location: [[10, -20]],
@@ -112,13 +111,13 @@ define(
112111
[
113112
{
114113
location: [[10, -20]],
115-
start_date: "1900-01-03 00:02"
114+
start_date: "1900-01-01 00:00"
116115
}, {
117116
location: [[10, -20]],
118117
start_date: "1900-01-02 00:01"
119118
}, {
120119
location: [[10, -20]],
121-
start_date: "1900-01-01 00:00"
120+
start_date: "1900-01-03 00:02"
122121
}
123122
]
124123
]
@@ -161,37 +160,37 @@ define(
161160
[
162161
{
163162
location: [[10, -20]],
164-
start_date: "1900-01-01 00:00"
163+
start_date: "1900-01-01T00:00:00.000Z"
165164
}, {
166165
location: [[10, -20]],
167-
start_date: "1900-01-01 00:01"
166+
start_date: "1900-01-01T00:01:00.000Z"
168167
}
169168
],
170169
[
171170
{
172171
location: [[10, -21]],
173-
start_date: "1900-01-01 00:01"
172+
start_date: "1900-01-01T00:01:00.000Z"
174173
}
175174
]
176175
];
177176

178177
this.events.handleResults([{
179178
location: [[10, -20]],
180-
start_date: "1900-01-01 00:00"
179+
start_date: "1900-01-01T00:00:00.000Z"
181180
}, {
182181
location: [[10, -20]],
183-
start_date: "1900-01-01 00:01"
182+
start_date: "1900-01-01T00:01:00.000Z"
184183
}, {
185184
location: [[10, -22]],
186-
start_date: "1900-01-01 00:01"
185+
start_date: "1900-01-01T00:01:00.000Z"
187186
}]);
188187

189188
//todo: why this mismatching double arrays around location?
190189
this.lastReset[0].should.eql([JSON.stringify({
191190
location: [10, -21],
192191
events: [{
193192
location: [[10, -21]],
194-
start_date: "1900-01-01 00:01"
193+
start_date: "1900-01-01T00:01:00.000Z"
195194
}]
196195
})]);
197196

@@ -201,37 +200,37 @@ define(
201200
[
202201
{
203202
location: [[10, -20]],
204-
start_date: "1900-01-01 00:00"
203+
start_date: "1900-01-01T00:00:00.000Z"
205204
}, {
206205
location: [[10, -20]],
207-
start_date: "1900-01-01 00:01"
206+
start_date: "1900-01-01T00:01:00.000Z"
208207
}
209208
],
210209
[
211210
{
212211
location: [[10, -21]],
213-
start_date: "1900-01-01 00:01"
212+
start_date: "1900-01-01T00:01:00.000Z"
214213
}
215214
]
216215
];
217216

218217
this.events.handleResults([{
219218
location: [[10, -20]],
220-
start_date: "1900-01-01 00:00"
219+
start_date: "1900-01-01T00:00:00.000Z"
221220
}, {
222221
location: [[10, -20]],
223-
start_date: "1900-01-01 00:01"
222+
start_date: "1900-01-01T00:01:00.000Z"
224223
}, {
225224
location: [[10, -22]],
226-
start_date: "1900-01-01 00:01"
225+
start_date: "1900-01-01T00:01:00.000Z"
227226
}]);
228227

229228
//todo: why this mismatching double arrays around location?
230229
this.lastReset[1].should.eql([JSON.stringify({
231230
location: [10, -22],
232231
events: [{
233232
location: [[10, -22]],
234-
start_date: "1900-01-01 00:01"
233+
start_date: "1900-01-01T00:01:00.000Z"
235234
}]
236235
})]);
237236
});

0 commit comments

Comments
 (0)