@fleetbase/fleetops-engine 0.6.8 → 0.6.9
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.
- package/addon/components/activity-event-selector.js +4 -0
- package/addon/components/display-place.hbs +27 -3
- package/addon/components/route-list.hbs +3 -3
- package/addon/controllers/operations/orders/index.js +0 -4
- package/addon/routes/operations/orders/index/view.js +18 -1
- package/addon/services/movement-tracker.js +1 -1
- package/addon/styles/fleetops-engine.css +7 -0
- package/addon/templates/operations/orders/index/new.hbs +2 -2
- package/addon/templates/operations/orders/index/view.hbs +5 -1
- package/addon/templates/operations/orders/index.hbs +6 -1
- package/addon/templates/settings/notifications.hbs +9 -1
- package/composer.json +1 -1
- package/extension.json +1 -1
- package/package.json +1 -1
- package/server/src/Console/Commands/TrackOrderDistanceAndTime.php +2 -2
- package/server/src/Events/OrderCanceled.php +6 -0
- package/server/src/Events/OrderCompleted.php +6 -0
- package/server/src/Events/OrderDispatched.php +6 -0
- package/server/src/Events/OrderFailed.php +6 -0
- package/server/src/Events/WaypointActivityChanged.php +119 -0
- package/server/src/Events/WaypointCompleted.php +119 -0
- package/server/src/Flow/Activity.php +28 -10
- package/server/src/Flow/Event.php +26 -2
- package/server/src/Http/Controllers/Api/v1/DriverController.php +19 -2
- package/server/src/Http/Controllers/Api/v1/OrderController.php +274 -164
- package/server/src/Http/Controllers/Internal/v1/OrderController.php +15 -8
- package/server/src/Http/Filter/OrderFilter.php +4 -4
- package/server/src/Http/Resources/v1/Payload.php +1 -1
- package/server/src/Listeners/HandleOrderCanceled.php +0 -10
- package/server/src/Listeners/NotifyOrderEvent.php +4 -4
- package/server/src/Models/OrderConfig.php +50 -35
- package/server/src/Models/Payload.php +26 -7
- package/server/src/Models/Waypoint.php +10 -0
- package/server/src/Notifications/OrderAssigned.php +3 -5
- package/server/src/Notifications/OrderCanceled.php +32 -12
- package/server/src/Notifications/OrderCompleted.php +31 -11
- package/server/src/Notifications/OrderDispatchFailed.php +3 -5
- package/server/src/Notifications/OrderDispatched.php +31 -11
- package/server/src/Notifications/OrderFailed.php +32 -12
- package/server/src/Notifications/OrderPing.php +2 -6
- package/server/src/Notifications/OrderSplit.php +1 -1
- package/server/src/Notifications/WaypointCompleted.php +157 -0
|
@@ -4,6 +4,7 @@ namespace Fleetbase\FleetOps\Notifications;
|
|
|
4
4
|
|
|
5
5
|
use Fleetbase\FleetOps\Http\Resources\v1\Order as OrderResource;
|
|
6
6
|
use Fleetbase\FleetOps\Models\Order;
|
|
7
|
+
use Fleetbase\FleetOps\Models\Waypoint;
|
|
7
8
|
use Fleetbase\FleetOps\Support\Utils;
|
|
8
9
|
use Fleetbase\Support\PushNotification;
|
|
9
10
|
use Illuminate\Broadcasting\Channel;
|
|
@@ -21,10 +22,17 @@ class OrderFailed extends Notification implements ShouldQueue
|
|
|
21
22
|
/**
|
|
22
23
|
* The order instance this notification is for.
|
|
23
24
|
*
|
|
24
|
-
* @var
|
|
25
|
+
* @var Order
|
|
25
26
|
*/
|
|
26
27
|
public $order;
|
|
27
28
|
|
|
29
|
+
/**
|
|
30
|
+
* The waypoint instance this notification is for.
|
|
31
|
+
*
|
|
32
|
+
* @var Waypoint
|
|
33
|
+
*/
|
|
34
|
+
public $waypoint;
|
|
35
|
+
|
|
28
36
|
/**
|
|
29
37
|
* Notification name.
|
|
30
38
|
*/
|
|
@@ -65,13 +73,14 @@ class OrderFailed extends Notification implements ShouldQueue
|
|
|
65
73
|
*
|
|
66
74
|
* @return void
|
|
67
75
|
*/
|
|
68
|
-
public function __construct(Order $order, string $reason = '')
|
|
76
|
+
public function __construct(Order $order, string $reason = '', ?Waypoint $waypoint = null)
|
|
69
77
|
{
|
|
70
|
-
$this->order
|
|
71
|
-
$this->reason
|
|
72
|
-
$this->
|
|
73
|
-
$this->
|
|
74
|
-
$this->
|
|
78
|
+
$this->order = $order;
|
|
79
|
+
$this->reason = $reason;
|
|
80
|
+
$this->waypoint = $waypoint;
|
|
81
|
+
$this->title = 'Order ' . $this->getTrackingNumber() . ' delivery has has failed';
|
|
82
|
+
$this->message = 'Order ' . $this->getTrackingNumber() . ' delivery has failed.';
|
|
83
|
+
$this->data = ['id' => $this->order->public_id, 'type' => 'order_canceled'];
|
|
75
84
|
}
|
|
76
85
|
|
|
77
86
|
/**
|
|
@@ -110,12 +119,10 @@ class OrderFailed extends Notification implements ShouldQueue
|
|
|
110
119
|
$order = new OrderResource($this->order);
|
|
111
120
|
|
|
112
121
|
return [
|
|
122
|
+
'event' => 'order.failed_notification',
|
|
113
123
|
'title' => $this->title,
|
|
114
124
|
'body' => $this->message . ' ' . $this->reason,
|
|
115
|
-
'data' =>
|
|
116
|
-
...$this->data,
|
|
117
|
-
'order' => $order->toWebhookPayload(),
|
|
118
|
-
],
|
|
125
|
+
'data' => $this->data,
|
|
119
126
|
];
|
|
120
127
|
}
|
|
121
128
|
|
|
@@ -131,7 +138,7 @@ class OrderFailed extends Notification implements ShouldQueue
|
|
|
131
138
|
->line($this->message)
|
|
132
139
|
->line($this->reason)
|
|
133
140
|
->line('No further action is necessary.')
|
|
134
|
-
->action('Track Order', Utils::consoleUrl('track-order', ['order' => $this->
|
|
141
|
+
->action('Track Order', Utils::consoleUrl('track-order', ['order' => $this->getTrackingNumber()]));
|
|
135
142
|
}
|
|
136
143
|
|
|
137
144
|
/**
|
|
@@ -153,4 +160,17 @@ class OrderFailed extends Notification implements ShouldQueue
|
|
|
153
160
|
{
|
|
154
161
|
return PushNotification::createApnMessage($this->title, $this->message, $this->data, 'view_order');
|
|
155
162
|
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Get the tracking number which should be used for this event.
|
|
166
|
+
* In the case that the order has a currentWaypoint attached use its tracking number otherwise use the orders.
|
|
167
|
+
*/
|
|
168
|
+
private function getTrackingNumber(): ?string
|
|
169
|
+
{
|
|
170
|
+
if ($this->waypoint instanceof Waypoint) {
|
|
171
|
+
return $this->waypoint->tracking;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return $this->order->tracking;
|
|
175
|
+
}
|
|
156
176
|
}
|
|
@@ -133,15 +133,11 @@ class OrderPing extends Notification implements ShouldQueue
|
|
|
133
133
|
*/
|
|
134
134
|
public function toArray()
|
|
135
135
|
{
|
|
136
|
-
$order = new OrderResource($this->order);
|
|
137
|
-
|
|
138
136
|
return [
|
|
137
|
+
'event' => 'order.ping_notification',
|
|
139
138
|
'title' => $this->title,
|
|
140
139
|
'body' => $this->message,
|
|
141
|
-
'data' =>
|
|
142
|
-
...$this->data,
|
|
143
|
-
'order' => $order->toWebhookPayload(),
|
|
144
|
-
],
|
|
140
|
+
'data' => $this->data,
|
|
145
141
|
];
|
|
146
142
|
}
|
|
147
143
|
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Fleetbase\FleetOps\Notifications;
|
|
4
|
+
|
|
5
|
+
use Fleetbase\FleetOps\Flow\Activity;
|
|
6
|
+
use Fleetbase\FleetOps\Models\Order;
|
|
7
|
+
use Fleetbase\FleetOps\Models\Waypoint;
|
|
8
|
+
use Fleetbase\FleetOps\Support\Utils;
|
|
9
|
+
use Fleetbase\Support\PushNotification;
|
|
10
|
+
use Illuminate\Broadcasting\Channel;
|
|
11
|
+
use Illuminate\Bus\Queueable;
|
|
12
|
+
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
13
|
+
use Illuminate\Notifications\Messages\MailMessage;
|
|
14
|
+
use Illuminate\Notifications\Notification;
|
|
15
|
+
use NotificationChannels\Apn\ApnChannel;
|
|
16
|
+
use NotificationChannels\Fcm\FcmChannel;
|
|
17
|
+
|
|
18
|
+
class WaypointCompleted extends Notification implements ShouldQueue
|
|
19
|
+
{
|
|
20
|
+
use Queueable;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The order instance this notification is for.
|
|
24
|
+
*
|
|
25
|
+
* @var Waypoint
|
|
26
|
+
*/
|
|
27
|
+
public $waypoint;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The activity which triggered this waypoint completed..
|
|
31
|
+
*
|
|
32
|
+
* @var Activity
|
|
33
|
+
*/
|
|
34
|
+
public $activity;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Notification name.
|
|
38
|
+
*/
|
|
39
|
+
public static string $name = 'Waypoint Completed';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Notification description.
|
|
43
|
+
*/
|
|
44
|
+
public static string $description = 'When an order waypoint/destination has been completed.';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Notification package.
|
|
48
|
+
*/
|
|
49
|
+
public static string $package = 'fleet-ops';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The title of the notification.
|
|
53
|
+
*/
|
|
54
|
+
public string $title;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The message body of the notification.
|
|
58
|
+
*/
|
|
59
|
+
public string $message;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Additional data to be sent with the notification.
|
|
63
|
+
*/
|
|
64
|
+
public array $data = [];
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Create a new notification instance.
|
|
68
|
+
*
|
|
69
|
+
* @return void
|
|
70
|
+
*/
|
|
71
|
+
public function __construct(Waypoint $waypoint, Activity $activity)
|
|
72
|
+
{
|
|
73
|
+
$this->waypoint = $waypoint;
|
|
74
|
+
$this->activity = $activity;
|
|
75
|
+
$this->title = 'Order ' . $this->waypoint->trackingNumber->tracking_number . ' ' . strtolower($activity->details);
|
|
76
|
+
$this->message = $activity->details;
|
|
77
|
+
$this->data = ['id' => $this->waypoint->public_id, 'type' => 'waypoint_completed'];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Get the notification's delivery channels.
|
|
82
|
+
*
|
|
83
|
+
* @return array
|
|
84
|
+
*/
|
|
85
|
+
public function via($notifiable)
|
|
86
|
+
{
|
|
87
|
+
return ['broadcast', 'mail', FcmChannel::class, ApnChannel::class];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Get the channels the event should broadcast on.
|
|
92
|
+
*
|
|
93
|
+
* @return Channel|array
|
|
94
|
+
*/
|
|
95
|
+
public function broadcastOn()
|
|
96
|
+
{
|
|
97
|
+
$channels = [new Channel('api.' . session('api_credential'))];
|
|
98
|
+
$order = Order::where('payload_uuid', $this->waypoint->payload_uuid)->first();
|
|
99
|
+
if ($order) {
|
|
100
|
+
$channels[] = new Channel('company.' . session('company', data_get($order, 'company.uuid')));
|
|
101
|
+
$channels[] = new Channel('company.' . data_get($order, 'company.public_id'));
|
|
102
|
+
$channels[] = new Channel('order.' . $order->uuid);
|
|
103
|
+
$channels[] = new Channel('order.' . $order->public_id);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return $channels;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Get notification as array.
|
|
111
|
+
*
|
|
112
|
+
* @return void
|
|
113
|
+
*/
|
|
114
|
+
public function toArray()
|
|
115
|
+
{
|
|
116
|
+
return [
|
|
117
|
+
'event.waypoint_completed_notification',
|
|
118
|
+
'title' => $this->title,
|
|
119
|
+
'body' => $this->message,
|
|
120
|
+
'data' => $this->data,
|
|
121
|
+
];
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Get the mail representation of the notification.
|
|
126
|
+
*
|
|
127
|
+
* @return MailMessage
|
|
128
|
+
*/
|
|
129
|
+
public function toMail($notifiable)
|
|
130
|
+
{
|
|
131
|
+
return (new MailMessage())
|
|
132
|
+
->subject($this->title)
|
|
133
|
+
->line($this->message)
|
|
134
|
+
->line('No further action is necessary.')
|
|
135
|
+
->action('Track Order', Utils::consoleUrl('track-order', ['order' => $this->waypoint->trackingNumber->tracking_number]));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get the firebase cloud message representation of the notification.
|
|
140
|
+
*
|
|
141
|
+
* @return array
|
|
142
|
+
*/
|
|
143
|
+
public function toFcm($notifiable)
|
|
144
|
+
{
|
|
145
|
+
return PushNotification::createFcmMessage($this->title, $this->message, $this->data);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Get the apns message representation of the notification.
|
|
150
|
+
*
|
|
151
|
+
* @return array
|
|
152
|
+
*/
|
|
153
|
+
public function toApn($notifiable)
|
|
154
|
+
{
|
|
155
|
+
return PushNotification::createApnMessage($this->title, $this->message, $this->data, 'view_order');
|
|
156
|
+
}
|
|
157
|
+
}
|