Skip to content

Commit

Permalink
Added support for sign sorting by route instead of departure time
Browse files Browse the repository at this point in the history
  • Loading branch information
sheldonabrown committed Feb 8, 2016
1 parent 9df4b58 commit 27db331
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions onebusaway-enterprise-webapp/src/main/webapp/js/oba/sign/Sign.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ OBA.Sign = function() {
var stopInfo = {};
var routeInfo = {};
var vehiclesPerStop = 3;
var sortByRoute = false; // otherwise sort by arrival distance/departure time

var url = window.location.href;
var signPosition = url.indexOf("/sign/sign");
Expand Down Expand Up @@ -89,7 +90,9 @@ OBA.Sign = function() {
refreshInterval = getParameterByName("refresh", refreshInterval);

vehiclesPerStop = getParameterByName("vehiclesPerStop", vehiclesPerStop);


sortByRoute = getParameterByName("sortByRoute", sortByRoute);

var fontSize = getParameterByName("fontSize", null);
if (fontSize) {
$("body, body input, body textarea").attr("style", "font-size: " + fontSize + "em;")
Expand Down Expand Up @@ -213,7 +216,7 @@ OBA.Sign = function() {
return newElement;
}

function updateElementForStop(stopId, stopElement, headsignToDistanceAways, applicableSituations) {
function updateElementForStop(stopId, stopElement, sortedHeadsigns, headsignToDistanceAways, applicableSituations) {
if(stopElement === null) {
return;
}
Expand Down Expand Up @@ -274,8 +277,24 @@ OBA.Sign = function() {
// arrivals
var r = 0;
var table = [];
// by default the routeIdAndHeadsign is sorted by arrival distance/departure time

jQuery.each(headsignToDistanceAways, function(routeIdAndHeadsign, distanceAways) {
if (sortByRoute) {
sortedHeadsigns.sort(function(a, b) {
var headsignA=a.toLowerCase();
var headsignB=b.toLowerCase();
console.log("" + headsignA + " ? " + headsignB);
if (headsignA < headsignB) //sort string ascending
return -1;
if (headsignA > headsignB)
return 1;
return 0; //default return value (no sorting)

});
}

jQuery.each(sortedHeadsigns, function(index, routeIdAndHeadsign) {
var distanceAways = headsignToDistanceAways[routeIdAndHeadsign];
var headsign = routeIdAndHeadsign.split("_")[2];
var row = {
etaCount : 0,
Expand Down Expand Up @@ -444,6 +463,8 @@ OBA.Sign = function() {
}

var headsignToDistanceAways = {};
var sortedHeadsigns = [];

var applicableSituations = {};
var r = 0;
jQuery.each(json.Siri.ServiceDelivery.StopMonitoringDelivery[0].MonitoredStopVisit, function(_, monitoredStopVisit) {
Expand Down Expand Up @@ -484,10 +505,13 @@ OBA.Sign = function() {
}

headsignToDistanceAways[routeIdAndHeadsign].push(vehicleInfo);
if (jQuery.inArray(routeIdAndHeadsign, sortedHeadsigns) == -1) {
sortedHeadsigns.push(routeIdAndHeadsign);
}
});

// update table for this stop ID
updateElementForStop(stopId, stopElement, headsignToDistanceAways, applicableSituations);
updateElementForStop(stopId, stopElement, sortedHeadsigns, headsignToDistanceAways, applicableSituations);

var oldContent = jQuery("#content");

Expand Down

0 comments on commit 27db331

Please sign in to comment.