updated as in the terminal and gate api's

This commit is contained in:
csawatzky 2025-04-17 15:42:19 -06:00
parent 76744c1b6f
commit 74c8ed661c
13 changed files with 109 additions and 75 deletions

View file

@ -32,6 +32,7 @@ interface Props {
export default function GateDevice(props: Props) { export default function GateDevice(props: Props) {
const { gate, comprehensiveDevice, linkedCompList, drawerView } = props; const { gate, comprehensiveDevice, linkedCompList, drawerView } = props;
const [{as}] = useGlobalState();
const [device, setDevice] = useState<Device>(Device.create()); const [device, setDevice] = useState<Device>(Device.create());
const [componentOptions, setComponentOptions] = useState<Map<string, Component>>( const [componentOptions, setComponentOptions] = useState<Map<string, Component>>(
new Map<string, Component>() new Map<string, Component>()
@ -159,7 +160,8 @@ export default function GateDevice(props: Props) {
device.id() + ":" + componentKey, device.id() + ":" + componentKey,
gateCompType, gateCompType,
[gate.key], [gate.key],
["gate"] ["gate"],
as
) )
.then(resp => { .then(resp => {
openSnack("Component Prefence Updated"); openSnack("Component Prefence Updated");

View file

@ -14,7 +14,7 @@ import SingleSetAreaChart, { SSAreaDataPoint } from "charts/SingleSetAreaChart";
import { Gate } from "models/Gate"; import { Gate } from "models/Gate";
import moment, { Moment } from "moment"; import moment, { Moment } from "moment";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { useGateAPI } from "providers"; import { useGateAPI, useGlobalState } from "providers";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
interface Props { interface Props {
@ -61,6 +61,7 @@ export default function GateFlowGraph(props: Props) {
newXDomain, newXDomain,
multiGraphZoom multiGraphZoom
} = props; } = props;
const [{as}] = useGlobalState();
const gateAPI = useGateAPI(); const gateAPI = useGateAPI();
const [flowData, setFlowData] = useState<SSAreaDataPoint[]>([]); const [flowData, setFlowData] = useState<SSAreaDataPoint[]>([]);
const [loadingChartData, setLoadingChartData] = useState(false); const [loadingChartData, setLoadingChartData] = useState(false);
@ -84,7 +85,10 @@ export default function GateFlowGraph(props: Props) {
ambient, ambient,
pressureComponent, pressureComponent,
start.toISOString(), start.toISOString(),
end.toISOString() end.toISOString(),
undefined,
undefined,
as
) )
.then(resp => { .then(resp => {
let data: SSAreaDataPoint[] = []; let data: SSAreaDataPoint[] = [];
@ -135,7 +139,7 @@ export default function GateFlowGraph(props: Props) {
setRecent(recent); setRecent(recent);
}); });
} }
}, [gateAPI, gate, ambient, pressureComponent, start, end, device, setPCAState]); // eslint-disable-line react-hooks/exhaustive-deps }, [gateAPI, gate, ambient, pressureComponent, start, end, device, setPCAState, as]); // eslint-disable-line react-hooks/exhaustive-deps
const loadFlowEvents = () => { const loadFlowEvents = () => {
if (ambient && pressureComponent) { if (ambient && pressureComponent) {
@ -149,7 +153,10 @@ export default function GateFlowGraph(props: Props) {
start.toISOString(), start.toISOString(),
end.toISOString(), end.toISOString(),
idleFlow, idleFlow,
eventThreshold eventThreshold,
undefined,
undefined,
as
) )
.then(resp => { .then(resp => {
console.log(resp); console.log(resp);

View file

@ -60,6 +60,7 @@ const useStyles = makeStyles((theme: Theme) => ({
export default function GateGraphs(props: Props) { export default function GateGraphs(props: Props) {
const { gate, display, compMap, device, pressure, ambient, setPCAState } = props; const { gate, display, compMap, device, pressure, ambient, setPCAState } = props;
const [{ as }] = useGlobalState();
const [xDomain, setXDomain] = useState<string[] | number[]>(["dataMin", "dataMax"]); const [xDomain, setXDomain] = useState<string[] | number[]>(["dataMin", "dataMax"]);
const [zoomed, setZoomed] = useState(false); const [zoomed, setZoomed] = useState(false);
const defaultDateRange = GetDefaultDateRange(); const defaultDateRange = GetDefaultDateRange();
@ -79,7 +80,7 @@ export default function GateGraphs(props: Props) {
setLoading(true); setLoading(true);
let measurementMap: Map<string, UnitMeasurement[]> = new Map<string, UnitMeasurement[]>(); let measurementMap: Map<string, UnitMeasurement[]> = new Map<string, UnitMeasurement[]>();
gateAPI gateAPI
.listGateMeasurements(gate.key, startDate.toISOString(), endDate.toISOString()) .listGateMeasurements(gate.key, startDate.toISOString(), endDate.toISOString(), as)
.then(resp => { .then(resp => {
resp.data.measurements.forEach(um => { resp.data.measurements.forEach(um => {
let unitMeasurement = UnitMeasurement.any(um, user); let unitMeasurement = UnitMeasurement.any(um, user);
@ -93,7 +94,7 @@ export default function GateGraphs(props: Props) {
setLoading(false); setLoading(false);
setCompMeasurements(measurementMap); setCompMeasurements(measurementMap);
}); });
}, [gate, endDate, gateAPI, startDate]); // eslint-disable-line react-hooks/exhaustive-deps }, [gate, endDate, gateAPI, startDate, as]); // eslint-disable-line react-hooks/exhaustive-deps
const updateDateRange = (newStartDate: any, newEndDate: any) => { const updateDateRange = (newStartDate: any, newEndDate: any) => {
let range = GetDefaultDateRange(); let range = GetDefaultDateRange();

View file

@ -10,7 +10,7 @@ import { makeStyles } from "@mui/styles";
import ResponsiveTable, { Column } from "common/ResponsiveTable"; import ResponsiveTable, { Column } from "common/ResponsiveTable";
import AddGateFab from "./AddGateFab"; import AddGateFab from "./AddGateFab";
import GateSettings from "./GateSettings"; import GateSettings from "./GateSettings";
import { useGateAPI } from "providers"; import { useGateAPI, useGlobalState } from "providers";
import { Settings } from "@mui/icons-material"; import { Settings } from "@mui/icons-material";
interface Props { interface Props {
@ -38,7 +38,8 @@ const useStyles = makeStyles((theme: Theme) => ({
})); }));
export default function GateList(props: Props) { export default function GateList(props: Props) {
const {terminals, currentTerminal } = props; const {terminals, currentTerminal } = props;
const [{as}] = useGlobalState();
// const history = useHistory(); // const history = useHistory();
const navigate = useNavigate(); const navigate = useNavigate();
const isMobile = useMobile(); const isMobile = useMobile();
@ -73,11 +74,11 @@ const {terminals, currentTerminal } = props;
keys = [currentTerminal] keys = [currentTerminal]
types = ["terminal"] types = ["terminal"]
} }
gateAPI.listGates(pageSize, pageSize * tablePage, "asc", "name", search, undefined, keys, types).then(resp => { gateAPI.listGates(pageSize, pageSize * tablePage, "asc", "name", search, undefined, keys, types, undefined, undefined, as).then(resp => {
setGates(resp.data.gates.map(gate => Gate.create(gate))) setGates(resp.data.gates.map(gate => Gate.create(gate)))
setTotal(resp.data.total) setTotal(resp.data.total)
}) })
},[currentTerminal, search, pageSize, tablePage]) },[currentTerminal, search, pageSize, tablePage, as])
useEffect(() => { useEffect(() => {
loadGates() loadGates()

View file

@ -19,7 +19,7 @@ import ResponsiveDialog from "common/ResponsiveDialog";
import { Terminal } from "models/Terminal"; import { Terminal } from "models/Terminal";
import { Gate } from "models/Gate"; import { Gate } from "models/Gate";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { useTerminalAPI, useGateAPI } from "providers"; import { useTerminalAPI, useGateAPI, useGlobalState } from "providers";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { useSnackbar } from "hooks"; import { useSnackbar } from "hooks";
//import { useHistory } from "react-router"; //import { useHistory } from "react-router";
@ -48,6 +48,7 @@ const steps = ["Gate", "Duct"];
export default function GateSettings(props: Props) { export default function GateSettings(props: Props) {
const { open, close, terminals, gate, long, lat } = props; const { open, close, terminals, gate, long, lat } = props;
const [{as}] = useGlobalState();
const [gateName, setGateName] = useState(""); const [gateName, setGateName] = useState("");
const [lowerFlowBound, setLowerFlowBound] = useState(0); const [lowerFlowBound, setLowerFlowBound] = useState(0);
const [upperFlowBound, setUpperFlowBound] = useState(0); const [upperFlowBound, setUpperFlowBound] = useState(0);
@ -83,7 +84,7 @@ export default function GateSettings(props: Props) {
if (loadingTerminals) return; if (loadingTerminals) return;
setLoadingTerminals(true); setLoadingTerminals(true);
terminalAPI terminalAPI
.listTerminals(500, 0) .listTerminals(500, 0, undefined, undefined, undefined, as)
.then(resp => { .then(resp => {
setTerminalOptions(resp.data.terminals.map(a => Terminal.any(a))); setTerminalOptions(resp.data.terminals.map(a => Terminal.any(a)));
}) })
@ -95,7 +96,7 @@ export default function GateSettings(props: Props) {
setTerminalOptions(terminals); setTerminalOptions(terminals);
} }
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, [terminals, terminalAPI]); }, [terminals, terminalAPI, as]);
useEffect(() => { useEffect(() => {
if (gate) { if (gate) {
@ -146,7 +147,7 @@ export default function GateSettings(props: Props) {
settings.hourlyApuCost = hourlyAPU; settings.hourlyApuCost = hourlyAPU;
settings.hourlyPcaCost = hourlyPCA; settings.hourlyPcaCost = hourlyPCA;
gateAPI gateAPI
.updateGate(gate.key, gateName, settings) .updateGate(gate.key, gateName, settings, as)
.then(resp => { .then(resp => {
openSnack("Gate update"); openSnack("Gate update");
close(); close();
@ -174,7 +175,7 @@ export default function GateSettings(props: Props) {
hourlyPcaCost: hourlyPCA hourlyPcaCost: hourlyPCA
}); });
gateAPI gateAPI
.addGate(gateName, settings) .addGate(gateName, settings, as)
.then(resp => { .then(resp => {
openSnack("New gate added"); openSnack("New gate added");
let newGate = Gate.create( let newGate = Gate.create(
@ -191,7 +192,7 @@ export default function GateSettings(props: Props) {
const remove = () => { const remove = () => {
if (gate) { if (gate) {
gateAPI gateAPI
.removeGate(gate.key) .removeGate(gate.key, as)
.then(resp => { .then(resp => {
openSnack("Gate Deleted"); openSnack("Gate Deleted");
}) })

View file

@ -1,7 +1,7 @@
import DisplayDrawer from "common/DisplayDrawer"; import DisplayDrawer from "common/DisplayDrawer";
import { Gate as IGate } from "models/Gate"; import { Gate as IGate } from "models/Gate";
import Gate from "pages/Gate"; import Gate from "pages/Gate";
import { useGateAPI, useSnackbar } from "providers"; import { useGateAPI, useGlobalState, useSnackbar } from "providers";
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
interface Props { interface Props {
@ -15,6 +15,7 @@ interface Props {
export default function GateDrawer(props: Props) { export default function GateDrawer(props: Props) {
const { open, onClose, gates, selectedGate, moveMap, removeMarker } = props; const { open, onClose, gates, selectedGate, moveMap, removeMarker } = props;
const [{as}] = useGlobalState();
const [gate, setGate] = useState(IGate.create()); const [gate, setGate] = useState(IGate.create());
const gateAPI = useGateAPI(); const gateAPI = useGateAPI();
const { openSnack } = useSnackbar(); const { openSnack } = useSnackbar();
@ -91,7 +92,7 @@ export default function GateDrawer(props: Props) {
settings.longitude = 0; settings.longitude = 0;
settings.latitude = 0; settings.latitude = 0;
gateAPI gateAPI
.updateGate(gate.key, gate.name, settings) .updateGate(gate.key, gate.name, settings, as)
.then(resp => { .then(resp => {
openSnack("Marker Removed"); openSnack("Marker Removed");
//then use the removeMarker prop function to update the markers in the parent map //then use the removeMarker prop function to update the markers in the parent map

View file

@ -1,7 +1,7 @@
import DisplayDrawer from "common/DisplayDrawer"; import DisplayDrawer from "common/DisplayDrawer";
import { Terminal as ITerminal } from "models/Terminal"; import { Terminal as ITerminal } from "models/Terminal";
import Terminal from "pages/Terminals"; import Terminal from "pages/Terminals";
import { useSnackbar, useTerminalAPI } from "providers"; import { useGlobalState, useSnackbar, useTerminalAPI } from "providers";
import React, { useState, useEffect } from "react"; import React, { useState, useEffect } from "react";
interface Props { interface Props {
@ -15,6 +15,7 @@ interface Props {
export default function TerminalDrawer(props: Props) { export default function TerminalDrawer(props: Props) {
const { terminals, selectedKey, open, onClose, moveMap, removeMarker } = props; const { terminals, selectedKey, open, onClose, moveMap, removeMarker } = props;
const [{as}] = useGlobalState();
const [terminal, setTerminal] = useState<ITerminal>(ITerminal.create()); const [terminal, setTerminal] = useState<ITerminal>(ITerminal.create());
const terminalAPI = useTerminalAPI(); const terminalAPI = useTerminalAPI();
const { openSnack } = useSnackbar(); const { openSnack } = useSnackbar();
@ -91,7 +92,7 @@ export default function TerminalDrawer(props: Props) {
settings.longitude = 0; settings.longitude = 0;
settings.latitude = 0; settings.latitude = 0;
terminalAPI terminalAPI
.updateTerminal(terminal.key, terminal.name, settings) .updateTerminal(terminal.key, terminal.name, settings, as)
.then(resp => { .then(resp => {
openSnack("Marker Removed"); openSnack("Marker Removed");
//then use the removeMarker prop function to update the markers in the parent map //then use the removeMarker prop function to update the markers in the parent map

View file

@ -31,7 +31,7 @@ interface Props {
} }
export default function AviationMapController(props: Props) { export default function AviationMapController(props: Props) {
const [{ user }] = useGlobalState(); const [{ user, as }] = useGlobalState();
const transDuration = 3000; const transDuration = 3000;
const [currentView, setCurrentView] = useState( const [currentView, setCurrentView] = useState(
props.startingView props.startingView
@ -99,7 +99,7 @@ export default function AviationMapController(props: Props) {
settings.longitude = longitude; settings.longitude = longitude;
settings.latitude = latitude; settings.latitude = latitude;
terminalAPI terminalAPI
.updateTerminal(terminal.key, terminal.name, settings) .updateTerminal(terminal.key, terminal.name, settings, as)
.then(resp => { .then(resp => {
openSnack("Terminal Location Updated"); openSnack("Terminal Location Updated");
if (newMarker) { if (newMarker) {
@ -139,7 +139,7 @@ export default function AviationMapController(props: Props) {
settings.longitude = longitude; settings.longitude = longitude;
settings.latitude = latitude; settings.latitude = latitude;
gateAPI gateAPI
.updateGate(gate.key, gate.name, settings) .updateGate(gate.key, gate.name, settings, as)
.then(resp => { .then(resp => {
openSnack("Gate Location Updated"); openSnack("Gate Location Updated");
if (newMarker) { if (newMarker) {
@ -170,7 +170,7 @@ export default function AviationMapController(props: Props) {
}; };
const loadTerminals = useCallback(() => { const loadTerminals = useCallback(() => {
terminalAPI.listTerminals(0, 0, undefined, undefined, undefined).then(resp => { terminalAPI.listTerminals(0, 0, undefined, undefined, undefined, as).then(resp => {
let terminalMap: Map<string, Terminal> = new Map(); let terminalMap: Map<string, Terminal> = new Map();
let terminalMarkers: Map<string, MarkerData> = new Map(); let terminalMarkers: Map<string, MarkerData> = new Map();
let terminalOps: Terminal[] = []; let terminalOps: Terminal[] = [];
@ -212,10 +212,10 @@ export default function AviationMapController(props: Props) {
setTerminalSearchEntries(searchEntries); setTerminalSearchEntries(searchEntries);
setTerminalOptions(terminalOps); setTerminalOptions(terminalOps);
}); });
}, [terminalAPI]); // eslint-disable-line react-hooks/exhaustive-deps }, [terminalAPI, as]); // eslint-disable-line react-hooks/exhaustive-deps
const loadGates = useCallback(() => { const loadGates = useCallback(() => {
gateAPI.listGates(0, 0, undefined, undefined, undefined, true).then(resp => { gateAPI.listGates(0, 0, undefined, undefined, undefined, true, undefined, undefined, undefined, undefined, as).then(resp => {
let gates: Map<string, Gate> = new Map(); let gates: Map<string, Gate> = new Map();
let gateOptions: Gate[] = []; let gateOptions: Gate[] = [];
let gateMarkers: Map<string, MarkerData> = new Map(); let gateMarkers: Map<string, MarkerData> = new Map();
@ -255,7 +255,7 @@ export default function AviationMapController(props: Props) {
setGateMarkers(gateMarkers); setGateMarkers(gateMarkers);
setGateSearchEntries(searchEntries); setGateSearchEntries(searchEntries);
}); });
}, [gateAPI]); // eslint-disable-line react-hooks/exhaustive-deps }, [gateAPI, as]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => { useEffect(() => {
loadTerminals(); loadTerminals();

View file

@ -132,7 +132,7 @@ export default function Gate(props: Props) {
if (loadingGate || id === undefined || id === "") return; if (loadingGate || id === undefined || id === "") return;
setLoadingGate(true); setLoadingGate(true);
gateAPI gateAPI
.getGatePageData(id) .getGatePageData(id, as)
.then(resp => { .then(resp => {
//console.log(resp.data); //console.log(resp.data);
let p = new Map<number, pond.GateDeviceType>(); let p = new Map<number, pond.GateDeviceType>();
@ -168,7 +168,7 @@ export default function Gate(props: Props) {
setLoadingGate(false); setLoadingGate(false);
}); });
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, [gateAPI, gateID]); }, [gateAPI, gateID, as]);
useEffect(() => { useEffect(() => {
loadGate(); loadGate();
@ -176,7 +176,7 @@ export default function Gate(props: Props) {
const updateGateDevicePrefs = (deviceID: number, newPref: pond.GateDeviceType) => { const updateGateDevicePrefs = (deviceID: number, newPref: pond.GateDeviceType) => {
gateAPI gateAPI
.updatePrefs(gate.key, "device", deviceID.toString(), newPref, [gate.key], ["gate"]) .updatePrefs(gate.key, "device", deviceID.toString(), newPref, [gate.key], ["gate"], as)
.then(resp => { .then(resp => {
openSnack("Updated gate device type"); openSnack("Updated gate device type");
// have to do the clone method to force the select box to update // have to do the clone method to force the select box to update
@ -226,7 +226,7 @@ export default function Gate(props: Props) {
"write", "write",
"grant", "grant",
"revoke" "revoke"
]) ], as)
.then(resp => { .then(resp => {
if (id) { if (id) {
devMap.set(id.toString(), device); devMap.set(id.toString(), device);
@ -238,7 +238,7 @@ export default function Gate(props: Props) {
console.log("error linking device"); console.log("error linking device");
}); });
} else { } else {
gateAPI.updateLink(gateID, "gate", id.toString(), "device", []).then(resp => { gateAPI.updateLink(gateID, "gate", id.toString(), "device", [], as).then(resp => {
if (id) { if (id) {
devMap.delete(id.toString()); devMap.delete(id.toString());
if (tabVal === id) { if (tabVal === id) {
@ -264,14 +264,14 @@ export default function Gate(props: Props) {
"write", "write",
"grant", "grant",
"revoke" "revoke"
]) ],as)
.then(resp => { .then(resp => {
c.push(component); c.push(component);
setComponents([...c]); setComponents([...c]);
}); });
} else { } else {
gateAPI gateAPI
.updateLink(gateID, "gate", deviceID + ":" + component.key(), "component", []) .updateLink(gateID, "gate", deviceID + ":" + component.key(), "component", [], as)
.then(resp => { .then(resp => {
c.forEach((comp, i) => { c.forEach((comp, i) => {
if (component.key() === comp.key()) { if (component.key() === comp.key()) {

View file

@ -181,14 +181,14 @@ export default function Terminals(props: Props) {
const load = useCallback(() => { const load = useCallback(() => {
if(loading) return if(loading) return
setLoading(true) setLoading(true)
terminalAPI.listTerminals(200, 0, "asc", "name").then(resp => { terminalAPI.listTerminals(200, 0, "asc", "name", as).then(resp => {
setTerminals(resp.data.terminals.map(a => Terminal.any(a))); setTerminals(resp.data.terminals.map(a => Terminal.any(a)));
}).catch(err => { }).catch(err => {
console.log("There was a problem loading Terminals") console.log("There was a problem loading Terminals")
}).finally(() => { }).finally(() => {
setLoading(false) setLoading(false)
}) })
}, [terminalAPI, openSnack]); //eslint-disable-line react-hooks/exhaustive-deps }, [terminalAPI, openSnack, as]); //eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => { useEffect(() => {
load(); load();
@ -197,7 +197,7 @@ export default function Terminals(props: Props) {
const remove = () => { const remove = () => {
if (currentTerminal) { if (currentTerminal) {
terminalAPI terminalAPI
.removeTerminal(currentTerminal.key) .removeTerminal(currentTerminal.key, as)
.then(resp => { .then(resp => {
openSnack("Terminal Deleted"); openSnack("Terminal Deleted");
let a = terminals; let a = terminals;

View file

@ -8,7 +8,8 @@ import { useGlobalState } from "providers";
export interface IGateInterface { export interface IGateInterface {
addGate: ( addGate: (
name: string, name: string,
settings: pond.GateSettings settings: pond.GateSettings,
as?: string
) => Promise<AxiosResponse<pond.AddGateResponse>>; ) => Promise<AxiosResponse<pond.AddGateResponse>>;
listGates: ( listGates: (
limit: number, limit: number,
@ -20,21 +21,24 @@ export interface IGateInterface {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
numerical?: boolean, numerical?: boolean,
specificUser?: string specificUser?: string,
as?: string
) => Promise<AxiosResponse<pond.ListGatesResponse>>; ) => Promise<AxiosResponse<pond.ListGatesResponse>>;
updateGate: ( updateGate: (
key: string, key: string,
name: string, name: string,
settings: pond.GateSettings settings: pond.GateSettings,
as?: string
) => Promise<AxiosResponse<pond.UpdateGateResponse>>; ) => Promise<AxiosResponse<pond.UpdateGateResponse>>;
getGate: (key: string) => Promise<AxiosResponse<pond.GetGateResponse>>; getGate: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGateResponse>>;
removeGate: (key: string) => Promise<AxiosResponse<pond.RemoveGateResponse>>; removeGate: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveGateResponse>>;
updateLink: ( updateLink: (
parentKey: string, parentKey: string,
parentType: string, parentType: string,
objectID: string, objectID: string,
objectType: string, objectType: string,
permissions: string[] permissions: string[],
as?: string
) => Promise<any>; ) => Promise<any>;
updatePrefs: ( updatePrefs: (
gateKey: string, gateKey: string,
@ -42,9 +46,10 @@ export interface IGateInterface {
childKey: string, childKey: string,
gatePref: pond.GateComponentType | pond.GateDeviceType, gatePref: pond.GateComponentType | pond.GateDeviceType,
keys?: string[], keys?: string[],
types?: string[] types?: string[],
as?: string
) => Promise<AxiosResponse<pond.UpdateGatePreferencesResponse>>; ) => Promise<AxiosResponse<pond.UpdateGatePreferencesResponse>>;
getGatePageData: (key: string) => Promise<AxiosResponse<pond.GetGatePageDataResponse>>; getGatePageData: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGatePageDataResponse>>;
listGateAirflow: ( listGateAirflow: (
gate: string, gate: string,
device: number | string, device: number | string,
@ -53,7 +58,8 @@ export interface IGateInterface {
start: string, start: string,
end: string, end: string,
keys?: string[], keys?: string[],
types?: string[] types?: string[],
as?: string
) => Promise<AxiosResponse<pond.ListGateAirflowResponse>>; ) => Promise<AxiosResponse<pond.ListGateAirflowResponse>>;
listGateFlowEvents: ( listGateFlowEvents: (
gate: string, gate: string,
@ -65,12 +71,14 @@ export interface IGateInterface {
idleFlow: number, idleFlow: number,
flowVariance: number, flowVariance: number,
keys?: string[], keys?: string[],
types?: string[] types?: string[],
as?: string
) => Promise<AxiosResponse<pond.ListGateFlowEventsResponse>>; ) => Promise<AxiosResponse<pond.ListGateFlowEventsResponse>>;
listGateMeasurements: ( listGateMeasurements: (
key: string, key: string,
start: string, start: string,
end: string end: string,
as?: string
) => Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>; ) => Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>;
} }
@ -81,9 +89,9 @@ interface Props {}
export default function GateProvider(props: PropsWithChildren<Props>) { export default function GateProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
const [{ as }] = useGlobalState(); //const [{ as }] = useGlobalState();
const addGate = (name: string, settings: pond.GateSettings) => { const addGate = (name: string, settings: pond.GateSettings, as?: string) => {
let url = pondURL("/gates?name=" + name + (as ? "&as=" + as : "")) let url = pondURL("/gates?name=" + name + (as ? "&as=" + as : ""))
return new Promise<AxiosResponse<pond.AddGateResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.AddGateResponse>>((resolve, reject) => {
post<pond.AddGateResponse>(url, settings).then(resp => { post<pond.AddGateResponse>(url, settings).then(resp => {
@ -105,7 +113,8 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
numerical?: boolean, numerical?: boolean,
specificUser?: string specificUser?: string,
as?: string
) => { ) => {
let asText = ""; let asText = "";
if (as) asText = "&as=" + as; if (as) asText = "&as=" + as;
@ -134,7 +143,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const updateGate = (key: string, name: string, settings: pond.GateSettings) => { const updateGate = (key: string, name: string, settings: pond.GateSettings, as?: string) => {
let url = pondURL("/gates/" + key + "?name=" + name + (as ? "&as=" + as : "")) let url = pondURL("/gates/" + key + "?name=" + name + (as ? "&as=" + as : ""))
return new Promise<AxiosResponse<pond.UpdateGateResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.UpdateGateResponse>>((resolve, reject) => {
put<pond.UpdateGateResponse>(url, settings).then(resp => { put<pond.UpdateGateResponse>(url, settings).then(resp => {
@ -146,7 +155,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const removeGate = (key: string) => { const removeGate = (key: string, as?: string) => {
let url = pondURL("/gates/" + key + (as ? "?as=" + as : "")) let url = pondURL("/gates/" + key + (as ? "?as=" + as : ""))
return new Promise<AxiosResponse<pond.RemoveGateResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.RemoveGateResponse>>((resolve, reject) => {
del<pond.RemoveGateResponse>(url).then(resp => { del<pond.RemoveGateResponse>(url).then(resp => {
@ -158,7 +167,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const getGate = (key: string) => { const getGate = (key: string, as?: string) => {
let url = pondURL("/gates/" + key + (as ? "?as=" + as : "")) let url = pondURL("/gates/" + key + (as ? "?as=" + as : ""))
return new Promise<AxiosResponse<pond.GetGateResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.GetGateResponse>>((resolve, reject) => {
get<pond.GetGateResponse>(url).then(resp => { get<pond.GetGateResponse>(url).then(resp => {
@ -170,7 +179,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const getGatePageData = (key: string) => { const getGatePageData = (key: string, as?: string) => {
let url = pondURL("/gatePage/" + key + (as ? "?as=" + as : "")) let url = pondURL("/gatePage/" + key + (as ? "?as=" + as : ""))
return new Promise<AxiosResponse<pond.GetGatePageDataResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.GetGatePageDataResponse>>((resolve, reject) => {
get<pond.GetGatePageDataResponse>(url).then(resp => { get<pond.GetGatePageDataResponse>(url).then(resp => {
@ -187,7 +196,8 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
parentType: string, parentType: string,
objectID: string, objectID: string,
objectType: string, objectType: string,
permissions: string[] permissions: string[],
as?: string
) => { ) => {
let url = pondURL(`/gates/` + parentID + "/link" + (as ? `?as=${as}` : "")) let url = pondURL(`/gates/` + parentID + "/link" + (as ? `?as=${as}` : ""))
return new Promise<AxiosResponse>((resolve, reject) => { return new Promise<AxiosResponse>((resolve, reject) => {
@ -212,7 +222,8 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
childKey: string, childKey: string,
gatePref: pond.GateComponentType | pond.GateDeviceType, gatePref: pond.GateComponentType | pond.GateDeviceType,
keys?: string[], keys?: string[],
types?: string[] types?: string[],
as?: string
) => { ) => {
let url = pondURL( let url = pondURL(
`/gatePrefs/` + `/gatePrefs/` +
@ -245,7 +256,8 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
start: string, start: string,
end: string, end: string,
keys?: string[], keys?: string[],
types?: string[] types?: string[],
as?: string
) => { ) => {
let url = pondURL( let url = pondURL(
"/gates/" + "/gates/" +
@ -274,7 +286,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const listGateMeasurements = (key: string, start: string, end: string) => { const listGateMeasurements = (key: string, start: string, end: string, as?: string) => {
let url = pondURL("/gates/" + key + "/measurements?start=" + start + "&end=" + end + "&as=" + as) let url = pondURL("/gates/" + key + "/measurements?start=" + start + "&end=" + end + "&as=" + as)
return new Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>((resolve, reject) => {
get<pond.ListGateMeasurementsResponse>(url).then(resp => { get<pond.ListGateMeasurementsResponse>(url).then(resp => {
@ -296,7 +308,8 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
idleFlow: number, idleFlow: number,
flowVariance: number, flowVariance: number,
keys?: string[], keys?: string[],
types?: string[] types?: string[],
as?: string
) => { ) => {
return get<pond.ListGateFlowEventsResponse>( return get<pond.ListGateFlowEventsResponse>(
pondURL( pondURL(

View file

@ -8,28 +8,32 @@ import { useGlobalState } from "providers";
export interface ITerminalAPIContext { export interface ITerminalAPIContext {
addTerminal: ( addTerminal: (
name: string, name: string,
terminal: pond.TerminalSettings terminal: pond.TerminalSettings,
as?: string
) => Promise<AxiosResponse<pond.AddTerminalResponse>>; ) => Promise<AxiosResponse<pond.AddTerminalResponse>>;
listTerminals: ( listTerminals: (
limit: number, limit: number,
offset: number, offset: number,
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string search?: string,
as?: string
) => Promise<AxiosResponse<pond.ListTerminalsResponse>>; ) => Promise<AxiosResponse<pond.ListTerminalsResponse>>;
listTerminalsAndGates: ( listTerminalsAndGates: (
limit: number, limit: number,
offset: number, offset: number,
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string search?: string,
as?: string
) => Promise<AxiosResponse<pond.ListTerminalsAndGatesResponse>>; ) => Promise<AxiosResponse<pond.ListTerminalsAndGatesResponse>>;
updateTerminal: ( updateTerminal: (
key: string, key: string,
name: string, name: string,
settings: pond.TerminalSettings settings: pond.TerminalSettings,
as?: string
) => Promise<AxiosResponse<pond.UpdateTerminalResponse>>; ) => Promise<AxiosResponse<pond.UpdateTerminalResponse>>;
removeTerminal: (key: string) => Promise<AxiosResponse<pond.RemoveTerminalResponse>>; removeTerminal: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveTerminalResponse>>;
} }
export const TerminalAPIContext = createContext<ITerminalAPIContext>({} as ITerminalAPIContext); export const TerminalAPIContext = createContext<ITerminalAPIContext>({} as ITerminalAPIContext);
@ -39,9 +43,9 @@ interface Props {}
export default function TerminalProvider(props: PropsWithChildren<Props>) { export default function TerminalProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
const [{ as }] = useGlobalState(); //const [{ as }] = useGlobalState();
const addTerminal = (name: string, terminal: pond.TerminalSettings) => { const addTerminal = (name: string, terminal: pond.TerminalSettings, as?: string) => {
if (as) if (as)
return post<pond.AddTerminalResponse>( return post<pond.AddTerminalResponse>(
pondURL("/terminals?name=" + name + "&as=" + as), pondURL("/terminals?name=" + name + "&as=" + as),
@ -55,7 +59,8 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
offset: number, offset: number,
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string search?: string,
as?: string
) => { ) => {
if (as) if (as)
return get<pond.ListTerminalsResponse>( return get<pond.ListTerminalsResponse>(
@ -89,7 +94,8 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
offset: number, offset: number,
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string search?: string,
as?: string
) => { ) => {
if (as) if (as)
return get<pond.ListTerminalsAndGatesResponse>( return get<pond.ListTerminalsAndGatesResponse>(
@ -118,7 +124,7 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
); );
}; };
const updateTerminal = (key: string, name: string, settings: pond.TerminalSettings) => { const updateTerminal = (key: string, name: string, settings: pond.TerminalSettings, as?: string) => {
if (as) { if (as) {
return put<pond.UpdateTerminalResponse>( return put<pond.UpdateTerminalResponse>(
pondURL("/terminals/" + key + "?as=" + as + "&name=" + name), pondURL("/terminals/" + key + "?as=" + as + "&name=" + name),
@ -131,7 +137,7 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
); );
}; };
const removeTerminal = (key: string) => { const removeTerminal = (key: string, as?: string) => {
if (as) { if (as) {
return del<pond.RemoveTerminalResponse>(pondURL("/terminals/" + key + "?as=" + as)); return del<pond.RemoveTerminalResponse>(pondURL("/terminals/" + key + "?as=" + as));
} }

View file

@ -1,7 +1,7 @@
import { Button, DialogActions, DialogContent, DialogTitle, TextField } from "@mui/material"; import { Button, DialogActions, DialogContent, DialogTitle, TextField } from "@mui/material";
import ResponsiveDialog from "common/ResponsiveDialog"; import ResponsiveDialog from "common/ResponsiveDialog";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useTerminalAPI } from "providers"; import { useGlobalState, useTerminalAPI } from "providers";
import { useSnackbar } from "hooks"; import { useSnackbar } from "hooks";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { Terminal } from "models/Terminal"; import { Terminal } from "models/Terminal";
@ -16,6 +16,7 @@ interface Props {
export default function TerminalSettings(props: Props) { export default function TerminalSettings(props: Props) {
const { open, closeDialog, terminal, long, lat } = props; const { open, closeDialog, terminal, long, lat } = props;
const [{as}] = useGlobalState();
const terminalAPI = useTerminalAPI(); const terminalAPI = useTerminalAPI();
const [name, setName] = useState(""); const [name, setName] = useState("");
const { openSnack } = useSnackbar(); const { openSnack } = useSnackbar();
@ -35,7 +36,7 @@ export default function TerminalSettings(props: Props) {
terminal.name = name; terminal.name = name;
//note: changing the terminal object passed in WILL in fact change it in the parent //note: changing the terminal object passed in WILL in fact change it in the parent
terminalAPI terminalAPI
.updateTerminal(terminal.key, terminal.name, terminal.settings) .updateTerminal(terminal.key, terminal.name, terminal.settings, as)
.then(resp => { .then(resp => {
openSnack("Terminal updated"); openSnack("Terminal updated");
closeDialog(); closeDialog();
@ -49,7 +50,7 @@ export default function TerminalSettings(props: Props) {
latitude: lat latitude: lat
}); });
terminalAPI terminalAPI
.addTerminal(name, settings) .addTerminal(name, settings, as)
.then(resp => { .then(resp => {
openSnack("New terminal added"); openSnack("New terminal added");
let newTerminal = Terminal.create( let newTerminal = Terminal.create(