Skip to content

Commit 8d407bc

Browse files
committed
feat(markbusdelayed)option to mark bus as delayed
Closes #1414
1 parent 7cc4dcb commit 8d407bc

File tree

1 file changed

+56
-40
lines changed

1 file changed

+56
-40
lines changed

intranet/static/js/bus-afternoon.js

Lines changed: 56 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { getSocket } from "./bus-shared.js";
33
/* globals Messenger */
44
var bus = {};
55

6-
$(function() {
6+
$(function () {
77
let base_url = window.location.host;
88

99
bus.sendUpdate = function (data) {
@@ -28,11 +28,11 @@ $(function() {
2828
bus.StatusGroupModel = Backbone.Model.extend();
2929

3030
bus.PersonalStatusView = Backbone.View.extend({
31-
initialize: function() {
31+
initialize: function () {
3232
_.bindAll(this, 'render');
3333
this.template = _.template($('#personal-status').html());
3434
},
35-
render: function() {
35+
render: function () {
3636
var container = this.$el,
3737
renderedContent = this.template(this.model.toJSON());
3838
container.html(renderedContent);
@@ -84,7 +84,7 @@ $(function() {
8484
'text': this.text
8585
};
8686
this.$el.html(this.buttonTemplate(data))
87-
.removeClass('search-widget');
87+
.removeClass('search-widget');
8888
return this;
8989
},
9090
renderSearchView: function (routeList, action) {
@@ -95,23 +95,32 @@ $(function() {
9595
let busList = [];
9696
if (action === 'Search for a bus') {
9797
busList = routeList.filter(bus => bus.attributes.status === 'a')
98-
.filter(bus => bus.attributes.route_name.includes('JT'))
99-
.map(bus => bus.attributes);
98+
.filter(bus => bus.attributes.route_name.includes('JT'))
99+
.map(bus => bus.attributes);
100100
} else if (action === 'Mark a bus as arrived or on time') {
101-
busList = routeList.filter(bus => !bus.attributes.route_name.includes('JT'))
102-
.map(bus => {
103-
if (bus.attributes.status === 'a') {
104-
// TODO: less hacky deep copy
105-
let attr = JSON.parse(JSON.stringify(bus.attributes));
106-
attr.route_name = `Mark ${bus.attributes.route_name} as on time`;
107-
return attr;
108-
} else {
109-
return bus.attributes;
110-
}
111-
});
101+
busList = routeList.filter(bus => bus.attributes.route_name.includes(''))
102+
.map(bus => {
103+
if (bus.attributes.status === 'a' || bus.attributes.status === 'd') {
104+
// TODO: less hacky deep copy
105+
let attr = JSON.parse(JSON.stringify(bus.attributes));
106+
attr.route_name = `Mark ${bus.attributes.route_name} as on time`;
107+
return attr;
108+
}
109+
//Adds two elements, one for marking delayed one for arrived
110+
//.flat() so that the added array gets convereted to two elements
111+
else if (bus.attributes.status === 'o') {
112+
let attr = JSON.parse(JSON.stringify(bus.attributes));
113+
let attr2 = JSON.parse(JSON.stringify(bus.attributes));
114+
attr.route_name = `Mark ${bus.attributes.route_name} as delayed`;
115+
attr2.route_name = `Mark ${bus.attributes.route_name} as arrived`;
116+
return [attr, attr2]
117+
} else {
118+
return bus.attributes;
119+
}
120+
}).flat();
112121
} else if (action === 'Assign a bus to this space') {
113122
busList = routeList.filter(bus => bus.attributes.status !== 'a')
114-
.map(bus => bus.attributes);
123+
.map(bus => bus.attributes);
115124
}
116125
let selectField = container.find('select').selectize({
117126
'options': busList,
@@ -159,7 +168,7 @@ $(function() {
159168
if (!this.selected) {
160169
return;
161170
}
162-
let route = this.model.findWhere({route_name: e.target.value}).attributes;
171+
let route = this.model.findWhere({ route_name: e.target.value }).attributes;
163172
route.space = this.selected.id;
164173
route.status = 'a';
165174
bus.sendUpdate(route);
@@ -169,14 +178,21 @@ $(function() {
169178
// TODO: this is also super hacky
170179
// Essentially, this checks if the selected route has "Mark"
171180
// at the beginning, implying that it's to be marked on time.
172-
if (e.target.value.indexOf('Mark') === 0) {
181+
if (e.target.value.includes('on time')) {
173182
route_name = e.target.value.split(' ')[1];
183+
alert(route_name);
174184
st = 'o';
175-
} else {
185+
}
186+
else if (e.target.value.includes('delayed')) {
187+
route_name = e.target.value.split(' ')[1];
188+
alert(route_name);
189+
st = 'd';
190+
}
191+
else {
176192
route_name = e.target.value;
177193
st = 'a';
178194
}
179-
let route = this.model.findWhere({route_name: route_name}).attributes;
195+
let route = this.model.findWhere({ route_name: route_name }).attributes;
180196
route.status = st;
181197
bus.sendUpdate(route);
182198
}
@@ -350,18 +366,18 @@ $(function() {
350366
// fallbacks to avoid issues that have appeared in the past with the "sans-serif" default.
351367
text.font("family", "Helvetica, Arial, 'Open Sans', 'Liberation Sans', sans-serif");
352368

353-
if(window.isSignage) {
369+
if (window.isSignage) {
354370
var tspan = $(text.node).find("tspan");
355-
tspan.attr({"x": 0, "dy": 20.5});
371+
tspan.attr({ "x": 0, "dy": 20.5 });
356372

357373
// If we run this directly, it hasn't rendered yet, so we have to run it after a timeout
358-
setTimeout(function() {
374+
setTimeout(function () {
359375
var tbox = tspan.get(0).getBBox();
360376
var sbox = space.getBBox();
361377

362378
var offset;
363379
var dimenDiff;
364-
if(tbox.width > tbox.height) {
380+
if (tbox.width > tbox.height) {
365381
dimenDiff = sbox.width - tbox.width;
366382
offset = tbox.x - sbox.x;
367383
}
@@ -370,9 +386,9 @@ $(function() {
370386
offset = tbox.y - sbox.y;
371387
}
372388

373-
if(dimenDiff < offset + 5) {
389+
if (dimenDiff < offset + 5) {
374390
text.node.classList.add("small");
375-
if(route.attributes.route_name.length > 5) {
391+
if (route.attributes.route_name.length > 5) {
376392
text.node.classList.add("extra-small");
377393
}
378394
}
@@ -381,21 +397,21 @@ $(function() {
381397
else {
382398
var tspan = $(text.node).find("tspan");
383399

384-
setTimeout(function() {
400+
setTimeout(function () {
385401
var tbox = tspan.get(0).getBBox();
386402
var sbox = space.getBBox();
387403

388404
var offset;
389405
var dimenDiff;
390-
if(tbox.width > tbox.height) {
406+
if (tbox.width > tbox.height) {
391407
dimenDiff = sbox.width - tbox.width;
392408
offset = tbox.x - sbox.x;
393409
}
394410
else {
395411
dimenDiff = sbox.height - tbox.height;
396412
offset = tbox.y - sbox.y;
397413
}
398-
if(dimenDiff < offset + 5 || route.attributes.route_name.length > 5) {
414+
if (dimenDiff < offset + 5 || route.attributes.route_name.length > 5) {
399415
text.node.classList.add("extra-small");
400416
}
401417
}, 0);
@@ -560,7 +576,7 @@ $(function() {
560576
// equatorial radius of Earth = 6,378.1370 km
561577
// polar radius of Earth = 6,356.7523 km
562578

563-
// length of 1 deg equatorial longitude
579+
// length of 1 deg equatorial longitude
564580
let deg_lng_eq = 6378.1370 * 2 * Math.PI / 360;
565581
// length of 1 deg equatorial latitude
566582
let deg_lat_eq = 6356.7523 * 2 * Math.PI / 360;
@@ -587,7 +603,7 @@ $(function() {
587603
}*/
588604
let degrees = (direction) * (180 / Math.PI) - 49 + 90;
589605
// let degrees = (direction) * (180 / Math.PI);
590-
this.busDriverEl.css({'transform' : 'rotate('+ degrees +'deg)'});
606+
this.busDriverEl.css({ 'transform': 'rotate(' + degrees + 'deg)' });
591607
this.mapbox.setCenter(this.busDriverBus.point.coordinates);
592608

593609
this.busDriverBus.lastFrame = time;
@@ -634,7 +650,7 @@ $(function() {
634650
container.empty();
635651
container.append(this.template(this.model.toJSON()));
636652
_.each(this.model.attributes.collection, function (route) {
637-
container.append(new bus.RouteView({model: route}).render().el);
653+
container.append(new bus.RouteView({ model: route }).render().el);
638654
});
639655
return this;
640656
}
@@ -699,23 +715,23 @@ $(function() {
699715
}
700716
});
701717

702-
if(isAdmin) {
703-
$(".bus-announcement-save").click(function() {
718+
if (isAdmin) {
719+
$(".bus-announcement-save").click(function () {
704720
bus.sendUpdate({
705721
announcement: $(".bus-announcement").text()
706722
});
707723
$(".bus-announcement-save").text("Saved!").css("color", "green");
708-
setTimeout(function() {
724+
setTimeout(function () {
709725
$(".bus-announcement-save").text("Save").css("color", "");
710726
}, 1500);
711727
});
712-
$(".bus-announcement-clear").click(function() {
728+
$(".bus-announcement-clear").click(function () {
713729
$(".bus-announcement").text("");
714730
bus.sendUpdate({
715731
announcement: "",
716732
});
717733
$(".bus-announcement-clear").text("Cleared!").css("color", "green");
718-
setTimeout(function() {
734+
setTimeout(function () {
719735
$(".bus-announcement-clear").text("Clear").css("color", "");
720736
}, 1500);
721737
});
@@ -740,7 +756,7 @@ $(function() {
740756
Backbone.trigger('recordScore', e);
741757
});
742758
}
743-
// window.personalStatusView = new bus.personalStatusView();
759+
// window.personalStatusView = new bus.personalStatusView();
744760
});
745761

746762
/* TODO: flip bus map to be horizontal

0 commit comments

Comments
 (0)