@@ -3,11 +3,11 @@ import { getSocket } from "./bus-shared.js";
33/* globals Messenger */
44var bus = { } ;
55
6- $ ( function ( ) {
6+ $ ( function ( ) {
77 let base_url = window . location . host ;
88
99 bus . sendUpdate = function ( data ) {
10- //console.log('Sending data:', data);
10+
1111 data . time = "afternoon" ;
1212 socket . send ( JSON . stringify ( data ) ) ;
1313 } ;
@@ -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,74 @@ $(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+ < << << << HEAD
102+ << << << < HEAD
103+ << << << < HEAD
104+ = = === ==
105+ >>> >>> > 443647ab (feat(bus): option to mark bus as delayed)
106+ busList = routeList.map(bus => {
107+ if ( ( bus . attributes . status === 'a' || bus . attributes . status === 'd' ) && ! bus . attributes . route_name . includes ( 'JT' ) ) {
108+ let attr = JSON . parse ( JSON . stringify ( bus . attributes ) ) ;
109+ attr . route_name = `Mark ${ bus . attributes . route_name } as on time` ;
110+ return attr ;
111+ }
112+ else if (bus.attributes.status === 'o') {
113+ let attr = JSON . parse ( JSON . stringify ( bus . attributes ) ) ;
114+ let attr2 = JSON . parse ( JSON . stringify ( bus . attributes ) ) ;
115+ if ( bus . attributes . route_name . includes ( 'JT' ) ) {
116+ attr . route_name = `Mark ${ bus . attributes . route_name } as delayed` ;
117+ return attr ;
118+ }
119+ attr.route_name = `Mark ${ bus . attributes . route_name } as delayed`;
120+ attr2.route_name = `Mark ${ bus . attributes . route_name } as arrived`;
121+ return [attr, attr2];
122+ } else {
123+ if ( ! bus . attributes . route_name . includes ( 'JT' ) ) {
124+ return bus . attributes ;
125+ }
126+ return null;
127+
128+ }
129+ } ) . flat ( ) . filter ( ( element ) => element != null ) ;
130+ === === =
131+ << << << < HEAD
132+ = === ===
133+ >>> >>> > dcacb3b1 (feat(bus): mark a bus as delayed in afternoon menu)
134+ =======
135+ >>> >>> > 443647 ab ( feat ( bus ) : option to mark bus as delayed )
136+ busList = routeList . filter ( bus => bus . attributes . route_name . includes ( '') )
137+ . map ( bus => {
138+ if ( bus . attributes . status === 'a' || bus . attributes . status === 'd' ) {
139+ // TODO: less hacky deep copy
140+ let attr = JSON . parse ( JSON . stringify ( bus . attributes ) ) ;
141+ attr . route_name = `Mark ${ bus . attributes . route_name } as on time` ;
142+ return attr ;
143+ }
144+ //Adds two elements, one for marking delayed one for arrived
145+ //.flat() so that the added array gets convereted to two elements
146+ else if (bus.attributes.status === 'o') {
147+ let attr = JSON . parse ( JSON . stringify ( bus . attributes ) ) ;
148+ let attr2 = JSON . parse ( JSON . stringify ( bus . attributes ) ) ;
149+ attr . route_name = `Mark ${ bus . attributes . route_name } as delayed` ;
150+ attr2 . route_name = `Mark ${ bus . attributes . route_name } as arrived` ;
151+ return [ attr , attr2 ]
152+ } else {
153+ return bus . attributes ;
154+ }
155+ } ) . flat ( ) ;
156+ << << << < HEAD
157+ << << << < HEAD
158+ > >>> >>> dcacb3b1 ( feat ( bus ) : mark a bus as delayed in afternoon menu )
159+ === = ===
160+ = === = ==
161+ > >>> > >> 443647 ab ( feat ( bus ) : option to mark bus as delayed )
162+ >>> > >>> dcacb3b1 ( feat ( bus ) : mark a bus as delayed in afternoon menu )
112163 } else if ( action === 'Assign a bus to this space' ) {
113164 busList = routeList . filter ( bus => bus . attributes . status !== 'a' )
114- . map ( bus => bus . attributes ) ;
165+ . map ( bus => bus . attributes ) ;
115166 }
116167 let selectField = container . find ( 'select' ) . selectize ( {
117168 'options' : busList ,
@@ -130,15 +181,7 @@ $(function() {
130181 ]
131182 } ) [ 0 ] . selectize ;
132183
133- // Make search input readonly on mobile by default so the keyboard doesn't pop up
134- // if (window.innerWidth < 768) {
135- // selectField.$control_input.prop('readonly', true);
136- // $('.selectize-control').one("focus click", function (){
137- // selectField.$control_input.prop('readonly', false);
138- // // TODO: Auto-focus the input field again and get the virtual keyboard to show up.
139- // // There doesn't seem to be an easy way to do this.
140- // });
141- // }
184+
142185
143186 selectField . $control_input . prop ( 'pattern' , '[0-9]*' ) ;
144187 selectField . focus ( ) ;
@@ -159,24 +202,60 @@ $(function() {
159202 if ( ! this . selected ) {
160203 return ;
161204 }
162- let route = this . model . findWhere ( { route_name : e . target . value } ) . attributes ;
205+ let route = this . model . findWhere ( { route_name : e . target . value } ) . attributes ;
163206 route . space = this . selected . id ;
164207 route . status = 'a' ;
165208 bus . sendUpdate ( route ) ;
166209 } else if ( this . action === 'Mark a bus as arrived or on time' ) {
167210 let route_name = '' ;
168211 let st = '' ;
212+ < << << << HEAD
213+ if ( e . target . value . includes ( 'on' ) ) {
214+ route_name = e . target . value . split ( ' ' ) [ 1 ] ;
215+
216+ = === ===
169217 // TODO: this is also super hacky
170218 // Essentially, this checks if the selected route has "Mark"
171219 // at the beginning, implying that it's to be marked on time.
172- if ( e . target . value . indexOf ( 'Mark' ) === 0 ) {
220+ if ( e . target . value . includes ( 'on time' ) ) {
173221 route_name = e . target . value . split ( ' ' ) [ 1 ] ;
222+ alert ( route_name ) ;
223+ < << << << HEAD
224+ << << << < HEAD
225+ > >>> >>> dcacb3b1 ( feat ( bus ) : mark a bus as delayed in afternoon menu )
226+ === = ===
227+ === = ===
228+ > >>> > >> 443647 ab ( feat ( bus ) : option to mark bus as delayed )
229+ >>> > >>> dcacb3b1 ( feat ( bus ) : mark a bus as delayed in afternoon menu )
174230 st = 'o' ;
175- } else {
231+ }
232+ else if ( e . target . value . includes ( 'delayed' ) ) {
233+ route_name = e . target . value . split ( ' ' ) [ 1 ] ;
234+ < << << << HEAD
235+ << << << < HEAD
236+ << << << < HEAD
237+ = = === ==
238+ >>> >>> > 443647ab (feat(bus): option to mark bus as delayed)
239+
240+ st = 'd';
241+ }
242+ else {
243+ route_name = e . target . value . split ( ' ' ) [ 1 ] ;
244+ === = ===
245+ < << << < < HEAD
246+ = === = ==
247+ > >>> > >> dcacb3b1 ( feat ( bus ) : mark a bus as delayed in afternoon menu )
248+ === = ===
249+ >>> > >>> 443647 ab ( feat ( bus ) : option to mark bus as delayed )
250+ alert ( route_name ) ;
251+ st = 'd' ;
252+ }
253+ else {
176254 route_name = e . target . value ;
255+ >>> > >>> dcacb3b1 ( feat ( bus ) : mark a bus as delayed in afternoon menu )
177256 st = 'a' ;
178257 }
179- let route = this . model . findWhere ( { route_name : route_name } ) . attributes ;
258+ let route = this.model.findWhere({ route_name : route_name } ).attributes;
180259 route.status = st;
181260 bus.sendUpdate(route);
182261 }
@@ -350,18 +429,18 @@ $(function() {
350429 // fallbacks to avoid issues that have appeared in the past with the "sans-serif" default.
351430 text . font ( "family" , "Helvetica, Arial, 'Open Sans', 'Liberation Sans', sans-serif" ) ;
352431
353- if ( window . isSignage ) {
432+ if ( window . isSignage ) {
354433 var tspan = $ ( text . node ) . find ( "tspan" ) ;
355- tspan . attr ( { "x" : 0 , "dy" : 20.5 } ) ;
434+ tspan . attr ( { "x" : 0 , "dy" : 20.5 } ) ;
356435
357436 // If we run this directly, it hasn't rendered yet, so we have to run it after a timeout
358- setTimeout ( function ( ) {
437+ setTimeout ( function ( ) {
359438 var tbox = tspan . get ( 0 ) . getBBox ( ) ;
360439 var sbox = space . getBBox ( ) ;
361440
362441 var offset ;
363442 var dimenDiff ;
364- if ( tbox . width > tbox . height ) {
443+ if ( tbox . width > tbox . height ) {
365444 dimenDiff = sbox . width - tbox . width ;
366445 offset = tbox . x - sbox . x ;
367446 }
@@ -370,9 +449,9 @@ $(function() {
370449 offset = tbox . y - sbox . y ;
371450 }
372451
373- if ( dimenDiff < offset + 5 ) {
452+ if ( dimenDiff < offset + 5 ) {
374453 text . node . classList . add ( "small" ) ;
375- if ( route . attributes . route_name . length > 5 ) {
454+ if ( route . attributes . route_name . length > 5 ) {
376455 text . node . classList . add ( "extra-small" ) ;
377456 }
378457 }
@@ -381,21 +460,21 @@ $(function() {
381460 else {
382461 var tspan = $ ( text . node ) . find ( "tspan" ) ;
383462
384- setTimeout ( function ( ) {
463+ setTimeout ( function ( ) {
385464 var tbox = tspan . get ( 0 ) . getBBox ( ) ;
386465 var sbox = space . getBBox ( ) ;
387466
388467 var offset ;
389468 var dimenDiff ;
390- if ( tbox . width > tbox . height ) {
469+ if ( tbox . width > tbox . height ) {
391470 dimenDiff = sbox . width - tbox . width ;
392471 offset = tbox . x - sbox . x ;
393472 }
394473 else {
395474 dimenDiff = sbox . height - tbox . height ;
396475 offset = tbox . y - sbox . y ;
397476 }
398- if ( dimenDiff < offset + 5 || route . attributes . route_name . length > 5 ) {
477+ if ( dimenDiff < offset + 5 || route . attributes . route_name . length > 5 ) {
399478 text . node . classList . add ( "extra-small" ) ;
400479 }
401480 } , 0 ) ;
@@ -560,7 +639,7 @@ $(function() {
560639 // equatorial radius of Earth = 6,378.1370 km
561640 // polar radius of Earth = 6,356.7523 km
562641
563- // length of 1 deg equatorial longitude
642+ // length of 1 deg equatorial longitude
564643 let deg_lng_eq = 6378.1370 * 2 * Math.PI / 360;
565644 // length of 1 deg equatorial latitude
566645 let deg_lat_eq = 6356.7523 * 2 * Math.PI / 360;
@@ -587,7 +666,7 @@ $(function() {
587666 } */
588667 let degrees = (direction) * (180 / Math.PI) - 49 + 90;
589668 // let degrees = (direction) * (180 / Math.PI);
590- this . busDriverEl . css ( { 'transform' : 'rotate(' + degrees + 'deg)' } ) ;
669+ this.busDriverEl.css({ 'transform' : 'rotate(' + degrees + 'deg)' } );
591670 this.mapbox.setCenter(this.busDriverBus.point.coordinates);
592671
593672 this.busDriverBus.lastFrame = time;
@@ -634,7 +713,7 @@ $(function() {
634713 container . empty ( ) ;
635714 container . append ( this . template ( this . model . toJSON ( ) ) ) ;
636715 _ . each ( this . model . attributes . collection , function ( route ) {
637- container . append ( new bus . RouteView ( { model : route } ) . render ( ) . el ) ;
716+ container . append ( new bus . RouteView ( { model : route } ) . render ( ) . el ) ;
638717 } ) ;
639718 return this ;
640719 }
@@ -699,23 +778,23 @@ $(function() {
699778 }
700779 } );
701780
702- if ( isAdmin ) {
703- $ ( ".bus-announcement-save" ) . click ( function ( ) {
781+ if (isAdmin) {
782+ $ ( ".bus-announcement-save" ) . click ( function ( ) {
704783 bus . sendUpdate ( {
705784 announcement : $ ( ".bus-announcement" ) . text ( )
706785 } ) ;
707786 $ ( ".bus-announcement-save" ) . text ( "Saved!" ) . css ( "color" , "green" ) ;
708- setTimeout ( function ( ) {
787+ setTimeout ( function ( ) {
709788 $ ( ".bus-announcement-save" ) . text ( "Save" ) . css ( "color" , "" ) ;
710789 } , 1500 ) ;
711790 } ) ;
712- $ ( ".bus-announcement-clear" ) . click ( function ( ) {
791+ $ ( ".bus-announcement-clear" ) . click ( function ( ) {
713792 $ ( ".bus-announcement" ) . text ( "" ) ;
714793 bus . sendUpdate ( {
715794 announcement : "" ,
716795 } ) ;
717796 $ ( ".bus-announcement-clear" ) . text ( "Cleared!" ) . css ( "color" , "green" ) ;
718- setTimeout ( function ( ) {
797+ setTimeout ( function ( ) {
719798 $ ( ".bus-announcement-clear" ) . text ( "Clear" ) . css ( "color" , "" ) ;
720799 } , 1500 ) ;
721800 } ) ;
@@ -740,7 +819,7 @@ $(function() {
740819 Backbone . trigger ( 'recordScore' , e ) ;
741820 } ) ;
742821 }
743- // window.personalStatusView = new bus.personalStatusView();
822+ // window.personalStatusView = new bus.personalStatusView();
744823} ) ;
745824
746825/* TODO: flip bus map to be horizontal
0 commit comments