@olenbetong/synergi-react 5.4.0 → 5.6.0

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 (133) hide show
  1. package/dist/styles/styles.css +1 -1
  2. package/dist/styles/styles.css.map +1 -1
  3. package/es/charts/CallOffDeliveries/TicketScanDialog.d.ts +7 -0
  4. package/es/charts/CallOffDeliveries/TicketScanDialog.js +47 -0
  5. package/es/charts/CallOffDeliveries/chartOptions.d.ts +8 -0
  6. package/es/charts/CallOffDeliveries/chartOptions.js +138 -0
  7. package/es/charts/CallOffDeliveries/data.d.ts +35 -0
  8. package/es/charts/CallOffDeliveries/data.js +30 -0
  9. package/es/charts/CallOffDeliveries/index.css +1 -0
  10. package/es/charts/CallOffDeliveries/index.d.ts +24 -0
  11. package/es/charts/CallOffDeliveries/index.js +115 -0
  12. package/es/charts/CallOffDeliveries/model.d.ts +37 -0
  13. package/es/charts/CallOffDeliveries/model.js +59 -0
  14. package/es/charts/ProductionPlan/PlanValueDialog.d.ts +14 -0
  15. package/es/charts/ProductionPlan/PlanValueDialog.js +47 -0
  16. package/es/charts/ProductionPlan/chartOptions.d.ts +20 -0
  17. package/es/charts/ProductionPlan/chartOptions.js +353 -0
  18. package/es/charts/ProductionPlan/data.d.ts +105 -0
  19. package/es/charts/ProductionPlan/data.js +61 -0
  20. package/es/charts/ProductionPlan/index.css +1 -0
  21. package/es/charts/ProductionPlan/index.d.ts +31 -0
  22. package/es/charts/ProductionPlan/index.js +203 -0
  23. package/es/charts/ProductionPlan/model.d.ts +29 -0
  24. package/es/charts/ProductionPlan/model.js +65 -0
  25. package/es/charts/Pumping/chartOptions.d.ts +12 -0
  26. package/es/charts/Pumping/chartOptions.js +197 -0
  27. package/es/charts/Pumping/data.d.ts +65 -0
  28. package/es/charts/Pumping/data.js +20 -0
  29. package/es/charts/Pumping/index.css +1 -0
  30. package/es/charts/Pumping/index.d.ts +27 -0
  31. package/es/charts/Pumping/index.js +124 -0
  32. package/es/charts/Pumping/model.d.ts +34 -0
  33. package/es/charts/Pumping/model.js +88 -0
  34. package/es/charts/UnboundPreview/chartOptions.d.ts +3 -0
  35. package/es/charts/UnboundPreview/chartOptions.js +126 -0
  36. package/es/charts/UnboundPreview/index.css +1 -0
  37. package/es/charts/UnboundPreview/index.d.ts +20 -0
  38. package/es/charts/UnboundPreview/index.js +55 -0
  39. package/es/charts/UnboundPreview/model.d.ts +49 -0
  40. package/es/charts/UnboundPreview/model.js +67 -0
  41. package/es/charts/VehicleDeliveries/chartOptions.d.ts +13 -0
  42. package/es/charts/VehicleDeliveries/chartOptions.js +270 -0
  43. package/es/charts/VehicleDeliveries/data.d.ts +71 -0
  44. package/es/charts/VehicleDeliveries/data.js +20 -0
  45. package/es/charts/VehicleDeliveries/deliveryXRange.d.ts +4 -0
  46. package/es/charts/VehicleDeliveries/deliveryXRange.js +62 -0
  47. package/es/charts/VehicleDeliveries/index.css +1 -0
  48. package/es/charts/VehicleDeliveries/index.d.ts +24 -0
  49. package/es/charts/VehicleDeliveries/index.js +129 -0
  50. package/es/charts/VehicleDeliveries/model.d.ts +24 -0
  51. package/es/charts/VehicleDeliveries/model.js +106 -0
  52. package/es/charts/format.d.ts +12 -0
  53. package/es/charts/format.js +34 -0
  54. package/es/charts/index.d.ts +5 -0
  55. package/es/charts/index.js +5 -0
  56. package/es/charts/storage.d.ts +5 -0
  57. package/es/charts/storage.js +35 -0
  58. package/es/chrome/assistant.d.ts +75 -0
  59. package/es/chrome/assistant.js +116 -0
  60. package/es/components/ColorCard/index.css +8 -8
  61. package/es/index.css +1 -1
  62. package/es/index.d.ts +1 -0
  63. package/es/index.js +1 -0
  64. package/es/vehicles/VehicleInfoDialog/OutOfServiceForm.d.ts +4 -0
  65. package/es/vehicles/VehicleInfoDialog/OutOfServiceForm.js +51 -0
  66. package/es/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.d.ts +99 -0
  67. package/es/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.js +499 -0
  68. package/es/vehicles/VehicleInfoDialog/data/dsDriverStatus.d.ts +13 -0
  69. package/es/vehicles/VehicleInfoDialog/data/dsDriverStatus.js +69 -0
  70. package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfo.d.ts +33 -0
  71. package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfo.js +164 -0
  72. package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.d.ts +15 -0
  73. package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.js +80 -0
  74. package/es/vehicles/VehicleInfoDialog/formatting.d.ts +13 -0
  75. package/es/vehicles/VehicleInfoDialog/formatting.js +48 -0
  76. package/es/vehicles/VehicleInfoDialog/index.css +1 -0
  77. package/es/vehicles/VehicleInfoDialog/index.d.ts +11 -0
  78. package/es/vehicles/VehicleInfoDialog/index.js +46 -0
  79. package/es/vehicles/VehicleInfoDialog/tabs.d.ts +6 -0
  80. package/es/vehicles/VehicleInfoDialog/tabs.js +85 -0
  81. package/es/vehicles/index.d.ts +1 -0
  82. package/es/vehicles/index.js +1 -0
  83. package/package.json +17 -8
  84. package/src/charts/CallOffDeliveries/TicketScanDialog.tsx +79 -0
  85. package/src/charts/CallOffDeliveries/chartOptions.ts +160 -0
  86. package/src/charts/CallOffDeliveries/data.ts +67 -0
  87. package/src/charts/CallOffDeliveries/index.scss +51 -0
  88. package/src/charts/CallOffDeliveries/index.tsx +217 -0
  89. package/src/charts/CallOffDeliveries/model.test.ts +90 -0
  90. package/src/charts/CallOffDeliveries/model.ts +87 -0
  91. package/src/charts/ProductionPlan/PlanValueDialog.tsx +107 -0
  92. package/src/charts/ProductionPlan/chartOptions.ts +406 -0
  93. package/src/charts/ProductionPlan/data.ts +170 -0
  94. package/src/charts/ProductionPlan/index.scss +148 -0
  95. package/src/charts/ProductionPlan/index.tsx +432 -0
  96. package/src/charts/ProductionPlan/model.test.ts +132 -0
  97. package/src/charts/ProductionPlan/model.ts +102 -0
  98. package/src/charts/Pumping/chartOptions.ts +224 -0
  99. package/src/charts/Pumping/data.ts +91 -0
  100. package/src/charts/Pumping/index.scss +42 -0
  101. package/src/charts/Pumping/index.tsx +222 -0
  102. package/src/charts/Pumping/model.test.ts +122 -0
  103. package/src/charts/Pumping/model.ts +104 -0
  104. package/src/charts/UnboundPreview/chartOptions.ts +137 -0
  105. package/src/charts/UnboundPreview/index.scss +17 -0
  106. package/src/charts/UnboundPreview/index.tsx +100 -0
  107. package/src/charts/UnboundPreview/model.test.ts +129 -0
  108. package/src/charts/UnboundPreview/model.ts +110 -0
  109. package/src/charts/VehicleDeliveries/chartOptions.ts +311 -0
  110. package/src/charts/VehicleDeliveries/data.ts +98 -0
  111. package/src/charts/VehicleDeliveries/deliveryXRange.ts +80 -0
  112. package/src/charts/VehicleDeliveries/index.scss +43 -0
  113. package/src/charts/VehicleDeliveries/index.tsx +262 -0
  114. package/src/charts/VehicleDeliveries/model.test.ts +117 -0
  115. package/src/charts/VehicleDeliveries/model.ts +139 -0
  116. package/src/charts/format.ts +38 -0
  117. package/src/charts/index.ts +20 -0
  118. package/src/charts/storage.ts +36 -0
  119. package/src/chrome/assistant.test.tsx +106 -0
  120. package/src/chrome/assistant.ts +178 -0
  121. package/src/components/ColorCard/index.css +8 -8
  122. package/src/index.ts +9 -0
  123. package/src/vehicles/VehicleInfoDialog/OutOfServiceForm.tsx +127 -0
  124. package/src/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.ts +600 -0
  125. package/src/vehicles/VehicleInfoDialog/data/dsDriverStatus.ts +84 -0
  126. package/src/vehicles/VehicleInfoDialog/data/dsVehicleInfo.ts +198 -0
  127. package/src/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.ts +97 -0
  128. package/src/vehicles/VehicleInfoDialog/formatting.test.ts +57 -0
  129. package/src/vehicles/VehicleInfoDialog/formatting.ts +58 -0
  130. package/src/vehicles/VehicleInfoDialog/index.scss +131 -0
  131. package/src/vehicles/VehicleInfoDialog/index.tsx +106 -0
  132. package/src/vehicles/VehicleInfoDialog/tabs.tsx +188 -0
  133. package/src/vehicles/index.ts +1 -0
@@ -0,0 +1,102 @@
1
+ import type {
2
+ CallOffWarningRecord,
3
+ PlannedDeliveryRecord,
4
+ PlantRecord,
5
+ ProdPlanResult,
6
+ ProdVolumeRecord,
7
+ ProdVolumeResult,
8
+ VehicleCountRecord,
9
+ } from "./data.js";
10
+
11
+ export type PlantPlan = {
12
+ plant: PlantRecord;
13
+ volume: ProdVolumeRecord[];
14
+ vehicleCounts: VehicleCountRecord[];
15
+ deliveries: PlannedDeliveryRecord[];
16
+ /** The warnings of each call-off, joined into one text. */
17
+ warnings: Map<number, string>;
18
+ };
19
+
20
+ export type PlanData = {
21
+ plants: PlantPlan[];
22
+ /** Call-offs of the day without planned loads, for all the plants together. */
23
+ unplanned: number;
24
+ };
25
+
26
+ export type DeliveryMethod = "pump" | "telescopic" | "conveyor" | "none";
27
+
28
+ /** The values the user can change on a planned load, from the columns left of the chart. */
29
+ export type PlanParameter = "arrival" | "interval" | "drivetime" | "unloadtime";
30
+
31
+ export function getPlanData(volume: ProdVolumeResult, plan: ProdPlanResult, selectedPlants: number[]): PlanData {
32
+ let plants = [...plan.Table3, ...volume.Table1];
33
+
34
+ return {
35
+ unplanned: Number(plan.Table2[0]?.Unplanned ?? 0),
36
+ plants: selectedPlants.flatMap((plantId) => {
37
+ let plant = plants.find((candidate) => candidate.PlantID === plantId);
38
+ if (!plant) return [];
39
+
40
+ let warnings = new Map<number, string>();
41
+ for (let warning of plan.Table4.filter((row: CallOffWarningRecord) => row.PlantID === plantId)) {
42
+ let current = warnings.get(warning.CallOffID);
43
+ warnings.set(warning.CallOffID, current ? `${current}\n${warning.WarningText}` : warning.WarningText);
44
+ }
45
+
46
+ return [
47
+ {
48
+ plant,
49
+ volume: volume.Table.filter((row) => row.PlantID === plantId),
50
+ vehicleCounts: plan.Table.filter((row) => row.PlantID === plantId),
51
+ deliveries: plan.Table1.filter((row) => row.PlantID === plantId),
52
+ warnings,
53
+ },
54
+ ];
55
+ }),
56
+ };
57
+ }
58
+
59
+ export function getDeliveryMethod(
60
+ row: Pick<PlannedDeliveryRecord, "Pumping" | "Telescopic" | "ConveyorBelt">,
61
+ ): DeliveryMethod {
62
+ if (row.Pumping) return "pump";
63
+ if (row.Telescopic) return "telescopic";
64
+ if (row.ConveyorBelt) return "conveyor";
65
+ return "none";
66
+ }
67
+
68
+ /** The call-off's name and quantity are only shown on its first load. */
69
+ export function isFirstLoad(deliveries: PlannedDeliveryRecord[], index: number) {
70
+ return index === 0 || deliveries[index - 1]?.CallOffID !== deliveries[index]?.CallOffID;
71
+ }
72
+
73
+ /** The top of a value axis: the largest value rounded up to the step, never below one step. */
74
+ export function getAxisMax(values: number[], step: number) {
75
+ return Math.max(Math.ceil(Math.max(0, ...values) / step) * step, step);
76
+ }
77
+
78
+ /**
79
+ * Reads what the user typed for a planning value. Minutes must be a whole number; the arrival a
80
+ * time of day, which also accepts "7.30" and "0730". Returns null when the text is not valid.
81
+ */
82
+ export function parsePlanValue(parameter: PlanParameter, text: string): number | string | null {
83
+ let value = text.trim();
84
+
85
+ if (parameter === "arrival") {
86
+ let match = /^(\d{1,2})[:.]?(\d{2})$/.exec(value);
87
+ if (!match) return null;
88
+
89
+ let hours = Number(match[1]);
90
+ let minutes = Number(match[2]);
91
+ if (hours > 23 || minutes > 59) return null;
92
+
93
+ return `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
94
+ }
95
+
96
+ if (!/^\d+$/.test(value)) return null;
97
+ return Number(value);
98
+ }
99
+
100
+ export function getChartHeight(deliveryCount: number) {
101
+ return deliveryCount * 20 + 110;
102
+ }
@@ -0,0 +1,224 @@
1
+ import Highcharts from "highcharts";
2
+
3
+ import { getLocalizedString, localize } from "../../i18n.js";
4
+ import type { PumpBookingRecord } from "./data.js";
5
+ import { type ChartData, getBookingPlant, getChartHeight, getPumpFeature, getPumpHome } from "./model.js";
6
+ import { formatTime, escapeHtml, barColor, PLANT_COLORS } from "../format.js";
7
+
8
+ const HOUR = 3600000;
9
+
10
+ export type MoveBooking = (booking: PumpBookingRecord, pumpNo: number, start: Date, end: Date) => void;
11
+
12
+ export type ChartSettings = {
13
+ date: Date;
14
+ minOffset: number;
15
+ maxOffset: number;
16
+ readOnly: boolean;
17
+ onMove: MoveBooking;
18
+ };
19
+
20
+ function plantColor(colorIndex: Map<number, number>, plantId: number) {
21
+ return PLANT_COLORS[(colorIndex.get(plantId) ?? 0) % PLANT_COLORS.length];
22
+ }
23
+
24
+ function pumpLabelHtml(data: ChartData, pumpNo: number) {
25
+ let pump = data.pumps.find((candidate) => candidate.ObjectNo === pumpNo);
26
+ if (!pump) return "";
27
+
28
+ let feature = getPumpFeature(pump);
29
+ let { show, home } = getPumpHome(pump, data.plants, data.merged);
30
+
31
+ return [
32
+ `<div style="min-width:95px">`,
33
+ `<a href="#vehicle-${pumpNo}">${pumpNo}</a>`,
34
+ feature
35
+ ? `<span style="background:${feature.color};margin-left:4px;padding:0 2px;color:#000">${feature.label}</span>`
36
+ : "",
37
+ show ? ` (${escapeHtml(home ?? "E")})` : "",
38
+ `</div>`,
39
+ ].join("");
40
+ }
41
+
42
+ function bookingTooltip(data: ChartData, booking: PumpBookingRecord, point: any) {
43
+ let pump = data.pumps.find((candidate) => candidate.ObjectNo === point.objectNo);
44
+ let { show, home } = getPumpHome(pump ?? { LocationID: null }, data.plants, data.merged);
45
+ let plant = getBookingPlant(booking, data.merged);
46
+
47
+ let vehicle = `${getLocalizedString("Vehicle")} ${point.objectNo}`;
48
+ if (show) vehicle += ` (${home === null ? getLocalizedString("external") : localize`from plant ${home}`})`;
49
+
50
+ let callOff = `${getLocalizedString("Call-off")} ${booking.CallOffID}`;
51
+ if (plant !== null) callOff += ` (${getLocalizedString("Plant")}: ${plant})`;
52
+
53
+ return `<div style="font-size:10px">
54
+ <div>${vehicle}</div>
55
+ <div>${getLocalizedString("Pumping at")} ${formatTime(point.x)} - ${formatTime(point.x2)}</div>
56
+ <div style="color:var(--ds-color-info-text-subtle)">
57
+ <div>${callOff}</div>
58
+ <div>${escapeHtml(booking.CustomerName)}</div>
59
+ <div>${escapeHtml(booking.Site)}</div>
60
+ </div>
61
+ </div>`;
62
+ }
63
+
64
+ export function getChartOptions(data: ChartData, settings: ChartSettings): Highcharts.Options {
65
+ let { date, minOffset, maxOffset, readOnly, onMove } = settings;
66
+ let midnight = date.getTime();
67
+ let min = midnight + minOffset * HOUR;
68
+ let max = midnight + maxOffset * HOUR;
69
+ let categories = data.pumps.map((pump) => pump.ObjectNo);
70
+ let bookings = new Map(data.bookings.map((row) => [`${row.PlantID}-${row.CallOffID}`, row]));
71
+
72
+ let pumpTimes = data.bookings.map((row) => {
73
+ let color = row.IndirectBooking
74
+ ? barColor("#bbb", 0.4)
75
+ : barColor(data.merged ? plantColor(data.colorIndex, row.PlantID) : PLANT_COLORS[0], 0.6);
76
+
77
+ return {
78
+ y: categories.indexOf(row.ObjectNo),
79
+ x: row.PumpStart.getTime(),
80
+ x2: row.PumpEnd.getTime(),
81
+ bookingKey: `${row.PlantID}-${row.CallOffID}`,
82
+ objectNo: row.ObjectNo,
83
+ ...color,
84
+ };
85
+ });
86
+
87
+ let outOfService = data.outOfService.map((row) => ({
88
+ y: categories.indexOf(row.ObjectNo),
89
+ x: row.FromDateTime.getTime(),
90
+ x2: row.ToDateTime.getTime(),
91
+ caption: row.Comment,
92
+ ...barColor("#ff9999", 0.6),
93
+ }));
94
+
95
+ let subtitle = data.merged
96
+ ? data.plants
97
+ .map(
98
+ (plant) =>
99
+ `<span style="color:${plantColor(data.colorIndex, plant.PlantID)}">●</span> ${plant.PlantID} - ${escapeHtml(plant.Description)}`,
100
+ )
101
+ .join("&nbsp;&nbsp;&nbsp;&nbsp;")
102
+ : `${data.plants[0].PlantID} - ${escapeHtml(data.plants[0].Description)}`;
103
+
104
+ let band = (from: number, to: number) => ({ color: "var(--ds-color-neutral-background-tinted)", from, to });
105
+
106
+ return {
107
+ chart: {
108
+ type: "xrange",
109
+ backgroundColor: "transparent",
110
+ zooming: { type: "x" },
111
+ height: getChartHeight(categories.length, data.merged),
112
+ marginTop: data.merged ? 100 : 70,
113
+ marginBottom: 40,
114
+ },
115
+ accessibility: { enabled: false },
116
+ credits: { enabled: false },
117
+ title: { text: undefined },
118
+ subtitle: { useHTML: true, text: subtitle },
119
+ xAxis: [
120
+ {
121
+ type: "datetime",
122
+ min,
123
+ max,
124
+ dateTimeLabelFormats: { hour: "%H", day: "%d.%m" },
125
+ tickInterval: HOUR,
126
+ minorTickInterval: 0.5 * HOUR,
127
+ plotBands: [band(min - 24 * HOUR, midnight + 6 * HOUR), band(midnight + 18 * HOUR, max + 24 * HOUR)],
128
+ plotLines: [
129
+ {
130
+ color: "#ffcc00",
131
+ width: 2,
132
+ dashStyle: "Dot",
133
+ // The bars are wall clock times carried as UTC, so "now" has to be as well.
134
+ value: Date.now() - new Date().getTimezoneOffset() * 60000,
135
+ },
136
+ ],
137
+ },
138
+ { type: "datetime", linkedTo: 0, opposite: true, dateTimeLabelFormats: { hour: "%H", day: "%d.%m" } },
139
+ ],
140
+ yAxis: {
141
+ categories: categories.map(String),
142
+ reversed: true,
143
+ min: 0,
144
+ max: categories.length - 1,
145
+ title: { text: "" },
146
+ tickInterval: 1,
147
+ gridLineColor: "var(--ds-color-neutral-border-subtle)",
148
+ labels: {
149
+ useHTML: true,
150
+ formatter(this: any) {
151
+ return pumpLabelHtml(data, Number(this.value));
152
+ },
153
+ },
154
+ },
155
+ tooltip: {
156
+ useHTML: true,
157
+ formatter(this: any) {
158
+ if (this.series.name !== "PumpTimes") return false;
159
+
160
+ let booking = bookings.get(this.point.bookingKey);
161
+ return booking ? bookingTooltip(data, booking, this.point) : false;
162
+ },
163
+ },
164
+ plotOptions: {
165
+ xrange: {
166
+ animation: false,
167
+ grouping: false,
168
+ groupPadding: 0.065,
169
+ colorByPoint: false,
170
+ borderWidth: 1,
171
+ borderColor: "#888",
172
+ borderRadius: 0,
173
+ dataLabels: {
174
+ enabled: true,
175
+ color: "var(--ds-color-neutral-text-default)",
176
+ align: "left",
177
+ y: 2,
178
+ style: { fontWeight: "normal", fontSize: "10px", textOutline: "none" },
179
+ formatter(this: any) {
180
+ if (this.series.name !== "PumpTimes") return this.point.caption;
181
+ return `${formatTime(this.point.x)}-${formatTime(this.point.x2)}`;
182
+ },
183
+ },
184
+ dragDrop: {
185
+ draggableX: !readOnly,
186
+ draggableY: !readOnly,
187
+ draggableX1: false,
188
+ draggableX2: false,
189
+ dragPrecisionX: 5 * 60 * 1000,
190
+ liveRedraw: true,
191
+ },
192
+ point: {
193
+ events: {
194
+ dragStart(this: any) {
195
+ if (this.series.name !== "PumpTimes" || !bookings.has(this.bookingKey)) return false;
196
+ },
197
+ drag(this: any, event: any) {
198
+ if (this.series.name !== "PumpTimes" || !event.newPoint) return false;
199
+
200
+ // The tooltip follows the pump the booking is dragged to.
201
+ if (event.newPoint.y !== undefined) this.objectNo = categories[event.newPoint.y];
202
+ },
203
+ drop(this: any, event: any) {
204
+ let booking = bookings.get(this.bookingKey);
205
+ if (this.series.name !== "PumpTimes" || !event.newPoint || !booking) {
206
+ event.preventDefault();
207
+ return false;
208
+ }
209
+
210
+ let { x = this.x, x2 = this.x2, y = this.y } = event.newPoint;
211
+ onMove(booking, categories[y], new Date(x), new Date(x2));
212
+ },
213
+ },
214
+ },
215
+ },
216
+ series: { states: { inactive: { opacity: 1 } } },
217
+ } as Highcharts.PlotOptions,
218
+ legend: { enabled: false },
219
+ series: [
220
+ { type: "xrange", name: "PumpTimes", data: pumpTimes, cursor: readOnly ? undefined : "move" },
221
+ { type: "xrange", name: "OosTimes", data: outOfService },
222
+ ] as unknown as Highcharts.SeriesOptionsType[],
223
+ };
224
+ }
@@ -0,0 +1,91 @@
1
+ import { ProcedureAPI } from "@olenbetong/appframe-data";
2
+
3
+ export type PlantRecord = {
4
+ PlantID: number;
5
+ Description: string;
6
+ };
7
+
8
+ export type PumpRecord = {
9
+ LocationID: number | null;
10
+ ObjectNo: number;
11
+ Model: string | null;
12
+ MixerCapacity: number | null;
13
+ BoomLength: number | null;
14
+ IsTruck: boolean | null;
15
+ IsPump: boolean | null;
16
+ BigPump: boolean | null;
17
+ Telescopic: boolean | null;
18
+ ConveyorBelt: boolean | null;
19
+ };
20
+
21
+ export type PumpBookingRecord = {
22
+ /** The plant whose chart shows the booking; for an indirect booking, the plant the pump belongs to. */
23
+ PlantID: number;
24
+ CallOffID: number;
25
+ ObjectNo: number;
26
+ /** A booking from a plant that is not shown, included to show when the pump is busy. */
27
+ IndirectBooking: boolean;
28
+ /** The plant the call-off of an indirect booking belongs to. */
29
+ IndirectPlantID: number | null;
30
+ CustomerName: string | null;
31
+ Qty: number | null;
32
+ DeliveredQty: number | null;
33
+ Site: string | null;
34
+ SiteAddress: string | null;
35
+ SiteCity: string | null;
36
+ SitePosition: string | null;
37
+ PumpStart: Date;
38
+ PumpEnd: Date;
39
+ Comment: string | null;
40
+ HoseLength: number | null;
41
+ ContactInfo: string | null;
42
+ };
43
+
44
+ export type OutOfServiceRecord = {
45
+ ObjectNo: number;
46
+ ObjectID: number;
47
+ FromDateTime: Date;
48
+ ToDateTime: Date;
49
+ Comment: string | null;
50
+ };
51
+
52
+ export type PumpBookingsParams = {
53
+ PlantIDs: [number][];
54
+ Date: Date;
55
+ PlantsMerged: boolean;
56
+ };
57
+
58
+ export type PumpBookingsResult = {
59
+ Table: PlantRecord[];
60
+ Table1: PumpRecord[];
61
+ Table2: PumpBookingRecord[];
62
+ Table3: OutOfServiceRecord[];
63
+ };
64
+
65
+ export type MovePumpBookingParams = {
66
+ CallOffID: number;
67
+ PumpNo: number;
68
+ StartDateTime: Date;
69
+ EndDateTime: Date;
70
+ };
71
+
72
+ export const procPumpBookings = new ProcedureAPI<PumpBookingsParams, PumpBookingsResult>({
73
+ procedureId: "astp_Plant_CallOffs_PumpBookings",
74
+ parameters: [
75
+ { name: "PlantIDs", type: "string", hasDefault: false, required: true },
76
+ { name: "Date", type: "date", hasDefault: false, required: true },
77
+ { name: "PlantsMerged", type: "boolean", hasDefault: false, required: true },
78
+ ],
79
+ timeout: 30000,
80
+ });
81
+
82
+ export const procMovePumpBooking = new ProcedureAPI<MovePumpBookingParams, unknown>({
83
+ procedureId: "astp_Plant_CallOffs_MovePumpBooking",
84
+ parameters: [
85
+ { name: "CallOffID", type: "number", hasDefault: false, required: true },
86
+ { name: "PumpNo", type: "number", hasDefault: false, required: true },
87
+ { name: "StartDateTime", type: "date", hasDefault: false, required: true },
88
+ { name: "EndDateTime", type: "date", hasDefault: false, required: true },
89
+ ],
90
+ timeout: 30000,
91
+ });
@@ -0,0 +1,42 @@
1
+ .ObPumping {
2
+ padding-block: 0.5rem;
3
+ }
4
+
5
+ .ObPumping-options {
6
+ display: flex;
7
+ gap: 0.5rem 1rem;
8
+ justify-content: flex-end;
9
+ position: sticky;
10
+ top: 0;
11
+ z-index: 1;
12
+ padding: 5px;
13
+ background-color: var(--ds-color-neutral-background-default);
14
+ }
15
+
16
+ // Out of the flow, so the spinner never changes the height of the bar while it loads.
17
+ .ObPumping-status {
18
+ position: absolute;
19
+ inset-block: 0;
20
+ inset-inline-start: 5px;
21
+ display: flex;
22
+ align-items: center;
23
+ pointer-events: none;
24
+ }
25
+
26
+ // Highcharts sets `light dark` here, which follows the OS instead of the colour scheme of the site.
27
+ .ObPumping-chart .highcharts-container {
28
+ color-scheme: inherit;
29
+ }
30
+
31
+ .ObPumping-chart a {
32
+ color: var(--ds-color-info-text-subtle);
33
+ }
34
+
35
+ .ObPumping-legend {
36
+ color: var(--ds-color-neutral-text-subtle);
37
+ }
38
+
39
+ .ObPumping hr {
40
+ border: 0;
41
+ border-block-start: 1px solid var(--ds-color-neutral-border-subtle);
42
+ }
@@ -0,0 +1,222 @@
1
+ import { Alert, Checkbox, Paragraph, Spinner } from "@digdir/designsystemet-react";
2
+ import Highcharts from "highcharts";
3
+ // In this order: draggable-points only sets up the drag behaviour of series types that already exist.
4
+ import "highcharts/modules/xrange";
5
+ import "highcharts/modules/draggable-points";
6
+ import { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
7
+ import type { Ref } from "react";
8
+
9
+ import { getLocalizedString } from "../../i18n.js";
10
+ import { VehicleInfoDialog } from "../../vehicles/VehicleInfoDialog/index.js";
11
+ import { type ChartSettings, getChartOptions, type MoveBooking } from "./chartOptions.js";
12
+ import { procMovePumpBooking, procPumpBookings, type PumpBookingsResult } from "./data.js";
13
+ import { type ChartData, getChartData, getChartHeight } from "./model.js";
14
+
15
+ import "./index.scss";
16
+ import { writeStored, useStoredFlag, readOffset } from "../storage.js";
17
+
18
+ export type PumpingHandle = {
19
+ /** Fetches the data again, keeping the zoom. */
20
+ reload: () => void;
21
+ /** Sets the hours shown around the day. An undefined offset forgets the stored one. */
22
+ setOffsets: (min?: number, max?: number) => void;
23
+ };
24
+
25
+ export type PumpingProps = {
26
+ plants: number[];
27
+ /** Midnight UTC of the day to show. */
28
+ date: Date;
29
+ readOnly?: boolean;
30
+ /** Prefix of the settings in localStorage. */
31
+ storageKey: string;
32
+ /** Called after the charts have drawn, when the height of the page may have changed. */
33
+ onRendered?: () => void;
34
+ ref?: Ref<PumpingHandle>;
35
+ };
36
+
37
+ function PumpChart({
38
+ data,
39
+ settings,
40
+ onShowVehicle,
41
+ onRendered,
42
+ }: {
43
+ data: ChartData;
44
+ settings: ChartSettings;
45
+ onShowVehicle?: (vehicleId: number) => void;
46
+ onRendered?: () => void;
47
+ }) {
48
+ let container = useRef<HTMLDivElement>(null);
49
+ let zoom = useRef<{ min: number; max: number } | null>(null);
50
+ let options = useMemo(() => getChartOptions(data, settings), [data, settings]);
51
+
52
+ useLayoutEffect(() => {
53
+ let chart = new Highcharts.Chart(container.current as HTMLElement, options);
54
+
55
+ if (zoom.current) {
56
+ chart.xAxis[0].setExtremes(zoom.current.min, zoom.current.max, true, false);
57
+ chart.showResetZoom();
58
+ }
59
+
60
+ onRendered?.();
61
+
62
+ return () => {
63
+ let { userMin, userMax } = chart.xAxis[0].getExtremes();
64
+ zoom.current = userMin !== undefined && userMax !== undefined ? { min: userMin, max: userMax } : null;
65
+ chart.destroy();
66
+ };
67
+ }, [options, onRendered]);
68
+
69
+ return (
70
+ <div
71
+ ref={container}
72
+ className="ObPumping-chart"
73
+ // Reserved up front, so the page keeps its scroll position while a chart is replaced.
74
+ style={{ minHeight: getChartHeight(data.pumps.length, data.merged) }}
75
+ onClick={(event) => {
76
+ let link = (event.target as Element).closest<HTMLAnchorElement>('a[href^="#vehicle-"]');
77
+ if (link) {
78
+ event.preventDefault();
79
+ onShowVehicle?.(Number(link.hash.replace("#vehicle-", "")));
80
+ }
81
+ }}
82
+ />
83
+ );
84
+ }
85
+
86
+ /**
87
+ * The pump bookings per pump through a day, one chart per plant or one for all of them. Grey bars
88
+ * are bookings from other plants, which show when a pump is busy. Bookings can be dragged to another
89
+ * time or pump unless `readOnly` is set.
90
+ */
91
+ export function Pumping({ plants, date, readOnly = false, storageKey, onRendered, ref }: PumpingProps) {
92
+ let [merged, setMerged] = useStoredFlag(`${storageKey}_showmerged`);
93
+ let [minOffset, setMinOffset] = useState(() => readOffset(`${storageKey}_minoffset`, -2));
94
+ let [maxOffset, setMaxOffset] = useState(() => readOffset(`${storageKey}_maxoffset`, 28));
95
+ let [result, setResult] = useState<{ data: PumpBookingsResult; merged: boolean } | null>(null);
96
+ let [error, setError] = useState<string | null>(null);
97
+ let [reloadCount, setReloadCount] = useState(0);
98
+ let [vehicleId, setVehicleId] = useState<number | null>(null);
99
+ let [loadedKey, setLoadedKey] = useState<string | null>(null);
100
+
101
+ let reload = useCallback(() => setReloadCount((count) => count + 1), []);
102
+ let plantsKey = plants.join(",");
103
+ let dateKey = date.getTime();
104
+ let requestKey = `${plantsKey}|${dateKey}|${merged}|${reloadCount}`;
105
+
106
+ useEffect(() => {
107
+ if (!plantsKey) return;
108
+
109
+ let controller = new AbortController();
110
+ // The windows app sends the plants and the date as separate messages.
111
+ let timeout = setTimeout(async () => {
112
+ try {
113
+ let data = await procPumpBookings.execute({
114
+ PlantIDs: plantsKey.split(",").map((plant) => [Number(plant)]),
115
+ Date: new Date(dateKey),
116
+ PlantsMerged: merged,
117
+ });
118
+ if (!controller.signal.aborted) {
119
+ // The bookings of other plants differ with the mode, so the data keeps the mode it was asked for.
120
+ setResult({ data, merged });
121
+ setError(null);
122
+ }
123
+ } catch (reason) {
124
+ if (!controller.signal.aborted) setError(reason instanceof Error ? reason.message : String(reason));
125
+ }
126
+ if (!controller.signal.aborted) setLoadedKey(requestKey);
127
+ }, 100);
128
+
129
+ return () => {
130
+ controller.abort();
131
+ clearTimeout(timeout);
132
+ };
133
+ }, [plantsKey, dateKey, merged, reloadCount, requestKey]);
134
+
135
+ useImperativeHandle(
136
+ ref,
137
+ () => ({
138
+ reload,
139
+ setOffsets(min, max) {
140
+ writeStored(`${storageKey}_minoffset`, min === undefined ? null : String(min));
141
+ writeStored(`${storageKey}_maxoffset`, max === undefined ? null : String(max));
142
+ if (min !== undefined) setMinOffset(min);
143
+ if (max !== undefined) setMaxOffset(max);
144
+ },
145
+ }),
146
+ [reload, storageKey],
147
+ );
148
+
149
+ let onMove = useCallback<MoveBooking>(
150
+ async (booking, pumpNo, start, end) => {
151
+ try {
152
+ await procMovePumpBooking.execute({
153
+ CallOffID: booking.CallOffID,
154
+ PumpNo: pumpNo,
155
+ StartDateTime: start,
156
+ EndDateTime: end,
157
+ });
158
+ setError(null);
159
+ } catch (reason) {
160
+ setError(reason instanceof Error ? reason.message : String(reason));
161
+ }
162
+ // After a refused move as well, or the bar would stay where it was dropped.
163
+ reload();
164
+ },
165
+ [reload],
166
+ );
167
+
168
+ let loading = !!plantsKey && loadedKey !== requestKey;
169
+
170
+ let charts = useMemo(
171
+ () => (result ? getChartData(result.data, plantsKey.split(",").map(Number), result.merged) : []),
172
+ [result, plantsKey],
173
+ );
174
+ let settings = useMemo(
175
+ () => ({ date: new Date(dateKey), minOffset, maxOffset, readOnly, onMove }),
176
+ [dateKey, minOffset, maxOffset, readOnly, onMove],
177
+ );
178
+
179
+ if (plants.length === 0) {
180
+ return <Alert data-color="warning">{getLocalizedString("No plant specified")}</Alert>;
181
+ }
182
+
183
+ return (
184
+ <div className="ObPumping">
185
+ <div className="ObPumping-options">
186
+ <div className="ObPumping-status">
187
+ {loading && <Spinner data-size="sm" aria-label={getLocalizedString("Loading")} />}
188
+ </div>
189
+ <Checkbox
190
+ data-size="sm"
191
+ label={getLocalizedString("Show vehicles together")}
192
+ checked={merged}
193
+ onChange={(event) => setMerged(event.target.checked)}
194
+ />
195
+ </div>
196
+ {error && <Alert data-color="danger">{error}</Alert>}
197
+ {result && result.data.Table1.length === 0 && (
198
+ <Alert data-color="info">{getLocalizedString("No pumps available at the selected plants")}</Alert>
199
+ )}
200
+ {charts.map((chart) => (
201
+ <div key={`${dateKey}-${chart.key}`}>
202
+ <PumpChart data={chart} settings={settings} onShowVehicle={setVehicleId} onRendered={onRendered} />
203
+ <hr />
204
+ </div>
205
+ ))}
206
+ <Paragraph data-size="xs" className="ObPumping-legend">
207
+ {getLocalizedString("No marking = Concrete mixer")}
208
+ <br />P = {getLocalizedString("Pump / combination vehicle")}
209
+ <br />S = {getLocalizedString("Large pump / tower pump")}
210
+ <br />T = {getLocalizedString("Vehicle with telescopic chute")}
211
+ <br />B = {getLocalizedString("Conveyor belt vehicle")}
212
+ <br />A = {getLocalizedString("Other transport (trailer, wheel loader, rental vehicle, pick-up load etc.)")}
213
+ </Paragraph>
214
+ <VehicleInfoDialog
215
+ vehicleId={vehicleId}
216
+ date={settings.date}
217
+ onClose={() => setVehicleId(null)}
218
+ onOutOfServiceChanged={reload}
219
+ />
220
+ </div>
221
+ );
222
+ }