Compare commits
10 commits
master
...
466-cmb-ri
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3c470177ea | ||
|
|
bf5a5c602f | ||
|
|
9a444051e4 | ||
|
|
6ff3ae8dbe | ||
|
|
66e46c4bad | ||
|
|
b20c61a830 | ||
|
|
b9706ede89 | ||
|
|
90918c49ef | ||
|
|
8006545242 | ||
|
|
74039a8011 |
7 changed files with 208 additions and 20 deletions
|
|
@ -56,3 +56,14 @@ rider_priority_down_jo:
|
|||
path: /riders/{id}/priority_down/{jo_id}
|
||||
controller: App\Controller\RiderController::priorityDownJO
|
||||
methods: [GET]
|
||||
|
||||
rider_ajax_avialable:
|
||||
path: /riders/{id}/available
|
||||
controller: App\Controller\RiderController::ajaxAvailable
|
||||
methods: [GET]
|
||||
|
||||
rider_ajax_rider_name:
|
||||
path: /riders/{id}/name
|
||||
controller: App\Controller\RiderController::ajaxRiderName
|
||||
methods: [GET]
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ class DashboardMap {
|
|||
this.options = options;
|
||||
this.rider_markers = rider_markers;
|
||||
this.cust_markers = cust_markers;
|
||||
this.rider_availability = {};
|
||||
this.rider_names = {};
|
||||
|
||||
// layer groups
|
||||
this.layer_groups = {
|
||||
|
|
@ -146,6 +148,49 @@ class DashboardMap {
|
|||
}
|
||||
}
|
||||
|
||||
putMarkerWithLabel(id, lat, lng, markers, icon, layer_group, popup_url, name) {
|
||||
var my = this;
|
||||
// existing marker
|
||||
if (markers.hasOwnProperty(id)) {
|
||||
markers[id].setLatLng(L.latLng(lat, lng));
|
||||
return;
|
||||
}
|
||||
|
||||
// new marker
|
||||
// add label
|
||||
markers[id] = L.marker(
|
||||
[lat, lng],
|
||||
{ icon: icon }
|
||||
);
|
||||
|
||||
var marker_label = id + ' - ' + name;
|
||||
|
||||
markers[id].bindTooltip(marker_label,
|
||||
{
|
||||
permanent: true,
|
||||
direction: 'right'
|
||||
}
|
||||
);
|
||||
|
||||
markers[id].addTo(layer_group);
|
||||
|
||||
if (my.options.enable_popup) {
|
||||
markers[id].bindPopup('Loading...');
|
||||
|
||||
// bind ajax for popup
|
||||
markers[id].on('click', function(e) {
|
||||
var popup = e.target.getPopup();
|
||||
var url = popup_url.replace('[id]', id);
|
||||
console.log(url);
|
||||
$.get(url).done(function(data) {
|
||||
popup.setContent(data);
|
||||
popup.update();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
putCustomerMarker(id, lat, lng) {
|
||||
this.putMarker(
|
||||
id,
|
||||
|
|
@ -170,6 +215,8 @@ class DashboardMap {
|
|||
|
||||
this.layer_groups.customer.removeLayer(markers[id]);
|
||||
this.layer_groups.mobile_customer.removeLayer(markers[id]);
|
||||
|
||||
delete markers[id];
|
||||
}
|
||||
|
||||
putMobileCustomerMarker(id, lat, lng) {
|
||||
|
|
@ -184,27 +231,29 @@ class DashboardMap {
|
|||
);
|
||||
}
|
||||
|
||||
putRiderAvailableMarker(id, lat, lng) {
|
||||
this.putMarker(
|
||||
putRiderAvailableMarker(id, lat, lng, name) {
|
||||
this.putMarkerWithLabel(
|
||||
id,
|
||||
lat,
|
||||
lng,
|
||||
this.rider_markers,
|
||||
this.options.icons.rider_available,
|
||||
this.layer_groups.rider_available,
|
||||
this.options.rider_popup_url
|
||||
this.options.rider_popup_url,
|
||||
name
|
||||
);
|
||||
}
|
||||
|
||||
putRiderActiveJOMarker(id, lat, lng) {
|
||||
this.putMarker(
|
||||
putRiderActiveJOMarker(id, lat, lng, name) {
|
||||
this.putMarkerWithLabel(
|
||||
id,
|
||||
lat,
|
||||
lng,
|
||||
this.rider_markers,
|
||||
this.options.icons.rider_active_jo,
|
||||
this.layer_groups.rider_active_jo,
|
||||
this.options.rider_popup_url
|
||||
this.options.rider_popup_url,
|
||||
name
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -219,6 +268,8 @@ class DashboardMap {
|
|||
|
||||
this.layer_groups.rider_active_jo.removeLayer(markers[id]);
|
||||
this.layer_groups.rider_available.removeLayer(markers[id]);
|
||||
|
||||
delete markers[id];
|
||||
}
|
||||
|
||||
loadLocations(location_url) {
|
||||
|
|
@ -252,14 +303,43 @@ class DashboardMap {
|
|||
$.each(riders, function(id, data) {
|
||||
var lat = data.latitude;
|
||||
var lng = data.longitude;
|
||||
var name = '';
|
||||
|
||||
if (data.has_jo)
|
||||
my.putRiderActiveJOMarker(id, lat, lng);
|
||||
else
|
||||
my.putRiderAvailableMarker(id, lat, lng);
|
||||
if (my.rider_names.hasOwnProperty(id)) {
|
||||
name = my.rider_names[id];
|
||||
|
||||
if (data.has_jo)
|
||||
my.putRiderActiveJOMarker(id, lat, lng, name);
|
||||
else
|
||||
my.putRiderAvailableMarker(id, lat, lng, name)
|
||||
|
||||
} else {
|
||||
getRiderName(id, my.options.rider_name_url, function(name) {
|
||||
my.rider_names[id] = name;
|
||||
|
||||
if (data.has_jo)
|
||||
my.putRiderActiveJOMarker(id, lat, lng, name);
|
||||
else
|
||||
my.putRiderAvailableMarker(id, lat, lng, name)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// console.log(rider_markers);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getRiderName(id, url, callback) {
|
||||
var name = '';
|
||||
var rider_url = url.replace('[id]', id);
|
||||
|
||||
$.ajax({
|
||||
method: "GET",
|
||||
url: rider_url
|
||||
}).done(function(response) {
|
||||
name = response.rider_name;
|
||||
callback(name);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
class MapEventHandler {
|
||||
constructor(options, dashmap) {
|
||||
constructor(options, dashmap, ssl) {
|
||||
this.options = options;
|
||||
this.dashmap = dashmap;
|
||||
this.ssl = ssl;
|
||||
}
|
||||
|
||||
connect(user_id, host, port) {
|
||||
|
|
@ -11,7 +12,7 @@ class MapEventHandler {
|
|||
|
||||
this.mqtt = new Paho.MQTT.Client(host, port, client_id);
|
||||
var options = {
|
||||
// useSSL: true,
|
||||
useSSL: this.ssl,
|
||||
timeout: 3,
|
||||
invocationContext: this,
|
||||
onSuccess: this.onConnect.bind(this),
|
||||
|
|
@ -35,6 +36,10 @@ class MapEventHandler {
|
|||
// subscribe to rider status
|
||||
console.log('subscribing to ' + my.options.channels.rider_status);
|
||||
my.mqtt.subscribe(my.options.channels.rider_status);
|
||||
|
||||
// subscribe to rider availability
|
||||
console.log('subscribing to ' + my.options.channels.rider_availability);
|
||||
my.mqtt.subscribe(my.options.channels.rider_availability);
|
||||
}
|
||||
|
||||
if (my.options.track_jo) {
|
||||
|
|
@ -55,7 +60,7 @@ class MapEventHandler {
|
|||
|
||||
onMessage(msg) {
|
||||
// console.log(msg);
|
||||
console.log('received message');
|
||||
// console.log('received message');
|
||||
|
||||
var channel = msg.destinationName;
|
||||
var chan_split = channel.split('/');
|
||||
|
|
@ -73,12 +78,50 @@ class MapEventHandler {
|
|||
}
|
||||
|
||||
handleRider(chan_split, payload) {
|
||||
console.log("rider message");
|
||||
// console.log("rider message");
|
||||
var rider_id = chan_split[1];
|
||||
switch (chan_split[2]) {
|
||||
case "availability":
|
||||
console.log("got availability for rider " + chan_split[1] + " - " + payload);
|
||||
var obj = JSON.parse(payload);
|
||||
|
||||
var status = obj.status;
|
||||
console.log("status " + status);
|
||||
switch (status) {
|
||||
case 'rider_offline':
|
||||
this.dashmap.rider_availability[chan_split[1]] = false;
|
||||
this.dashmap.removeRiderMarker(chan_split[1]);
|
||||
break;
|
||||
case 'rider_online':
|
||||
this.dashmap.rider_availability[chan_split[1]] = true;
|
||||
var lat = parseFloat(obj.latitude);
|
||||
var lng = parseFloat(obj.longitude);
|
||||
|
||||
// cheeck if rider is available / unavailable
|
||||
// TODO: make url not hardcoded
|
||||
var dashmap = this.dashmap;
|
||||
$.get('https://cmbdev.wildcard.cc/riders/' + chan_split[1] + '/available').done(function(data) {
|
||||
console.log('rider availability - ' + data);
|
||||
switch (data) {
|
||||
case 'available':
|
||||
console.log('putting available marker ' + chan_split[1] + ' ' + lat + ':' + lng);
|
||||
dashmap.switchRiderStatus(chan_split[1], 'available');
|
||||
dashmap.putRiderAvailableMarker(chan_split[1], lat, lng);
|
||||
break;
|
||||
case 'unavailable':
|
||||
console.log('putting active jo marker ' + chan_split[1] + ' ' + lat + ':' + lng);
|
||||
dashmap.switchRiderStatus(chan_split[1], 'jo');
|
||||
dashmap.putRiderActiveJOMarker(chan_split[1], lat, lng);
|
||||
break;
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "location":
|
||||
console.log("got location for rider " + chan_split[1] + " - " + payload);
|
||||
// console.log("got location for rider " + chan_split[1] + " - " + payload
|
||||
var pl_split = payload.split(':');
|
||||
console.log(pl_split);
|
||||
// console.log(pl_split);
|
||||
|
||||
// check for correct format
|
||||
if (pl_split.length != 2)
|
||||
|
|
@ -87,8 +130,21 @@ 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);
|
||||
var display_marker = true;
|
||||
if (this.dashmap.rider_availability.hasOwnProperty(chan_split[1])) {
|
||||
if (!this.dashmap.rider_availability[chan_split[1]]) {
|
||||
console.log('NOT displaying marker for inactive rider');
|
||||
display_marker = false;
|
||||
}
|
||||
} else {
|
||||
console.log('rider not in availability check');
|
||||
}
|
||||
|
||||
// TODO: cache rider availability (available vs active jo) status and check before displaying icon
|
||||
// NOTE: we really should fix our terms since available can mean many things
|
||||
if (display_marker) {
|
||||
this.dashmap.putRiderAvailableMarker(chan_split[1], lat, lng);
|
||||
}
|
||||
break;
|
||||
case "status":
|
||||
console.log("got status for rider " + chan_split[1] + " - " + payload);
|
||||
|
|
|
|||
|
|
@ -596,4 +596,38 @@ class RiderController extends Controller
|
|||
|
||||
return $this->redirecttoRoute('rider_update', ['id' => $rider->getID()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @ParamConverter("rider", class="App\Entity\Rider")
|
||||
*/
|
||||
public function ajaxAvailable(EntityManagerInterface $em, Rider $rider)
|
||||
{
|
||||
$jo = $rider->getRiderActiveJobOrder();
|
||||
if ($jo == null || $jo->isClosed())
|
||||
$avail = 'available';
|
||||
else
|
||||
$avail = 'unavailable';
|
||||
|
||||
$response = new Response(
|
||||
$avail,
|
||||
Response::HTTP_OK,
|
||||
['content-type' => 'text/plain']
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ParamConverter("rider", class="App\Entity\Rider")
|
||||
*/
|
||||
public function ajaxRiderName(EntityManagerInterface $em, Rider $rider)
|
||||
{
|
||||
$rider_name = '';
|
||||
if ($rider != null)
|
||||
$rider_name = $rider->getFullName();
|
||||
|
||||
return $this->json([
|
||||
'rider_name' => $rider_name,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@ class CMBServiceType extends NameValue
|
|||
{
|
||||
const BATTERY_REPLACEMENT_NEW = 'battery_new';
|
||||
const BATTERY_REPLACEMENT_WARRANTY = 'battery_warranty';
|
||||
const WARRANTY_CLAIM = 'warranty_claim';
|
||||
const JUMPSTART = 'jumpstart';
|
||||
|
||||
const COLLECTION = [
|
||||
'battery_new' => 'Battery Sales',
|
||||
'battery_warranty' => 'Under Warranty',
|
||||
'battery_warranty' => 'Warranty Replacement',
|
||||
'warranty_claim' => 'Warranty Claim',
|
||||
'jumpstart' => 'Jumpstart',
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -86,6 +86,10 @@ class CMBInvoiceGenerator implements InvoiceGeneratorInterface
|
|||
case CMBServiceType::BATTERY_REPLACEMENT_WARRANTY:
|
||||
$this->processWarranty($total, $criteria, $invoice);
|
||||
break;
|
||||
case CMBServiceType::WARRANTY_CLAIM:
|
||||
// TODO: this will change once we confirm what needs to be computed
|
||||
$this->processOtherServices($total, $invoice, $stype);
|
||||
break;
|
||||
//case ServiceType::POST_RECHARGED:
|
||||
// $this->processRecharge($total, $invoice);
|
||||
// break;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@ function initMap(r_markers, c_markers, icons) {
|
|||
'zoom': 13,
|
||||
'rider_popup_url': '/riders/[id]/popup',
|
||||
'cust_popup_url': '/job-order/[id]/popup',
|
||||
'icons': icons
|
||||
'icons': icons,
|
||||
'rider_name_url': '/riders/[id]/name'
|
||||
};
|
||||
|
||||
var dashmap = new DashboardMap(options, r_markers, c_markers);
|
||||
|
|
|
|||
Loading…
Reference in a new issue