Add ability to remove customer markers via status publish #299

This commit is contained in:
Kendrick Chan 2020-01-27 04:04:30 +08:00
parent a5a95a45d0
commit 2d6193318a
5 changed files with 52 additions and 8 deletions

View file

@ -88,6 +88,20 @@ class DashboardMap {
);
}
removeCustomerMarker(id) {
console.log('removing customer marker for ' + id);
var layer_group = this.layer_groups.customer;
var markers = this.cust_markers;
// no customer marker with that id
if (!markers.hasOwnProperty(id)) {
console.log('no such marker to remove');
return;
}
layer_group.removeLayer(markers[id]);
}
putRiderAvailableMarker(id, lat, lng) {
this.putMarker(
id,

View file

@ -34,6 +34,7 @@ class MapEventHandler {
// subscribe to jo locations
console.log('subscribing to ' + my.options.channels.jo_location);
my.mqtt.subscribe(my.options.channels.jo_location);
my.mqtt.subscribe(my.options.channels.jo_status);
}
onMessage(msg) {
@ -77,10 +78,10 @@ class MapEventHandler {
handleJobOrder(chan_split, payload) {
console.log("jo message");
var id = chan_split[1];
switch (chan_split[2]) {
case "location":
var my = this;
var id = chan_split[1];
// var my = this;
console.log("got location for jo " + id + " - " + payload);
var pl_split = payload.split(':');
@ -96,6 +97,14 @@ class MapEventHandler {
this.dashmap.putCustomerMarker(id, lat, lng);
break;
case "status":
switch (payload) {
case 'cancel':
case 'fulfill':
case 'delete':
this.dashmap.removeCustomerMarker(id);
break;
}
}
}
}

View file

@ -36,8 +36,10 @@ class JobOrderActiveCacheListener
break;
// inactive
case JOStatus::CANCELLED:
$this->processInactiveJO($jo, 'cancel');
break;
case JOStatus::FULFILLED:
$this->processInactiveJO($jo);
$this->processInactiveJO($jo, 'fulfill');
break;
}
}
@ -59,8 +61,10 @@ class JobOrderActiveCacheListener
break;
// inactive
case JOStatus::CANCELLED:
$this->processInactiveJO($jo, 'cancel');
break;
case JOStatus::FULFILLED:
$this->processInactiveJO($jo);
$this->processInactiveJO($jo, 'fulfill');
break;
}
}
@ -68,14 +72,17 @@ class JobOrderActiveCacheListener
// when a job order is deleted
public function postRemove(JobOrder $jo, LifecycleEventArgs $args)
{
$this->processInactiveJO($jo, 'delete');
}
protected function processActiveJO($jo)
{
// save in cache
$jo_cache->addActiveJobOrder($jo);
$this->jo_cache->addActiveJobOrder($jo);
// publish to mqtt
$coords = $jo->getCoordinates();
// TODO: do we put the key in config?
$this->mqtt->publish(
'jo/' . $jo->getID() . '/location',
@ -83,11 +90,16 @@ class JobOrderActiveCacheListener
);
}
protected function processInactiveJO($jo)
protected function processInactiveJO($jo, $status = 'cancel')
{
// TODO: remove from redis cache
// remove from redis cache
$this->jo_cache->removeActiveJobOrder($jo);
// TODO: publich to mqtt
$this->mqtt->publish(
'jo/' . $jo->getID() . '/status',
$status
);
}
}

View file

@ -55,4 +55,12 @@ class JobOrderCache
// error_log(print_r($all_jo, true));
return $jo_locs;
}
public function removeActiveJobOrder(JobOrder $jo)
{
$this->redis->zrem(
$this->active_jo_key,
$jo->getID()
);
}
}

View file

@ -45,7 +45,8 @@ function initEventHandler(dashmap) {
var options = {
'channels': {
'rider_location': 'rider/+/location',
'jo_location': 'jo/+/location'
'jo_location': 'jo/+/location',
'jo_status': 'jo/+/status'
},
};