From 95ecda6c51c197c3171c0784583d079b3ae5ff67 Mon Sep 17 00:00:00 2001
From: Jacek Kowalski <Jacek@jacekk.info>
Date: Sat, 31 Jul 2021 00:05:59 +0000
Subject: [PATCH] [common] Fix deepMerge() as typeof null is object
---
map.js | 128 +++++++++++++++++++++++++++---------------
1 files changed, 81 insertions(+), 47 deletions(-)
diff --git a/map.js b/map.js
index d957dbb..2cf2272 100644
--- a/map.js
+++ b/map.js
@@ -188,8 +188,8 @@
});
ttss_types.forEach(function(ttss_type) {
- vehicles_source[ttss_type].forEachFeature(function(feature) {
- if(feature.get('vehicle_type') && feature.get('vehicle_type').num.indexOf(query) > -1) {
+ vehicles[ttss_type].source.forEachFeature(function(feature) {
+ if(feature.get('type') && feature.get('type').num.indexOf(query) > -1) {
features.push(feature);
}
});
@@ -268,12 +268,6 @@
}),
text: new ol.style.Text({
font: 'bold 10px sans-serif',
- // TODO: special directions
- // vehicle.line = vehicle.name.substr(0, vehicle_name_space);
- // vehicle.direction = normalizeName(vehicle.name.substr(vehicle_name_space+1));
- // if(special_directions[vehicle.direction]) {
- // vehicle.line = special_directions[vehicle.direction];
- // }
text: feature.get('line'),
fill: new ol.style.Fill({color: 'white'}),
}),
@@ -328,10 +322,10 @@
},
_removeFeature: function(feature) {
if(!feature) return;
- this.source.removeFeature(feature);
if(this.selectedFeatureId === feature.getId()) {
this.deselect();
}
+ this.source.removeFeature(feature);
},
loadFullData: function(data) {
var self = this;
@@ -386,12 +380,15 @@
api_url + '/positions/?type=' + this.prefix + '&last=' + this.lastUpdate
).done(function(data) {
try {
+ if(data['date'] < self.lastUpdate) {
+ console.log('Data older than lastUpdate!');
+ }
if(data['type'] == 'full') {
self.loadFullData(data['pos']);
} else {
self.loadDiffData(data['pos']);
}
- self.lastUpdate = data['last'];
+ self.lastUpdate = data['date'];
setTimeout(self.fetchXhr.bind(self), api_refresh);
} catch(e) {
console.log(e);
@@ -548,7 +545,7 @@
return path_xhr;
}
-function vehicleTable(feature, table) {
+function vehicleTable(feature, table, post, trip) {
if(feature_xhr) feature_xhr.abort();
if(feature_timer) clearTimeout(feature_timer);
@@ -557,9 +554,13 @@
var featureSource = featureDiscriminator.substr(1, 1);
var featureStatus = feature.get('status');
+ var isTripCurrent = !trip || feature.get('trip') == trip;
+
feature_xhr = $.get(
- api_url + '/trip/?type=' + featureSource + '&id=' + feature.get('trip')
- ).done(function(data) {
+ api_url + '/trip/?type=' + featureSource + '&id=' + (trip ? trip : feature.get('trip'))
+ ).done(function(results) {
+ var data = results['data'];
+
deleteChildren(table);
var tr;
@@ -571,10 +572,12 @@
stopsToMark.push(data[i].stop);
- if(data[i].seq < feature.get('seq')) {
- tr.className = 'active';
- } else if(data[i].seq == feature.get('seq') && featureStatus < 2) {
- tr.className = 'success';
+ if(isTripCurrent) {
+ if(data[i].seq < feature.get('seq')) {
+ tr.className = 'active';
+ } else if(data[i].seq == feature.get('seq') && featureStatus < 2) {
+ tr.className = 'success';
+ }
}
table.appendChild(tr);
}
@@ -587,9 +590,42 @@
tr.className = 'active';
}
+ deleteChildren(post);
+
+ if(results['prev']) {
+ tr = addElementWithText(post, 'a', lang.trip_previous);
+ tr.className = 'left';
+ tr.onclick = function() {
+ vehicleTable(feature, table, post, results['prev']);
+ };
+ } else {
+ tr = document.createElement('span');
+ post.appendChild(tr);
+ }
+ if(!isTripCurrent) {
+ tr = addElementWithText(post, 'a', lang.trip_current);
+ tr.className = 'center';
+ tr.onclick = function() {
+ vehicleTable(feature, table, post);
+ };
+ } else {
+ tr = document.createElement('span');
+ post.appendChild(tr);
+ }
+ if(results['next']) {
+ tr = addElementWithText(post, 'a', lang.trip_next);
+ tr.className = 'right';
+ tr.onclick = function() {
+ vehicleTable(feature, table, post, results['next']);
+ };
+ } else {
+ tr = document.createElement('span');
+ post.appendChild(tr);
+ }
+
markStops(stopsToMark, featureSource, true);
- feature_timer = setTimeout(function() { vehicleTable(feature, table); }, api_refresh);
+ feature_timer = setTimeout(function() { vehicleTable(feature, table, post, trip); }, api_refresh);
}).fail(fail_ajax_popup);
return feature_xhr;
}
@@ -603,23 +639,22 @@
var featureSource = featureDiscriminator.substr(1, 1);
feature_xhr = $.get(
- api_url + '/stop/?type=' + featureSource + '&id=' + feature.getId()
+ api_url + '/schedule/?type=' + featureSource + '&id=' + feature.getId()
).done(function(data) {
deleteChildren(table);
- var all_departures = data.old.concat(data.actual);
var tr, dir_cell, vehicle, status, status_cell, delay, delay_cell;
- for(var i = 0, il = all_departures.length; i < il; i++) {
+ for(var i = 0, il = data.length; i < il; i++) {
tr = document.createElement('tr');
- addCellWithText(tr, all_departures[i].patternText);
- dir_cell = addCellWithText(tr, normalizeName(all_departures[i].direction));
+ addCellWithText(tr, data[i].line);
+ dir_cell = addCellWithText(tr, data[i].direction);
//vehicle = vehicles_info.getParsed(all_departures[i].vehicleId);
- dir_cell.appendChild(displayVehicle(vehicle));
- status = parseStatus(all_departures[i]);
- status_cell = addCellWithText(tr, status);
- delay = parseDelay(all_departures[i]);
- delay_cell = addCellWithText(tr, delay);
-
+ //dir_cell.appendChild(displayVehicle(vehicle));
+ //status = parseStatus(all_departures[i]);
+ status_cell = addCellWithText(tr, data[i].time);
+ //delay = parseDelay(all_departures[i]);
+ delay_cell = addCellWithText(tr, '');
+ /*
if(i < data.old.length) {
tr.className = 'active';
} else if(status === lang.boarding_sign) {
@@ -631,7 +666,7 @@
} else if(parseInt(delay) > 3) {
tr.className = 'warning';
}
-
+ */
table.appendChild(tr);
}
@@ -665,6 +700,7 @@
var tbody = document.createElement('tbody');
table.appendChild(thead);
table.appendChild(tbody);
+ var post;
var tabular_data = true;
@@ -684,8 +720,10 @@
var span = displayVehicle(feature.get('type'));
additional = document.createElement('p');
- if(span.title) {
- setText(additional, span.title);
+ if(span.dataset.typeShort) {
+ setText(additional, span.dataset.typeShort);
+ additional.title = span.dataset.typeAdditional;
+ span.removeAttribute('title');
} else {
setText(additional, feature.getId());
}
@@ -694,7 +732,10 @@
addElementWithText(thead, 'th', lang.header_time);
addElementWithText(thead, 'th', lang.header_stop);
- vehicleTable(feature, tbody);
+ post = document.createElement('div');
+ post.className = 'post-nav';
+
+ vehicleTable(feature, tbody, post);
//vehiclePath(feature);
}
// Stop or stop point
@@ -768,6 +809,10 @@
if(tabular_data) {
div.appendChild(table);
+ }
+
+ if(post) {
+ div.appendChild(post);
}
showOnMapFunction();
@@ -901,7 +946,9 @@
return false;
},
_updateOld: function() {
- if(window.location.hash.match(/^#![bt][0-9]{3}$/)) {
+ if(window.location.hash.match(/^#!s[bt][0-9]{1,3}$/)) {
+ this.go('s' + window.location.hash.charAt(3) + window.location.hash.substr(4).padStart(4, '0'));
+ } else if(window.location.hash.match(/^#![bt][0-9]{3}$/)) {
this.go('v' + window.location.hash.substr(2));
} else if(window.location.hash.match(/^#![RHrh][A-Za-z][0-9]{3}$/)) {
this.go('vt'+ window.location.hash.substr(4));
@@ -1146,19 +1193,6 @@
hash = new Hash();
Deferred.all(future_requests).done(hash.ready.bind(hash));
-
- setTimeout(function() {
- ttss_types.forEach(function(type) {
- if(vehicles_xhr[type]) {
- vehicles_xhr[type].abort();
- }
- if(vehicles_timer[type]) {
- clearTimeout(vehicles_timer[type]);
- }
- });
-
- fail(lang.error_refresh);
- }, 1800000);
}
init();
--
Gitblit v1.9.1