diff --git a/app/server/station.py b/app/server/station.py index 51191d9..3c79b47 100644 --- a/app/server/station.py +++ b/app/server/station.py @@ -66,8 +66,8 @@ class Refusal(ValueError): def stations(): - runs = sorted(f"{d.parent.parent.name}{RUN}{d.name}" for d in DATA_DIFF.glob("*/runs/*") if d.is_dir()) - return sorted(d.name for d in DATA.iterdir() if d.is_dir()) + runs + runs = [f"{d.parent.parent.name}{RUN}{d.name}" for d in DATA_DIFF.glob("*/runs/*") if d.is_dir()] + return sorted([d.name for d in DATA.iterdir() if d.is_dir()] + runs) # a run right after its station def serial(station): diff --git a/app/web/src/common.jsx b/app/web/src/common.jsx index 70674ce..e1a25c9 100644 --- a/app/web/src/common.jsx +++ b/app/web/src/common.jsx @@ -17,16 +17,28 @@ export async function call(path, method = "GET", body) { return null; } -// The station and the range (UTC, To excluded; empty: the whole period), shared by the pages through the address +// The station and the range (UTC, To excluded; empty: the whole period), shared by the pages through the address. Source: +// Cloud, the stations of data/; Emulator, the runs of data_diff/, @ for the server +const SOURCES = [{ value: "cloud", label: "Cloud" }, { value: "emulator", label: "Emulator" }]; +const sourceOf = station => (station || "").includes("@") ? "emulator" : "cloud"; + export function Selector({ selection, choose }) { - const [stations, setStations] = useState([]), [s, setS] = useState(selection); + const [stations, setStations] = useState([]), [s, setS] = useState(selection), [source, setSource] = useState(sourceOf(selection.station)); useEffect(() => { call("/api/stations").then(l => l && setStations(l)); }, []); - useEffect(() => setS(selection), [selection]); // a new object at each change of the address + useEffect(() => { setS(selection); if (selection.station) setSource(sourceOf(selection.station)); }, [selection]); // a new object at each change of the address + const [serial, run] = (s.station || "").split("@"); + const runsOf = st => stations.filter(n => n.startsWith(st + "@")).map(n => n.split("@")[1]); + const names = source === "cloud" ? stations.filter(n => !n.includes("@")) + : [...new Set(stations.filter(n => n.includes("@")).map(n => n.split("@")[0]))]; return ( - { setSource(v); setS({ ...s, station: "" }); }} /> + setS({ ...s, station: `${serial}@${v}` })} />} setS({ ...s, start: e.currentTarget.value })} /> setS({ ...s, end: e.currentTarget.value })} />