From a30f9b2ce8cd6828214abe0b59f408e2554a67a2 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 17 Apr 2020 05:17:00 +0000 Subject: [PATCH 1/2] Modify how mobile customer markers are loaded when dashboard map is loaded. #380 --- public/assets/js/dashboard_map.js | 63 ++++++++++++++++--------------- src/Controller/HomeController.php | 11 +++--- templates/home.html.twig | 7 ++-- 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/public/assets/js/dashboard_map.js b/public/assets/js/dashboard_map.js index 16f8a78d..874883a7 100644 --- a/public/assets/js/dashboard_map.js +++ b/public/assets/js/dashboard_map.js @@ -1,9 +1,8 @@ class DashboardMap { - constructor(options, rider_markers, cust_markers, mc_markers) { + constructor(options, rider_markers, cust_markers) { this.options = options; this.rider_markers = rider_markers; this.cust_markers = cust_markers; - this.mobile_cust_markers = mc_markers; // 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) { var my = this; // existing marker @@ -106,7 +129,7 @@ class DashboardMap { $.get(url).done(function(data) { popup.setContent(data); popup.update(); - }); + }); }); } } @@ -125,7 +148,6 @@ 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 @@ -134,7 +156,8 @@ class DashboardMap { 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) { @@ -142,27 +165,13 @@ class DashboardMap { id, lat, lng, - this.mobile_cust_markers, + this.cust_markers, this.options.icons.mobile_customer, this.layer_groups.mobile_customer, 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) { this.putMarker( id, @@ -215,22 +224,16 @@ class DashboardMap { // get riders and job orders var riders = response.riders; var jos = response.jos; - var mobile_jos = response.mobile_jos; // job orders $.each(jos, function(id, data) { var lat = data.latitude; var lng = data.longitude; - my.putCustomerMarker(id, lat, lng); - }); - - // mobile app job orders - $.each(mobile_jos, function(id, data) { - var lat = data.latitude; - var lng = data.longitude; - - my.putMobileCustomerMarker(id, lat, lng); + if (data.is_mobile) + my.putMobileCustomerMarker(id, lat, lng); + else + my.putCustomerMarker(id, lat, lng); }); // riders diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index cbc4afa7..1a157b78 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -65,8 +65,7 @@ class HomeController extends Controller $riders[$rider_id]['has_jo'] = true; } - // get JOs with transaction origin TransactionOrigin::MOBILE_APP from list of active_jos - $mobile_jos = []; + // get active JOs and check transaction origin for TransactionOrigin::MOBILE_APP foreach ($active_jos as $jo_id => $jo_data) { $jo = $em->getRepository(JobOrder::class)->find($jo_id); @@ -78,8 +77,11 @@ class HomeController extends Controller if ($jo->getSource() == TransactionOrigin::MOBILE_APP) { - $mobile_jos[$jo_id] = $jo_data; - unset($active_jos[$jo_id]); + $active_jos[$jo_id]['is_mobile'] = true; + } + else + { + $active_jos[$jo_id]['is_mobile'] = false; } } @@ -140,7 +142,6 @@ class HomeController extends Controller return $this->json([ 'jos' => $active_jos, 'riders' => $riders, - 'mobile_jos' => $mobile_jos, ]); } diff --git a/templates/home.html.twig b/templates/home.html.twig index c9e4953e..aa3382eb 100644 --- a/templates/home.html.twig +++ b/templates/home.html.twig @@ -20,7 +20,7 @@ {% endif %}