Stations: a page of its own, under Data (the tracked stations, their position, the pumping), instead of the window of the selector
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c8c8c1587a
commit
d72dccb14e
4 files changed
+97
-85
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { ActionIcon, Button, Card, Checkbox, Code, Group, ScrollArea, Stack, Table, Text, TextInput, Title } from "@mantine/core";
|
||||
import { IconPlus, IconX } from "@tabler/icons-react";
|
||||
import { call } from "../common.jsx";
|
||||
|
||||
const shift = (d, n) => (d ? new Date(Date.parse(d) + n * 864e5).toISOString().slice(0, 10) : "");
|
||||
|
||||
// The tracked stations (extraction/stations.txt of ~/aimsight-data): serial and position (for the weather of the Data page);
|
||||
// the checked ones pumped (extraction/pump.sh) over a range, or without range their missing days up to now. The state of
|
||||
// the pumping read every 2 s. By default, the station and the range of the address (From 3 days before: the history of
|
||||
// the detectors)
|
||||
export default function Stations({ selection }) {
|
||||
const [rows, setRows] = useState([]), [checked, setChecked] = useState(selection.station ? [selection.station] : []);
|
||||
const [range, setRange] = useState({ start: shift(selection.start, -3), end: selection.end });
|
||||
const [images, setImages] = useState(true), [state, setState] = useState(null);
|
||||
useEffect(() => { call("/api/tracked").then(l => l && setRows(l)); }, []);
|
||||
useEffect(() => {
|
||||
const read = () => fetch("/api/pump").then(r => r.ok && r.json()).then(p => p && setState(p)).catch(() => {}); // silently
|
||||
read();
|
||||
const timer = setInterval(read, 2000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
const running = !!state?.running;
|
||||
const set = (i, k, v) => setRows(rows.map((r, n) => (n === i ? { ...r, [k]: v } : r)));
|
||||
const save = () => call("/api/tracked", "PUT", { stations: rows.filter(r => r.serial) }).then(l => l && setRows(l));
|
||||
const pump = () => call("/api/pump", "POST", { stations: checked, ...range, images }).then(p => p && setState(p));
|
||||
return (
|
||||
<Stack gap="lg" maw={1000}>
|
||||
<div>
|
||||
<Title order={2}>Stations</Title>
|
||||
<Text c="dimmed">The tracked stations and their position (for the weather of the Data page); the checked ones pumped from
|
||||
the platform, read-only.</Text>
|
||||
</div>
|
||||
<Card shadow="sm" withBorder>
|
||||
<Stack gap="md">
|
||||
<Table withRowBorders={false} verticalSpacing={4}>
|
||||
<Table.Thead><Table.Tr><Table.Th w={50}>Pump</Table.Th><Table.Th>Serial</Table.Th>
|
||||
<Table.Th>Position (lat,lon or a Swiss place, for the weather)</Table.Th><Table.Th w={40} /></Table.Tr></Table.Thead>
|
||||
<Table.Tbody>
|
||||
{rows.map((r, i) => (
|
||||
<Table.Tr key={i}>
|
||||
<Table.Td><Checkbox checked={checked.includes(r.serial)} disabled={!r.serial} aria-label={`Pump ${r.serial}`}
|
||||
onChange={e => setChecked(e.currentTarget.checked ? [...checked, r.serial] : checked.filter(c => c !== r.serial))} /></Table.Td>
|
||||
<Table.Td><TextInput size="xs" value={r.serial} onChange={e => set(i, "serial", e.currentTarget.value.trim())} /></Table.Td>
|
||||
<Table.Td><TextInput size="xs" value={r.position} placeholder="46.6895,7.7790"
|
||||
onChange={e => set(i, "position", e.currentTarget.value)} /></Table.Td>
|
||||
<Table.Td><ActionIcon variant="subtle" color="gray" aria-label="Remove" onClick={() => setRows(rows.filter((_, n) => n !== i))}>
|
||||
<IconX size={16} /></ActionIcon></Table.Td>
|
||||
</Table.Tr>
|
||||
))}
|
||||
</Table.Tbody>
|
||||
</Table>
|
||||
<Group gap="sm">
|
||||
<Button size="xs" variant="default" leftSection={<IconPlus size={14} />}
|
||||
onClick={() => setRows([...rows, { serial: "", position: "" }])}>Add a station</Button>
|
||||
<Button size="xs" onClick={save}>Save the list</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</Card>
|
||||
<Card shadow="sm" withBorder>
|
||||
<Stack gap="md">
|
||||
<Group align="flex-end" gap="md">
|
||||
<TextInput label="From (UTC)" type="date" value={range.start} onChange={e => setRange({ ...range, start: e.currentTarget.value })} />
|
||||
<TextInput label="To (excluded)" type="date" value={range.end} onChange={e => setRange({ ...range, end: e.currentTarget.value })} />
|
||||
<Checkbox label="Images" checked={images} onChange={e => setImages(e.currentTarget.checked)} mb={8} />
|
||||
<Button onClick={pump} loading={running} disabled={!checked.length}>Pump {checked.length || ""}</Button>
|
||||
</Group>
|
||||
<Text size="xs" c="dimmed">By default From is 3 days before the range of the Data page (the history of the detectors);
|
||||
without dates, the missing days of each station up to now. A long range, outside busy hours.</Text>
|
||||
{state?.log?.length > 0 && (
|
||||
<ScrollArea h={320} viewportRef={v => v && (v.scrollTop = v.scrollHeight)}>
|
||||
<Code block>{state.log.join("\n")}</Code>
|
||||
</ScrollArea>
|
||||
)}
|
||||
</Stack>
|
||||
</Card>
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user