@fleetbase/fleetops-engine 0.6.11 → 0.6.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/addon/components/customer/orders.js +6 -8
  2. package/addon/components/layout/fleet-ops-sidebar.js +8 -0
  3. package/addon/components/leaflet-tracking-marker.js +19 -0
  4. package/addon/components/live-map.hbs +5 -0
  5. package/addon/components/live-map.js +6 -8
  6. package/addon/components/order-config/fields-editor.js +1 -1
  7. package/addon/components/route-optimization-engine-select-button.hbs +25 -0
  8. package/addon/components/route-optimization-engine-select-button.js +13 -0
  9. package/addon/controllers/operations/orders/index/new.js +78 -171
  10. package/addon/controllers/operations/orders/index/view.js +30 -29
  11. package/addon/controllers/settings/routing.js +47 -0
  12. package/addon/engine.js +27 -0
  13. package/addon/routes/application.js +8 -0
  14. package/addon/routes/operations/orders/index/view.js +12 -3
  15. package/addon/routes/settings/routing.js +3 -0
  16. package/addon/routes.js +1 -0
  17. package/addon/services/leaflet-router-control.js +64 -0
  18. package/addon/services/osrm.js +46 -0
  19. package/addon/services/route-optimization-interface.js +9 -0
  20. package/addon/services/route-optimization.js +67 -0
  21. package/addon/templates/operations/orders/index/new.hbs +21 -16
  22. package/addon/templates/settings/routing.hbs +32 -0
  23. package/app/components/route-optimization-engine-select-button.js +1 -0
  24. package/app/controllers/settings/routing.js +1 -0
  25. package/app/routes/settings/routing.js +1 -0
  26. package/app/services/leaflet-router-control.js +1 -0
  27. package/app/services/osrm.js +1 -0
  28. package/app/services/route-optimization-interface.js +1 -0
  29. package/app/services/route-optimization.js +1 -0
  30. package/app/templates/settings/routing.js +1 -0
  31. package/composer.json +1 -1
  32. package/extension.json +1 -1
  33. package/package.json +2 -2
  34. package/server/config/api.php +10 -1
  35. package/server/src/Auth/Schemas/FleetOps.php +5 -0
  36. package/server/src/Console/Commands/DebugOrderTracker.php +5 -5
  37. package/server/src/Events/EntityActivityChanged.php +118 -0
  38. package/server/src/Events/EntityCompleted.php +118 -0
  39. package/server/src/Http/Controllers/Api/v1/ServiceAreaController.php +3 -1
  40. package/server/src/Http/Controllers/Internal/v1/OrderController.php +16 -13
  41. package/server/src/Http/Controllers/Internal/v1/SettingController.php +31 -1
  42. package/server/src/Http/Resources/v1/Waypoint.php +1 -1
  43. package/server/src/Models/Order.php +44 -8
  44. package/server/src/Models/Payload.php +29 -10
  45. package/server/src/Models/Place.php +49 -13
  46. package/server/src/Support/Geocoding.php +0 -2
  47. package/server/src/routes.php +2 -0
  48. package/translations/en-us.yaml +5 -0
@@ -366,6 +366,22 @@ class Place extends Model
366
366
  return static::createFromGoogleAddress($results->first(), $saveInstance);
367
367
  }
368
368
 
369
+ /**
370
+ * Create a new Place instance from a geocoding lookup.
371
+ *
372
+ * @return \Fleetbase\Models\Place|null
373
+ */
374
+ public static function getValuesFromGeocodingLookup(string $address): array
375
+ {
376
+ $results = \Geocoder\Laravel\Facades\Geocoder::geocode($address)->get();
377
+
378
+ if ($results->isEmpty() || !$results->first()) {
379
+ return ['street1' => $address];
380
+ }
381
+
382
+ return static::getGoogleAddressArray($results->first());
383
+ }
384
+
369
385
  /**
370
386
  * Create a new Place instance from a geocoding lookup.
371
387
  *
@@ -482,12 +498,12 @@ class Place extends Model
482
498
  if (is_string($place)) {
483
499
  // Check if $place is a valid public_id, return matching Place object if found
484
500
  if (Utils::isPublicId($place)) {
485
- return Place::where('public_id', $place)->first();
501
+ return static::where('public_id', $place)->first();
486
502
  }
487
503
 
488
504
  // Check if $place is a valid uuid, return matching Place object if found
489
505
  if (Str::isUuid($place)) {
490
- return Place::where('uuid', $place)->first();
506
+ return static::where('uuid', $place)->first();
491
507
  }
492
508
 
493
509
  // Attempt to find by address or name
@@ -521,12 +537,27 @@ class Place extends Model
521
537
  $uuid = data_get($place, 'uuid');
522
538
 
523
539
  // If $place has a valid uuid and a matching Place object exists, return the uuid
524
- if (Str::isUuid($uuid) && $existingPlace = Place::where('uuid', $uuid)->first()) {
540
+ if (Str::isUuid($uuid) && $existingPlace = static::where('uuid', $uuid)->first()) {
525
541
  return $existingPlace;
526
542
  }
527
543
 
528
- // Otherwise, create a new Place object with the given attributes
529
- return Place::create($place);
544
+ // If has $attributes['address']
545
+ if (!empty($place['address'])) {
546
+ return static::createFromGeocodingLookup($place['address'], $saveInstance);
547
+ }
548
+
549
+ // Perform google lookup to fill address
550
+ $street1 = $place['street1'];
551
+ if ($street1) {
552
+ return static::create(array_merge($place, static::getValuesFromGeocodingLookup($street1)));
553
+ }
554
+
555
+ // Otherwise, create a new Place owith the given attributes
556
+ if (empty($place['location'])) {
557
+ $place['location'] = new SpatialPoint(0, 0);
558
+ }
559
+
560
+ return static::create($place);
530
561
  }
531
562
  // If $place is a GoogleAddress object
532
563
  elseif ($place instanceof \Geocoder\Provider\GoogleMaps\Model\GoogleAddress) {
@@ -547,10 +578,10 @@ class Place extends Model
547
578
  {
548
579
  if (Utils::isCoordinatesStrict($place)) {
549
580
  // create a place from coordinates using reverse loopup
550
- return Place::insertFromCoordinates($place);
581
+ return static::insertFromCoordinates($place);
551
582
  } elseif (is_string($place)) {
552
583
  if (Utils::isPublicId($place)) {
553
- $resolvedPlace = Place::where('public_id', $place)->first();
584
+ $resolvedPlace = static::where('public_id', $place)->first();
554
585
 
555
586
  if ($resolvedPlace) {
556
587
  return $resolvedPlace->uuid;
@@ -558,14 +589,19 @@ class Place extends Model
558
589
  }
559
590
 
560
591
  if (Str::isUuid($place)) {
561
- $resolvedPlace = Place::where('uuid', $place)->first();
592
+ $resolvedPlace = static::where('uuid', $place)->first();
562
593
 
563
594
  if ($resolvedPlace) {
564
595
  return $resolvedPlace->uuid;
565
596
  }
566
597
  }
567
598
 
568
- return Place::insertFromGeocodingLookup($place);
599
+ // handle address if set
600
+ if (!empty($place['address'])) {
601
+ return static::insertFromGeocodingLookup($place['address']);
602
+ }
603
+
604
+ return static::insertFromGeocodingLookup($place);
569
605
  } elseif (is_array($place) || is_object($place)) {
570
606
  // if place already exists just return uuid
571
607
  if (static::isValidPlaceUuid(data_get($place, 'uuid'))) {
@@ -592,12 +628,12 @@ class Place extends Model
592
628
 
593
629
  public static function isValidPlaceUuid($uuid): bool
594
630
  {
595
- return is_string($uuid) && Str::isUuid($uuid) && Place::where('uuid', $uuid)->exists();
631
+ return is_string($uuid) && Str::isUuid($uuid) && static::where('uuid', $uuid)->exists();
596
632
  }
597
633
 
598
634
  public static function isValidPlacePublicId($publicId): bool
599
635
  {
600
- return is_string($publicId) && Utils::isPublicId($publicId) && Place::where('public_id', $publicId)->exists();
636
+ return is_string($publicId) && Utils::isPublicId($publicId) && static::where('public_id', $publicId)->exists();
601
637
  }
602
638
 
603
639
  /**
@@ -717,7 +753,7 @@ class Place extends Model
717
753
  return null;
718
754
  }
719
755
 
720
- $place = Place::createFromGeocodingLookup($address, false);
756
+ $place = static::createFromGeocodingLookup($address, false);
721
757
  foreach ($addressFields as $field => $options) {
722
758
  if ($place->isFillable($field) && empty($place->{$field})) {
723
759
  $value = Utils::or($row, array_merge([$field], $options['alias']));
@@ -783,7 +819,7 @@ class Place extends Model
783
819
  * $data = ['address' => '123 Main St, Anytown, USA'];
784
820
  * $place = Place::createFromImport($data, true);
785
821
  */
786
- public static function createFromImport(array $row, bool $saveInstance = false): Place
822
+ public static function createFromImport(array $row, bool $saveInstance = false): ?Place
787
823
  {
788
824
  // Filter array for null key values
789
825
  $row = array_filter($row);
@@ -209,8 +209,6 @@ class Geocoding
209
209
  throw $e;
210
210
  }
211
211
 
212
- // dd($reverseQueryResults, $geodingQueryResults);
213
-
214
212
  return $reverseQueryResults->merge($geodingQueryResults)->unique('street1');
215
213
  }
216
214
 
@@ -469,6 +469,8 @@ Route::prefix(config('fleetops.api.routing.prefix', null))->namespace('Fleetbase
469
469
  $router->get('notification-registry', 'SettingController@getNotificationRegistry');
470
470
  $router->get('notification-settings', 'SettingController@getNotificationSettings');
471
471
  $router->post('notification-settings', 'SettingController@saveNotificationSettings');
472
+ $router->get('routing-settings', 'SettingController@getRoutingSettings');
473
+ $router->post('routing-settings', 'SettingController@saveRoutingSettings');
472
474
  }
473
475
  );
474
476
  $router->group(
@@ -298,6 +298,7 @@ fleet-ops:
298
298
  loading-vehicle: Loading fleet vehicles...
299
299
  layout:
300
300
  fleet-ops-sidebar:
301
+ routing: Routing
301
302
  notifications: Notifications
302
303
  payments: Payments
303
304
  navigator-app: Navigator App
@@ -1635,6 +1636,10 @@ fleet-ops:
1635
1636
  fleet-ops-notification-settings: Fleet-Ops Notification Settings
1636
1637
  fleet-ops-notifications: Fleet-Ops Notifications
1637
1638
  configure-notifications: Configure Notifications
1639
+ routing:
1640
+ fleet-ops-routing-settings: Fleet-Ops Routing Settings
1641
+ fleet-ops-routing: Fleet-Ops Routing
1642
+ configure-routing: Configure Routing
1638
1643
  navigator-app:
1639
1644
  navigator-app-settings: Navigator App Settings
1640
1645
  payments: