diff --git a/public/assets/js/dashboard_map.js b/public/assets/js/dashboard_map.js index 4691a11d..6cba7d68 100644 --- a/public/assets/js/dashboard_map.js +++ b/public/assets/js/dashboard_map.js @@ -51,6 +51,32 @@ class DashboardMap { return this.map; } + switchRiderStatus(rider_id, rider_status) { + console.log('switching rider ' + rider_id + ' to ' + rider_status); + + // find the marker + console.log(this.rider_markers); + if (this.rider_markers.hasOwnProperty(rider_id)) { + var marker = this.rider_markers[rider_id]; + } else { + // TODO: call ajax to get location and create marker + console.log('marker not found for rider'); + return true; + } + + // add it to proper layer group + console.log(rider_status); + if (rider_status == 'available') { + this.layer_groups.rider_active_jo.removeLayer(marker); + this.layer_groups.rider_available.addLayer(marker); + marker.setIcon(this.options.icons.rider_available); + } else if (rider_status == 'jo') { + this.layer_groups.rider_available.removeLayer(marker); + this.layer_groups.rider_active_jo.addLayer(marker); + marker.setIcon(this.options.icons.rider_active_jo); + } + } + putMarker(id, lat, lng, markers, icon, layer_group, popup_url) { var my = this; // existing marker @@ -131,6 +157,19 @@ class DashboardMap { ); } + removeRiderMarker(id) { + console.log('removing rider marker for ' + id); + var markers = this.rider_markers; + + if (!markers.hasOwnProperty(id)) { + console.log('no such marker to remove'); + return; + } + + this.layer_groups.rider_active_jo.removeLayer(markers[id]); + this.layer_groups.rider_available.removeLayer(markers[id]); + } + loadLocations(location_url) { console.log(this.rider_markers); var my = this; diff --git a/public/assets/js/map_mqtt.js b/public/assets/js/map_mqtt.js index 6eac1f65..8cf3a6af 100644 --- a/public/assets/js/map_mqtt.js +++ b/public/assets/js/map_mqtt.js @@ -27,18 +27,26 @@ class MapEventHandler { console.log('mqtt connected!'); var my = icontext.invocationContext; - // subscribe to rider locations if (my.options.track_rider) { + // subscribe to rider locations console.log('subscribing to ' + my.options.channels.rider_location); my.mqtt.subscribe(my.options.channels.rider_location); + + // subscribe to rider status + console.log('subscribing to ' + my.options.channels.rider_status); + my.mqtt.subscribe(my.options.channels.rider_status); } - // subscribe to jo locations if (my.options.track_jo) { + // subscribe to jo locations console.log('subscribing to ' + my.options.channels.jo_location); my.mqtt.subscribe(my.options.channels.jo_location); + + // subscribe to jo status + console.log('subscribing to ' + my.options.channels.jo_status); my.mqtt.subscribe(my.options.channels.jo_status); } + } onMessage(msg) { @@ -75,8 +83,24 @@ class MapEventHandler { var lat = parseFloat(pl_split[0]); var lng = parseFloat(pl_split[1]); + // TODO: check if available or not this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng); break; + case "status": + console.log("got status for rider " + chan_split[1] + " - " + payload); + switch (payload) { + case 'available': + this.dashmap.switchRiderStatus(chan_split[1], 'available'); + break; + case 'jo': + console.log('jo status'); + this.dashmap.switchRiderStatus(chan_split[1], 'jo'); + break; + case 'logout': + this.dashmap.removeRiderMarker(chan_split[1]); + break; + } + break; } } @@ -102,6 +126,7 @@ class MapEventHandler { this.dashmap.putCustomerMarker(id, lat, lng); break; case "status": + console.log("got status for jo " + payload); switch (payload) { case 'cancel': case 'fulfill': diff --git a/src/EventListener/JobOrderActiveCacheListener.php b/src/EventListener/JobOrderActiveCacheListener.php index 541ce158..b5dbbd83 100644 --- a/src/EventListener/JobOrderActiveCacheListener.php +++ b/src/EventListener/JobOrderActiveCacheListener.php @@ -92,6 +92,7 @@ class JobOrderActiveCacheListener protected function processInactiveJO($jo, $status = 'cancel') { + error_log('got inactive jo, sending mqtt message for ' . $jo->getID()); // remove from redis cache $this->jo_cache->removeActiveJobOrder($jo); diff --git a/templates/home.html.twig b/templates/home.html.twig index b7ac2c24..19e99011 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -51,6 +51,7 @@ function initEventHandler(dashmap) { 'track_rider': true, 'channels': { 'rider_location': 'rider/+/location', + 'rider_status': 'rider/+/status', 'jo_location': 'jo/+/location', 'jo_status': 'jo/+/status' },