@fleetbase/fleetops-engine 0.2.9 → 0.3.1

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 (70) hide show
  1. package/addon/components/context-panel.hbs +1 -1
  2. package/addon/components/driver-card-mini.js +34 -13
  3. package/addon/components/driver-form-panel.hbs +3 -3
  4. package/addon/components/driver-form-panel.js +87 -29
  5. package/addon/components/driver-panel.hbs +5 -5
  6. package/addon/components/driver-panel.js +118 -31
  7. package/addon/components/live-map.js +221 -10
  8. package/addon/components/map-container/toolbar/visibility-control-panel.hbs +66 -0
  9. package/addon/components/map-container/toolbar/visibility-control-panel.js +74 -0
  10. package/addon/components/map-container/toolbar/zones-panel.hbs +10 -10
  11. package/addon/components/map-container/toolbar/zones-panel.js +90 -61
  12. package/addon/components/map-container/toolbar.hbs +12 -7
  13. package/addon/components/modals/vehicle-form.hbs +35 -35
  14. package/addon/components/vehicle-form-panel.hbs +6 -7
  15. package/addon/components/vehicle-form-panel.js +86 -26
  16. package/addon/components/vehicle-panel.hbs +5 -5
  17. package/addon/components/vehicle-panel.js +124 -31
  18. package/addon/controllers/management/drivers/index/details.js +53 -0
  19. package/addon/controllers/management/drivers/index/edit.js +77 -46
  20. package/addon/controllers/management/drivers/index/new.js +39 -79
  21. package/addon/controllers/management/drivers/index.js +17 -221
  22. package/addon/controllers/management/fleets/index/edit.js +1 -1
  23. package/addon/controllers/management/fleets/index/new.js +1 -1
  24. package/addon/controllers/management/fuel-reports/index.js +2 -2
  25. package/addon/controllers/management/vehicles/index/details.js +49 -0
  26. package/addon/controllers/management/vehicles/index/edit.js +104 -1
  27. package/addon/controllers/management/vehicles/index/new.js +71 -0
  28. package/addon/controllers/operations/orders/index/new.js +1 -1
  29. package/addon/controllers/operations/orders/index/view.js +17 -7
  30. package/addon/controllers/operations/orders/index.js +109 -48
  31. package/addon/controllers/operations/service-rates/index/edit.js +1 -1
  32. package/addon/controllers/operations/service-rates/index/new.js +1 -1
  33. package/addon/helpers/is-visibility-control-visible.js +18 -0
  34. package/addon/routes/application.js +1 -1
  35. package/addon/routes/home.js +1 -1
  36. package/addon/routes/management/drivers/index/details.js +5 -0
  37. package/addon/routes/operations/service-rates/index.js +1 -1
  38. package/addon/routes/operations/zones/index.js +1 -1
  39. package/addon/services/context-panel.js +81 -14
  40. package/addon/templates/management/drivers/index/details.hbs +1 -1
  41. package/addon/templates/management/drivers/index/edit.hbs +1 -1
  42. package/addon/templates/management/drivers/index/new.hbs +1 -1
  43. package/addon/templates/management/vehicles/index/details.hbs +1 -1
  44. package/addon/templates/management/vehicles/index/edit.hbs +1 -1
  45. package/addon/templates/management/vehicles/index/new.hbs +1 -1
  46. package/addon/templates/operations/orders/index/view.hbs +2 -2
  47. package/addon/templates/operations/orders/index.hbs +1 -1
  48. package/addon/utils/apply-context-component-arguments.js +31 -0
  49. package/addon/utils/context-component-callback.js +16 -0
  50. package/app/components/map-container/toolbar/visibility-control-panel.js +1 -0
  51. package/app/helpers/is-visibility-control-visible.js +1 -0
  52. package/app/utils/apply-context-component-arguments.js +1 -0
  53. package/app/utils/context-component-callback.js +1 -0
  54. package/composer.json +2 -2
  55. package/extension.json +1 -1
  56. package/package.json +3 -3
  57. package/server/migrations/2023_09_14_074512_update_vehicles_table.php +89 -88
  58. package/server/migrations/2023_10_25_093014_create_vehicle_device_events_table.php +56 -0
  59. package/server/src/Http/Resources/v1/Vehicle.php +1 -0
  60. package/server/src/Models/Fleet.php +2 -0
  61. package/server/src/Models/VehicleDevice.php +17 -3
  62. package/server/src/Models/VehicleDeviceEvent.php +90 -0
  63. package/server/src/Notifications/OrderAssigned.php +21 -0
  64. package/server/src/Notifications/OrderCanceled.php +21 -0
  65. package/server/src/Notifications/OrderDispatchFailed.php +21 -0
  66. package/server/src/Notifications/OrderDispatched.php +21 -0
  67. package/server/src/Notifications/OrderPing.php +21 -0
  68. package/server/src/Notifications/OrderSplit.php +32 -5
  69. package/server/src/Providers/FleetOpsServiceProvider.php +22 -0
  70. package/server/src/Providers/NotificationServiceProvider.php +43 -0
@@ -1,5 +1,5 @@
1
1
  {{#if this.contextPanel.currentContextRegistry}}
2
2
  {{#let this.contextPanel.currentContext this.contextPanel.currentContextRegistry this.contextPanel.currentContextComponentArguments as |model registry dynamicArgs|}}
3
- {{component registry.component context=model dynamicArgs=dynamicArgs onPressCancel=this.contextPanel.clear}}
3
+ {{component registry.component context=model dynamicArgs=dynamicArgs onPressCancel=this.contextPanel.clear options=this.contextPanel.contextOptions}}
4
4
  {{/let}}
5
5
  {{/if}}
@@ -1,25 +1,46 @@
1
1
  import Component from '@glimmer/component';
2
- import { inject as controller } from '@ember/controller';
3
2
  import { inject as service } from '@ember/service';
4
3
  import { action } from '@ember/object';
5
4
 
5
+ /**
6
+ * DriverCardMiniComponent
7
+ *
8
+ * A mini-component responsible for displaying a specific driver's card.
9
+ *
10
+ * @extends Component
11
+ *
12
+ * @property {Service} store - Ember's store service.
13
+ * @property {Service} fetch - Service for fetching data.
14
+ * @property {Service} contextPanel - Service for context panel operations.
15
+ */
6
16
  export default class DriverCardMiniComponent extends Component {
7
- @controller('management.drivers.index') drivers;
17
+ /**
18
+ * Ember's store service.
19
+ * @type {Service}
20
+ */
8
21
  @service store;
9
22
 
10
- toModel(record, modelName) {
11
- // set id
12
- if (!record.id && record.uuid) {
13
- record.id = record.uuid;
14
- }
23
+ /**
24
+ * Fetch service.
25
+ * @type {Service}
26
+ */
27
+ @service fetch;
15
28
 
16
- const normalized = this.store.normalize(modelName, record);
17
- return this.store.push(normalized);
18
- }
29
+ /**
30
+ * ContextPanel service.
31
+ * @type {Service}
32
+ */
33
+ @service contextPanel;
19
34
 
35
+ /**
36
+ * View the details of a specific driver.
37
+ *
38
+ * @param {Object} record - The driver record to view.
39
+ * @action
40
+ * @returns {Promise} Resolves when the driver's details are focused in the context panel.
41
+ */
20
42
  @action viewDriver(record) {
21
- const driver = this.toModel(record, 'driver');
22
-
23
- return this.drivers.viewDriver(driver);
43
+ const driver = this.fetch.jsonToModel(record, 'driver');
44
+ return this.contextPanel.focus(driver);
24
45
  }
25
46
  }
@@ -1,16 +1,16 @@
1
- <Overlay @position="right" @noBackdrop={{true}} @fullHeight={{true}} @isResizeble={{or this.isResizable @isResizable}} @width={{or this.width @width "600px"}}>
1
+ <Overlay @onLoad={{this.setOverlayContext}} @position="right" @noBackdrop={{true}} @fullHeight={{true}} @isResizeble={{or this.isResizable @isResizable}} @width={{or this.width @width "600px"}}>
2
2
  <Overlay::Header @hideLeftSection={{true}} @actionsWrapperClass="flex-1 flex-col py-3" class="h-auto-i min-h-[127px]">
3
3
  <div class="flex flex-row items-center justify-between w-full mb-4">
4
4
  <div class="flex flex-1 space-x-2">
5
5
  {{#if this.driver.id}}
6
- <Button @type="default" @icon="id-card" @helpText="View driver details" @onClick={{this.viewDetails}} />
6
+ <Button @type="default" @icon="id-card" @helpText="View driver details" @onClick={{this.onViewDetails}} />
7
7
  {{/if}}
8
8
  </div>
9
9
  <div class="flex flex-1 justify-end">
10
10
  <div class="mr-2">
11
11
  <Button @icon={{if this.driver.id "save" "check"}} @type="primary" @text={{if this.driver.id "Save Driver" "Create Driver"}} @onClick={{this.save}} />
12
12
  </div>
13
- <Button @type="default" @icon="times" @helpText={{if this.driver.id "Cancel edit driver" "Cancel new driver"}} @onClick={{@onPressCancel}} />
13
+ <Button @type="default" @icon="times" @helpText={{if this.driver.id "Cancel edit driver" "Cancel new driver"}} @onClick={{this.onPressCancel}} />
14
14
  </div>
15
15
  </div>
16
16
  <div class="flex flex-row justify-between w-full">
@@ -2,63 +2,121 @@ import Component from '@glimmer/component';
2
2
  import { tracked } from '@glimmer/tracking';
3
3
  import { inject as service } from '@ember/service';
4
4
  import { action } from '@ember/object';
5
+ import contextComponentCallback from '../utils/context-component-callback';
6
+ import applyContextComponentArguments from '../utils/apply-context-component-arguments';
5
7
 
6
8
  export default class DriverFormPanelComponent extends Component {
9
+ /**
10
+ * @service store
11
+ */
7
12
  @service store;
13
+
14
+ /**
15
+ * @service notifications
16
+ */
8
17
  @service notifications;
18
+
19
+ /**
20
+ * @service hostRouter
21
+ */
9
22
  @service hostRouter;
10
- @service contextPanel;
23
+
24
+ /**
25
+ * @service loader
26
+ */
11
27
  @service loader;
12
- @tracked driver;
13
28
 
29
+ /**
30
+ * @service contextPanel
31
+ */
32
+ @service contextPanel;
33
+
34
+ /**
35
+ * Overlay context.
36
+ * @type {any}
37
+ */
38
+ @tracked context;
39
+
40
+ /**
41
+ * Indicates whether the component is in a loading state.
42
+ * @type {boolean}
43
+ */
44
+ @tracked isLoading = false;
45
+
46
+ /**
47
+ * Constructs the component and applies initial state.
48
+ */
14
49
  constructor() {
15
50
  super(...arguments);
16
51
  this.driver = this.args.driver;
17
- this.applyDynamicArguments();
52
+ applyContextComponentArguments(this);
18
53
  }
19
54
 
20
- applyDynamicArguments() {
21
- // Apply context if available
22
- if (this.args.context) {
23
- this.driver = this.args.context;
24
- }
25
-
26
- // Apply dynamic arguments if available
27
- if (this.args.dynamicArgs) {
28
- const keys = Object.keys(this.args.dynamicArgs);
29
-
30
- keys.forEach((key) => {
31
- this[key] = this.args.dynamicArgs[key];
32
- });
33
- }
55
+ /**
56
+ * Sets the overlay context.
57
+ *
58
+ * @action
59
+ * @param {OverlayContextObject} overlayContext
60
+ */
61
+ @action setOverlayContext(overlayContext) {
62
+ this.context = overlayContext;
63
+ contextComponentCallback(this, 'onLoad', ...arguments);
34
64
  }
35
65
 
66
+ /**
67
+ * Saves the driver changes.
68
+ *
69
+ * @action
70
+ * @returns {Promise<any>}
71
+ */
36
72
  @action save() {
37
73
  const { driver } = this;
38
- const { onAfterSave } = this.args;
39
74
 
40
- this.loader.showLoader('.overlay-inner-content', 'Saving driver...');
75
+ this.loader.showLoader('.next-content-overlay-panel-container', { loadingMessage: 'Saving driver...', preserveTargetPosition: true });
76
+ this.isLoading = true;
77
+
78
+ contextComponentCallback(this, 'onBeforeSave', driver);
41
79
 
42
80
  try {
43
81
  return driver
44
82
  .save()
45
- .then((vehicle) => {
83
+ .then((driver) => {
46
84
  this.notifications.success(`Driver (${driver.name}) saved successfully.`);
47
-
48
- if (typeof onAfterSave === 'function') {
49
- onAfterSave(vehicle);
50
- }
85
+ contextComponentCallback(this, 'onAfterSave', driver);
86
+ })
87
+ .catch((error) => {
88
+ this.notifications.serverError(error);
51
89
  })
52
- .catch(this.notifications.serverError)
53
90
  .finally(() => {
54
- this.loader.removeLoader();
91
+ this.loader.removeLoader('.next-content-overlay-panel-container ');
92
+ this.isLoading = false;
55
93
  });
56
94
  } catch (error) {
57
- this.loader.removeLoader();
95
+ this.loader.removeLoader('.next-content-overlay-panel-container ');
96
+ this.isLoading = false;
97
+ }
98
+ }
99
+
100
+ /**
101
+ * View the details of the driver.
102
+ *
103
+ * @action
104
+ */
105
+ @action onViewDetails() {
106
+ const isActionOverrided = contextComponentCallback(this, 'onViewDetails', this.driver);
107
+
108
+ if (!isActionOverrided) {
109
+ this.contextPanel.focus(this.driver, 'viewing');
58
110
  }
59
111
  }
60
112
 
61
- @action viewDetails() {
62
- this.contextPanel.focus(this.driver, 'viewing');
113
+ /**
114
+ * Handles cancel button press.
115
+ *
116
+ * @action
117
+ * @returns {any}
118
+ */
119
+ @action onPressCancel() {
120
+ return contextComponentCallback(this, 'onPressCancel', this.driver);
63
121
  }
64
122
  }
@@ -1,12 +1,12 @@
1
- <Overlay @position="right" @noBackdrop={{true}} @fullHeight={{true}} @isResizeble={{or this.isResizable @isResizable}} @width={{or this.width @width "600px"}}>
1
+ <Overlay @onLoad={{this.setOverlayContext}} @position="right" @noBackdrop={{true}} @fullHeight={{true}} @isResizeble={{or this.isResizable @isResizable}} @width={{or this.width @width "600px"}}>
2
2
  <Overlay::Header @hideLeftSection={{true}} @actionsWrapperClass="flex-1 flex-col py-3" class="h-auto-i min-h-[127px]">
3
3
  <div class="flex flex-row items-center justify-between w-full mb-4">
4
4
  <div class="flex flex-1 space-x-2">
5
5
  {{!-- <Button @type="default" @icon="location-arrow" @helpText="Locate driver" @onClick={{@onPressCancel}} /> --}}
6
- <Button @type="default" @icon="pen" @helpText="Edit driver" @onClick={{this.editDriver}} />
6
+ <Button @type="default" @icon="pen" @helpText="Edit driver" @onClick={{this.onEdit}} />
7
7
  </div>
8
8
  <div class="flex flex-1 justify-end">
9
- <Button @type="default" @icon="times" @helpText="Close driver details" @onClick={{@onPressCancel}} />
9
+ <Button @type="default" @icon="times" @helpText="Close driver details" @onClick={{this.onPressCancel}} />
10
10
  </div>
11
11
  </div>
12
12
  <div class="flex flex-row justify-between w-full">
@@ -45,7 +45,7 @@
45
45
  <div class="ui-tabs mt-4">
46
46
  <nav>
47
47
  {{#each this.tabs as |tab|}}
48
- <a href="javascript:;" class="ui-tab {{if (eq this.currentTab tab.slug) 'active' }}" {{on "click" (fn this.changeTab tab.slug)}}>
48
+ <a href="javascript:;" class="ui-tab {{if (eq this.tab.slug tab.slug) 'active' }}" {{on "click" (fn this.onTabChanged tab.slug)}}>
49
49
  <FaIcon @icon={{tab.icon}} class="mr-1" />
50
50
  <span>{{tab.title}}</span>
51
51
  </a>
@@ -53,7 +53,7 @@
53
53
  </nav>
54
54
  </div>
55
55
  </div>
56
- <div class="tab-content tab-{{this.currentTab}}">
56
+ <div class="tab-content tab-{{this.tab.slug}}">
57
57
  {{component this.tab.component driver=this.driver tabOptions=this.tab params=this.tab.componentParams}}
58
58
  </div>
59
59
  </Overlay::Body>
@@ -1,22 +1,76 @@
1
1
  import Component from '@glimmer/component';
2
2
  import { tracked } from '@glimmer/tracking';
3
- import { action, computed } from '@ember/object';
3
+ import { action } from '@ember/object';
4
4
  import { inject as service } from '@ember/service';
5
5
  import { isArray } from '@ember/array';
6
6
  import DriverPanelDetailComponent from './driver-panel/details';
7
+ import contextComponentCallback from '../utils/context-component-callback';
8
+ import applyContextComponentArguments from '../utils/apply-context-component-arguments';
7
9
 
8
10
  export default class DriverPanelComponent extends Component {
11
+ /**
12
+ * Service for fetching data.
13
+ *
14
+ * @type {Service}
15
+ */
9
16
  @service fetch;
17
+
18
+ /**
19
+ * Service for managing modals.
20
+ *
21
+ * @type {Service}
22
+ */
10
23
  @service modalsManager;
24
+
25
+ /**
26
+ * Universe service for managing global data and settings.
27
+ *
28
+ * @type {Service}
29
+ */
11
30
  @service universe;
31
+
32
+ /**
33
+ * Ember data store service.
34
+ *
35
+ * @type {Service}
36
+ */
12
37
  @service store;
38
+
39
+ /**
40
+ * Service for managing routing within the host app.
41
+ *
42
+ * @type {Service}
43
+ */
13
44
  @service hostRouter;
45
+
46
+ /**
47
+ * Service for managing the context panel.
48
+ *
49
+ * @type {Service}
50
+ */
14
51
  @service contextPanel;
15
- @tracked currentTab;
16
- @tracked devices = [];
17
- @tracked deviceApi = {};
52
+
53
+ /**
54
+ * The current active tab.
55
+ *
56
+ * @type {Object}
57
+ * @tracked
58
+ */
59
+ @tracked tab;
60
+
61
+ /**
62
+ * The driver being displayed or edited.
63
+ *
64
+ * @type {DriverModel}
65
+ * @tracked
66
+ */
18
67
  @tracked driver;
19
68
 
69
+ /**
70
+ * Returns the array of tabs available for the panel.
71
+ *
72
+ * @type {Array}
73
+ */
20
74
  get tabs() {
21
75
  const registeredTabs = this.universe.getMenuItemsFromRegistry('component:driver-panel');
22
76
  // this.universe._createMenuItem('Tracking', null, { icon: 'satellite-dish', component: DriverPanelTrackingComponent }),
@@ -29,46 +83,79 @@ export default class DriverPanelComponent extends Component {
29
83
  return defaultTabs;
30
84
  }
31
85
 
32
- @computed('currentTab', 'tabs') get tab() {
33
- if (this.currentTab) {
34
- return this.tabs.find(({ slug }) => slug === this.currentTab);
35
- }
36
-
37
- return null;
38
- }
39
-
86
+ /**
87
+ * Initializes the driver panel component.
88
+ */
40
89
  constructor() {
41
90
  super(...arguments);
42
91
  this.driver = this.args.driver;
43
- this.changeTab(this.args.tab);
44
- this.applyDynamicArguments();
92
+ this.tab = this.getTabUsingSlug(this.args.tab);
93
+ applyContextComponentArguments(this);
45
94
  }
46
95
 
47
- applyDynamicArguments() {
48
- // Apply context if available
49
- if (this.args.context) {
50
- this.driver = this.args.context;
51
- }
96
+ /**
97
+ * Sets the overlay context.
98
+ *
99
+ * @action
100
+ * @param {OverlayContextObject} overlayContext
101
+ */
102
+ @action setOverlayContext(overlayContext) {
103
+ this.context = overlayContext;
104
+ contextComponentCallback(this, 'onLoad', ...arguments);
105
+ }
52
106
 
53
- // Apply dynamic arguments if available
54
- if (this.args.dynamicArgs) {
55
- const keys = Object.keys(this.args.dynamicArgs);
107
+ /**
108
+ * Handles changing the active tab.
109
+ *
110
+ * @method
111
+ * @param {String} tab - The new tab to switch to.
112
+ * @action
113
+ */
114
+ @action onTabChanged(tab) {
115
+ this.tab = this.getTabUsingSlug(tab);
116
+ contextComponentCallback(this, 'onTabChanged', tab);
117
+ }
118
+
119
+ /**
120
+ * Handles edit action for the driver.
121
+ *
122
+ * @method
123
+ * @action
124
+ */
125
+ @action onEdit() {
126
+ const isActionOverrided = contextComponentCallback(this, 'onEdit', this.driver);
56
127
 
57
- keys.forEach((key) => {
58
- this[key] = this.args.dynamicArgs[key];
128
+ if (!isActionOverrided) {
129
+ this.contextPanel.focus(this.driver, 'editing', {
130
+ onAfterSave: () => {
131
+ this.contextPanel.clear();
132
+ },
59
133
  });
60
134
  }
61
135
  }
62
136
 
63
- @action async changeTab(tab = 'details') {
64
- this.currentTab = tab;
137
+ /**
138
+ * Handles the cancel action.
139
+ *
140
+ * @method
141
+ * @action
142
+ * @returns {Boolean} Indicates whether the cancel action was overridden.
143
+ */
144
+ @action onPressCancel() {
145
+ return contextComponentCallback(this, 'onPressCancel', this.driver);
146
+ }
65
147
 
66
- if (typeof this.args.onTabChanged === 'function') {
67
- this.args.onTabChanged(tab);
148
+ /**
149
+ * Finds and returns a tab based on its slug.
150
+ *
151
+ * @param {String} tabSlug - The slug of the tab.
152
+ * @returns {Object|null} The found tab or null.
153
+ */
154
+ getTabUsingSlug(tabSlug) {
155
+ if (tabSlug) {
156
+ return this.tabs.find(({ slug }) => slug === tabSlug);
68
157
  }
69
- }
70
158
 
71
- @action editDriver() {
72
- this.contextPanel.focus(this.driver, 'editing');
159
+ return this.tabs[0];
73
160
  }
74
161
  }