updated as in the terminal and gate api's
This commit is contained in:
parent
76744c1b6f
commit
74c8ed661c
13 changed files with 109 additions and 75 deletions
|
|
@ -32,6 +32,7 @@ interface Props {
|
|||
|
||||
export default function GateDevice(props: Props) {
|
||||
const { gate, comprehensiveDevice, linkedCompList, drawerView } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const [device, setDevice] = useState<Device>(Device.create());
|
||||
const [componentOptions, setComponentOptions] = useState<Map<string, Component>>(
|
||||
new Map<string, Component>()
|
||||
|
|
@ -159,7 +160,8 @@ export default function GateDevice(props: Props) {
|
|||
device.id() + ":" + componentKey,
|
||||
gateCompType,
|
||||
[gate.key],
|
||||
["gate"]
|
||||
["gate"],
|
||||
as
|
||||
)
|
||||
.then(resp => {
|
||||
openSnack("Component Prefence Updated");
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import SingleSetAreaChart, { SSAreaDataPoint } from "charts/SingleSetAreaChart";
|
|||
import { Gate } from "models/Gate";
|
||||
import moment, { Moment } from "moment";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useGateAPI } from "providers";
|
||||
import { useGateAPI, useGlobalState } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
interface Props {
|
||||
|
|
@ -61,6 +61,7 @@ export default function GateFlowGraph(props: Props) {
|
|||
newXDomain,
|
||||
multiGraphZoom
|
||||
} = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const gateAPI = useGateAPI();
|
||||
const [flowData, setFlowData] = useState<SSAreaDataPoint[]>([]);
|
||||
const [loadingChartData, setLoadingChartData] = useState(false);
|
||||
|
|
@ -84,7 +85,10 @@ export default function GateFlowGraph(props: Props) {
|
|||
ambient,
|
||||
pressureComponent,
|
||||
start.toISOString(),
|
||||
end.toISOString()
|
||||
end.toISOString(),
|
||||
undefined,
|
||||
undefined,
|
||||
as
|
||||
)
|
||||
.then(resp => {
|
||||
let data: SSAreaDataPoint[] = [];
|
||||
|
|
@ -135,7 +139,7 @@ export default function GateFlowGraph(props: Props) {
|
|||
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 = () => {
|
||||
if (ambient && pressureComponent) {
|
||||
|
|
@ -149,7 +153,10 @@ export default function GateFlowGraph(props: Props) {
|
|||
start.toISOString(),
|
||||
end.toISOString(),
|
||||
idleFlow,
|
||||
eventThreshold
|
||||
eventThreshold,
|
||||
undefined,
|
||||
undefined,
|
||||
as
|
||||
)
|
||||
.then(resp => {
|
||||
console.log(resp);
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
|||
|
||||
export default function GateGraphs(props: Props) {
|
||||
const { gate, display, compMap, device, pressure, ambient, setPCAState } = props;
|
||||
const [{ as }] = useGlobalState();
|
||||
const [xDomain, setXDomain] = useState<string[] | number[]>(["dataMin", "dataMax"]);
|
||||
const [zoomed, setZoomed] = useState(false);
|
||||
const defaultDateRange = GetDefaultDateRange();
|
||||
|
|
@ -79,7 +80,7 @@ export default function GateGraphs(props: Props) {
|
|||
setLoading(true);
|
||||
let measurementMap: Map<string, UnitMeasurement[]> = new Map<string, UnitMeasurement[]>();
|
||||
gateAPI
|
||||
.listGateMeasurements(gate.key, startDate.toISOString(), endDate.toISOString())
|
||||
.listGateMeasurements(gate.key, startDate.toISOString(), endDate.toISOString(), as)
|
||||
.then(resp => {
|
||||
resp.data.measurements.forEach(um => {
|
||||
let unitMeasurement = UnitMeasurement.any(um, user);
|
||||
|
|
@ -93,7 +94,7 @@ export default function GateGraphs(props: Props) {
|
|||
setLoading(false);
|
||||
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) => {
|
||||
let range = GetDefaultDateRange();
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { makeStyles } from "@mui/styles";
|
|||
import ResponsiveTable, { Column } from "common/ResponsiveTable";
|
||||
import AddGateFab from "./AddGateFab";
|
||||
import GateSettings from "./GateSettings";
|
||||
import { useGateAPI } from "providers";
|
||||
import { useGateAPI, useGlobalState } from "providers";
|
||||
import { Settings } from "@mui/icons-material";
|
||||
|
||||
interface Props {
|
||||
|
|
@ -39,6 +39,7 @@ const useStyles = makeStyles((theme: Theme) => ({
|
|||
|
||||
export default function GateList(props: Props) {
|
||||
const {terminals, currentTerminal } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
// const history = useHistory();
|
||||
const navigate = useNavigate();
|
||||
const isMobile = useMobile();
|
||||
|
|
@ -73,11 +74,11 @@ const {terminals, currentTerminal } = props;
|
|||
keys = [currentTerminal]
|
||||
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)))
|
||||
setTotal(resp.data.total)
|
||||
})
|
||||
},[currentTerminal, search, pageSize, tablePage])
|
||||
},[currentTerminal, search, pageSize, tablePage, as])
|
||||
|
||||
useEffect(() => {
|
||||
loadGates()
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import ResponsiveDialog from "common/ResponsiveDialog";
|
|||
import { Terminal } from "models/Terminal";
|
||||
import { Gate } from "models/Gate";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useTerminalAPI, useGateAPI } from "providers";
|
||||
import { useTerminalAPI, useGateAPI, useGlobalState } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { useSnackbar } from "hooks";
|
||||
//import { useHistory } from "react-router";
|
||||
|
|
@ -48,6 +48,7 @@ const steps = ["Gate", "Duct"];
|
|||
|
||||
export default function GateSettings(props: Props) {
|
||||
const { open, close, terminals, gate, long, lat } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const [gateName, setGateName] = useState("");
|
||||
const [lowerFlowBound, setLowerFlowBound] = useState(0);
|
||||
const [upperFlowBound, setUpperFlowBound] = useState(0);
|
||||
|
|
@ -83,7 +84,7 @@ export default function GateSettings(props: Props) {
|
|||
if (loadingTerminals) return;
|
||||
setLoadingTerminals(true);
|
||||
terminalAPI
|
||||
.listTerminals(500, 0)
|
||||
.listTerminals(500, 0, undefined, undefined, undefined, as)
|
||||
.then(resp => {
|
||||
setTerminalOptions(resp.data.terminals.map(a => Terminal.any(a)));
|
||||
})
|
||||
|
|
@ -95,7 +96,7 @@ export default function GateSettings(props: Props) {
|
|||
setTerminalOptions(terminals);
|
||||
}
|
||||
//eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [terminals, terminalAPI]);
|
||||
}, [terminals, terminalAPI, as]);
|
||||
|
||||
useEffect(() => {
|
||||
if (gate) {
|
||||
|
|
@ -146,7 +147,7 @@ export default function GateSettings(props: Props) {
|
|||
settings.hourlyApuCost = hourlyAPU;
|
||||
settings.hourlyPcaCost = hourlyPCA;
|
||||
gateAPI
|
||||
.updateGate(gate.key, gateName, settings)
|
||||
.updateGate(gate.key, gateName, settings, as)
|
||||
.then(resp => {
|
||||
openSnack("Gate update");
|
||||
close();
|
||||
|
|
@ -174,7 +175,7 @@ export default function GateSettings(props: Props) {
|
|||
hourlyPcaCost: hourlyPCA
|
||||
});
|
||||
gateAPI
|
||||
.addGate(gateName, settings)
|
||||
.addGate(gateName, settings, as)
|
||||
.then(resp => {
|
||||
openSnack("New gate added");
|
||||
let newGate = Gate.create(
|
||||
|
|
@ -191,7 +192,7 @@ export default function GateSettings(props: Props) {
|
|||
const remove = () => {
|
||||
if (gate) {
|
||||
gateAPI
|
||||
.removeGate(gate.key)
|
||||
.removeGate(gate.key, as)
|
||||
.then(resp => {
|
||||
openSnack("Gate Deleted");
|
||||
})
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import DisplayDrawer from "common/DisplayDrawer";
|
||||
import { Gate as IGate } from "models/Gate";
|
||||
import Gate from "pages/Gate";
|
||||
import { useGateAPI, useSnackbar } from "providers";
|
||||
import { useGateAPI, useGlobalState, useSnackbar } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
interface Props {
|
||||
|
|
@ -15,6 +15,7 @@ interface Props {
|
|||
|
||||
export default function GateDrawer(props: Props) {
|
||||
const { open, onClose, gates, selectedGate, moveMap, removeMarker } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const [gate, setGate] = useState(IGate.create());
|
||||
const gateAPI = useGateAPI();
|
||||
const { openSnack } = useSnackbar();
|
||||
|
|
@ -91,7 +92,7 @@ export default function GateDrawer(props: Props) {
|
|||
settings.longitude = 0;
|
||||
settings.latitude = 0;
|
||||
gateAPI
|
||||
.updateGate(gate.key, gate.name, settings)
|
||||
.updateGate(gate.key, gate.name, settings, as)
|
||||
.then(resp => {
|
||||
openSnack("Marker Removed");
|
||||
//then use the removeMarker prop function to update the markers in the parent map
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import DisplayDrawer from "common/DisplayDrawer";
|
||||
import { Terminal as ITerminal } from "models/Terminal";
|
||||
import Terminal from "pages/Terminals";
|
||||
import { useSnackbar, useTerminalAPI } from "providers";
|
||||
import { useGlobalState, useSnackbar, useTerminalAPI } from "providers";
|
||||
import React, { useState, useEffect } from "react";
|
||||
|
||||
interface Props {
|
||||
|
|
@ -15,6 +15,7 @@ interface Props {
|
|||
|
||||
export default function TerminalDrawer(props: Props) {
|
||||
const { terminals, selectedKey, open, onClose, moveMap, removeMarker } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const [terminal, setTerminal] = useState<ITerminal>(ITerminal.create());
|
||||
const terminalAPI = useTerminalAPI();
|
||||
const { openSnack } = useSnackbar();
|
||||
|
|
@ -91,7 +92,7 @@ export default function TerminalDrawer(props: Props) {
|
|||
settings.longitude = 0;
|
||||
settings.latitude = 0;
|
||||
terminalAPI
|
||||
.updateTerminal(terminal.key, terminal.name, settings)
|
||||
.updateTerminal(terminal.key, terminal.name, settings, as)
|
||||
.then(resp => {
|
||||
openSnack("Marker Removed");
|
||||
//then use the removeMarker prop function to update the markers in the parent map
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ interface Props {
|
|||
}
|
||||
|
||||
export default function AviationMapController(props: Props) {
|
||||
const [{ user }] = useGlobalState();
|
||||
const [{ user, as }] = useGlobalState();
|
||||
const transDuration = 3000;
|
||||
const [currentView, setCurrentView] = useState(
|
||||
props.startingView
|
||||
|
|
@ -99,7 +99,7 @@ export default function AviationMapController(props: Props) {
|
|||
settings.longitude = longitude;
|
||||
settings.latitude = latitude;
|
||||
terminalAPI
|
||||
.updateTerminal(terminal.key, terminal.name, settings)
|
||||
.updateTerminal(terminal.key, terminal.name, settings, as)
|
||||
.then(resp => {
|
||||
openSnack("Terminal Location Updated");
|
||||
if (newMarker) {
|
||||
|
|
@ -139,7 +139,7 @@ export default function AviationMapController(props: Props) {
|
|||
settings.longitude = longitude;
|
||||
settings.latitude = latitude;
|
||||
gateAPI
|
||||
.updateGate(gate.key, gate.name, settings)
|
||||
.updateGate(gate.key, gate.name, settings, as)
|
||||
.then(resp => {
|
||||
openSnack("Gate Location Updated");
|
||||
if (newMarker) {
|
||||
|
|
@ -170,7 +170,7 @@ export default function AviationMapController(props: Props) {
|
|||
};
|
||||
|
||||
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 terminalMarkers: Map<string, MarkerData> = new Map();
|
||||
let terminalOps: Terminal[] = [];
|
||||
|
|
@ -212,10 +212,10 @@ export default function AviationMapController(props: Props) {
|
|||
setTerminalSearchEntries(searchEntries);
|
||||
setTerminalOptions(terminalOps);
|
||||
});
|
||||
}, [terminalAPI]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
}, [terminalAPI, as]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
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 gateOptions: Gate[] = [];
|
||||
let gateMarkers: Map<string, MarkerData> = new Map();
|
||||
|
|
@ -255,7 +255,7 @@ export default function AviationMapController(props: Props) {
|
|||
setGateMarkers(gateMarkers);
|
||||
setGateSearchEntries(searchEntries);
|
||||
});
|
||||
}, [gateAPI]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
}, [gateAPI, as]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
useEffect(() => {
|
||||
loadTerminals();
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ export default function Gate(props: Props) {
|
|||
if (loadingGate || id === undefined || id === "") return;
|
||||
setLoadingGate(true);
|
||||
gateAPI
|
||||
.getGatePageData(id)
|
||||
.getGatePageData(id, as)
|
||||
.then(resp => {
|
||||
//console.log(resp.data);
|
||||
let p = new Map<number, pond.GateDeviceType>();
|
||||
|
|
@ -168,7 +168,7 @@ export default function Gate(props: Props) {
|
|||
setLoadingGate(false);
|
||||
});
|
||||
//eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [gateAPI, gateID]);
|
||||
}, [gateAPI, gateID, as]);
|
||||
|
||||
useEffect(() => {
|
||||
loadGate();
|
||||
|
|
@ -176,7 +176,7 @@ export default function Gate(props: Props) {
|
|||
|
||||
const updateGateDevicePrefs = (deviceID: number, newPref: pond.GateDeviceType) => {
|
||||
gateAPI
|
||||
.updatePrefs(gate.key, "device", deviceID.toString(), newPref, [gate.key], ["gate"])
|
||||
.updatePrefs(gate.key, "device", deviceID.toString(), newPref, [gate.key], ["gate"], as)
|
||||
.then(resp => {
|
||||
openSnack("Updated gate device type");
|
||||
// have to do the clone method to force the select box to update
|
||||
|
|
@ -226,7 +226,7 @@ export default function Gate(props: Props) {
|
|||
"write",
|
||||
"grant",
|
||||
"revoke"
|
||||
])
|
||||
], as)
|
||||
.then(resp => {
|
||||
if (id) {
|
||||
devMap.set(id.toString(), device);
|
||||
|
|
@ -238,7 +238,7 @@ export default function Gate(props: Props) {
|
|||
console.log("error linking device");
|
||||
});
|
||||
} else {
|
||||
gateAPI.updateLink(gateID, "gate", id.toString(), "device", []).then(resp => {
|
||||
gateAPI.updateLink(gateID, "gate", id.toString(), "device", [], as).then(resp => {
|
||||
if (id) {
|
||||
devMap.delete(id.toString());
|
||||
if (tabVal === id) {
|
||||
|
|
@ -264,14 +264,14 @@ export default function Gate(props: Props) {
|
|||
"write",
|
||||
"grant",
|
||||
"revoke"
|
||||
])
|
||||
],as)
|
||||
.then(resp => {
|
||||
c.push(component);
|
||||
setComponents([...c]);
|
||||
});
|
||||
} else {
|
||||
gateAPI
|
||||
.updateLink(gateID, "gate", deviceID + ":" + component.key(), "component", [])
|
||||
.updateLink(gateID, "gate", deviceID + ":" + component.key(), "component", [], as)
|
||||
.then(resp => {
|
||||
c.forEach((comp, i) => {
|
||||
if (component.key() === comp.key()) {
|
||||
|
|
|
|||
|
|
@ -181,14 +181,14 @@ export default function Terminals(props: Props) {
|
|||
const load = useCallback(() => {
|
||||
if(loading) return
|
||||
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)));
|
||||
}).catch(err => {
|
||||
console.log("There was a problem loading Terminals")
|
||||
}).finally(() => {
|
||||
setLoading(false)
|
||||
})
|
||||
}, [terminalAPI, openSnack]); //eslint-disable-line react-hooks/exhaustive-deps
|
||||
}, [terminalAPI, openSnack, as]); //eslint-disable-line react-hooks/exhaustive-deps
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
|
|
@ -197,7 +197,7 @@ export default function Terminals(props: Props) {
|
|||
const remove = () => {
|
||||
if (currentTerminal) {
|
||||
terminalAPI
|
||||
.removeTerminal(currentTerminal.key)
|
||||
.removeTerminal(currentTerminal.key, as)
|
||||
.then(resp => {
|
||||
openSnack("Terminal Deleted");
|
||||
let a = terminals;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ import { useGlobalState } from "providers";
|
|||
export interface IGateInterface {
|
||||
addGate: (
|
||||
name: string,
|
||||
settings: pond.GateSettings
|
||||
settings: pond.GateSettings,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.AddGateResponse>>;
|
||||
listGates: (
|
||||
limit: number,
|
||||
|
|
@ -20,21 +21,24 @@ export interface IGateInterface {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
numerical?: boolean,
|
||||
specificUser?: string
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListGatesResponse>>;
|
||||
updateGate: (
|
||||
key: string,
|
||||
name: string,
|
||||
settings: pond.GateSettings
|
||||
settings: pond.GateSettings,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateGateResponse>>;
|
||||
getGate: (key: string) => Promise<AxiosResponse<pond.GetGateResponse>>;
|
||||
removeGate: (key: string) => Promise<AxiosResponse<pond.RemoveGateResponse>>;
|
||||
getGate: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGateResponse>>;
|
||||
removeGate: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveGateResponse>>;
|
||||
updateLink: (
|
||||
parentKey: string,
|
||||
parentType: string,
|
||||
objectID: string,
|
||||
objectType: string,
|
||||
permissions: string[]
|
||||
permissions: string[],
|
||||
as?: string
|
||||
) => Promise<any>;
|
||||
updatePrefs: (
|
||||
gateKey: string,
|
||||
|
|
@ -42,9 +46,10 @@ export interface IGateInterface {
|
|||
childKey: string,
|
||||
gatePref: pond.GateComponentType | pond.GateDeviceType,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateGatePreferencesResponse>>;
|
||||
getGatePageData: (key: string) => Promise<AxiosResponse<pond.GetGatePageDataResponse>>;
|
||||
getGatePageData: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGatePageDataResponse>>;
|
||||
listGateAirflow: (
|
||||
gate: string,
|
||||
device: number | string,
|
||||
|
|
@ -53,7 +58,8 @@ export interface IGateInterface {
|
|||
start: string,
|
||||
end: string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListGateAirflowResponse>>;
|
||||
listGateFlowEvents: (
|
||||
gate: string,
|
||||
|
|
@ -65,12 +71,14 @@ export interface IGateInterface {
|
|||
idleFlow: number,
|
||||
flowVariance: number,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListGateFlowEventsResponse>>;
|
||||
listGateMeasurements: (
|
||||
key: string,
|
||||
start: string,
|
||||
end: string
|
||||
end: string,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -81,9 +89,9 @@ interface Props {}
|
|||
export default function GateProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
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 : ""))
|
||||
return new Promise<AxiosResponse<pond.AddGateResponse>>((resolve, reject) => {
|
||||
post<pond.AddGateResponse>(url, settings).then(resp => {
|
||||
|
|
@ -105,7 +113,8 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
numerical?: boolean,
|
||||
specificUser?: string
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
) => {
|
||||
let asText = "";
|
||||
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 : ""))
|
||||
return new Promise<AxiosResponse<pond.UpdateGateResponse>>((resolve, reject) => {
|
||||
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 : ""))
|
||||
return new Promise<AxiosResponse<pond.RemoveGateResponse>>((resolve, reject) => {
|
||||
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 : ""))
|
||||
return new Promise<AxiosResponse<pond.GetGateResponse>>((resolve, reject) => {
|
||||
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 : ""))
|
||||
return new Promise<AxiosResponse<pond.GetGatePageDataResponse>>((resolve, reject) => {
|
||||
get<pond.GetGatePageDataResponse>(url).then(resp => {
|
||||
|
|
@ -187,7 +196,8 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
parentType: string,
|
||||
objectID: string,
|
||||
objectType: string,
|
||||
permissions: string[]
|
||||
permissions: string[],
|
||||
as?: string
|
||||
) => {
|
||||
let url = pondURL(`/gates/` + parentID + "/link" + (as ? `?as=${as}` : ""))
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
|
|
@ -212,7 +222,8 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
childKey: string,
|
||||
gatePref: pond.GateComponentType | pond.GateDeviceType,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => {
|
||||
let url = pondURL(
|
||||
`/gatePrefs/` +
|
||||
|
|
@ -245,7 +256,8 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
start: string,
|
||||
end: string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => {
|
||||
let url = pondURL(
|
||||
"/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)
|
||||
return new Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>((resolve, reject) => {
|
||||
get<pond.ListGateMeasurementsResponse>(url).then(resp => {
|
||||
|
|
@ -296,7 +308,8 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
idleFlow: number,
|
||||
flowVariance: number,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => {
|
||||
return get<pond.ListGateFlowEventsResponse>(
|
||||
pondURL(
|
||||
|
|
|
|||
|
|
@ -8,28 +8,32 @@ import { useGlobalState } from "providers";
|
|||
export interface ITerminalAPIContext {
|
||||
addTerminal: (
|
||||
name: string,
|
||||
terminal: pond.TerminalSettings
|
||||
terminal: pond.TerminalSettings,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.AddTerminalResponse>>;
|
||||
listTerminals: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string
|
||||
search?: string,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListTerminalsResponse>>;
|
||||
listTerminalsAndGates: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string
|
||||
search?: string,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListTerminalsAndGatesResponse>>;
|
||||
updateTerminal: (
|
||||
key: string,
|
||||
name: string,
|
||||
settings: pond.TerminalSettings
|
||||
settings: pond.TerminalSettings,
|
||||
as?: string
|
||||
) => 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);
|
||||
|
|
@ -39,9 +43,9 @@ interface Props {}
|
|||
export default function TerminalProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
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)
|
||||
return post<pond.AddTerminalResponse>(
|
||||
pondURL("/terminals?name=" + name + "&as=" + as),
|
||||
|
|
@ -55,7 +59,8 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
|
|||
offset: number,
|
||||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string
|
||||
search?: string,
|
||||
as?: string
|
||||
) => {
|
||||
if (as)
|
||||
return get<pond.ListTerminalsResponse>(
|
||||
|
|
@ -89,7 +94,8 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
|
|||
offset: number,
|
||||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string
|
||||
search?: string,
|
||||
as?: string
|
||||
) => {
|
||||
if (as)
|
||||
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) {
|
||||
return put<pond.UpdateTerminalResponse>(
|
||||
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) {
|
||||
return del<pond.RemoveTerminalResponse>(pondURL("/terminals/" + key + "?as=" + as));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Button, DialogActions, DialogContent, DialogTitle, TextField } from "@mui/material";
|
||||
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTerminalAPI } from "providers";
|
||||
import { useGlobalState, useTerminalAPI } from "providers";
|
||||
import { useSnackbar } from "hooks";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { Terminal } from "models/Terminal";
|
||||
|
|
@ -16,6 +16,7 @@ interface Props {
|
|||
|
||||
export default function TerminalSettings(props: Props) {
|
||||
const { open, closeDialog, terminal, long, lat } = props;
|
||||
const [{as}] = useGlobalState();
|
||||
const terminalAPI = useTerminalAPI();
|
||||
const [name, setName] = useState("");
|
||||
const { openSnack } = useSnackbar();
|
||||
|
|
@ -35,7 +36,7 @@ export default function TerminalSettings(props: Props) {
|
|||
terminal.name = name;
|
||||
//note: changing the terminal object passed in WILL in fact change it in the parent
|
||||
terminalAPI
|
||||
.updateTerminal(terminal.key, terminal.name, terminal.settings)
|
||||
.updateTerminal(terminal.key, terminal.name, terminal.settings, as)
|
||||
.then(resp => {
|
||||
openSnack("Terminal updated");
|
||||
closeDialog();
|
||||
|
|
@ -49,7 +50,7 @@ export default function TerminalSettings(props: Props) {
|
|||
latitude: lat
|
||||
});
|
||||
terminalAPI
|
||||
.addTerminal(name, settings)
|
||||
.addTerminal(name, settings, as)
|
||||
.then(resp => {
|
||||
openSnack("New terminal added");
|
||||
let newTerminal = Terminal.create(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue