@fleetbase/fleetops-engine 0.1.4 → 0.1.5

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.
@@ -21,6 +21,7 @@ export default class LiveMapComponent extends Component {
21
21
  @service notifications;
22
22
  @service serviceAreas;
23
23
  @service appCache;
24
+ @service engineContext;
24
25
 
25
26
  @tracked routes = [];
26
27
  @tracked drivers = [];
@@ -41,6 +42,7 @@ export default class LiveMapComponent extends Component {
41
42
  @tracked drawControl;
42
43
  @tracked latitude = DEFAULT_LATITUDE;
43
44
  @tracked longitude = DEFAULT_LONGITUDE;
45
+ @tracked skipSetCoordinates = false;
44
46
  @tracked mapId = guidFor(this);
45
47
  @alias('currentUser.latitude') userLatitude;
46
48
  @alias('currentUser.longitude') userLongitude;
@@ -59,6 +61,16 @@ export default class LiveMapComponent extends Component {
59
61
  return tileSourceUrl ?? 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png';
60
62
  }
61
63
 
64
+ /**
65
+ * Creates an instance of LiveMapComponent.
66
+ * @memberof LiveMapComponent
67
+ */
68
+ constructor() {
69
+ super(...arguments);
70
+
71
+ this.skipSetCoordinates = this.args.skipSetCoordinates ?? false;
72
+ }
73
+
62
74
  /**
63
75
  * ----------------------------------------------------------------------------
64
76
  * SETUP
@@ -66,23 +78,31 @@ export default class LiveMapComponent extends Component {
66
78
  *
67
79
  * Functions for initialization and setup.
68
80
  */
69
-
70
81
  @action async setupLiveMap() {
71
- if (this.appCache.has(['map_latitude', 'map_longitude'])) {
72
- this.latitude = this.appCache.get('map_latitude');
73
- this.longitude = this.appCache.get('map_longitude');
74
- this.isReady = true;
75
- }
82
+ // trigger that initial coordinates have been set
83
+ this.engineContext.trigger('livemap.loaded', this);
84
+
85
+ if (this.skipSetCoordinates === false) {
86
+ if (this.appCache.has(['map_latitude', 'map_longitude'])) {
87
+ this.latitude = this.appCache.get('map_latitude');
88
+ this.longitude = this.appCache.get('map_longitude');
89
+ this.isReady = true;
90
+ }
76
91
 
77
- const { latitude, longitude } = await this.getInitialCoordinates();
92
+ const { latitude, longitude } = await this.getInitialCoordinates();
78
93
 
79
- if (this.appCache.doesntHave(['map_latitude', 'map_longitude'])) {
80
- this.appCache.set('map_latitude', latitude);
81
- this.appCache.set('map_longitude', longitude);
94
+ if (this.appCache.doesntHave(['map_latitude', 'map_longitude'])) {
95
+ this.appCache.set('map_latitude', latitude);
96
+ this.appCache.set('map_longitude', longitude);
97
+ }
98
+
99
+ this.latitude = latitude;
100
+ this.longitude = longitude;
82
101
  }
83
102
 
84
- this.latitude = latitude;
85
- this.longitude = longitude;
103
+ // trigger that initial coordinates have been set
104
+ this.engineContext.trigger('livemap.has_coordinates', { latitude: this.latitude, longitude: this.longitude });
105
+
86
106
  this.routes = await this.fetchActiveRoutes();
87
107
  this.drivers = await this.fetchActiveDrivers();
88
108
  this.serviceAreaRecords = await this.fetchServiceAreas();
@@ -93,6 +113,9 @@ export default class LiveMapComponent extends Component {
93
113
  if (typeof this.args.onReady === 'function') {
94
114
  this.args.onReady(this);
95
115
  }
116
+
117
+ // add context event
118
+ this.engineContext.trigger('livemap.ready', this);
96
119
  }
97
120
 
98
121
  @action setMapReference(event) {
@@ -175,6 +198,10 @@ export default class LiveMapComponent extends Component {
175
198
  this[actionName] = callback;
176
199
  }
177
200
 
201
+ @action shouldSkipSettingInitialCoordinates() {
202
+ this.skipSetCoordinates = true;
203
+ }
204
+
178
205
  /**
179
206
  * ----------------------------------------------------------------------------
180
207
  * TRACKED LAYER UTILITIES
@@ -182,7 +209,6 @@ export default class LiveMapComponent extends Component {
182
209
  *
183
210
  * Functions provide utility for managing tracked editable layers.
184
211
  */
185
-
186
212
  @action pushEditableLayer(layer) {
187
213
  if (!this.editableLayers.includes(layer)) {
188
214
  this.editableLayers.pushObject(layer);
@@ -320,7 +346,6 @@ export default class LiveMapComponent extends Component {
320
346
  * Functions are used to help or utilize on Leaflet Layers/ Controls.
321
347
  *
322
348
  */
323
-
324
349
  @action removeDrawingControl() {
325
350
  if (isBlank(this.drawControl)) {
326
351
  return;
@@ -7,7 +7,7 @@
7
7
  <div class="px-5 py-4">
8
8
  <InputGroup @name="Default Adhoc Ping Distance" @type="number" @value={{this.company.options.fleetops.adhoc_distance}} @wrapperClass="mb-0" @helpText="This setting determines the default distance in meters adhoc orders should ping drivers within vicinity of the order pickup point." />
9
9
  <div class="mt-2 px-3 py-1 rounded-lg border border-blue-600 bg-blue-100 flex items-center">
10
- <FaIcon @icon="comment-exclamation" class="text-blue-900 mr-1.5" />
10
+ <FaIcon @icon="triangle-exclamation" class="text-blue-900 mr-1.5" />
11
11
  <span class="text-blue-900 text-xs">Distance must be in meters</span>
12
12
  </div>
13
13
  </div>
@@ -82,6 +82,13 @@ export default class OperationsOrdersIndexViewController extends Controller {
82
82
  */
83
83
  @service hostRouter;
84
84
 
85
+ /**
86
+ * Inject the `engineContext` service
87
+ *
88
+ * @var {Service}
89
+ */
90
+ @service engineContext;
91
+
85
92
  @tracked isLoadingAdditionalData = false;
86
93
  @tracked isWaypointsCollapsed;
87
94
  @tracked leafletRoute;
@@ -200,13 +207,40 @@ export default class OperationsOrdersIndexViewController extends Controller {
200
207
  // always set map layout
201
208
  this.ordersController.setLayoutMode('map');
202
209
 
203
- setTimeout(() => {
204
- this.leafletMap?.liveMap?.hideDrivers();
205
- this.leafletMap?.liveMap?.hideRoutes();
210
+ // create initial setup function which runs 600ms after invoked
211
+ const setup = (ms = 500) => {
212
+ return later(
213
+ this,
214
+ () => {
215
+ this.leafletMap?.liveMap?.hideDrivers();
216
+ this.leafletMap?.liveMap?.hideRoutes();
217
+
218
+ // display order route on map
219
+ this.displayOrderRoute();
220
+ },
221
+ ms
222
+ );
223
+ };
224
+
225
+ // create a display order route only function
226
+ const displayOrderRoute = () => {
227
+ return this.displayOrderRoute();
228
+ };
229
+
230
+ // re-display order routes when livemap has coordinates
231
+ this.engineContext.on('livemap.has_coordinates', this, displayOrderRoute);
232
+
233
+ // when transitioning away kill event listener
234
+ this.hostRouter.on('routeWillChange', () => {
235
+ const isListening = this.engineContext.has('livemap.has_coordinates');
236
+
237
+ if (isListening) {
238
+ this.engineContext.off('livemap.has_coordinates', this, displayOrderRoute);
239
+ }
240
+ });
206
241
 
207
- // display order route on map
208
- this.displayOrderRoute();
209
- }, 600);
242
+ // run setup
243
+ setup();
210
244
  }
211
245
 
212
246
  @action displayOrderRoute() {
@@ -251,16 +285,20 @@ export default class OperationsOrdersIndexViewController extends Controller {
251
285
  this.leafletRoute = routes.firstObject;
252
286
  });
253
287
 
254
- setTimeout(() => {
255
- leafletMap?.flyToBounds(waypoints, {
256
- paddingBottomRight: [200, 0],
257
- maxZoom: 14,
258
- animate: true,
259
- });
260
- leafletMap.once('moveend', function () {
261
- leafletMap.panBy([250, 0]);
262
- });
263
- }, 300);
288
+ later(
289
+ this,
290
+ () => {
291
+ leafletMap?.flyToBounds(waypoints, {
292
+ paddingBottomRight: [200, 0],
293
+ maxZoom: 14,
294
+ animate: true,
295
+ });
296
+ leafletMap.once('moveend', function () {
297
+ leafletMap.panBy([250, 0]);
298
+ });
299
+ },
300
+ 300
301
+ );
264
302
  }
265
303
 
266
304
  /**
@@ -73,6 +73,13 @@ export default class OperationsOrdersIndexController extends Controller {
73
73
  */
74
74
  @service crud;
75
75
 
76
+ /**
77
+ * Inject the `engineContext` service
78
+ *
79
+ * @var {Service}
80
+ */
81
+ @service engineContext;
82
+
76
83
  /**
77
84
  * Queryable parameters for this controller's model
78
85
  *
@@ -520,6 +527,8 @@ export default class OperationsOrdersIndexController extends Controller {
520
527
  if (mode === 'table') {
521
528
  this.isSearchVisible = false;
522
529
  }
530
+
531
+ this.engineContext.trigger('dashboard.layout.changed', mode);
523
532
  }
524
533
 
525
534
  @action setMapReference({ target }) {
@@ -0,0 +1,17 @@
1
+ import Service from '@ember/service';
2
+ import Evented from '@ember/object/evented';
3
+
4
+ export default class EngineContextService extends Service.extend(Evented) {
5
+ options = {};
6
+
7
+ setOption(key, value) {
8
+ this.options = {
9
+ ...this.options,
10
+ [key]: value,
11
+ };
12
+ }
13
+
14
+ getOption(key) {
15
+ return this.options[key];
16
+ }
17
+ }
@@ -129,7 +129,7 @@
129
129
  <div>
130
130
  <InputGroup @name="Adhoc Ping Distance" @type="number" @value={{this.order.adhoc_distance}} @wrapperClass="mb-0" @helpText="This setting determines the adhoc distance to ping for this order, if unset it will fallback to the default setting." />
131
131
  <div class="mt-2 px-3 py-1 rounded-lg border border-blue-600 bg-blue-100 flex items-center">
132
- <FaIcon @icon="comment-exclamation" class="text-blue-900 mr-1.5" />
132
+ <FaIcon @icon="triangle-exclamation" class="text-blue-900 mr-1.5" />
133
133
  <span class="text-blue-900 text-xs">Distance must be in meters</span>
134
134
  </div>
135
135
  </div>
@@ -0,0 +1 @@
1
+ export { default } from '@fleetbase/fleetops-engine/services/engine-context';
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@fleetbase/fleetops-engine",
3
3
  "extension": "Fleet Ops",
4
4
  "icon": "route",
5
- "version": "0.1.4",
5
+ "version": "0.1.5",
6
6
  "priority": 0,
7
7
  "fleetbase": {
8
8
  "dashboard": "int/v1/fleet-ops/dashboard"