@olenbetong/synergi-react 5.4.0 → 5.5.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.
- package/dist/styles/styles.css +1 -1
- package/dist/styles/styles.css.map +1 -1
- package/es/charts/CallOffDeliveries/TicketScanDialog.d.ts +7 -0
- package/es/charts/CallOffDeliveries/TicketScanDialog.js +47 -0
- package/es/charts/CallOffDeliveries/chartOptions.d.ts +8 -0
- package/es/charts/CallOffDeliveries/chartOptions.js +138 -0
- package/es/charts/CallOffDeliveries/data.d.ts +35 -0
- package/es/charts/CallOffDeliveries/data.js +30 -0
- package/es/charts/CallOffDeliveries/index.css +1 -0
- package/es/charts/CallOffDeliveries/index.d.ts +24 -0
- package/es/charts/CallOffDeliveries/index.js +115 -0
- package/es/charts/CallOffDeliveries/model.d.ts +37 -0
- package/es/charts/CallOffDeliveries/model.js +59 -0
- package/es/charts/ProductionPlan/PlanValueDialog.d.ts +14 -0
- package/es/charts/ProductionPlan/PlanValueDialog.js +47 -0
- package/es/charts/ProductionPlan/chartOptions.d.ts +20 -0
- package/es/charts/ProductionPlan/chartOptions.js +353 -0
- package/es/charts/ProductionPlan/data.d.ts +105 -0
- package/es/charts/ProductionPlan/data.js +61 -0
- package/es/charts/ProductionPlan/index.css +1 -0
- package/es/charts/ProductionPlan/index.d.ts +31 -0
- package/es/charts/ProductionPlan/index.js +203 -0
- package/es/charts/ProductionPlan/model.d.ts +29 -0
- package/es/charts/ProductionPlan/model.js +65 -0
- package/es/charts/Pumping/chartOptions.d.ts +12 -0
- package/es/charts/Pumping/chartOptions.js +197 -0
- package/es/charts/Pumping/data.d.ts +65 -0
- package/es/charts/Pumping/data.js +20 -0
- package/es/charts/Pumping/index.css +1 -0
- package/es/charts/Pumping/index.d.ts +27 -0
- package/es/charts/Pumping/index.js +124 -0
- package/es/charts/Pumping/model.d.ts +34 -0
- package/es/charts/Pumping/model.js +88 -0
- package/es/charts/UnboundPreview/chartOptions.d.ts +3 -0
- package/es/charts/UnboundPreview/chartOptions.js +126 -0
- package/es/charts/UnboundPreview/index.css +1 -0
- package/es/charts/UnboundPreview/index.d.ts +20 -0
- package/es/charts/UnboundPreview/index.js +55 -0
- package/es/charts/UnboundPreview/model.d.ts +49 -0
- package/es/charts/UnboundPreview/model.js +67 -0
- package/es/charts/VehicleDeliveries/chartOptions.d.ts +13 -0
- package/es/charts/VehicleDeliveries/chartOptions.js +270 -0
- package/es/charts/VehicleDeliveries/data.d.ts +71 -0
- package/es/charts/VehicleDeliveries/data.js +20 -0
- package/es/charts/VehicleDeliveries/deliveryXRange.d.ts +4 -0
- package/es/charts/VehicleDeliveries/deliveryXRange.js +62 -0
- package/es/charts/VehicleDeliveries/index.css +1 -0
- package/es/charts/VehicleDeliveries/index.d.ts +24 -0
- package/es/charts/VehicleDeliveries/index.js +129 -0
- package/es/charts/VehicleDeliveries/model.d.ts +24 -0
- package/es/charts/VehicleDeliveries/model.js +106 -0
- package/es/charts/format.d.ts +12 -0
- package/es/charts/format.js +34 -0
- package/es/charts/index.d.ts +5 -0
- package/es/charts/index.js +5 -0
- package/es/charts/storage.d.ts +5 -0
- package/es/charts/storage.js +35 -0
- package/es/components/ColorCard/index.css +8 -8
- package/es/index.css +1 -1
- package/es/vehicles/VehicleInfoDialog/OutOfServiceForm.d.ts +4 -0
- package/es/vehicles/VehicleInfoDialog/OutOfServiceForm.js +51 -0
- package/es/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.d.ts +99 -0
- package/es/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.js +499 -0
- package/es/vehicles/VehicleInfoDialog/data/dsDriverStatus.d.ts +13 -0
- package/es/vehicles/VehicleInfoDialog/data/dsDriverStatus.js +69 -0
- package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfo.d.ts +33 -0
- package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfo.js +164 -0
- package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.d.ts +15 -0
- package/es/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.js +80 -0
- package/es/vehicles/VehicleInfoDialog/formatting.d.ts +13 -0
- package/es/vehicles/VehicleInfoDialog/formatting.js +48 -0
- package/es/vehicles/VehicleInfoDialog/index.css +1 -0
- package/es/vehicles/VehicleInfoDialog/index.d.ts +11 -0
- package/es/vehicles/VehicleInfoDialog/index.js +46 -0
- package/es/vehicles/VehicleInfoDialog/tabs.d.ts +6 -0
- package/es/vehicles/VehicleInfoDialog/tabs.js +85 -0
- package/es/vehicles/index.d.ts +1 -0
- package/es/vehicles/index.js +1 -0
- package/package.json +17 -8
- package/src/charts/CallOffDeliveries/TicketScanDialog.tsx +79 -0
- package/src/charts/CallOffDeliveries/chartOptions.ts +160 -0
- package/src/charts/CallOffDeliveries/data.ts +67 -0
- package/src/charts/CallOffDeliveries/index.scss +51 -0
- package/src/charts/CallOffDeliveries/index.tsx +217 -0
- package/src/charts/CallOffDeliveries/model.test.ts +90 -0
- package/src/charts/CallOffDeliveries/model.ts +87 -0
- package/src/charts/ProductionPlan/PlanValueDialog.tsx +107 -0
- package/src/charts/ProductionPlan/chartOptions.ts +406 -0
- package/src/charts/ProductionPlan/data.ts +170 -0
- package/src/charts/ProductionPlan/index.scss +148 -0
- package/src/charts/ProductionPlan/index.tsx +432 -0
- package/src/charts/ProductionPlan/model.test.ts +132 -0
- package/src/charts/ProductionPlan/model.ts +102 -0
- package/src/charts/Pumping/chartOptions.ts +224 -0
- package/src/charts/Pumping/data.ts +91 -0
- package/src/charts/Pumping/index.scss +42 -0
- package/src/charts/Pumping/index.tsx +222 -0
- package/src/charts/Pumping/model.test.ts +122 -0
- package/src/charts/Pumping/model.ts +104 -0
- package/src/charts/UnboundPreview/chartOptions.ts +137 -0
- package/src/charts/UnboundPreview/index.scss +17 -0
- package/src/charts/UnboundPreview/index.tsx +100 -0
- package/src/charts/UnboundPreview/model.test.ts +129 -0
- package/src/charts/UnboundPreview/model.ts +110 -0
- package/src/charts/VehicleDeliveries/chartOptions.ts +311 -0
- package/src/charts/VehicleDeliveries/data.ts +98 -0
- package/src/charts/VehicleDeliveries/deliveryXRange.ts +80 -0
- package/src/charts/VehicleDeliveries/index.scss +43 -0
- package/src/charts/VehicleDeliveries/index.tsx +262 -0
- package/src/charts/VehicleDeliveries/model.test.ts +117 -0
- package/src/charts/VehicleDeliveries/model.ts +139 -0
- package/src/charts/format.ts +38 -0
- package/src/charts/index.ts +20 -0
- package/src/charts/storage.ts +36 -0
- package/src/components/ColorCard/index.css +8 -8
- package/src/vehicles/VehicleInfoDialog/OutOfServiceForm.tsx +127 -0
- package/src/vehicles/VehicleInfoDialog/data/dsDeliveryTickets.ts +600 -0
- package/src/vehicles/VehicleInfoDialog/data/dsDriverStatus.ts +84 -0
- package/src/vehicles/VehicleInfoDialog/data/dsVehicleInfo.ts +198 -0
- package/src/vehicles/VehicleInfoDialog/data/dsVehicleInfoLog.ts +97 -0
- package/src/vehicles/VehicleInfoDialog/formatting.test.ts +57 -0
- package/src/vehicles/VehicleInfoDialog/formatting.ts +58 -0
- package/src/vehicles/VehicleInfoDialog/index.scss +131 -0
- package/src/vehicles/VehicleInfoDialog/index.tsx +106 -0
- package/src/vehicles/VehicleInfoDialog/tabs.tsx +188 -0
- package/src/vehicles/index.ts +1 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Alert, Checkbox, Paragraph, Spinner } from "@digdir/designsystemet-react";
|
|
3
|
+
import Highcharts from "highcharts";
|
|
4
|
+
// In this order: draggable-points only sets up the drag behaviour of series types that already exist.
|
|
5
|
+
import "highcharts/modules/xrange";
|
|
6
|
+
import "highcharts/modules/draggable-points";
|
|
7
|
+
import { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
8
|
+
import { getLocalizedString } from "../../i18n.js";
|
|
9
|
+
import { VehicleInfoDialog } from "../../vehicles/VehicleInfoDialog/index.js";
|
|
10
|
+
import { getChartOptions } from "./chartOptions.js";
|
|
11
|
+
import { procMovePumpBooking, procPumpBookings } from "./data.js";
|
|
12
|
+
import { getChartData, getChartHeight } from "./model.js";
|
|
13
|
+
import "./index.css";
|
|
14
|
+
import { writeStored, useStoredFlag, readOffset } from "../storage.js";
|
|
15
|
+
function PumpChart({ data, settings, onShowVehicle, onRendered, }) {
|
|
16
|
+
let container = useRef(null);
|
|
17
|
+
let zoom = useRef(null);
|
|
18
|
+
let options = useMemo(() => getChartOptions(data, settings), [data, settings]);
|
|
19
|
+
useLayoutEffect(() => {
|
|
20
|
+
let chart = new Highcharts.Chart(container.current, options);
|
|
21
|
+
if (zoom.current) {
|
|
22
|
+
chart.xAxis[0].setExtremes(zoom.current.min, zoom.current.max, true, false);
|
|
23
|
+
chart.showResetZoom();
|
|
24
|
+
}
|
|
25
|
+
onRendered?.();
|
|
26
|
+
return () => {
|
|
27
|
+
let { userMin, userMax } = chart.xAxis[0].getExtremes();
|
|
28
|
+
zoom.current = userMin !== undefined && userMax !== undefined ? { min: userMin, max: userMax } : null;
|
|
29
|
+
chart.destroy();
|
|
30
|
+
};
|
|
31
|
+
}, [options, onRendered]);
|
|
32
|
+
return (_jsx("div", { ref: container, className: "ObPumping-chart",
|
|
33
|
+
// Reserved up front, so the page keeps its scroll position while a chart is replaced.
|
|
34
|
+
style: { minHeight: getChartHeight(data.pumps.length, data.merged) }, onClick: (event) => {
|
|
35
|
+
let link = event.target.closest('a[href^="#vehicle-"]');
|
|
36
|
+
if (link) {
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
onShowVehicle?.(Number(link.hash.replace("#vehicle-", "")));
|
|
39
|
+
}
|
|
40
|
+
} }));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The pump bookings per pump through a day, one chart per plant or one for all of them. Grey bars
|
|
44
|
+
* are bookings from other plants, which show when a pump is busy. Bookings can be dragged to another
|
|
45
|
+
* time or pump unless `readOnly` is set.
|
|
46
|
+
*/
|
|
47
|
+
export function Pumping({ plants, date, readOnly = false, storageKey, onRendered, ref }) {
|
|
48
|
+
let [merged, setMerged] = useStoredFlag(`${storageKey}_showmerged`);
|
|
49
|
+
let [minOffset, setMinOffset] = useState(() => readOffset(`${storageKey}_minoffset`, -2));
|
|
50
|
+
let [maxOffset, setMaxOffset] = useState(() => readOffset(`${storageKey}_maxoffset`, 28));
|
|
51
|
+
let [result, setResult] = useState(null);
|
|
52
|
+
let [error, setError] = useState(null);
|
|
53
|
+
let [reloadCount, setReloadCount] = useState(0);
|
|
54
|
+
let [vehicleId, setVehicleId] = useState(null);
|
|
55
|
+
let [loadedKey, setLoadedKey] = useState(null);
|
|
56
|
+
let reload = useCallback(() => setReloadCount((count) => count + 1), []);
|
|
57
|
+
let plantsKey = plants.join(",");
|
|
58
|
+
let dateKey = date.getTime();
|
|
59
|
+
let requestKey = `${plantsKey}|${dateKey}|${merged}|${reloadCount}`;
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
if (!plantsKey)
|
|
62
|
+
return;
|
|
63
|
+
let controller = new AbortController();
|
|
64
|
+
// The windows app sends the plants and the date as separate messages.
|
|
65
|
+
let timeout = setTimeout(async () => {
|
|
66
|
+
try {
|
|
67
|
+
let data = await procPumpBookings.execute({
|
|
68
|
+
PlantIDs: plantsKey.split(",").map((plant) => [Number(plant)]),
|
|
69
|
+
Date: new Date(dateKey),
|
|
70
|
+
PlantsMerged: merged,
|
|
71
|
+
});
|
|
72
|
+
if (!controller.signal.aborted) {
|
|
73
|
+
// The bookings of other plants differ with the mode, so the data keeps the mode it was asked for.
|
|
74
|
+
setResult({ data, merged });
|
|
75
|
+
setError(null);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (reason) {
|
|
79
|
+
if (!controller.signal.aborted)
|
|
80
|
+
setError(reason instanceof Error ? reason.message : String(reason));
|
|
81
|
+
}
|
|
82
|
+
if (!controller.signal.aborted)
|
|
83
|
+
setLoadedKey(requestKey);
|
|
84
|
+
}, 100);
|
|
85
|
+
return () => {
|
|
86
|
+
controller.abort();
|
|
87
|
+
clearTimeout(timeout);
|
|
88
|
+
};
|
|
89
|
+
}, [plantsKey, dateKey, merged, reloadCount, requestKey]);
|
|
90
|
+
useImperativeHandle(ref, () => ({
|
|
91
|
+
reload,
|
|
92
|
+
setOffsets(min, max) {
|
|
93
|
+
writeStored(`${storageKey}_minoffset`, min === undefined ? null : String(min));
|
|
94
|
+
writeStored(`${storageKey}_maxoffset`, max === undefined ? null : String(max));
|
|
95
|
+
if (min !== undefined)
|
|
96
|
+
setMinOffset(min);
|
|
97
|
+
if (max !== undefined)
|
|
98
|
+
setMaxOffset(max);
|
|
99
|
+
},
|
|
100
|
+
}), [reload, storageKey]);
|
|
101
|
+
let onMove = useCallback(async (booking, pumpNo, start, end) => {
|
|
102
|
+
try {
|
|
103
|
+
await procMovePumpBooking.execute({
|
|
104
|
+
CallOffID: booking.CallOffID,
|
|
105
|
+
PumpNo: pumpNo,
|
|
106
|
+
StartDateTime: start,
|
|
107
|
+
EndDateTime: end,
|
|
108
|
+
});
|
|
109
|
+
setError(null);
|
|
110
|
+
}
|
|
111
|
+
catch (reason) {
|
|
112
|
+
setError(reason instanceof Error ? reason.message : String(reason));
|
|
113
|
+
}
|
|
114
|
+
// After a refused move as well, or the bar would stay where it was dropped.
|
|
115
|
+
reload();
|
|
116
|
+
}, [reload]);
|
|
117
|
+
let loading = !!plantsKey && loadedKey !== requestKey;
|
|
118
|
+
let charts = useMemo(() => (result ? getChartData(result.data, plantsKey.split(",").map(Number), result.merged) : []), [result, plantsKey]);
|
|
119
|
+
let settings = useMemo(() => ({ date: new Date(dateKey), minOffset, maxOffset, readOnly, onMove }), [dateKey, minOffset, maxOffset, readOnly, onMove]);
|
|
120
|
+
if (plants.length === 0) {
|
|
121
|
+
return _jsx(Alert, { "data-color": "warning", children: getLocalizedString("No plant specified") });
|
|
122
|
+
}
|
|
123
|
+
return (_jsxs("div", { className: "ObPumping", children: [_jsxs("div", { className: "ObPumping-options", children: [_jsx("div", { className: "ObPumping-status", children: loading && _jsx(Spinner, { "data-size": "sm", "aria-label": getLocalizedString("Loading") }) }), _jsx(Checkbox, { "data-size": "sm", label: getLocalizedString("Show vehicles together"), checked: merged, onChange: (event) => setMerged(event.target.checked) })] }), error && _jsx(Alert, { "data-color": "danger", children: error }), result && result.data.Table1.length === 0 && (_jsx(Alert, { "data-color": "info", children: getLocalizedString("No pumps available at the selected plants") })), charts.map((chart) => (_jsxs("div", { children: [_jsx(PumpChart, { data: chart, settings: settings, onShowVehicle: setVehicleId, onRendered: onRendered }), _jsx("hr", {})] }, `${dateKey}-${chart.key}`))), _jsxs(Paragraph, { "data-size": "xs", className: "ObPumping-legend", children: [getLocalizedString("No marking = Concrete mixer"), _jsx("br", {}), "P = ", getLocalizedString("Pump / combination vehicle"), _jsx("br", {}), "S = ", getLocalizedString("Large pump / tower pump"), _jsx("br", {}), "T = ", getLocalizedString("Vehicle with telescopic chute"), _jsx("br", {}), "B = ", getLocalizedString("Conveyor belt vehicle"), _jsx("br", {}), "A = ", getLocalizedString("Other transport (trailer, wheel loader, rental vehicle, pick-up load etc.)")] }), _jsx(VehicleInfoDialog, { vehicleId: vehicleId, date: settings.date, onClose: () => setVehicleId(null), onOutOfServiceChanged: reload })] }));
|
|
124
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { OutOfServiceRecord, PlantRecord, PumpBookingRecord, PumpBookingsResult, PumpRecord } from "./data.js";
|
|
2
|
+
export type ChartData = {
|
|
3
|
+
key: string;
|
|
4
|
+
plants: PlantRecord[];
|
|
5
|
+
pumps: PumpRecord[];
|
|
6
|
+
bookings: PumpBookingRecord[];
|
|
7
|
+
outOfService: OutOfServiceRecord[];
|
|
8
|
+
merged: boolean;
|
|
9
|
+
/** Index into the palette for each plant, stable however the charts are split. */
|
|
10
|
+
colorIndex: Map<number, number>;
|
|
11
|
+
};
|
|
12
|
+
/** Pumps with a mixer first, then the big pumps, each by number. */
|
|
13
|
+
export declare function comparePumps(a: PumpRecord, z: PumpRecord): number;
|
|
14
|
+
/**
|
|
15
|
+
* One chart per selected plant, with the pumps based there and those booked by it, or a single
|
|
16
|
+
* chart for all of them. In merged mode the procedure already leaves out the indirect bookings of
|
|
17
|
+
* call-offs from the selected plants, so nothing is shown twice.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getChartData(result: PumpBookingsResult, selectedPlants: number[], merged: boolean): ChartData[];
|
|
20
|
+
/**
|
|
21
|
+
* Where a pump is based, when the chart should say so: always with several plants in one chart,
|
|
22
|
+
* otherwise only for a pump from somewhere else. `null` home means an external pump.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getPumpHome(pump: Pick<PumpRecord, "LocationID">, plants: PlantRecord[], merged: boolean): {
|
|
25
|
+
show: boolean;
|
|
26
|
+
home: number | null;
|
|
27
|
+
};
|
|
28
|
+
/** The plant to name in a booking's tooltip, or `null` when the chart's own plant goes without saying. */
|
|
29
|
+
export declare function getBookingPlant(booking: PumpBookingRecord, merged: boolean): number | null;
|
|
30
|
+
export declare function getPumpFeature(pump: PumpRecord): {
|
|
31
|
+
label: string;
|
|
32
|
+
color: string;
|
|
33
|
+
} | null;
|
|
34
|
+
export declare function getChartHeight(pumpCount: number, merged: boolean): number;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/** Pumps with a mixer first, then the big pumps, each by number. */
|
|
2
|
+
export function comparePumps(a, z) {
|
|
3
|
+
if (!!a.BigPump !== !!z.BigPump)
|
|
4
|
+
return a.BigPump ? 1 : -1;
|
|
5
|
+
return a.ObjectNo - z.ObjectNo;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* One chart per selected plant, with the pumps based there and those booked by it, or a single
|
|
9
|
+
* chart for all of them. In merged mode the procedure already leaves out the indirect bookings of
|
|
10
|
+
* call-offs from the selected plants, so nothing is shown twice.
|
|
11
|
+
*/
|
|
12
|
+
export function getChartData(result, selectedPlants, merged) {
|
|
13
|
+
let { Table: plants, Table1: pumps, Table2: bookings, Table3: outOfService } = result;
|
|
14
|
+
let colorIndex = new Map(selectedPlants.map((plantId, index) => [plantId, index]));
|
|
15
|
+
if (plants.length === 0 || pumps.length === 0)
|
|
16
|
+
return [];
|
|
17
|
+
if (merged) {
|
|
18
|
+
return [
|
|
19
|
+
{
|
|
20
|
+
key: "merged",
|
|
21
|
+
plants,
|
|
22
|
+
pumps: pumps.toSorted(comparePumps),
|
|
23
|
+
bookings,
|
|
24
|
+
outOfService,
|
|
25
|
+
merged,
|
|
26
|
+
colorIndex,
|
|
27
|
+
},
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
return selectedPlants.flatMap((plantId) => {
|
|
31
|
+
let plant = plants.find((candidate) => candidate.PlantID === plantId);
|
|
32
|
+
if (!plant)
|
|
33
|
+
return [];
|
|
34
|
+
let plantBookings = bookings.filter((booking) => booking.PlantID === plantId);
|
|
35
|
+
let bookedPumps = new Set(plantBookings.map((booking) => booking.ObjectNo));
|
|
36
|
+
let plantPumps = pumps.filter((pump) => pump.LocationID === plantId || bookedPumps.has(pump.ObjectNo));
|
|
37
|
+
if (plantPumps.length === 0)
|
|
38
|
+
return [];
|
|
39
|
+
let pumpIds = new Set(plantPumps.map((pump) => pump.ObjectNo));
|
|
40
|
+
return [
|
|
41
|
+
{
|
|
42
|
+
key: String(plantId),
|
|
43
|
+
plants: [plant],
|
|
44
|
+
pumps: plantPumps.toSorted(comparePumps),
|
|
45
|
+
bookings: plantBookings,
|
|
46
|
+
outOfService: outOfService.filter((entry) => pumpIds.has(entry.ObjectNo)),
|
|
47
|
+
merged,
|
|
48
|
+
colorIndex,
|
|
49
|
+
},
|
|
50
|
+
];
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Where a pump is based, when the chart should say so: always with several plants in one chart,
|
|
55
|
+
* otherwise only for a pump from somewhere else. `null` home means an external pump.
|
|
56
|
+
*/
|
|
57
|
+
export function getPumpHome(pump, plants, merged) {
|
|
58
|
+
let isHome = plants.some((plant) => plant.PlantID === pump.LocationID);
|
|
59
|
+
return { show: merged || !isHome, home: pump.LocationID };
|
|
60
|
+
}
|
|
61
|
+
/** The plant to name in a booking's tooltip, or `null` when the chart's own plant goes without saying. */
|
|
62
|
+
export function getBookingPlant(booking, merged) {
|
|
63
|
+
if (merged)
|
|
64
|
+
return booking.IndirectPlantID ?? booking.PlantID;
|
|
65
|
+
if (booking.IndirectBooking)
|
|
66
|
+
return booking.IndirectPlantID;
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
export function getPumpFeature(pump) {
|
|
70
|
+
let feature = null;
|
|
71
|
+
if (pump.BigPump)
|
|
72
|
+
feature = { label: "S", color: "#FFE4C4" };
|
|
73
|
+
else if (pump.IsPump)
|
|
74
|
+
feature = { label: "P", color: "#DDDDFF" };
|
|
75
|
+
else if (pump.Telescopic)
|
|
76
|
+
feature = { label: "T", color: "#D1FFDB" };
|
|
77
|
+
else if (pump.ConveyorBelt)
|
|
78
|
+
feature = { label: "B", color: "#DDDDDD" };
|
|
79
|
+
else if (!pump.IsTruck)
|
|
80
|
+
feature = { label: "A", color: "#EEEEEE" };
|
|
81
|
+
if (feature && pump.BoomLength && pump.BoomLength > 0) {
|
|
82
|
+
return { ...feature, label: `${feature.label} ${pump.BoomLength}m` };
|
|
83
|
+
}
|
|
84
|
+
return feature;
|
|
85
|
+
}
|
|
86
|
+
export function getChartHeight(pumpCount, merged) {
|
|
87
|
+
return pumpCount * 26 + 45 + (merged ? 120 : 70);
|
|
88
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import Highcharts from "highcharts";
|
|
2
|
+
import { getLocalizedString } from "../../i18n.js";
|
|
3
|
+
import { cropCaption, getChartHeight, getStatusTimes } from "./model.js";
|
|
4
|
+
import { formatTime, escapeHtml } from "../format.js";
|
|
5
|
+
const HOUR = 3600000;
|
|
6
|
+
// The colours the dialog has always used: the first of the old Highcharts palette for the plan,
|
|
7
|
+
// red for what other call-offs already have booked.
|
|
8
|
+
const PLANNED_COLOR = "#7cb5ec";
|
|
9
|
+
const OTHER_COLOR = "#ff0000";
|
|
10
|
+
function fill(color, opacity) {
|
|
11
|
+
return Highcharts.color(color).setOpacity(opacity).get("rgba");
|
|
12
|
+
}
|
|
13
|
+
function timesHtml(point) {
|
|
14
|
+
let body = `${formatTime(point.x)} - ${formatTime(point.x2)}`;
|
|
15
|
+
if (point.driverID)
|
|
16
|
+
body += `<br>${getLocalizedString("Driver")}: ${escapeHtml(point.driverID)}`;
|
|
17
|
+
return `<div style="color:var(--ds-color-info-text-subtle)">${body}</div>`;
|
|
18
|
+
}
|
|
19
|
+
function otherHtml(point) {
|
|
20
|
+
return `<div>${getLocalizedString("Call-off")}: ${point.callOffID}</div>
|
|
21
|
+
<div>${escapeHtml(point.customer)}</div>
|
|
22
|
+
<div style="color:var(--ds-color-neutral-text-subtle)">${escapeHtml(point.buildSite)}</div>`;
|
|
23
|
+
}
|
|
24
|
+
export function getChartOptions(data, date) {
|
|
25
|
+
let midnight = date.getTime();
|
|
26
|
+
let min = midnight - 2 * HOUR;
|
|
27
|
+
let max = midnight + 28 * HOUR;
|
|
28
|
+
let categories = data.vehicles;
|
|
29
|
+
let planned = data.planned.map((row) => ({
|
|
30
|
+
y: categories.indexOf(row.VehicleID),
|
|
31
|
+
x: row.StartTime.getTime(),
|
|
32
|
+
x2: row.EndTime.getTime(),
|
|
33
|
+
...getStatusTimes(row),
|
|
34
|
+
color: fill(PLANNED_COLOR, 0.6),
|
|
35
|
+
caption: formatTime(row.StartTime),
|
|
36
|
+
driverID: row.DriverID,
|
|
37
|
+
}));
|
|
38
|
+
let other = data.other.map((row) => ({
|
|
39
|
+
y: categories.indexOf(row.VehicleID),
|
|
40
|
+
x: row.StartTime.getTime(),
|
|
41
|
+
x2: row.EndTime.getTime(),
|
|
42
|
+
color: fill(OTHER_COLOR, 0.35),
|
|
43
|
+
caption: "",
|
|
44
|
+
driverID: row.DriverID,
|
|
45
|
+
callOffID: row.CallOffID,
|
|
46
|
+
customer: row.CustomerAdr1,
|
|
47
|
+
buildSite: row.BuildSiteAdr1,
|
|
48
|
+
}));
|
|
49
|
+
let band = (from, to) => ({ color: "var(--ds-color-neutral-background-tinted)", from, to });
|
|
50
|
+
return {
|
|
51
|
+
chart: {
|
|
52
|
+
type: "deliveryxrange",
|
|
53
|
+
backgroundColor: "transparent",
|
|
54
|
+
zooming: { type: "x" },
|
|
55
|
+
height: getChartHeight(categories.length),
|
|
56
|
+
marginTop: 50,
|
|
57
|
+
marginBottom: 10,
|
|
58
|
+
},
|
|
59
|
+
accessibility: { enabled: false },
|
|
60
|
+
credits: { enabled: false },
|
|
61
|
+
title: { text: undefined },
|
|
62
|
+
xAxis: {
|
|
63
|
+
type: "datetime",
|
|
64
|
+
title: { text: undefined },
|
|
65
|
+
opposite: true,
|
|
66
|
+
min,
|
|
67
|
+
max,
|
|
68
|
+
dateTimeLabelFormats: { hour: "%H", day: "%d.%m" },
|
|
69
|
+
tickInterval: HOUR,
|
|
70
|
+
minorTickInterval: 0.5 * HOUR,
|
|
71
|
+
plotBands: [band(min - 24 * HOUR, midnight + 6 * HOUR), band(midnight + 18 * HOUR, max + 24 * HOUR)],
|
|
72
|
+
},
|
|
73
|
+
yAxis: {
|
|
74
|
+
categories: categories.map(String),
|
|
75
|
+
reversed: true,
|
|
76
|
+
min: 0,
|
|
77
|
+
// Every vehicle gets a row, also one whose loads are all outside the zoom.
|
|
78
|
+
max: categories.length - 1,
|
|
79
|
+
tickInterval: 1,
|
|
80
|
+
title: { text: "" },
|
|
81
|
+
gridLineColor: "var(--ds-color-neutral-border-subtle)",
|
|
82
|
+
labels: {
|
|
83
|
+
useHTML: true,
|
|
84
|
+
formatter() {
|
|
85
|
+
let vehicleId = Number(this.value);
|
|
86
|
+
return `<div style="min-width:40px"><a href="#vehicle-${vehicleId}">${vehicleId}</a></div>`;
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
tooltip: {
|
|
91
|
+
useHTML: true,
|
|
92
|
+
formatter() {
|
|
93
|
+
let content = this.series.name === "OtherDeliveries" ? otherHtml(this.point) : "";
|
|
94
|
+
return `<div style="font-size:10px">${content}${timesHtml(this.point)}</div>`;
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
plotOptions: {
|
|
98
|
+
deliveryxrange: {
|
|
99
|
+
animation: false,
|
|
100
|
+
grouping: false,
|
|
101
|
+
groupPadding: 0.1,
|
|
102
|
+
colorByPoint: false,
|
|
103
|
+
borderWidth: 1,
|
|
104
|
+
borderColor: "#888",
|
|
105
|
+
borderRadius: 0,
|
|
106
|
+
dataLabels: {
|
|
107
|
+
enabled: true,
|
|
108
|
+
useHTML: false,
|
|
109
|
+
color: "var(--ds-color-neutral-text-default)",
|
|
110
|
+
align: "left",
|
|
111
|
+
y: 2,
|
|
112
|
+
style: { fontWeight: "normal", fontSize: "10px", textOutline: "none" },
|
|
113
|
+
formatter() {
|
|
114
|
+
return cropCaption(this.point.caption ?? "", this.point.shapeArgs.width / 6 - 3);
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
series: { states: { inactive: { opacity: 1 } } },
|
|
119
|
+
},
|
|
120
|
+
legend: { enabled: false },
|
|
121
|
+
series: [
|
|
122
|
+
{ type: "deliveryxrange", name: "Deliveries", data: planned },
|
|
123
|
+
{ type: "deliveryxrange", name: "OtherDeliveries", data: other },
|
|
124
|
+
],
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
.ObUnboundPreview{padding-block:.5rem}.ObUnboundPreview-chart .highcharts-container{color-scheme:inherit}.ObUnboundPreview-chart a{color:var(--ds-color-info-text-subtle)}.ObUnboundPreview-empty{color:var(--ds-color-neutral-text-subtle);padding-inline:.75rem}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type OtherDelivery, type PlannedDelivery } from "./model.js";
|
|
2
|
+
import "./index.css";
|
|
3
|
+
export type { OtherDelivery, PlannedDelivery } from "./model.js";
|
|
4
|
+
export { parseOtherDeliveries, parsePlannedDeliveries } from "./model.js";
|
|
5
|
+
export type UnboundPreviewProps = {
|
|
6
|
+
/** Midnight UTC of the day to show. */
|
|
7
|
+
date: Date;
|
|
8
|
+
/** The plan being edited. Nothing is drawn while this is null, before the first plan arrives. */
|
|
9
|
+
deliveries: PlannedDelivery[] | null;
|
|
10
|
+
/** Loads from other call-offs. Only those on vehicles in the plan are shown. */
|
|
11
|
+
otherDeliveries?: OtherDelivery[];
|
|
12
|
+
/** Called after the chart has drawn, when the height of the page may have changed. */
|
|
13
|
+
onRendered?: () => void;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* A preview of a delivery plan that is not saved yet: the planned loads per vehicle through the
|
|
17
|
+
* day, with the loads the same vehicles already have for other call-offs. The data comes from the
|
|
18
|
+
* caller; the chart reads nothing itself.
|
|
19
|
+
*/
|
|
20
|
+
export declare function UnboundPreview({ date, deliveries, otherDeliveries, onRendered }: UnboundPreviewProps): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Paragraph } from "@digdir/designsystemet-react";
|
|
3
|
+
import Highcharts from "highcharts";
|
|
4
|
+
import { useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { getLocalizedString } from "../../i18n.js";
|
|
6
|
+
import { VehicleInfoDialog } from "../../vehicles/VehicleInfoDialog/index.js";
|
|
7
|
+
import { registerDeliveryXRange } from "../VehicleDeliveries/deliveryXRange.js";
|
|
8
|
+
import { getChartOptions } from "./chartOptions.js";
|
|
9
|
+
import { getChartHeight, getPreviewData } from "./model.js";
|
|
10
|
+
import "./index.css";
|
|
11
|
+
registerDeliveryXRange();
|
|
12
|
+
export { parseOtherDeliveries, parsePlannedDeliveries } from "./model.js";
|
|
13
|
+
const NO_DELIVERIES = [];
|
|
14
|
+
/**
|
|
15
|
+
* A preview of a delivery plan that is not saved yet: the planned loads per vehicle through the
|
|
16
|
+
* day, with the loads the same vehicles already have for other call-offs. The data comes from the
|
|
17
|
+
* caller; the chart reads nothing itself.
|
|
18
|
+
*/
|
|
19
|
+
export function UnboundPreview({ date, deliveries, otherDeliveries = NO_DELIVERIES, onRendered }) {
|
|
20
|
+
let container = useRef(null);
|
|
21
|
+
let zoom = useRef(null);
|
|
22
|
+
let [vehicleId, setVehicleId] = useState(null);
|
|
23
|
+
let data = useMemo(() => (deliveries ? getPreviewData(deliveries, otherDeliveries) : null), [deliveries, otherDeliveries]);
|
|
24
|
+
let dateKey = date.getTime();
|
|
25
|
+
let options = useMemo(() => (data?.vehicles.length ? getChartOptions(data, new Date(dateKey)) : null), [data, dateKey]);
|
|
26
|
+
useLayoutEffect(() => {
|
|
27
|
+
if (!options) {
|
|
28
|
+
onRendered?.();
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
let chart = new Highcharts.Chart(container.current, options);
|
|
32
|
+
// The plan is sent again on every change in the dialog; the zoom stays.
|
|
33
|
+
if (zoom.current) {
|
|
34
|
+
chart.xAxis[0].setExtremes(zoom.current.min, zoom.current.max, true, false);
|
|
35
|
+
chart.showResetZoom();
|
|
36
|
+
}
|
|
37
|
+
onRendered?.();
|
|
38
|
+
return () => {
|
|
39
|
+
let { userMin, userMax } = chart.xAxis[0].getExtremes();
|
|
40
|
+
zoom.current = userMin !== undefined && userMax !== undefined ? { min: userMin, max: userMax } : null;
|
|
41
|
+
chart.destroy();
|
|
42
|
+
};
|
|
43
|
+
}, [options, onRendered]);
|
|
44
|
+
if (!data)
|
|
45
|
+
return null;
|
|
46
|
+
return (_jsxs("div", { className: "ObUnboundPreview", children: [data.vehicles.length === 0 ? (_jsx(Paragraph, { "data-size": "sm", className: "ObUnboundPreview-empty", children: getLocalizedString("No planned loads") })) : (_jsx("div", { ref: container, className: "ObUnboundPreview-chart",
|
|
47
|
+
// Reserved up front, so the page keeps its scroll position while the chart is replaced.
|
|
48
|
+
style: { minHeight: getChartHeight(data.vehicles.length) }, onClick: (event) => {
|
|
49
|
+
let link = event.target.closest('a[href^="#vehicle-"]');
|
|
50
|
+
if (link) {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
setVehicleId(Number(link.hash.replace("#vehicle-", "")));
|
|
53
|
+
}
|
|
54
|
+
} })), _jsx(VehicleInfoDialog, { vehicleId: vehicleId, date: date, onClose: () => setVehicleId(null) })] }));
|
|
55
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** A load in the plan being edited, before it is saved. */
|
|
2
|
+
export type PlannedDelivery = {
|
|
3
|
+
VehicleID: number;
|
|
4
|
+
StartTime: Date;
|
|
5
|
+
/** Minutes from the start until the vehicle has loaded. */
|
|
6
|
+
LoadTime: number;
|
|
7
|
+
DriveToSiteTime: number;
|
|
8
|
+
WaitTime: number;
|
|
9
|
+
UnloadTime: number;
|
|
10
|
+
DriveFromSiteTime: number;
|
|
11
|
+
EndTime: Date;
|
|
12
|
+
DriverID: string | null;
|
|
13
|
+
};
|
|
14
|
+
/** A load from another call-off that already occupies one of the vehicles. */
|
|
15
|
+
export type OtherDelivery = {
|
|
16
|
+
VehicleID: number;
|
|
17
|
+
StartTime: Date;
|
|
18
|
+
EndTime: Date;
|
|
19
|
+
DriverID: string | null;
|
|
20
|
+
CallOffID: number;
|
|
21
|
+
CustomerAdr1: string | null;
|
|
22
|
+
BuildSiteAdr1: string | null;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Times are wall clock carried as UTC. A value without a zone is read as UTC as well, so it is
|
|
26
|
+
* never shifted to the time zone of the browser.
|
|
27
|
+
*/
|
|
28
|
+
export declare function parseTime(value: string): Date;
|
|
29
|
+
/** Reads the plan as the planning dialog sends it. */
|
|
30
|
+
export declare function parsePlannedDeliveries(json: string | null | undefined): PlannedDelivery[];
|
|
31
|
+
/** Reads the other call-offs' loads as the planning dialog sends them. */
|
|
32
|
+
export declare function parseOtherDeliveries(json: string | null | undefined): OtherDelivery[];
|
|
33
|
+
/** The vehicles in the plan, in the order they first appear. */
|
|
34
|
+
export declare function getVehicles(deliveries: PlannedDelivery[]): number[];
|
|
35
|
+
export type PreviewData = {
|
|
36
|
+
vehicles: number[];
|
|
37
|
+
planned: PlannedDelivery[];
|
|
38
|
+
/** Only the loads on vehicles in the plan: the chart has no row for the others. */
|
|
39
|
+
other: OtherDelivery[];
|
|
40
|
+
};
|
|
41
|
+
export declare function getPreviewData(planned: PlannedDelivery[], other: OtherDelivery[]): PreviewData;
|
|
42
|
+
/** Arrival on site, start and end of unloading, for the status strip of a planned load. */
|
|
43
|
+
export declare function getStatusTimes(delivery: PlannedDelivery): {
|
|
44
|
+
m1: number;
|
|
45
|
+
m2: number;
|
|
46
|
+
m3: number;
|
|
47
|
+
};
|
|
48
|
+
export declare function getChartHeight(vehicleCount: number): number;
|
|
49
|
+
export declare function cropCaption(caption: string, maxLength: number): string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const MINUTE = 60000;
|
|
2
|
+
/**
|
|
3
|
+
* Times are wall clock carried as UTC. A value without a zone is read as UTC as well, so it is
|
|
4
|
+
* never shifted to the time zone of the browser.
|
|
5
|
+
*/
|
|
6
|
+
export function parseTime(value) {
|
|
7
|
+
let hasZone = /(Z|[+-]\d\d:?\d\d)$/i.test(value);
|
|
8
|
+
return new Date(hasZone || !value.includes("T") ? value : `${value}Z`);
|
|
9
|
+
}
|
|
10
|
+
function text(value) {
|
|
11
|
+
return typeof value === "string" && value !== "" ? value : null;
|
|
12
|
+
}
|
|
13
|
+
function parseArray(json) {
|
|
14
|
+
if (!json)
|
|
15
|
+
return [];
|
|
16
|
+
let parsed = JSON.parse(json);
|
|
17
|
+
return Array.isArray(parsed) ? parsed : [];
|
|
18
|
+
}
|
|
19
|
+
/** Reads the plan as the planning dialog sends it. */
|
|
20
|
+
export function parsePlannedDeliveries(json) {
|
|
21
|
+
return parseArray(json).map((row) => ({
|
|
22
|
+
VehicleID: Number(row.VehicleID),
|
|
23
|
+
StartTime: parseTime(row.StartTime),
|
|
24
|
+
LoadTime: Number(row.LoadTime) || 0,
|
|
25
|
+
DriveToSiteTime: Number(row.DriveToSiteTime) || 0,
|
|
26
|
+
WaitTime: Number(row.WaitTime) || 0,
|
|
27
|
+
UnloadTime: Number(row.UnloadTime) || 0,
|
|
28
|
+
DriveFromSiteTime: Number(row.DriveFromSiteTime) || 0,
|
|
29
|
+
EndTime: parseTime(row.EndTime),
|
|
30
|
+
DriverID: text(row.DriverID),
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
/** Reads the other call-offs' loads as the planning dialog sends them. */
|
|
34
|
+
export function parseOtherDeliveries(json) {
|
|
35
|
+
return parseArray(json).map((row) => ({
|
|
36
|
+
VehicleID: Number(row.VehicleID),
|
|
37
|
+
StartTime: parseTime(row.StartTime),
|
|
38
|
+
EndTime: parseTime(row.EndTime),
|
|
39
|
+
DriverID: text(row.DriverID),
|
|
40
|
+
CallOffID: Number(row.CallOffID),
|
|
41
|
+
CustomerAdr1: text(row.CustomerAdr1),
|
|
42
|
+
BuildSiteAdr1: text(row.BuildSiteAdr1),
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
/** The vehicles in the plan, in the order they first appear. */
|
|
46
|
+
export function getVehicles(deliveries) {
|
|
47
|
+
return [...new Set(deliveries.map((delivery) => delivery.VehicleID))];
|
|
48
|
+
}
|
|
49
|
+
export function getPreviewData(planned, other) {
|
|
50
|
+
let vehicles = getVehicles(planned);
|
|
51
|
+
let inPlan = new Set(vehicles);
|
|
52
|
+
return { vehicles, planned, other: other.filter((delivery) => inPlan.has(delivery.VehicleID)) };
|
|
53
|
+
}
|
|
54
|
+
/** Arrival on site, start and end of unloading, for the status strip of a planned load. */
|
|
55
|
+
export function getStatusTimes(delivery) {
|
|
56
|
+
let start = delivery.StartTime.getTime();
|
|
57
|
+
let arrival = start + (delivery.LoadTime + delivery.DriveToSiteTime) * MINUTE;
|
|
58
|
+
let unloadStart = arrival + delivery.WaitTime * MINUTE;
|
|
59
|
+
let unloadComplete = unloadStart + delivery.UnloadTime * MINUTE;
|
|
60
|
+
return { m1: arrival, m2: unloadStart, m3: unloadComplete };
|
|
61
|
+
}
|
|
62
|
+
export function getChartHeight(vehicleCount) {
|
|
63
|
+
return vehicleCount * 30 + 65;
|
|
64
|
+
}
|
|
65
|
+
export function cropCaption(caption, maxLength) {
|
|
66
|
+
return caption.length > maxLength ? `${caption.slice(0, Math.max(0, maxLength))}...` : caption;
|
|
67
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import Highcharts from "highcharts";
|
|
2
|
+
import type { DeliveryRecord } from "./data.js";
|
|
3
|
+
import { type ChartData } from "./model.js";
|
|
4
|
+
export type MoveDelivery = (delivery: DeliveryRecord, prodTime: Date, vehicleId: number) => void;
|
|
5
|
+
export type ChartSettings = {
|
|
6
|
+
date: Date;
|
|
7
|
+
minOffset: number;
|
|
8
|
+
maxOffset: number;
|
|
9
|
+
thickBars: boolean;
|
|
10
|
+
readOnly: boolean;
|
|
11
|
+
onMove: MoveDelivery;
|
|
12
|
+
};
|
|
13
|
+
export declare function getChartOptions(data: ChartData, settings: ChartSettings): Highcharts.Options;
|