Merge branch '380-resq-mobile-customer-icon-wrong-color-in-realtime-update' of gitlab.com:jankstudio/resq into 381-resq-auto-assign-with-advance-order
This commit is contained in:
commit
cc055f34f9
5 changed files with 63 additions and 41 deletions
|
|
@ -1,9 +1,8 @@
|
||||||
class DashboardMap {
|
class DashboardMap {
|
||||||
constructor(options, rider_markers, cust_markers, mc_markers) {
|
constructor(options, rider_markers, cust_markers) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.rider_markers = rider_markers;
|
this.rider_markers = rider_markers;
|
||||||
this.cust_markers = cust_markers;
|
this.cust_markers = cust_markers;
|
||||||
this.mobile_cust_markers = mc_markers;
|
|
||||||
|
|
||||||
// layer groups
|
// layer groups
|
||||||
this.layer_groups = {
|
this.layer_groups = {
|
||||||
|
|
@ -81,6 +80,30 @@ class DashboardMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switchJobOrderOrigin(jo_id, jo_origin) {
|
||||||
|
console.log('switching jo ' + jo_id + ' to ' + jo_origin);
|
||||||
|
|
||||||
|
// find the marker
|
||||||
|
if (this.cust_markers.hasOwnProperty(jo_id)) {
|
||||||
|
var marker = this.cust_markers[jo_id];
|
||||||
|
} else {
|
||||||
|
console.log('marker not found for customer');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add marker to proper layer group
|
||||||
|
console.log(jo_origin);
|
||||||
|
if (jo_origin == 'mobile') {
|
||||||
|
this.layer_groups.customer.removeLayer(marker);
|
||||||
|
this.layer_groups.mobile_customer.addLayer(marker);
|
||||||
|
marker.setIcon(this.options.icons.mobile_customer);
|
||||||
|
} else {
|
||||||
|
this.layer_groups.mobile_customer.removeLayer(marker);
|
||||||
|
this.layer_groups.customer.addLayer(marker);
|
||||||
|
marker.setIcon(this.options.icons.customer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
putMarker(id, lat, lng, markers, icon, layer_group, popup_url) {
|
putMarker(id, lat, lng, markers, icon, layer_group, popup_url) {
|
||||||
var my = this;
|
var my = this;
|
||||||
// existing marker
|
// existing marker
|
||||||
|
|
@ -106,7 +129,7 @@ class DashboardMap {
|
||||||
$.get(url).done(function(data) {
|
$.get(url).done(function(data) {
|
||||||
popup.setContent(data);
|
popup.setContent(data);
|
||||||
popup.update();
|
popup.update();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +148,6 @@ class DashboardMap {
|
||||||
|
|
||||||
removeCustomerMarker(id) {
|
removeCustomerMarker(id) {
|
||||||
console.log('removing customer marker for ' + id);
|
console.log('removing customer marker for ' + id);
|
||||||
var layer_group = this.layer_groups.customer;
|
|
||||||
var markers = this.cust_markers;
|
var markers = this.cust_markers;
|
||||||
|
|
||||||
// no customer marker with that id
|
// no customer marker with that id
|
||||||
|
|
@ -134,7 +156,8 @@ class DashboardMap {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
layer_group.removeLayer(markers[id]);
|
this.layer_groups.customer.removeLayer(markers[id]);
|
||||||
|
this.layer_groups.mobile_customer.removeLayer(markers[id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
putMobileCustomerMarker(id, lat, lng) {
|
putMobileCustomerMarker(id, lat, lng) {
|
||||||
|
|
@ -142,27 +165,13 @@ class DashboardMap {
|
||||||
id,
|
id,
|
||||||
lat,
|
lat,
|
||||||
lng,
|
lng,
|
||||||
this.mobile_cust_markers,
|
this.cust_markers,
|
||||||
this.options.icons.mobile_customer,
|
this.options.icons.mobile_customer,
|
||||||
this.layer_groups.mobile_customer,
|
this.layer_groups.mobile_customer,
|
||||||
this.options.cust_popup_url
|
this.options.cust_popup_url
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
removeMobileCustomerMarker(id) {
|
|
||||||
console.log('removing mobile customer marker for ' + id);
|
|
||||||
var layer_group = this.layer_groups.mobile_customer;
|
|
||||||
var markers = this.mobile_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) {
|
putRiderAvailableMarker(id, lat, lng) {
|
||||||
this.putMarker(
|
this.putMarker(
|
||||||
id,
|
id,
|
||||||
|
|
@ -215,22 +224,16 @@ class DashboardMap {
|
||||||
// get riders and job orders
|
// get riders and job orders
|
||||||
var riders = response.riders;
|
var riders = response.riders;
|
||||||
var jos = response.jos;
|
var jos = response.jos;
|
||||||
var mobile_jos = response.mobile_jos;
|
|
||||||
|
|
||||||
// job orders
|
// job orders
|
||||||
$.each(jos, function(id, data) {
|
$.each(jos, function(id, data) {
|
||||||
var lat = data.latitude;
|
var lat = data.latitude;
|
||||||
var lng = data.longitude;
|
var lng = data.longitude;
|
||||||
|
|
||||||
my.putCustomerMarker(id, lat, lng);
|
if (data.is_mobile)
|
||||||
});
|
my.putMobileCustomerMarker(id, lat, lng);
|
||||||
|
else
|
||||||
// mobile app job orders
|
my.putCustomerMarker(id, lat, lng);
|
||||||
$.each(mobile_jos, function(id, data) {
|
|
||||||
var lat = data.latitude;
|
|
||||||
var lng = data.longitude;
|
|
||||||
|
|
||||||
my.putMobileCustomerMarker(id, lat, lng);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// riders
|
// riders
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,10 @@ class MapEventHandler {
|
||||||
// subscribe to jo status
|
// subscribe to jo status
|
||||||
console.log('subscribing to ' + my.options.channels.jo_status);
|
console.log('subscribing to ' + my.options.channels.jo_status);
|
||||||
my.mqtt.subscribe(my.options.channels.jo_status);
|
my.mqtt.subscribe(my.options.channels.jo_status);
|
||||||
|
|
||||||
|
// subscribe to jo origin
|
||||||
|
console.log('subscribing to ' + my.options.channels.jo_origin);
|
||||||
|
my.mqtt.subscribe(my.options.channels.jo_origin);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -134,6 +138,14 @@ class MapEventHandler {
|
||||||
this.dashmap.removeCustomerMarker(id);
|
this.dashmap.removeCustomerMarker(id);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case "origin":
|
||||||
|
console.log("got origin for jo " + payload);
|
||||||
|
if (payload == 'mobile_app')
|
||||||
|
{
|
||||||
|
this.dashmap.switchJobOrderOrigin(chan_split[1], 'mobile');
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,8 +65,7 @@ class HomeController extends Controller
|
||||||
$riders[$rider_id]['has_jo'] = true;
|
$riders[$rider_id]['has_jo'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get JOs with transaction origin TransactionOrigin::MOBILE_APP from list of active_jos
|
// get active JOs and check transaction origin for TransactionOrigin::MOBILE_APP
|
||||||
$mobile_jos = [];
|
|
||||||
foreach ($active_jos as $jo_id => $jo_data)
|
foreach ($active_jos as $jo_id => $jo_data)
|
||||||
{
|
{
|
||||||
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
|
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
|
||||||
|
|
@ -78,8 +77,11 @@ class HomeController extends Controller
|
||||||
|
|
||||||
if ($jo->getSource() == TransactionOrigin::MOBILE_APP)
|
if ($jo->getSource() == TransactionOrigin::MOBILE_APP)
|
||||||
{
|
{
|
||||||
$mobile_jos[$jo_id] = $jo_data;
|
$active_jos[$jo_id]['is_mobile'] = true;
|
||||||
unset($active_jos[$jo_id]);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$active_jos[$jo_id]['is_mobile'] = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,7 +142,6 @@ class HomeController extends Controller
|
||||||
return $this->json([
|
return $this->json([
|
||||||
'jos' => $active_jos,
|
'jos' => $active_jos,
|
||||||
'riders' => $riders,
|
'riders' => $riders,
|
||||||
'mobile_jos' => $mobile_jos,
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,13 @@ class JobOrderActiveCacheListener
|
||||||
// send jo location
|
// send jo location
|
||||||
$this->mqtt->publish(
|
$this->mqtt->publish(
|
||||||
'jo/' . $jo->getID() . '/location',
|
'jo/' . $jo->getID() . '/location',
|
||||||
$coords->getLatitude() . ':' . $coords->getLongitude()
|
$coords->getLatitude() . ':' . $coords->getLongitude()
|
||||||
|
);
|
||||||
|
|
||||||
|
// send transaction origin
|
||||||
|
$this->mqtt->publish(
|
||||||
|
'jo/' . $jo->getID() . '/origin',
|
||||||
|
$jo->getSource()
|
||||||
);
|
);
|
||||||
|
|
||||||
// TODO: do we still need to send jo status?
|
// TODO: do we still need to send jo status?
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function initMap(r_markers, c_markers, mc_markers, icons) {
|
function initMap(r_markers, c_markers, icons) {
|
||||||
var default_lat = {% trans %}default_lat{% endtrans %};
|
var default_lat = {% trans %}default_lat{% endtrans %};
|
||||||
var default_lng = {% trans %}default_long{% endtrans %};
|
var default_lng = {% trans %}default_long{% endtrans %};
|
||||||
|
|
||||||
|
|
@ -38,7 +38,7 @@ function initMap(r_markers, c_markers, mc_markers, icons) {
|
||||||
'icons': icons
|
'icons': icons
|
||||||
};
|
};
|
||||||
|
|
||||||
var dashmap = new DashboardMap(options, r_markers, c_markers, mc_markers);
|
var dashmap = new DashboardMap(options, r_markers, c_markers);
|
||||||
dashmap.initialize();
|
dashmap.initialize();
|
||||||
dashmap.loadLocations('{{ path('rider_locations') }}');
|
dashmap.loadLocations('{{ path('rider_locations') }}');
|
||||||
|
|
||||||
|
|
@ -53,7 +53,8 @@ function initEventHandler(dashmap) {
|
||||||
'rider_location': 'rider/+/location',
|
'rider_location': 'rider/+/location',
|
||||||
'rider_status': 'rider/+/status',
|
'rider_status': 'rider/+/status',
|
||||||
'jo_location': 'jo/+/location',
|
'jo_location': 'jo/+/location',
|
||||||
'jo_status': 'jo/+/status'
|
'jo_status': 'jo/+/status',
|
||||||
|
'jo_origin': 'jo/+/origin'
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -92,9 +93,8 @@ var icons = {
|
||||||
|
|
||||||
var r_markers = {};
|
var r_markers = {};
|
||||||
var c_markers = {};
|
var c_markers = {};
|
||||||
var mc_markers = {};
|
|
||||||
|
|
||||||
var dashmap = initMap(r_markers, c_markers, mc_markers, icons);
|
var dashmap = initMap(r_markers, c_markers, icons);
|
||||||
initEventHandler(dashmap, icons);
|
initEventHandler(dashmap, icons);
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue