@fleetbase/fleetops-engine 0.6.69 → 0.6.70

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 (209) hide show
  1. package/RELEASE.md +41 -8
  2. package/addon/components/admin/telematics-settings.hbs +143 -0
  3. package/addon/components/admin/telematics-settings.js +145 -0
  4. package/addon/components/fuel-integration/hub.hbs +1 -1
  5. package/addon/components/layout/fleet-ops-sidebar.js +37 -17
  6. package/addon/components/map/leaflet-live-map.hbs +4 -242
  7. package/addon/components/map/leaflet-live-map.js +2 -1
  8. package/addon/components/map/marker-card/driver.hbs +57 -0
  9. package/addon/components/map/marker-card/driver.js +3 -0
  10. package/addon/components/map/marker-card/vehicle.hbs +78 -0
  11. package/addon/components/map/marker-card/vehicle.js +3 -0
  12. package/addon/components/telematic/hub.hbs +1 -1
  13. package/addon/components/widget/live-fleet.hbs +8 -40
  14. package/addon/controllers/analytics/reports/index.js +5 -0
  15. package/addon/controllers/connectivity/devices/index.js +4 -0
  16. package/addon/controllers/connectivity/fuel-providers/index.js +6 -4
  17. package/addon/controllers/connectivity/sensors/index.js +4 -0
  18. package/addon/controllers/connectivity/telematics/index.js +4 -0
  19. package/addon/controllers/maintenance/equipment/index.js +11 -4
  20. package/addon/controllers/maintenance/inspection-forms/index.js +2 -2
  21. package/addon/controllers/maintenance/inspection-submissions/index.js +8 -2
  22. package/addon/controllers/maintenance/maintenances/index.js +4 -0
  23. package/addon/controllers/maintenance/parts/index.js +11 -4
  24. package/addon/controllers/maintenance/schedules/index.js +17 -4
  25. package/addon/controllers/maintenance/work-orders/index.js +11 -4
  26. package/addon/controllers/management/contacts/index.js +4 -0
  27. package/addon/controllers/management/drivers/index.js +4 -0
  28. package/addon/controllers/management/fleets/index.js +4 -0
  29. package/addon/controllers/management/fuel-reports/index.js +4 -0
  30. package/addon/controllers/management/fuel-transactions/index.js +9 -7
  31. package/addon/controllers/management/issues/index.js +4 -0
  32. package/addon/controllers/management/places/index.js +4 -0
  33. package/addon/controllers/management/vehicles/index.js +4 -0
  34. package/addon/controllers/management/vendors/index.js +4 -0
  35. package/addon/controllers/operations/orders/index/details.js +30 -1
  36. package/addon/controllers/operations/orders/index.js +7 -0
  37. package/addon/controllers/operations/service-rates/index.js +3 -0
  38. package/addon/controllers/settings/index.js +13 -0
  39. package/addon/controllers/settings/telematics.js +113 -0
  40. package/addon/extension.js +38 -6
  41. package/addon/routes/analytics/index.js +14 -1
  42. package/addon/routes/analytics/reports/index/details.js +1 -1
  43. package/addon/routes/analytics/reports/index/edit.js +1 -1
  44. package/addon/routes/analytics/reports/index/new.js +14 -1
  45. package/addon/routes/analytics/reports.js +14 -1
  46. package/addon/routes/connectivity/devices/index/new.js +14 -1
  47. package/addon/routes/connectivity/devices.js +14 -1
  48. package/addon/routes/connectivity/events.js +14 -1
  49. package/addon/routes/connectivity/fuel-providers/details/transactions.js +12 -0
  50. package/addon/routes/connectivity/fuel-providers/details.js +9 -0
  51. package/addon/routes/connectivity/fuel-providers/edit.js +9 -0
  52. package/addon/routes/connectivity/fuel-providers/new.js +14 -1
  53. package/addon/routes/connectivity/fuel-providers.js +14 -1
  54. package/addon/routes/connectivity/sensors/index/new.js +14 -1
  55. package/addon/routes/connectivity/sensors.js +14 -1
  56. package/addon/routes/connectivity/telematics/new.js +14 -1
  57. package/addon/routes/connectivity/telematics.js +14 -1
  58. package/addon/routes/connectivity/tracking.js +14 -1
  59. package/addon/routes/maintenance/equipment/index/details.js +2 -2
  60. package/addon/routes/maintenance/equipment/index/edit.js +2 -2
  61. package/addon/routes/maintenance/equipment/index/new.js +14 -1
  62. package/addon/routes/maintenance/equipment.js +14 -1
  63. package/addon/routes/maintenance/index.js +14 -1
  64. package/addon/routes/maintenance/inspection-forms/index/details.js +10 -1
  65. package/addon/routes/maintenance/inspection-forms/index/edit.js +10 -1
  66. package/addon/routes/maintenance/inspection-forms/index/new.js +14 -1
  67. package/addon/routes/maintenance/inspection-forms.js +14 -1
  68. package/addon/routes/maintenance/inspection-submissions/index/details.js +10 -1
  69. package/addon/routes/maintenance/inspection-submissions/index/edit.js +10 -1
  70. package/addon/routes/maintenance/inspection-submissions/index/new.js +14 -1
  71. package/addon/routes/maintenance/inspection-submissions.js +14 -1
  72. package/addon/routes/maintenance/maintenances/index/details.js +2 -2
  73. package/addon/routes/maintenance/maintenances/index/edit.js +2 -2
  74. package/addon/routes/maintenance/maintenances/index/new.js +14 -1
  75. package/addon/routes/maintenance/maintenances.js +14 -1
  76. package/addon/routes/maintenance/parts/index/details.js +2 -2
  77. package/addon/routes/maintenance/parts/index/edit.js +2 -2
  78. package/addon/routes/maintenance/parts/index/new.js +14 -1
  79. package/addon/routes/maintenance/parts.js +14 -1
  80. package/addon/routes/maintenance/schedules/index/details.js +2 -2
  81. package/addon/routes/maintenance/schedules/index/edit.js +2 -2
  82. package/addon/routes/maintenance/schedules/index/new.js +15 -1
  83. package/addon/routes/maintenance/schedules.js +15 -1
  84. package/addon/routes/maintenance/work-orders/index/details.js +2 -2
  85. package/addon/routes/maintenance/work-orders/index/edit.js +2 -2
  86. package/addon/routes/maintenance/work-orders/index/new.js +14 -1
  87. package/addon/routes/maintenance/work-orders.js +14 -1
  88. package/addon/routes/management/fuel-transactions/index/details.js +9 -0
  89. package/addon/routes/management/fuel-transactions.js +14 -1
  90. package/addon/routes/management/index.js +13 -0
  91. package/addon/routes/management/trailers.js +16 -0
  92. package/addon/routes/management/vendors/integrated/details.js +14 -1
  93. package/addon/routes/management/vendors/integrated/edit.js +14 -1
  94. package/addon/routes/management/vendors/integrated/new.js +14 -1
  95. package/addon/routes/management/vendors/integrated.js +14 -1
  96. package/addon/routes/operations/orders.js +40 -1
  97. package/addon/routes/operations/routes/index/details.js +14 -1
  98. package/addon/routes/operations/routes/index/new.js +13 -0
  99. package/addon/routes/operations/routes.js +14 -1
  100. package/addon/routes/operations/service-rates/index/new.js +11 -0
  101. package/addon/routes/operations/service-rates.js +14 -1
  102. package/addon/routes/settings/avatars.js +14 -1
  103. package/addon/routes/settings/custom-fields.js +14 -1
  104. package/addon/routes/settings/map.js +14 -1
  105. package/addon/routes/settings/notifications.js +11 -0
  106. package/addon/routes/settings/orchestrator.js +1 -1
  107. package/addon/routes/settings/payments/index.js +1 -1
  108. package/addon/routes/settings/routing.js +14 -1
  109. package/addon/routes/settings/scheduling.js +14 -1
  110. package/addon/routes/settings/telematics.js +21 -0
  111. package/addon/routes/virtual.js +11 -0
  112. package/addon/routes.js +1 -0
  113. package/addon/templates/settings/telematics.hbs +70 -0
  114. package/app/components/admin/telematics-settings.js +1 -0
  115. package/app/components/map/marker-card/driver.js +1 -0
  116. package/app/components/map/marker-card/vehicle.js +1 -0
  117. package/app/controllers/settings/telematics.js +1 -0
  118. package/app/routes/settings/telematics.js +1 -0
  119. package/app/templates/settings/telematics.js +1 -0
  120. package/composer.json +2 -2
  121. package/docs/AFAQY.md +1 -1
  122. package/docs/TELEMATICS_QUEUES.md +1 -1
  123. package/docs/TELEMETRY_ARCHITECTURE.md +72 -1
  124. package/extension.json +1 -1
  125. package/package.json +1 -1
  126. package/server/config/telemetry.php +12 -0
  127. package/server/migrations/2026_09_23_000001_add_retention_index_to_device_events.php +40 -0
  128. package/server/migrations/2026_09_23_000002_add_retention_index_to_positions.php +40 -0
  129. package/server/migrations/2026_09_23_000003_add_retention_index_to_telematic_sync_runs.php +40 -0
  130. package/server/src/Auth/Schemas/FleetOps.php +104 -5
  131. package/server/src/Console/Commands/DrainTelematicInbox.php +3 -13
  132. package/server/src/Console/Commands/ProcessOperationalAlerts.php +3 -3
  133. package/server/src/Console/Commands/PruneTelematicsData.php +318 -0
  134. package/server/src/Http/Controllers/Api/v1/OrchestrationController.php +9 -0
  135. package/server/src/Http/Controllers/FleetOpsController.php +21 -0
  136. package/server/src/Http/Controllers/Internal/v1/AnalyticsController.php +11 -0
  137. package/server/src/Http/Controllers/Internal/v1/ContactController.php +11 -0
  138. package/server/src/Http/Controllers/Internal/v1/CustomerController.php +14 -0
  139. package/server/src/Http/Controllers/Internal/v1/DeviceController.php +13 -0
  140. package/server/src/Http/Controllers/Internal/v1/DeviceEventController.php +11 -0
  141. package/server/src/Http/Controllers/Internal/v1/DriverController.php +22 -0
  142. package/server/src/Http/Controllers/Internal/v1/FuelProviderConnectionController.php +13 -0
  143. package/server/src/Http/Controllers/Internal/v1/FuelProviderTransactionController.php +15 -0
  144. package/server/src/Http/Controllers/Internal/v1/FuelReportController.php +9 -3
  145. package/server/src/Http/Controllers/Internal/v1/InspectionFormController.php +15 -0
  146. package/server/src/Http/Controllers/Internal/v1/LiveController.php +16 -0
  147. package/server/src/Http/Controllers/Internal/v1/MaintenanceController.php +15 -0
  148. package/server/src/Http/Controllers/Internal/v1/MaintenanceScheduleController.php +15 -0
  149. package/server/src/Http/Controllers/Internal/v1/ManifestController.php +15 -0
  150. package/server/src/Http/Controllers/Internal/v1/MetricsController.php +11 -0
  151. package/server/src/Http/Controllers/Internal/v1/NavigatorController.php +42 -1
  152. package/server/src/Http/Controllers/Internal/v1/OrchestrationController.php +12 -0
  153. package/server/src/Http/Controllers/Internal/v1/OrderController.php +22 -0
  154. package/server/src/Http/Controllers/Internal/v1/PaymentController.php +13 -0
  155. package/server/src/Http/Controllers/Internal/v1/RadarController.php +19 -0
  156. package/server/src/Http/Controllers/Internal/v1/ServiceAreaController.php +9 -3
  157. package/server/src/Http/Controllers/Internal/v1/SettingController.php +465 -14
  158. package/server/src/Http/Controllers/Internal/v1/TelematicController.php +21 -0
  159. package/server/src/Http/Controllers/Internal/v1/TrailerController.php +21 -0
  160. package/server/src/Http/Controllers/Internal/v1/VehicleController.php +21 -0
  161. package/server/src/Http/Controllers/Internal/v1/VendorController.php +17 -0
  162. package/server/src/Http/Controllers/Internal/v1/WorkOrderController.php +11 -0
  163. package/server/src/Jobs/DispatchTelematicsRetentionJobs.php +70 -0
  164. package/server/src/Jobs/PruneTelematicsDataJob.php +74 -0
  165. package/server/src/Listeners/NotifyDriverOnShiftChange.php +3 -3
  166. package/server/src/Mail/CustomerCredentialsMail.php +1 -1
  167. package/server/src/Orchestration/Engines/VroomOrchestrationEngine.php +9 -1
  168. package/server/src/Providers/FleetOpsServiceProvider.php +3 -0
  169. package/server/src/Support/Analytics/LiveFleet.php +18 -2
  170. package/server/src/Support/Authorization.php +103 -0
  171. package/server/src/Support/Database/TableIndexes.php +66 -0
  172. package/server/src/Support/OrderTracker.php +2 -2
  173. package/server/src/Support/Reporting/FleetOpsReportSchema.php +476 -116
  174. package/server/src/Support/Telematics/Retention/RetentionPolicy.php +300 -0
  175. package/server/src/Support/Telematics/Retention/TelemetryActivity.php +40 -0
  176. package/server/src/Support/Telematics/TelematicService.php +12 -2
  177. package/server/src/Support/Telematics/Telemetry/Ingestor.php +4 -2
  178. package/server/src/Tracking/TrackingIntelligenceService.php +1 -1
  179. package/server/src/Tracking/TrackingOptions.php +2 -2
  180. package/server/src/Traits/AuthorizesMethods.php +37 -0
  181. package/server/src/routes.php +9 -1
  182. package/server/tests/AnalyticsRoutesTest.php +29 -2
  183. package/server/tests/Feature/Http/AfaqyRealtimeIngestionTest.php +16 -1
  184. package/server/tests/Feature/Http/Api/TelematicsRetentionIndexMigrationTest.php +115 -0
  185. package/server/tests/Feature/Http/Internal/SettingControllerHelpersTest.php +71 -0
  186. package/server/tests/Feature/Http/Internal/TelematicsStorageDeadlinesTest.php +119 -0
  187. package/server/tests/InternalImportExportControllerContractsTest.php +5 -8
  188. package/server/tests/NavigatorControllerContractsTest.php +36 -4
  189. package/server/tests/NotificationAndMailContractsTest.php +31 -0
  190. package/server/tests/ObserverContractsTest.php +1 -1
  191. package/server/tests/OrchestratorConsumableApiTest.php +42 -0
  192. package/server/tests/ProviderContractsTest.php +10 -0
  193. package/server/tests/ReportSchemaContractsTest.php +120 -6
  194. package/server/tests/SettingControllerContractsTest.php +429 -18
  195. package/server/tests/SmallControllerContractsTest.php +8 -5
  196. package/server/tests/Support/PruneTelematicsDataProbe.php +55 -0
  197. package/server/tests/Unit/Console/Commands/ProcessOperationalAlertsCommandTest.php +2 -2
  198. package/server/tests/Unit/Console/PruneTelematicsDataCommandTest.php +353 -0
  199. package/server/tests/Unit/Jobs/DispatchTelematicsRetentionJobsTest.php +114 -0
  200. package/server/tests/Unit/Jobs/PruneTelematicsDataJobTest.php +60 -0
  201. package/server/tests/Unit/Orchestration/VroomEngineTransportAndSettingsTest.php +20 -0
  202. package/server/tests/Unit/Support/Analytics/LiveFleetTest.php +6 -0
  203. package/server/tests/Unit/Support/AuthorizationTest.php +142 -0
  204. package/server/tests/Unit/Support/MaintainableAndOperationalAlertsTest.php +12 -1
  205. package/server/tests/Unit/Support/MoreQuerySeamsTest.php +11 -2
  206. package/server/tests/Unit/Support/Telematics/Retention/RetentionPolicyTest.php +190 -0
  207. package/server/tests/Unit/Support/Telematics/Retention/TelemetryActivityTest.php +68 -0
  208. package/server/tests/Unit/Tracking/TrackingOptionsCompanySettingsTest.php +109 -0
  209. package/translations/en-us.yaml +48 -0
package/RELEASE.md CHANGED
@@ -1,23 +1,56 @@
1
- > v0.6.69 ~ "Fleet-Ops tools for Fleetbase AI"
1
+ > v0.6.70 ~ "Telematics data retention"
2
2
 
3
3
  ---
4
4
  ## What's New
5
- - **Fleet-Ops works with Fleetbase AI tool calling.** Creating orders from the AI prompt works again with the tool-calling assistant, and the assistant can also propose an optimized waypoint sequence for an order and explain what an order or resource import needs. Every change is a preview card the user confirms.
6
- - **Fleet-Ops console actions.** The assistant can offer to open Fleet-Ops pages and dialogs, such as **Operations › Orders** and **New Order**, as confirmation cards.
7
- - **Resource search for the assistant.** A `fleetops_search` tool finds orders, vehicles, drivers, work orders, maintenances, devices, sensors and telematics records by id, name, plate, VIN, email or phone.
5
+ - **Telematics Data settings.** A new Fleet-Ops → Settings → Telematics Data page lets each organization decide how long telemetry is kept: device events, raw event payloads, positions, processed and quarantined delivery envelopes, and sync run diagnostics. Administrators set system-wide defaults from the admin console (Fleet-Ops Config → Telematics Data). A value of 0 keeps rows forever.
6
+ - **Scheduled retention sweep.** `fleetops:prune-telematics-data` runs every fifteen minutes and applies each organization's policy in bounded batches, so a large backlog is drained gradually without stalling ingestion. Defaults: events 30 days, raw payloads stripped after 7 days, positions 90 days, processed deliveries 24 hours, quarantined deliveries 7 days, sync runs 7 days.
7
+ - **Storage usage and on-demand cleanup.** The settings page shows rows, oldest row and estimated size per table for your organization, and "Run cleanup now" queues an immediate retention run.
8
8
 
9
9
  ---
10
10
  ## Fixes
11
- - AI resource search no longer fails on every call with `Unknown column 'sensor_type'`, and database errors are no longer passed to the model.
11
+ - Device events no longer store the raw provider unit twice. `payload` keeps the raw unit; `meta` holds only the normalized block (speed, heading, odometer, ignition, fuel level, timing). New event rows are roughly half the size.
12
+ - Telemetry-driven saves (device, event, position, vehicle, sensors) no longer write to the activity log on every poll. Organizations that want them can enable "Log telemetry activity" in Telematics Data settings. Manual edits are logged as before.
13
+ - Delivery inbox and sync run retention moved from the drain command into the retention sweep; `fleetops:drain-telematic-inbox` now only recovers deliveries and finishes interrupted runs.
14
+
15
+ ---
16
+ ## Upgrade notes
17
+ - New indexes on `device_events (company_uuid, created_at)`, `positions (company_uuid, created_at)` and `telematic_sync_runs (telematic_uuid, updated_at)`; on very large tables run `php artisan migrate` in a maintenance window.
18
+ - Retention is enabled by default. Existing rows older than the defaults are removed over successive runs after upgrading; set the values to 0 before upgrading if you need to keep history indefinitely.
19
+ - Deleting rows frees space inside the database files, not on disk. Run `OPTIMIZE TABLE` off-peak to return space to the operating system.
20
+ - Run `php artisan fleetbase:create-permissions` to register the `telematics-settings` permission and the Telematics Settings Manager policy and role.
21
+
22
+ ---
23
+ ## Testing
24
+ - Backend tests cover the retention policy layering and clamping, the prune command (per-company policies, compaction, inbox tables via connections, orphans, batch caps, dry runs, filters, locking), the settings and storage usage endpoints, the index migrations, the on-demand job, and the meta and activity-log changes to ingestion.
25
+ - Ember tests cover the settings route guard, the settings controller, and the admin defaults component.
26
+ > v0.6.70 ~ "Order reporting and a cleaner default dashboard"
27
+
28
+ ---
29
+ ## What's New
30
+ - **Report on orders, their items and tracking.** The report builder can answer questions like "Which products sold the most this month?" and "What did orders total this month?".
31
+ - Orders expose their ID and Internal ID, and relationships for tracking (tracking number, region, latest status), Order Config, Customer Vendor, Created By, Purchase Rate › Service Quote and Payload Return.
32
+ - `Payload` exposes its items with name, SKU, price, dimensions, metadata and destination. Select an item column for one row per item, or group by one to summarise per product.
33
+ - Summary columns count orders distinctly, so they stay correct when item rows are selected. Distance, duration and transaction amount have totals and averages.
34
+ - `meta` has no fixed shape, so no column assumes a key in it. Read keys with a computed column, for example `CAST(JSON_UNQUOTE(JSON_EXTRACT(payload.entities.meta, '$.quantity')) AS DECIMAL(15,2))`.
35
+ - Column labels drop the table name ("Type", not "Order Type"). Distance and duration are labelled in meters and seconds, and money columns are marked "(minor units)".
36
+ - **A cleaner default dashboard.** Fleet-Ops widgets declare their place on the default dashboard: Radar first, then Active Orders and Drivers Online, a full-width Live Fleet map, and Revenue Trend, Top Drivers and Maintenance side by side.
37
+ - **Live Fleet widget cards match the live map.** Clicking a driver or vehicle on the widget map shows the same card as **Operations › Live Map**.
38
+
39
+ ---
40
+ ## Fixes
41
+ - Custom field values on fuel reports and service areas are saved. They were dropped because the save hooks read the snake_case payload root, while the console sends `fuelReport` and `serviceArea`.
42
+ - The report schema no longer references 13 columns and join keys that don't exist: driver name, email and phone and the driver's vehicle, the vehicle's driver, and the fuel report cost, odometer and date. Transaction summaries sum `transaction.amount`.
43
+ - Every report table, and the item join, leaves soft-deleted rows out on core-api v1.6.64 and later.
12
44
 
13
45
  ---
14
46
  ## Dependencies
15
- - `@fleetbase/fleetops-data` upgraded to `^0.2.2`, which adds the read-only login state (`is_staff_linked`, `login_status`) to the driver and contact models.
16
- - `@fleetbase/ember-ui` upgraded to `^0.4.3`, which provides the `btn-auth` style the Track Order button on the login page uses.
47
+ - Order items, JSON totals and soft deletes in reports need `fleetbase/core-api` v1.6.64. The schema still registers on older versions.
48
+ - The report builder and the default dashboard order ship in `@fleetbase/ember-ui` v0.4.4.
17
49
 
18
50
  ---
19
51
  ## Testing
20
- - Unit tests cover the new AI tools and console commands, and the AI capability registration.
52
+ - Every declared report column and join key was checked against the database schema, and order reports were run against real storefront orders on MySQL in strict mode.
53
+ - Tests cover the report schema at 100% line coverage, the Live Fleet map cards and the default dashboard order.
21
54
 
22
55
  ---
23
56
  ## Need help?
@@ -0,0 +1,143 @@
1
+ <div class="space-y-6">
2
+ <InfoBlock @type="info" @icon="circle-info" class="mb-4">
3
+ Configure telematics retention policy and activity logging for all organizations. Organizations can choose device event and position history retention within these limits from Fleet-Ops &rsaquo; Settings &rsaquo; Telematics.
4
+ A maximum takes precedence over organization preferences, inherited defaults and requests to keep history forever. Reducing a maximum can delete existing history at the next cleanup.
5
+ </InfoBlock>
6
+
7
+ <ContentPanel @title="System Device Events Retention Policy" @open={{true}} @wrapperClass="bordered-classic">
8
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
9
+ <InputGroup @name="Default Device Event Retention (days)" @helpText="Retention for organizations that inherit the system default. 0 keeps history forever, subject to the maximum below.">
10
+ <Input @type="number" @value={{this.eventRetentionDays}} min="0" max="3650" class="form-input w-full" />
11
+ </InputGroup>
12
+ <InputGroup @name="Maximum Device Event Retention (days)" @helpText="The longest any organization can keep device events. 0 sets no maximum and allows organizations to keep history forever.">
13
+ <Input @type="number" @value={{this.maxEventRetentionDays}} min="0" max="3650" class="form-input w-full" />
14
+ </InputGroup>
15
+ </div>
16
+ </ContentPanel>
17
+
18
+ <ContentPanel @title="System Position History Retention Policy" @open={{true}} @wrapperClass="bordered-classic">
19
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
20
+ <InputGroup @name="Default Position History Retention (days)" @helpText="Retention for organizations that inherit the system default. 0 keeps history forever, subject to the maximum below.">
21
+ <Input @type="number" @value={{this.positionRetentionDays}} min="0" max="3650" class="form-input w-full" />
22
+ </InputGroup>
23
+ <InputGroup @name="Maximum Position History Retention (days)" @helpText="The longest any organization can keep vehicle and trailer positions. 0 sets no maximum and allows organizations to keep history forever.">
24
+ <Input @type="number" @value={{this.maxPositionRetentionDays}} min="0" max="3650" class="form-input w-full" />
25
+ </InputGroup>
26
+ </div>
27
+ </ContentPanel>
28
+
29
+ <ContentPanel @title="System Device Event Raw Payload Retention" @open={{true}} @wrapperClass="bordered-classic">
30
+ <InputGroup @name="Device Event Raw Payload Retention (days)" @helpText="Remove raw provider payloads from retained device events across all organizations after this many days. 0 disables compaction. This does not change how long the event history itself is kept.">
31
+ <Input @type="number" @value={{this.eventCompactAfterDays}} min="0" max="3650" class="form-input w-full" />
32
+ </InputGroup>
33
+ </ContentPanel>
34
+
35
+ <ContentPanel @title="System Delivery Inbox and Sync Run Retention Policy" @open={{true}} @wrapperClass="bordered-classic">
36
+ <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
37
+ <InputGroup @name="Processed Delivery Retention (hours)" @helpText="Delete processed delivery envelopes across all organizations after this many hours. 0 keeps them forever.">
38
+ <Input @type="number" @value={{this.processedRetentionHours}} min="0" max="720" class="form-input w-full" />
39
+ </InputGroup>
40
+ <InputGroup @name="Quarantined Delivery Retention (days)" @helpText="Delete quarantined delivery envelopes across all organizations after this many days. 0 keeps them forever.">
41
+ <Input @type="number" @value={{this.quarantineRetentionDays}} min="0" max="365" class="form-input w-full" />
42
+ </InputGroup>
43
+ <InputGroup @name="Sync Run Diagnostics Retention (days)" @helpText="Delete finished sync run diagnostics across all organizations after this many days. 0 keeps them forever.">
44
+ <Input @type="number" @value={{this.syncRunRetentionDays}} min="0" max="365" class="form-input w-full" />
45
+ </InputGroup>
46
+ </div>
47
+ </ContentPanel>
48
+
49
+ <ContentPanel @title="System Telemetry Activity Logging" @open={{true}} @wrapperClass="bordered-classic">
50
+ <Toggle
51
+ @label="Log Telemetry Activity"
52
+ @helpText="Write telemetry-driven device, event and vehicle saves to the activity log for all organizations. Every poll can add several activity rows per device."
53
+ @isToggled={{this.logTelemetryActivity}}
54
+ @onToggle={{fn (mut this.logTelemetryActivity)}}
55
+ />
56
+ </ContentPanel>
57
+
58
+ <div class="flex justify-end">
59
+ <Button
60
+ @type="primary"
61
+ @size="sm"
62
+ @icon="save"
63
+ @text="Save System Policy"
64
+ @onClick={{perform this.saveSettings}}
65
+ @disabled={{or this.saveSettings.isRunning this.loadSettings.isRunning (not this.settingsLoaded)}}
66
+ @isLoading={{or this.saveSettings.isRunning this.loadSettings.isRunning}}
67
+ />
68
+ </div>
69
+
70
+ <ContentPanel @title={{t "settings.telematics.storage-usage"}} @open={{true}} @wrapperClass="bordered-classic">
71
+ <p class="mb-3 text-sm text-gray-600 dark:text-gray-300">
72
+ Storage usage includes telematics data across all organizations. Cleanup applies system-wide, using the saved system policy and each organization's history preferences within that policy.
73
+ </p>
74
+ <div class="flex items-center justify-end gap-2 mb-3">
75
+ <Button
76
+ @size="xs"
77
+ @icon="rotate"
78
+ @text={{t "settings.telematics.refresh"}}
79
+ @onClick={{perform this.loadUsage}}
80
+ @disabled={{this.loadUsage.isRunning}}
81
+ @isLoading={{this.loadUsage.isRunning}}
82
+ />
83
+ <Button
84
+ @type="danger"
85
+ @size="xs"
86
+ @icon="broom"
87
+ @text={{t "settings.telematics.run-cleanup"}}
88
+ @onClick={{this.confirmRunCleanup}}
89
+ @disabled={{or this.runCleanup.isRunning this.loadSettings.isRunning this.saveSettings.isRunning (not this.settingsLoaded)}}
90
+ @isLoading={{this.runCleanup.isRunning}}
91
+ />
92
+ </div>
93
+ {{#if this.usageRows.length}}
94
+ <div class="overflow-x-auto">
95
+ <table class="w-full text-sm">
96
+ <thead>
97
+ <tr class="text-left text-xs uppercase text-gray-500 dark:text-gray-400">
98
+ <th class="py-2 pr-3">{{t "settings.telematics.table"}}</th>
99
+ <th class="py-2 pr-3 text-right">{{t "settings.telematics.rows"}}</th>
100
+ <th class="py-2 pr-3 text-right">{{t "settings.telematics.estimated-size"}}</th>
101
+ <th class="py-2 pl-6 text-right whitespace-nowrap">{{t "settings.telematics.oldest"}}</th>
102
+ </tr>
103
+ </thead>
104
+ <tbody class="divide-y divide-gray-100 dark:divide-gray-700">
105
+ {{#each this.usageRows as |row|}}
106
+ <tr class="text-gray-800 dark:text-gray-100">
107
+ <td class="py-2 pr-3">
108
+ <div class="font-medium">{{row.label}}</div>
109
+ {{#if row.raw_payload_rows}}
110
+ <div class="text-xs text-gray-500 dark:text-gray-400">
111
+ {{t "settings.telematics.raw-payload-rows" count=(format-number row.raw_payload_rows) compactable=(format-number row.compactable_rows)}}
112
+ </div>
113
+ {{/if}}
114
+ </td>
115
+ <td class="py-2 pr-3 text-right">
116
+ {{#if (eq row.rows null)}}
117
+ {{t "settings.telematics.not-available"}}
118
+ {{else if row.rows_estimated}}
119
+ {{t "settings.telematics.estimated-rows" count=(format-number row.rows)}}
120
+ {{else}}
121
+ {{format-number row.rows}}
122
+ {{/if}}
123
+ </td>
124
+ <td class="py-2 pr-3 text-right">{{#if (or row.estimated_bytes (eq row.estimated_bytes 0))}}{{format-bytes row.estimated_bytes}}{{else}}{{t "settings.telematics.not-available"}}{{/if}}</td>
125
+ <td class="py-2 pl-6 text-right text-xs whitespace-nowrap">{{#if row.oldest}}{{row.oldest}}{{else}}{{t "settings.telematics.not-available"}}{{/if}}</td>
126
+ </tr>
127
+ {{/each}}
128
+ </tbody>
129
+ </table>
130
+ </div>
131
+ <p class="mt-3 text-xs text-gray-500 dark:text-gray-400">{{t "settings.telematics.space-reclaim-note"}}</p>
132
+ {{else if this.loadUsage.isRunning}}
133
+ <div class="flex items-center justify-center py-8">
134
+ <Spinner />
135
+ </div>
136
+ {{else}}
137
+ <div class="text-center py-8 text-sm text-gray-400 dark:text-gray-500">
138
+ {{t "settings.telematics.usage-unavailable"}}
139
+ </div>
140
+ {{/if}}
141
+ </ContentPanel>
142
+ <Spacer @height="200px" />
143
+ </div>
@@ -0,0 +1,145 @@
1
+ import Component from '@glimmer/component';
2
+ import { tracked } from '@glimmer/tracking';
3
+ import { inject as service } from '@ember/service';
4
+ import { action } from '@ember/object';
5
+ import { task, timeout } from 'ember-concurrency';
6
+
7
+ /**
8
+ * System-wide telematics policy, storage diagnostics and operational controls.
9
+ */
10
+ export default class AdminTelematicsSettingsComponent extends Component {
11
+ @service fetch;
12
+ @service notifications;
13
+ @service intl;
14
+ @service modalsManager;
15
+ @tracked eventRetentionDays = 30;
16
+ @tracked maxEventRetentionDays = 0;
17
+ @tracked eventCompactAfterDays = 7;
18
+ @tracked positionRetentionDays = 90;
19
+ @tracked maxPositionRetentionDays = 0;
20
+ @tracked processedRetentionHours = 24;
21
+ @tracked quarantineRetentionDays = 7;
22
+ @tracked syncRunRetentionDays = 7;
23
+ @tracked logTelemetryActivity = false;
24
+ @tracked settingsLoaded = false;
25
+ @tracked usage = null;
26
+
27
+ constructor() {
28
+ super(...arguments);
29
+ this.loadSettings.perform();
30
+ this.loadUsage.perform();
31
+ }
32
+
33
+ @task({ drop: true }) *loadSettings() {
34
+ try {
35
+ const settings = yield this.fetch.get('fleet-ops/settings/admin-telematics-settings');
36
+ this.applySettings(settings);
37
+ this.settingsLoaded = true;
38
+ } catch (error) {
39
+ this.notifications.serverError(error);
40
+ }
41
+ }
42
+
43
+ @task({ drop: true }) *saveSettings() {
44
+ if (!this.settingsLoaded) {
45
+ return;
46
+ }
47
+
48
+ try {
49
+ const settings = yield this.fetch.post('fleet-ops/settings/admin-telematics-settings', this.settingsPayload);
50
+ this.applySettings(settings);
51
+ this.notifications.success('System telematics settings saved.');
52
+ } catch (error) {
53
+ this.notifications.serverError(error);
54
+ }
55
+ }
56
+
57
+ /** Load system-wide storage usage across all organizations. */
58
+ @task({ drop: true }) *loadUsage() {
59
+ const abortController = new AbortController();
60
+ const requestTimeout = setTimeout(() => abortController.abort(), 30000);
61
+
62
+ try {
63
+ // Pass the signal as request data; fetch.get options do not forward it.
64
+ const usage = yield this.fetch.request('fleet-ops/settings/telematics-storage-usage?include_payload_counts=0', 'GET', { signal: abortController.signal });
65
+ if (usage?.scope !== 'system') {
66
+ throw new Error(this.intl.t('settings.telematics.usage-unavailable'));
67
+ }
68
+ this.usage = usage;
69
+ } catch (error) {
70
+ this.notifications.serverError(abortController.signal.aborted ? new Error(this.intl.t('settings.telematics.usage-unavailable')) : error);
71
+ } finally {
72
+ clearTimeout(requestTimeout);
73
+ abortController.abort();
74
+ }
75
+ }
76
+
77
+ /** Queue cleanup for all organizations using the saved policy. */
78
+ @task({ drop: true }) *runCleanup() {
79
+ try {
80
+ const cleanup = yield this.fetch.post('fleet-ops/settings/telematics-retention/run');
81
+ if (cleanup?.scope !== 'system') {
82
+ throw new Error(this.intl.t('settings.telematics.cleanup-unavailable'));
83
+ }
84
+ this.notifications.success(this.intl.t('settings.telematics.cleanup-queued'));
85
+ yield timeout(5000);
86
+ yield this.loadUsage.perform();
87
+ } catch (error) {
88
+ this.notifications.serverError(error);
89
+ }
90
+ }
91
+
92
+ @action confirmRunCleanup() {
93
+ return this.modalsManager.confirm({
94
+ title: this.intl.t('settings.telematics.run-cleanup'),
95
+ body: this.intl.t('settings.telematics.run-cleanup-confirm'),
96
+ acceptButtonText: this.intl.t('settings.telematics.run-cleanup'),
97
+ acceptButtonIcon: 'broom',
98
+ onConfirm: () => this.runCleanup.perform(),
99
+ });
100
+ }
101
+
102
+ get usageRows() {
103
+ const tables = this.usage?.tables ?? {};
104
+
105
+ return ['device_events', 'positions', 'telematic_deliveries', 'telematic_sync_runs']
106
+ .filter((table) => tables[table])
107
+ .map((table) => ({ table, label: this.intl.t(`settings.telematics.tables.${table}`), ...tables[table] }));
108
+ }
109
+
110
+ get settingsPayload() {
111
+ return {
112
+ event_retention_days: this.toInteger(this.eventRetentionDays),
113
+ max_event_retention_days: this.maxEventRetentionDays,
114
+ event_compact_after_days: this.toInteger(this.eventCompactAfterDays),
115
+ position_retention_days: this.toInteger(this.positionRetentionDays),
116
+ max_position_retention_days: this.maxPositionRetentionDays,
117
+ processed_retention_hours: this.toInteger(this.processedRetentionHours),
118
+ quarantine_retention_days: this.toInteger(this.quarantineRetentionDays),
119
+ sync_run_retention_days: this.toInteger(this.syncRunRetentionDays),
120
+ log_telemetry_activity: Boolean(this.logTelemetryActivity),
121
+ };
122
+ }
123
+
124
+ applySettings(settings = {}) {
125
+ if (!Object.prototype.hasOwnProperty.call(settings ?? {}, 'max_event_retention_days') || !Object.prototype.hasOwnProperty.call(settings ?? {}, 'max_position_retention_days')) {
126
+ throw new Error(this.intl.t('settings.telematics.settings-unavailable'));
127
+ }
128
+
129
+ this.eventRetentionDays = settings.event_retention_days ?? this.eventRetentionDays;
130
+ this.maxEventRetentionDays = settings.max_event_retention_days ?? this.maxEventRetentionDays;
131
+ this.eventCompactAfterDays = settings.event_compact_after_days ?? this.eventCompactAfterDays;
132
+ this.positionRetentionDays = settings.position_retention_days ?? this.positionRetentionDays;
133
+ this.maxPositionRetentionDays = settings.max_position_retention_days ?? this.maxPositionRetentionDays;
134
+ this.processedRetentionHours = settings.processed_retention_hours ?? this.processedRetentionHours;
135
+ this.quarantineRetentionDays = settings.quarantine_retention_days ?? this.quarantineRetentionDays;
136
+ this.syncRunRetentionDays = settings.sync_run_retention_days ?? this.syncRunRetentionDays;
137
+ this.logTelemetryActivity = settings.log_telemetry_activity ?? this.logTelemetryActivity;
138
+ }
139
+
140
+ toInteger(value) {
141
+ const number = parseInt(value, 10);
142
+
143
+ return Number.isFinite(number) && number > 0 ? number : 0;
144
+ }
145
+ }
@@ -17,7 +17,7 @@
17
17
  </div>
18
18
  <div class="flex flex-shrink-0 items-center gap-2 whitespace-nowrap">
19
19
  <Button @icon="refresh" @size="sm" @helpText={{t "common.reload"}} @onClick={{@onRefresh}} />
20
- <Button @icon="plus" @text="Connect Integration" @type="primary" @size="sm" @onClick={{this.createIntegration}} />
20
+ <Button @icon="plus" @text="Connect Integration" @type="primary" @size="sm" @permission="fleet-ops create fuel-provider-connection" @onClick={{this.createIntegration}} />
21
21
  </div>
22
22
  </div>
23
23
  </section>
@@ -151,14 +151,14 @@ export default class LayoutFleetOpsSidebarComponent extends Component {
151
151
  this.createItem('menu.contacts', 'address-book', 'management.contacts', 'fleet-ops list contact', 'fleet-ops see contact'),
152
152
  this.createItem('menu.places', 'location-dot', 'management.places', 'fleet-ops list place', 'fleet-ops see place'),
153
153
  this.createItem('menu.fuel-reports', 'gas-pump', 'management.fuel-reports', 'fleet-ops list fuel-report', 'fleet-ops see fuel-report'),
154
- this.createItem('menu.fuel-transactions', 'credit-card', 'management.fuel-transactions', 'fleet-ops list fuel-report', 'fleet-ops see fuel-report'),
154
+ this.createItem('menu.fuel-transactions', 'credit-card', 'management.fuel-transactions', 'fleet-ops list fuel-provider-transaction', 'fleet-ops see fuel-provider-transaction'),
155
155
  this.createItem('menu.issues', 'triangle-exclamation', 'management.issues', 'fleet-ops list issue', 'fleet-ops see issue'),
156
156
  ]);
157
157
  }
158
158
 
159
159
  get maintenanceItems() {
160
160
  return this.withRegistryItems('maintenance', [
161
- this.createHubItem('Maintenance Hub', 'wrench', 'maintenance.index', 'fleet-ops list maintenance-schedule', 'fleet-ops see maintenance-schedule', [
161
+ this.createHubItem('Maintenance Hub', 'wrench', 'maintenance.index', 'fleet-ops list work-order', 'fleet-ops see work-order', [
162
162
  'maintenance hub',
163
163
  'service readiness',
164
164
  'maintenance control panel',
@@ -182,7 +182,9 @@ export default class LayoutFleetOpsSidebarComponent extends Component {
182
182
  get connectivityItems() {
183
183
  return this.withRegistryItems('connectivity', [
184
184
  this.createHubItem(this.intl.t('menu.telematics'), 'satellite-dish', 'connectivity.telematics', 'fleet-ops list telematic', 'fleet-ops see telematic', ['connectivity hub']),
185
- this.createItem('menu.fuel-providers', 'gas-pump', 'connectivity.fuel-providers', 'fleet-ops list fuel-report', 'fleet-ops see fuel-report', ['fuel integrations']),
185
+ this.createItem('menu.fuel-providers', 'gas-pump', 'connectivity.fuel-providers', 'fleet-ops list fuel-provider-connection', 'fleet-ops see fuel-provider-connection', [
186
+ 'fuel integrations',
187
+ ]),
186
188
  this.createItem('menu.devices', 'hard-drive', 'connectivity.devices', 'fleet-ops list device', 'fleet-ops see device'),
187
189
  this.createItem('menu.sensors', 'temperature-full', 'connectivity.sensors', 'fleet-ops list sensor', 'fleet-ops see sensor'),
188
190
  this.createItem('menu.events', 'stream', 'connectivity.events', 'fleet-ops list device-event', 'fleet-ops see device-event'),
@@ -191,18 +193,14 @@ export default class LayoutFleetOpsSidebarComponent extends Component {
191
193
 
192
194
  get analyticsItems() {
193
195
  return this.withRegistryItems('analytics', [
194
- this.createHubItem('Dashboard', 'chart-line', 'analytics.index', 'iam list report', 'fleet-ops see report', ['dashboard', 'fleetops dashboard', 'metrics']),
195
- this.createItem('menu.reports', 'file-import', 'analytics.reports', 'iam list report', 'fleet-ops see report'),
196
+ this.createHubItem('Dashboard', 'chart-line', 'analytics.index', 'fleet-ops view analytics', 'fleet-ops see analytics', ['dashboard', 'fleetops dashboard', 'metrics']),
197
+ this.createItem('menu.reports', 'file-import', 'analytics.reports', 'iam list report', 'iam see report'),
196
198
  ]);
197
199
  }
198
200
 
199
201
  get settingsItems() {
200
202
  return this.withRegistryItems('settings', [
201
- this.createHubItem('Settings Hub', 'sliders', 'settings.index', 'fleet-ops view navigator-settings', 'fleet-ops see navigator-settings', [
202
- 'settings hub',
203
- 'configuration dashboard',
204
- 'setup focus',
205
- ]),
203
+ this.createHubItem('Settings Hub', 'sliders', 'settings.index', null, null, ['settings hub', 'configuration dashboard', 'setup focus']),
206
204
  this.createItem('menu.navigator-app', 'location-arrow', 'settings.navigator-app', 'fleet-ops view navigator-settings', 'fleet-ops see navigator-settings'),
207
205
  this.createItem('menu.map', 'map', 'settings.map', 'fleet-ops view map-settings', 'fleet-ops see map-settings'),
208
206
  this.createItem('menu.payments', 'cash-register', 'settings.payments', 'fleet-ops view payments', 'fleet-ops see payments'),
@@ -210,8 +208,9 @@ export default class LayoutFleetOpsSidebarComponent extends Component {
210
208
  this.createItem('menu.routing', 'route', 'settings.routing', 'fleet-ops view routing-settings', 'fleet-ops see routing-settings'),
211
209
  this.createItem('menu.orchestrator', 'circle-nodes', 'settings.orchestrator', 'fleet-ops view routing-settings', 'fleet-ops see routing-settings'),
212
210
  this.createItem('menu.scheduling', 'calendar-days', 'settings.scheduling', 'fleet-ops view scheduling-settings', 'fleet-ops see scheduling-settings'),
213
- this.createItem('menu.custom-fields', 'pen-to-square', 'settings.custom-fields', 'fleet-ops view custom-field', 'fleet-ops see custom-field'),
214
- this.createItem('menu.avatars', 'icons', 'settings.avatars', 'fleet-ops view avatar', 'fleet-ops see avatar'),
211
+ this.createItem('menu.telematics-settings', 'satellite-dish', 'settings.telematics', 'fleet-ops view telematics-settings', 'fleet-ops see telematics-settings'),
212
+ this.createItem('menu.custom-fields', 'pen-to-square', 'settings.custom-fields', 'fleet-ops list custom-field', 'fleet-ops see custom-field'),
213
+ this.createItem('menu.avatars', 'icons', 'settings.avatars', 'fleet-ops list avatar', 'fleet-ops see avatar'),
215
214
  ]);
216
215
  }
217
216
 
@@ -265,18 +264,36 @@ export default class LayoutFleetOpsSidebarComponent extends Component {
265
264
  }
266
265
 
267
266
  createBranch({ id, label, icon, route, defaultRoute, requiresVisibleChildren = false, children, keywords = [] }) {
267
+ const visibleChildren = children.filter((item) => item.visible !== false);
268
+
268
269
  return {
269
270
  id,
270
271
  label,
271
272
  icon,
272
273
  route: this.fullRoute(route),
273
- defaultRoute: this.fullRoute(defaultRoute),
274
+ defaultRoute: this.resolveDefaultRoute(this.fullRoute(defaultRoute), visibleChildren),
274
275
  requiresVisibleChildren,
275
- children: children.filter((item) => item.visible !== false),
276
+ children: visibleChildren,
276
277
  keywords,
277
278
  };
278
279
  }
279
280
 
281
+ /**
282
+ * Keep the branch's default route when the user may open it; otherwise fall back to the
283
+ * first child route they are permitted to open, so clicking the branch does not land on a
284
+ * route guard that bounces them back out.
285
+ */
286
+ resolveDefaultRoute(defaultRoute, children = []) {
287
+ const permitted = (item) => [item.visiblePermission, item.permission].every((permission) => !permission || this.abilities.can(permission));
288
+ const defaultChild = children.find((item) => item.route === defaultRoute);
289
+
290
+ if (!defaultChild || permitted(defaultChild)) {
291
+ return defaultRoute;
292
+ }
293
+
294
+ return children.find((item) => item.route && permitted(item))?.route ?? defaultRoute;
295
+ }
296
+
280
297
  createItem(intl, icon, route, permission, ability, keywords = []) {
281
298
  return {
282
299
  priority: this.defaultPriorityForRoute(route),
@@ -290,7 +307,7 @@ export default class LayoutFleetOpsSidebarComponent extends Component {
290
307
  };
291
308
  }
292
309
 
293
- createHubItem(label, icon, route, _permission, _ability, keywords = []) {
310
+ createHubItem(label, icon, route, permission, ability, keywords = []) {
294
311
  return {
295
312
  pinnedFirst: true,
296
313
  priority: this.defaultPriorityForRoute(route),
@@ -298,6 +315,8 @@ export default class LayoutFleetOpsSidebarComponent extends Component {
298
315
  description: label,
299
316
  icon,
300
317
  route: this.fullRoute(route),
318
+ permission,
319
+ visiblePermission: ability,
301
320
  isNavigationHub: true,
302
321
  keywords: [label, route, ...keywords].filter(Boolean),
303
322
  };
@@ -387,8 +406,9 @@ export default class LayoutFleetOpsSidebarComponent extends Component {
387
406
  'settings.routing': 5,
388
407
  'settings.orchestrator': 6,
389
408
  'settings.scheduling': 7,
390
- 'settings.custom-fields': 8,
391
- 'settings.avatars': 9,
409
+ 'settings.telematics': 8,
410
+ 'settings.custom-fields': 9,
411
+ 'settings.avatars': 10,
392
412
  };
393
413
 
394
414
  return priorities[route] ?? 0;