Merge branch 'dev_environment' of gitlab.com:brandx/bxt-app into dev_environment
This commit is contained in:
commit
eb7efada69
39 changed files with 346 additions and 651 deletions
|
|
@ -108,7 +108,7 @@ export default function BinComponents(props: Props) {
|
||||||
let mounted = true;
|
let mounted = true;
|
||||||
setDevicesLoading(true);
|
setDevicesLoading(true);
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.list(100000, 0, "asc", "name")
|
.list(100000, 0, "asc", "name",undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,as)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
let data = response.data.devices ? response.data.devices : [];
|
let data = response.data.devices ? response.data.devices : [];
|
||||||
|
|
@ -135,7 +135,7 @@ export default function BinComponents(props: Props) {
|
||||||
return () => {
|
return () => {
|
||||||
mounted = false;
|
mounted = false;
|
||||||
};
|
};
|
||||||
}, [deviceAPI]);
|
}, [deviceAPI, as]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadDevices();
|
loadDevices();
|
||||||
|
|
@ -149,7 +149,7 @@ export default function BinComponents(props: Props) {
|
||||||
comps = [];
|
comps = [];
|
||||||
setComponentsLoading(true);
|
setComponentsLoading(true);
|
||||||
componentAPI
|
componentAPI
|
||||||
.list(selectedDevice, false, [selectedDevice.toString()], ["device"], true)
|
.list(selectedDevice, false, [selectedDevice.toString()], ["device"], true, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
let d = pond.ListComponentsResponse.fromObject(resp.data);
|
let d = pond.ListComponentsResponse.fromObject(resp.data);
|
||||||
d.components.forEach(comp => {
|
d.components.forEach(comp => {
|
||||||
|
|
@ -171,7 +171,7 @@ export default function BinComponents(props: Props) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[selectedDevice, componentAPI, deviceComponents, snackbar]
|
[selectedDevice, componentAPI, deviceComponents, snackbar, as]
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
@ -326,7 +326,7 @@ export default function BinComponents(props: Props) {
|
||||||
settings.grainType = binGrain;
|
settings.grainType = binGrain;
|
||||||
settings.defaultMutations = [pond.Mutator.MUTATOR_EMC];
|
settings.defaultMutations = [pond.Mutator.MUTATOR_EMC];
|
||||||
componentAPI
|
componentAPI
|
||||||
.update(device, settings)
|
.update(device, settings, undefined, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
snackbar.info("Component added to bin, and updated cables grain type");
|
snackbar.info("Component added to bin, and updated cables grain type");
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -150,29 +150,12 @@ const useStyles = makeStyles((theme: Theme) => {
|
||||||
bottomSpacing: {
|
bottomSpacing: {
|
||||||
marginBottom: theme.spacing(1)
|
marginBottom: theme.spacing(1)
|
||||||
},
|
},
|
||||||
sliderRoot: {},
|
|
||||||
sliderThumb: {
|
|
||||||
left: 23
|
|
||||||
},
|
|
||||||
mobileSliderThumb: {
|
|
||||||
left: 28
|
|
||||||
},
|
|
||||||
sliderTrack: {
|
|
||||||
height: "100%",
|
|
||||||
},
|
|
||||||
sliderRail: {
|
|
||||||
height: "100%",
|
|
||||||
},
|
|
||||||
sliderValLabel: {
|
sliderValLabel: {
|
||||||
// left: -20,
|
|
||||||
height: 30,
|
height: 30,
|
||||||
width: 30,
|
width: 30,
|
||||||
top: -15,
|
//top: -15,
|
||||||
background: "transparent"
|
background: "transparent"
|
||||||
},
|
},
|
||||||
sliderLabel: {
|
|
||||||
background: "gold"
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1483,10 +1466,10 @@ export default function BinVisualizer(props: Props) {
|
||||||
orientation="vertical"
|
orientation="vertical"
|
||||||
value={fillPercentage}
|
value={fillPercentage}
|
||||||
classes={{
|
classes={{
|
||||||
root: classes.sliderRoot,
|
// root: classes.sliderRoot,
|
||||||
rail: classes.sliderRail,
|
// rail: classes.sliderRail,
|
||||||
track: classes.sliderTrack,
|
// track: classes.sliderTrack,
|
||||||
thumb: isMobile ? classes.mobileSliderThumb : classes.sliderThumb,
|
// thumb: isMobile ? classes.mobileSliderThumb : classes.sliderThumb,
|
||||||
valueLabel: classes.sliderValLabel,
|
valueLabel: classes.sliderValLabel,
|
||||||
}}
|
}}
|
||||||
style={{ height: "100%", color: sliderColour }}
|
style={{ height: "100%", color: sliderColour }}
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ export default function GrainNodeInteractions(props: Props) {
|
||||||
settings.defaultMutations = [pond.Mutator.MUTATOR_EMC];
|
settings.defaultMutations = [pond.Mutator.MUTATOR_EMC];
|
||||||
settings.grainType = grain;
|
settings.grainType = grain;
|
||||||
componentAPI
|
componentAPI
|
||||||
.update(device.id(), settings, [binKey], ["bin"])
|
.update(device.id(), settings, [binKey], ["bin"], as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("EMC set on cable " + cable.name());
|
openSnack("EMC set on cable " + cable.name());
|
||||||
updateComponentCallback(cable.key());
|
updateComponentCallback(cable.key());
|
||||||
|
|
@ -157,7 +157,7 @@ export default function GrainNodeInteractions(props: Props) {
|
||||||
|
|
||||||
const submit = () => {
|
const submit = () => {
|
||||||
componentAPI
|
componentAPI
|
||||||
.update(device.id(), cable.settings, [binKey], ["bin"])
|
.update(device.id(), cable.settings, [binKey], ["bin"], as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
//after updating the component update the interactions with the new subtypes
|
//after updating the component update the interactions with the new subtypes
|
||||||
//TODO-CS: make function to update multiple interactions at once to avoid this loop if it becomes a problem
|
//TODO-CS: make function to update multiple interactions at once to avoid this loop if it becomes a problem
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import ResponsiveDialog from "common/ResponsiveDialog";
|
||||||
import { useComponentAPI, useSnackbar } from "hooks";
|
import { useComponentAPI, useSnackbar } from "hooks";
|
||||||
import { Component } from "models";
|
import { Component } from "models";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
// import { MatchParams } from "navigation/Routes";
|
// import { MatchParams } from "navigation/Routes";
|
||||||
// import { useRouteMatch } from "react-router";
|
// import { useRouteMatch } from "react-router";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
|
|
@ -40,6 +41,7 @@ export default function GraphSettings(props: Props) {
|
||||||
currentMax,
|
currentMax,
|
||||||
newChart
|
newChart
|
||||||
} = props;
|
} = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const [newMutation, setNewMutation] = useState<pond.Mutator>(0);
|
const [newMutation, setNewMutation] = useState<pond.Mutator>(0);
|
||||||
const componentAPI = useComponentAPI();
|
const componentAPI = useComponentAPI();
|
||||||
const deviceID = useParams<{ deviceID: string }>()?.deviceID ?? "";
|
const deviceID = useParams<{ deviceID: string }>()?.deviceID ?? "";
|
||||||
|
|
@ -58,7 +60,7 @@ export default function GraphSettings(props: Props) {
|
||||||
defaultMutations.push(newMutation);
|
defaultMutations.push(newMutation);
|
||||||
}
|
}
|
||||||
componentAPI
|
componentAPI
|
||||||
.update(parseInt(deviceID), comp.settings)
|
.update(parseInt(deviceID), comp.settings, undefined, undefined, as)
|
||||||
.then(() => openSnack("Mutations Updated"));
|
.then(() => openSnack("Mutations Updated"));
|
||||||
closeDialog();
|
closeDialog();
|
||||||
};
|
};
|
||||||
|
|
@ -70,7 +72,7 @@ export default function GraphSettings(props: Props) {
|
||||||
defaultMuts.splice(defaultMuts.indexOf(mutation));
|
defaultMuts.splice(defaultMuts.indexOf(mutation));
|
||||||
}
|
}
|
||||||
componentAPI
|
componentAPI
|
||||||
.update(parseInt(deviceID), comp.settings)
|
.update(parseInt(deviceID), comp.settings, undefined, undefined, as)
|
||||||
.then(() => openSnack("Mutations Updated"));
|
.then(() => openSnack("Mutations Updated"));
|
||||||
closeDialog();
|
closeDialog();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ import { Component, Device } from "models";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { makeStyles } from "@mui/styles";
|
import { makeStyles } from "@mui/styles";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
interface TabPanelProps {
|
interface TabPanelProps {
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
|
|
@ -83,6 +84,7 @@ export default function DeviceLinkDrawer(props: Props) {
|
||||||
devicePrefChanged
|
devicePrefChanged
|
||||||
} = props;
|
} = props;
|
||||||
const [value, setValue] = useState(0);
|
const [value, setValue] = useState(0);
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const deviceAPI = useDeviceAPI();
|
const deviceAPI = useDeviceAPI();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const isMobile = useMobile();
|
const isMobile = useMobile();
|
||||||
|
|
@ -114,7 +116,13 @@ export default function DeviceLinkDrawer(props: Props) {
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
true
|
true,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
as
|
||||||
)
|
)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
let devMap = new Map<string, pond.ComprehensiveDevice>();
|
let devMap = new Map<string, pond.ComprehensiveDevice>();
|
||||||
|
|
@ -131,7 +139,7 @@ export default function DeviceLinkDrawer(props: Props) {
|
||||||
setLoadingDevices(false);
|
setLoadingDevices(false);
|
||||||
});
|
});
|
||||||
//eslint-disable-next-line react-hooks/exhaustive-deps
|
//eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [deviceAPI]);
|
}, [deviceAPI, as]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let searchedDevices: Map<string, pond.ComprehensiveDevice> = new Map();
|
let searchedDevices: Map<string, pond.ComprehensiveDevice> = new Map();
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import { Dialog, DialogActions, DialogContent, DialogTitle, Grid2, TextField } f
|
||||||
import CancelSubmit from "common/CancelSubmit";
|
import CancelSubmit from "common/CancelSubmit";
|
||||||
import { useComponentAPI, useSnackbar } from "hooks";
|
import { useComponentAPI, useSnackbar } from "hooks";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { or } from "utils";
|
import { or } from "utils";
|
||||||
|
|
||||||
|
|
@ -13,12 +14,13 @@ interface Props {
|
||||||
|
|
||||||
export default function AddComponentManualDialog (props: Props) {
|
export default function AddComponentManualDialog (props: Props) {
|
||||||
const { open, onClose, device } = props;
|
const { open, onClose, device } = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const componentAPI = useComponentAPI();
|
const componentAPI = useComponentAPI();
|
||||||
const snackbar = useSnackbar();
|
const snackbar = useSnackbar();
|
||||||
const [component, setComponent] = useState<pond.ComponentSettings>(pond.ComponentSettings.create())
|
const [component, setComponent] = useState<pond.ComponentSettings>(pond.ComponentSettings.create())
|
||||||
|
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
componentAPI.add(device, component).then(() => {
|
componentAPI.add(device, component, as).then(() => {
|
||||||
snackbar.success("Component added")
|
snackbar.success("Component added")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import {
|
||||||
import ResponsiveDialog from "common/ResponsiveDialog";
|
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||||
import { Component, Device } from "models";
|
import { Component, Device } from "models";
|
||||||
import { pond, quack } from "protobuf-ts/pond";
|
import { pond, quack } from "protobuf-ts/pond";
|
||||||
import { useComponentAPI, useSnackbar } from "providers";
|
import { useComponentAPI, useGlobalState, useSnackbar } from "providers";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { CableInfo } from "./ComponentDiagnostics";
|
import { CableInfo } from "./ComponentDiagnostics";
|
||||||
import ComponentForm from "./ComponentForm";
|
import ComponentForm from "./ComponentForm";
|
||||||
|
|
@ -67,6 +67,7 @@ interface CompStep {
|
||||||
export default function AddCompsFromDiag(props: Props) {
|
export default function AddCompsFromDiag(props: Props) {
|
||||||
const { diagComponent, port, cableInfo, open, closeDialog, device, refreshCallback } = props;
|
const { diagComponent, port, cableInfo, open, closeDialog, device, refreshCallback } = props;
|
||||||
const [steps, setSteps] = useState<CompStep[]>([]);
|
const [steps, setSteps] = useState<CompStep[]>([]);
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [currentStep, setCurrentStep] = useState(0);
|
const [currentStep, setCurrentStep] = useState(0);
|
||||||
const [components, setComponents] = useState<Component[]>([]);
|
const [components, setComponents] = useState<Component[]>([]);
|
||||||
|
|
@ -125,7 +126,7 @@ export default function AddCompsFromDiag(props: Props) {
|
||||||
c.components.push(component.settings);
|
c.components.push(component.settings);
|
||||||
});
|
});
|
||||||
compAPI
|
compAPI
|
||||||
.addMultiComponents(device.id(), c)
|
.addMultiComponents(device.id(), c, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
success("Components added to Device");
|
success("Components added to Device");
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ export default function ComponentActions(props: Props) {
|
||||||
const [anchorEl, setAnchorEl] = useState<Element | null>(null);
|
const [anchorEl, setAnchorEl] = useState<Element | null>(null);
|
||||||
const [componentSettingsMode, setComponentSettingsMode] = useState<string>("");
|
const [componentSettingsMode, setComponentSettingsMode] = useState<string>("");
|
||||||
const [isJSON, setIsJSON] = useState(false);
|
const [isJSON, setIsJSON] = useState(false);
|
||||||
const [{ user }] = useGlobalState();
|
const [{ user, as }] = useGlobalState();
|
||||||
|
|
||||||
const openMoreMenu = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
const openMoreMenu = (event: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
||||||
setAnchorEl(event.currentTarget);
|
setAnchorEl(event.currentTarget);
|
||||||
|
|
@ -182,6 +182,7 @@ export default function ComponentActions(props: Props) {
|
||||||
isJSON={isJSON}
|
isJSON={isJSON}
|
||||||
// newMeasurements={newStructure}
|
// newMeasurements={newStructure}
|
||||||
user={user}
|
user={user}
|
||||||
|
as={as}
|
||||||
/>
|
/>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ export default function ComponentCard(props: Props) {
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const location = useLocation()
|
const location = useLocation()
|
||||||
const [sensors, setSensors] = useState<Sensor[]>([]);
|
const [sensors, setSensors] = useState<Sensor[]>([]);
|
||||||
const [{ user, showErrors }] = useGlobalState();
|
const [{ user, showErrors, as }] = useGlobalState();
|
||||||
|
|
||||||
const updateControllerState = (checked: boolean) => {
|
const updateControllerState = (checked: boolean) => {
|
||||||
let updatedComponent = cloneDeep(component);
|
let updatedComponent = cloneDeep(component);
|
||||||
|
|
@ -130,7 +130,7 @@ export default function ComponentCard(props: Props) {
|
||||||
let describe = controllerModeLabel(newMode);
|
let describe = controllerModeLabel(newMode);
|
||||||
|
|
||||||
componentAPI
|
componentAPI
|
||||||
.update(device.id(), updatedComponent.settings)
|
.update(device.id(), updatedComponent.settings, undefined, undefined, as)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
success(component.name() + "'s mode was set to " + describe);
|
success(component.name() + "'s mode was set to " + describe);
|
||||||
refreshCallback(updatedComponent);
|
refreshCallback(updatedComponent);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ import moment from "moment";
|
||||||
import { getHumanReadableAddress } from "pbHelpers/AddressType";
|
import { getHumanReadableAddress } from "pbHelpers/AddressType";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { quack } from "protobuf-ts/quack";
|
import { quack } from "protobuf-ts/quack";
|
||||||
import { useComponentAPI } from "providers";
|
import { useComponentAPI, useGlobalState } from "providers";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
// import { getThemeType } from "theme";
|
// import { getThemeType } from "theme";
|
||||||
import AddCompsFromDiag from "./AddCompsFromDiag";
|
import AddCompsFromDiag from "./AddCompsFromDiag";
|
||||||
|
|
@ -60,6 +60,7 @@ const useStyles = makeStyles((theme: Theme) => {
|
||||||
|
|
||||||
export default function ComponentDiagnostics(props: Props) {
|
export default function ComponentDiagnostics(props: Props) {
|
||||||
const { component, device, refreshCallback } = props;
|
const { component, device, refreshCallback } = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const [portNumber, setPortNumber] = useState("");
|
const [portNumber, setPortNumber] = useState("");
|
||||||
const compAPI = useComponentAPI();
|
const compAPI = useComponentAPI();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
|
|
@ -91,7 +92,12 @@ export default function ComponentDiagnostics(props: Props) {
|
||||||
moment().toISOString(),
|
moment().toISOString(),
|
||||||
2,
|
2,
|
||||||
0,
|
0,
|
||||||
"desc"
|
"desc",
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
as
|
||||||
)
|
)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
setMeasurements(resp.data.measurements);
|
setMeasurements(resp.data.measurements);
|
||||||
|
|
@ -100,7 +106,7 @@ export default function ComponentDiagnostics(props: Props) {
|
||||||
setLoadingMeasurements(false);
|
setLoadingMeasurements(false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [component, device, compAPI]); //eslint-disable-line react-hooks/exhaustive-deps
|
}, [component, device, compAPI, as]); //eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let cableIDs: number[] = [];
|
let cableIDs: number[] = [];
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ import { pond, quack } from "protobuf-ts/pond";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { DragDropContext, Draggable, Droppable, DropResult } from "react-beautiful-dnd";
|
import { DragDropContext, Draggable, Droppable, DropResult } from "react-beautiful-dnd";
|
||||||
import { useThemeType } from "../hooks/useThemeType";
|
import { useThemeType } from "../hooks/useThemeType";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
const useStyles = makeStyles((_theme: Theme) => {
|
const useStyles = makeStyles((_theme: Theme) => {
|
||||||
const themeType = useThemeType()
|
const themeType = useThemeType()
|
||||||
|
|
@ -87,6 +88,7 @@ const filteredComponents = (components: Component[]) => {
|
||||||
|
|
||||||
export default function ComponentOrder(props: ListProps) {
|
export default function ComponentOrder(props: ListProps) {
|
||||||
const { open, close, device, devicePreferences } = props;
|
const { open, close, device, devicePreferences } = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const deviceAPI = useDeviceAPI();
|
const deviceAPI = useDeviceAPI();
|
||||||
const { error, success } = useSnackbar();
|
const { error, success } = useSnackbar();
|
||||||
const prevDisplayOrder = usePrevious(devicePreferences.childDisplayOrder);
|
const prevDisplayOrder = usePrevious(devicePreferences.childDisplayOrder);
|
||||||
|
|
@ -113,7 +115,7 @@ export default function ComponentOrder(props: ListProps) {
|
||||||
let updatedPreferences = cloneDeep(devicePreferences);
|
let updatedPreferences = cloneDeep(devicePreferences);
|
||||||
updatedPreferences.childDisplayOrder = componentOrder.map(c => c.locationString());
|
updatedPreferences.childDisplayOrder = componentOrder.map(c => c.locationString());
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.updatePreferences(device.id(), updatedPreferences)
|
.updatePreferences(device.id(), updatedPreferences, undefined, undefined, as)
|
||||||
.then(() => success("Successfully update the component display order"))
|
.then(() => success("Successfully update the component display order"))
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
error("Error occured while updating the component display order");
|
error("Error occured while updating the component display order");
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ import {
|
||||||
|
|
||||||
} from "@mui/icons-material"
|
} from "@mui/icons-material"
|
||||||
import CancelSubmit from "common/CancelSubmit";
|
import CancelSubmit from "common/CancelSubmit";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => {
|
const useStyles = makeStyles((theme: Theme) => {
|
||||||
return ({
|
return ({
|
||||||
|
|
@ -158,6 +159,7 @@ export default function ComponentSettings(props: Props) {
|
||||||
addressTypeRestriction,
|
addressTypeRestriction,
|
||||||
deviceComponentPrefs
|
deviceComponentPrefs
|
||||||
} = props;
|
} = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const prevComponent = usePrevious(props.component);
|
const prevComponent = usePrevious(props.component);
|
||||||
const prevIsDialogOpen = usePrevious(isDialogOpen);
|
const prevIsDialogOpen = usePrevious(isDialogOpen);
|
||||||
const steps = [0, 1];
|
const steps = [0, 1];
|
||||||
|
|
@ -304,7 +306,7 @@ export default function ComponentSettings(props: Props) {
|
||||||
//component.settings.calibrationCoefficient = Number(form.coefficient);
|
//component.settings.calibrationCoefficient = Number(form.coefficient);
|
||||||
if (cableID > 0) component.settings.addressType = cableID + 8;
|
if (cableID > 0) component.settings.addressType = cableID + 8;
|
||||||
componentAPI
|
componentAPI
|
||||||
.add(device.id(), component.settings)
|
.add(device.id(), component.settings, as)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
success(component.name() + " was successfully added!");
|
success(component.name() + " was successfully added!");
|
||||||
refresh();
|
refresh();
|
||||||
|
|
@ -318,13 +320,13 @@ export default function ComponentSettings(props: Props) {
|
||||||
const updateComponent = () => {
|
const updateComponent = () => {
|
||||||
const component = formComponent;
|
const component = formComponent;
|
||||||
componentAPI
|
componentAPI
|
||||||
.update(device.id(), component.settings, getContextKeys(), getContextTypes())
|
.update(device.id(), component.settings, getContextKeys(), getContextTypes(), as)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
success(component.name() + " was successfully updated!");
|
success(component.name() + " was successfully updated!");
|
||||||
let updatedPrefs = pond.DeviceComponentPreferences.create();
|
let updatedPrefs = pond.DeviceComponentPreferences.create();
|
||||||
updatedPrefs.excludedNodes = excludedNodes;
|
updatedPrefs.excludedNodes = excludedNodes;
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.updateComponentPreferences(device.id(), component.key(), updatedPrefs)
|
.updateComponentPreferences(device.id(), component.key(), updatedPrefs, undefined, undefined, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
console.log("Preferences updated");
|
console.log("Preferences updated");
|
||||||
})
|
})
|
||||||
|
|
@ -343,7 +345,7 @@ export default function ComponentSettings(props: Props) {
|
||||||
|
|
||||||
const removeComponent = () => {
|
const removeComponent = () => {
|
||||||
componentAPI
|
componentAPI
|
||||||
.remove(device.id(), formComponent.key(), getContextKeys(), getContextTypes())
|
.remove(device.id(), formComponent.key(), getContextKeys(), getContextTypes(), as)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
success(formComponent.name() + " was successfully removed!");
|
success(formComponent.name() + " was successfully removed!");
|
||||||
refresh();
|
refresh();
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ interface Props extends WithStyles<typeof styles> {
|
||||||
isJSON?: boolean;
|
isJSON?: boolean;
|
||||||
newMeasurements?: boolean;
|
newMeasurements?: boolean;
|
||||||
user?: User;
|
user?: User;
|
||||||
|
as?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
|
|
@ -91,9 +92,9 @@ class ExportDataSettings extends React.Component<Props, State> {
|
||||||
};
|
};
|
||||||
|
|
||||||
submit = () => {
|
submit = () => {
|
||||||
const { device, component, user } = this.props;
|
const { device, component, user, as } = this.props;
|
||||||
const { startDate, endDate } = this.state;
|
const { startDate, endDate } = this.state;
|
||||||
const { sampleMeasurements, listUnitMeasurements } = this.context;
|
const { /*sampleMeasurements*/ listUnitMeasurements } = this.context;
|
||||||
|
|
||||||
this.setState({ isLoading: true });
|
this.setState({ isLoading: true });
|
||||||
// if (newMeasurements) {
|
// if (newMeasurements) {
|
||||||
|
|
@ -107,7 +108,9 @@ class ExportDataSettings extends React.Component<Props, State> {
|
||||||
"desc",
|
"desc",
|
||||||
undefined,
|
undefined,
|
||||||
[device.id().toString()],
|
[device.id().toString()],
|
||||||
["device"]
|
["device"],
|
||||||
|
undefined,
|
||||||
|
as
|
||||||
)
|
)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
let measurements = resp.data.measurements.map(um => UnitMeasurement.any(um, user));
|
let measurements = resp.data.measurements.map(um => UnitMeasurement.any(um, user));
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import DateSelect from "common/time/DateSelect";
|
||||||
import { useDeviceAPI } from "hooks";
|
import { useDeviceAPI } from "hooks";
|
||||||
import { Component, Device } from "models";
|
import { Component, Device } from "models";
|
||||||
import { Moment } from "moment";
|
import { Moment } from "moment";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { downloadJSON } from "utils";
|
import { downloadJSON } from "utils";
|
||||||
|
|
||||||
|
|
@ -27,6 +28,7 @@ interface Props {
|
||||||
|
|
||||||
export default function ArcGISDeviceData(props: Props) {
|
export default function ArcGISDeviceData(props: Props) {
|
||||||
const { open, close, device, components } = props;
|
const { open, close, device, components } = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const [startDate, setStartDate] = useState<Moment>(GetDefaultDateRange().start);
|
const [startDate, setStartDate] = useState<Moment>(GetDefaultDateRange().start);
|
||||||
const [endDate, setEndDate] = useState<Moment>(GetDefaultDateRange().end);
|
const [endDate, setEndDate] = useState<Moment>(GetDefaultDateRange().end);
|
||||||
const [includedComponents, setIncludedComponents] = useState<Component[]>([]);
|
const [includedComponents, setIncludedComponents] = useState<Component[]>([]);
|
||||||
|
|
@ -89,7 +91,8 @@ export default function ArcGISDeviceData(props: Props) {
|
||||||
limit,
|
limit,
|
||||||
0,
|
0,
|
||||||
"asc",
|
"asc",
|
||||||
"timestamp"
|
"timestamp",
|
||||||
|
as
|
||||||
)
|
)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
downloadJSON(resp.data, filename + ".json");
|
downloadJSON(resp.data, filename + ".json");
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import { useDeviceAPI, useSnackbar } from "hooks";
|
||||||
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
|
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { makeStyles } from "@mui/styles";
|
import { makeStyles } from "@mui/styles";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => {
|
const useStyles = makeStyles((theme: Theme) => {
|
||||||
return ({
|
return ({
|
||||||
|
|
@ -36,6 +37,7 @@ export default function Connection(props: Props) {
|
||||||
const deviceAPI = useDeviceAPI();
|
const deviceAPI = useDeviceAPI();
|
||||||
const { success, error } = useSnackbar();
|
const { success, error } = useSnackbar();
|
||||||
const { deviceID, deviceName, open, close } = props;
|
const { deviceID, deviceName, open, close } = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const [gateway, setGateway] = useState<string>("");
|
const [gateway, setGateway] = useState<string>("");
|
||||||
const [password, setPassword] = useState<string>("");
|
const [password, setPassword] = useState<string>("");
|
||||||
const [passwordVisible, setPasswordVisible] = useState<boolean>(false);
|
const [passwordVisible, setPasswordVisible] = useState<boolean>(false);
|
||||||
|
|
@ -71,7 +73,7 @@ export default function Connection(props: Props) {
|
||||||
let keys = getContextKeys();
|
let keys = getContextKeys();
|
||||||
let types = getContextTypes();
|
let types = getContextTypes();
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.setWifi(deviceID, gateway, password, keys, types)
|
.setWifi(deviceID, gateway, password, keys, types, as)
|
||||||
.then(() => success("Connection settings sent to " + deviceName))
|
.then(() => success("Connection settings sent to " + deviceName))
|
||||||
.catch(() => error("Failed to send connection settings to " + deviceName))
|
.catch(() => error("Failed to send connection settings to " + deviceName))
|
||||||
.finally(() => handleClose());
|
.finally(() => handleClose());
|
||||||
|
|
|
||||||
|
|
@ -193,7 +193,7 @@ export default function DevicePresets(props: DevicePresetsProps) {
|
||||||
comps = [];
|
comps = [];
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
let interactionPromise = interactionAPI.listInteractionsByDevice(deviceIndex, undefined, as);
|
let interactionPromise = interactionAPI.listInteractionsByDevice(deviceIndex, undefined, as);
|
||||||
let componentPromise = componentAPI.list(deviceIndex, undefined, [binKey], ["bin"], true);
|
let componentPromise = componentAPI.list(deviceIndex, undefined, [binKey], ["bin"], true, as);
|
||||||
let dComponents = new Map<string, Component[]>();
|
let dComponents = new Map<string, Component[]>();
|
||||||
Promise.all([componentPromise, interactionPromise])
|
Promise.all([componentPromise, interactionPromise])
|
||||||
.then(([compResp, interactionResp]) => {
|
.then(([compResp, interactionResp]) => {
|
||||||
|
|
@ -367,13 +367,13 @@ export default function DevicePresets(props: DevicePresetsProps) {
|
||||||
//if the device id was passed in the mode was set to storage and we need to set them to off
|
//if the device id was passed in the mode was set to storage and we need to set them to off
|
||||||
heaters.forEach(heater => {
|
heaters.forEach(heater => {
|
||||||
componentAPI
|
componentAPI
|
||||||
.update(deviceIndex, heater.settings)
|
.update(deviceIndex, heater.settings, undefined, undefined, as)
|
||||||
.then()
|
.then()
|
||||||
.catch();
|
.catch();
|
||||||
});
|
});
|
||||||
fans.forEach(fan => {
|
fans.forEach(fan => {
|
||||||
componentAPI
|
componentAPI
|
||||||
.update(deviceIndex, fan.settings)
|
.update(deviceIndex, fan.settings, undefined, undefined, as)
|
||||||
.then()
|
.then()
|
||||||
.catch();
|
.catch();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ const deviceFromForm = (device: Device): Device => {
|
||||||
|
|
||||||
export default function DeviceSettings(props: Props) {
|
export default function DeviceSettings(props: Props) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [{ user }] = useGlobalState();
|
const [{ user, as }] = useGlobalState();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const { success, error } = useSnackbar();
|
const { success, error } = useSnackbar();
|
||||||
const deviceAPI = useDeviceAPI();
|
const deviceAPI = useDeviceAPI();
|
||||||
|
|
@ -254,7 +254,7 @@ export default function DeviceSettings(props: Props) {
|
||||||
deviceForm.settings.extensionComponents = [compExtOne, compExtTwo, compExtThree];
|
deviceForm.settings.extensionComponents = [compExtOne, compExtTwo, compExtThree];
|
||||||
deviceForm.settings.mutations = linearMutations;
|
deviceForm.settings.mutations = linearMutations;
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.update(deviceID, deviceForm.settings)
|
.update(deviceID, deviceForm.settings, as)
|
||||||
.then((_response: any) => {
|
.then((_response: any) => {
|
||||||
success(deviceName + " was successfully updated!");
|
success(deviceName + " was successfully updated!");
|
||||||
close();
|
close();
|
||||||
|
|
@ -277,7 +277,7 @@ export default function DeviceSettings(props: Props) {
|
||||||
const removeDevice = () => {
|
const removeDevice = () => {
|
||||||
const deviceName = deviceForm.name();
|
const deviceName = deviceForm.name();
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.remove(device.id())
|
.remove(device.id(), as)
|
||||||
.then((_response: any) => {
|
.then((_response: any) => {
|
||||||
success(deviceName + " was successfully deleted!");
|
success(deviceName + " was successfully deleted!");
|
||||||
navigate("/");
|
navigate("/");
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,8 @@ export default function Device(props: Props) {
|
||||||
undefined,
|
undefined,
|
||||||
[deviceID.toString()],
|
[deviceID.toString()],
|
||||||
["device"],
|
["device"],
|
||||||
true
|
true,
|
||||||
|
as
|
||||||
);
|
);
|
||||||
let interactionsPromise = interactionsAPI.listInteractionsByDevice(deviceID, undefined, as);
|
let interactionsPromise = interactionsAPI.listInteractionsByDevice(deviceID, undefined, as);
|
||||||
let groupPromise: Promise<any> = Promise.resolve(undefined);
|
let groupPromise: Promise<any> = Promise.resolve(undefined);
|
||||||
|
|
@ -343,7 +344,7 @@ export default function Device(props: Props) {
|
||||||
let updatedPreferences = cloneDeep(preferences);
|
let updatedPreferences = cloneDeep(preferences);
|
||||||
updatedPreferences.notify = !preferences.notify;
|
updatedPreferences.notify = !preferences.notify;
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.updatePreferences(deviceID, updatedPreferences)
|
.updatePreferences(deviceID, updatedPreferences, undefined, undefined, as)
|
||||||
.then(() => setPreferences(updatedPreferences))
|
.then(() => setPreferences(updatedPreferences))
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
error(
|
error(
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import {
|
||||||
import { GetDeviceProductIcon, GetDeviceProductLabel } from "products/DeviceProduct";
|
import { GetDeviceProductIcon, GetDeviceProductLabel } from "products/DeviceProduct";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { quack } from "protobuf-ts/quack";
|
import { quack } from "protobuf-ts/quack";
|
||||||
import { useComponentAPI, useSnackbar } from "providers";
|
import { useComponentAPI, useGlobalState, useSnackbar } from "providers";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import DeviceSVG, { PortInformation } from "./deviceSVG";
|
import DeviceSVG, { PortInformation } from "./deviceSVG";
|
||||||
import { makeStyles } from "@mui/styles";
|
import { makeStyles } from "@mui/styles";
|
||||||
|
|
@ -69,6 +69,7 @@ const useStyles = makeStyles((theme: Theme) => {
|
||||||
|
|
||||||
export default function DeviceWizard(props: Props) {
|
export default function DeviceWizard(props: Props) {
|
||||||
const { device, components, refreshCallback } = props;
|
const { device, components, refreshCallback } = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const [componentDialogOpen, setComponentDialogOpen] = useState(false);
|
const [componentDialogOpen, setComponentDialogOpen] = useState(false);
|
||||||
const [availableOffsets, setAvailableOffsets] = useState<OffsetAvailabilityMap>(new Map());
|
const [availableOffsets, setAvailableOffsets] = useState<OffsetAvailabilityMap>(new Map());
|
||||||
const [availablePositions, setAvailablePositions] = useState<DeviceAvailabilityMap>(new Map());
|
const [availablePositions, setAvailablePositions] = useState<DeviceAvailabilityMap>(new Map());
|
||||||
|
|
@ -159,7 +160,7 @@ export default function DeviceWizard(props: Props) {
|
||||||
componentSettings.reportPeriodMs = 600000;
|
componentSettings.reportPeriodMs = 600000;
|
||||||
componentSettings.name = "Port " + selectedPort.label + " Auto Detect";
|
componentSettings.name = "Port " + selectedPort.label + " Auto Detect";
|
||||||
compAPI
|
compAPI
|
||||||
.add(device.id(), componentSettings)
|
.add(device.id(), componentSettings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
success("Added Auto Detect Component to Port");
|
success("Added Auto Detect Component to Port");
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import { Backpack, Device } from "models";
|
||||||
import { backpackOptions, genericBackpacks } from "pbHelpers/Backpack";
|
import { backpackOptions, genericBackpacks } from "pbHelpers/Backpack";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
isOpen: boolean;
|
isOpen: boolean;
|
||||||
|
|
@ -34,6 +35,7 @@ export default function ProvisionDevice(props: Props) {
|
||||||
const deviceAPI = useDeviceAPI();
|
const deviceAPI = useDeviceAPI();
|
||||||
const backpackAPI = useBackpackAPI();
|
const backpackAPI = useBackpackAPI();
|
||||||
const { error, success, warning, info } = useSnackbar();
|
const { error, success, warning, info } = useSnackbar();
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const { isOpen, closeDialogCallback, refreshCallback } = props;
|
const { isOpen, closeDialogCallback, refreshCallback } = props;
|
||||||
const [provisioned, setProvisioned] = useState<boolean>(false);
|
const [provisioned, setProvisioned] = useState<boolean>(false);
|
||||||
const [idHex, setIdHex] = useState<string>("");
|
const [idHex, setIdHex] = useState<string>("");
|
||||||
|
|
@ -98,7 +100,7 @@ export default function ProvisionDevice(props: Props) {
|
||||||
setDeviceLoading(true);
|
setDeviceLoading(true);
|
||||||
const deviceID = parseInt(idHex, 16);
|
const deviceID = parseInt(idHex, 16);
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.get(deviceID)
|
.get(deviceID, undefined, undefined, undefined, as)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let rDevice = Device.any(response.data);
|
let rDevice = Device.any(response.data);
|
||||||
setDevice(rDevice);
|
setDevice(rDevice);
|
||||||
|
|
@ -149,7 +151,7 @@ export default function ProvisionDevice(props: Props) {
|
||||||
const submitProvision = () => {
|
const submitProvision = () => {
|
||||||
setProvisioned(false);
|
setProvisioned(false);
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.add("", "", assembleBackpack())
|
.add("", "", assembleBackpack(), as)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
let updatedIdHex = response.data.idHex;
|
let updatedIdHex = response.data.idHex;
|
||||||
let updatedKeyHex = response.data.keyHex;
|
let updatedKeyHex = response.data.keyHex;
|
||||||
|
|
@ -173,7 +175,7 @@ export default function ProvisionDevice(props: Props) {
|
||||||
settings.name = name;
|
settings.name = name;
|
||||||
settings.description = description;
|
settings.description = description;
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.update(deviceID, settings)
|
.update(deviceID, settings, as)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
success("Device " + deviceID.toString() + " was successfully updated");
|
success("Device " + deviceID.toString() + " was successfully updated");
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,388 +0,0 @@
|
||||||
import {
|
|
||||||
Alert,
|
|
||||||
AlertTitle,
|
|
||||||
Box,
|
|
||||||
Button,
|
|
||||||
Card,
|
|
||||||
CardActions,
|
|
||||||
CardContent,
|
|
||||||
CardHeader,
|
|
||||||
darken,
|
|
||||||
Divider,
|
|
||||||
Grid2 as Grid,
|
|
||||||
InputAdornment,
|
|
||||||
Skeleton,
|
|
||||||
Step,
|
|
||||||
StepLabel,
|
|
||||||
Stepper,
|
|
||||||
TextField,
|
|
||||||
Theme,
|
|
||||||
Typography
|
|
||||||
} from "@mui/material";
|
|
||||||
import { GrainOptions, MoistureToHumidity } from "grain";
|
|
||||||
import GrainDryingChart, { GrainDryingPoint } from "charts/GrainDryingChart";
|
|
||||||
import SearchSelect, { Option } from "common/SearchSelect";
|
|
||||||
import { DateRange, GetDefaultDateRange } from "common/time/DateRange";
|
|
||||||
import DateSelect from "common/time/DateSelect";
|
|
||||||
import { useComponentAPI } from "hooks";
|
|
||||||
import { cloneDeep } from "lodash";
|
|
||||||
import { Component, Device } from "models";
|
|
||||||
import moment, { Moment } from "moment";
|
|
||||||
import { extension } from "pbHelpers/ComponentType";
|
|
||||||
import { pond } from "protobuf-ts/pond";
|
|
||||||
import { quack } from "protobuf-ts/quack";
|
|
||||||
import { useEffect, useState } from "react";
|
|
||||||
import { FindPlenumSensors } from "./GrainUtils";
|
|
||||||
import { makeStyles } from "@mui/styles";
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => {
|
|
||||||
const bg = darken(theme.palette.background.paper, theme.palette.mode === "light" ? 0.1 : 0.15);
|
|
||||||
|
|
||||||
return ({
|
|
||||||
card: {
|
|
||||||
backgroundColor: bg
|
|
||||||
},
|
|
||||||
stepper: {
|
|
||||||
padding: 0
|
|
||||||
},
|
|
||||||
header: {
|
|
||||||
paddingBottom: theme.spacing(1)
|
|
||||||
},
|
|
||||||
actions: {
|
|
||||||
paddingTop: theme.spacing(1)
|
|
||||||
},
|
|
||||||
gutter: {
|
|
||||||
padding: `${theme.spacing(1)}px ${theme.spacing(2)}px`
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
devices: Device[];
|
|
||||||
loading: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
const devicesToOptions = (devices: Device[]): Option[] => {
|
|
||||||
return devices.map(d => {
|
|
||||||
return { value: d.id().toString(), label: d.name() } as Option;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
//NOREF: has no references in codebase, is this not used anywhere?
|
|
||||||
export default function GrainDryingCalculator(props: Props) {
|
|
||||||
const classes = useStyles();
|
|
||||||
const componentAPI = useComponentAPI();
|
|
||||||
const grainOptions = GrainOptions();
|
|
||||||
const { devices, loading } = props;
|
|
||||||
const [device, setDevice] = useState<Option | undefined>(undefined);
|
|
||||||
const [deviceOptions, setDeviceOptions] = useState(devicesToOptions(devices));
|
|
||||||
const [components, setComponents] = useState<Component[]>([]);
|
|
||||||
const [componentOptions, setComponentOptions] = useState<Option[]>([]);
|
|
||||||
const [component, setComponent] = useState<Option | undefined>(undefined);
|
|
||||||
const [dateRange, setDateRange] = useState<DateRange>(GetDefaultDateRange());
|
|
||||||
const [grainType, setGrainType] = useState<Option | undefined>(
|
|
||||||
grainOptions.find(o => o.value === pond.Grain[pond.Grain.GRAIN_NONE])
|
|
||||||
);
|
|
||||||
const [rawGrainMoisture, setRawGrainMoisture] = useState<string>("15.0");
|
|
||||||
const [samples, setSamples] = useState<pond.Measurement[]>([]);
|
|
||||||
const [componentsLoading, setComponentsLoading] = useState(false);
|
|
||||||
const [samplesLoading, setSamplesLoading] = useState(false);
|
|
||||||
const steps = [0, 1, 2];
|
|
||||||
const [activeStep, setActiveStep] = useState(0);
|
|
||||||
const [chartData, setChartData] = useState<GrainDryingPoint[]>([]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setDeviceOptions(devicesToOptions(devices));
|
|
||||||
}, [devices]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let options = FindPlenumSensors(components).map(
|
|
||||||
c =>
|
|
||||||
({
|
|
||||||
value: c.key(),
|
|
||||||
label: c.name()
|
|
||||||
} as Option)
|
|
||||||
);
|
|
||||||
setComponentOptions(options);
|
|
||||||
setComponent(options[0] ? options[0] : undefined);
|
|
||||||
}, [components]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (device) {
|
|
||||||
const deviceID = Number(device.value);
|
|
||||||
setComponentsLoading(true);
|
|
||||||
componentAPI
|
|
||||||
.list(deviceID)
|
|
||||||
.then(response => {
|
|
||||||
let data = response.data.components ? response.data.components : [];
|
|
||||||
let rComponents: Component[] = data.map((c: any) => {
|
|
||||||
return Component.create(pond.Component.fromObject(c));
|
|
||||||
});
|
|
||||||
setComponents(rComponents);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setComponents([]);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setComponentsLoading(false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [componentAPI, device]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (device && component) {
|
|
||||||
const deviceID = Number(device.value);
|
|
||||||
const componentKey = String(component.value);
|
|
||||||
setSamplesLoading(true);
|
|
||||||
componentAPI
|
|
||||||
.sampleMeasurements(deviceID, componentKey, dateRange.start, dateRange.end, 500)
|
|
||||||
.then(response => {
|
|
||||||
let measurements: pond.Measurement[] | undefined = response.data.measurements;
|
|
||||||
let newSamples = measurements
|
|
||||||
? cloneDeep(measurements).sort((a, b) => {
|
|
||||||
return b.timestamp > a.timestamp ? 1 : -1;
|
|
||||||
})
|
|
||||||
: [];
|
|
||||||
|
|
||||||
setSamples(newSamples);
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
setSamples([]);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setSamplesLoading(false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, [componentAPI, device, component, dateRange]);
|
|
||||||
|
|
||||||
// T = temperature im degrees Celsius
|
|
||||||
// RH = relative humidity (%)
|
|
||||||
const calculateVPD = (T: number, RH: number) => {
|
|
||||||
const es = 0.6108 * Math.exp((17.27 * T) / (T + 237.3));
|
|
||||||
const ea = (RH / 100) * es;
|
|
||||||
return ea - es;
|
|
||||||
};
|
|
||||||
|
|
||||||
const calculateEffectiveVPD = (initialVPD: number, curVPD: number) => {
|
|
||||||
return initialVPD - curVPD;
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
let data: GrainDryingPoint[] = [];
|
|
||||||
let curComponent = component
|
|
||||||
? components.find(c => c.key() === component.value.toString())
|
|
||||||
: undefined;
|
|
||||||
if (curComponent) {
|
|
||||||
let ext = extension(curComponent.settings.type, curComponent.settings.subtype);
|
|
||||||
const grainMoisture = parseFloat(rawGrainMoisture) || 15.0;
|
|
||||||
samples.forEach(s => {
|
|
||||||
let measurement = s.measurement;
|
|
||||||
if (measurement) {
|
|
||||||
let T = 0;
|
|
||||||
let RH = 0;
|
|
||||||
ext.measurements.forEach(cm => {
|
|
||||||
if (cm.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_TEMPERATURE) {
|
|
||||||
T = cm.extract(measurement as quack.Measurement);
|
|
||||||
}
|
|
||||||
if (cm.measurementType === quack.MeasurementType.MEASUREMENT_TYPE_PERCENT) {
|
|
||||||
RH = cm.extract(measurement as quack.Measurement);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const grain = grainType
|
|
||||||
? pond.Grain[grainType.value as keyof typeof pond.Grain]
|
|
||||||
: pond.Grain.GRAIN_NONE;
|
|
||||||
let initialRH = MoistureToHumidity(grain, T, grainMoisture);
|
|
||||||
let initialVPD = calculateVPD(T, initialRH);
|
|
||||||
let vpd = calculateVPD(T, RH);
|
|
||||||
data.push({
|
|
||||||
timestamp: moment(s.timestamp).valueOf(),
|
|
||||||
dryScore: calculateEffectiveVPD(initialVPD, vpd)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
setChartData(data);
|
|
||||||
}, [samples, rawGrainMoisture, grainType, component, components]);
|
|
||||||
|
|
||||||
const grainMoistureInvalid = () => {
|
|
||||||
return rawGrainMoisture === "" || isNaN(Number(rawGrainMoisture));
|
|
||||||
};
|
|
||||||
|
|
||||||
const initialSetup = () => {
|
|
||||||
const invalidGrainMoisture = grainMoistureInvalid();
|
|
||||||
return (
|
|
||||||
<Box marginX={1}>
|
|
||||||
<Typography variant="subtitle1" color="textSecondary" gutterBottom align="center">
|
|
||||||
Please input your grain type and moisture
|
|
||||||
</Typography>
|
|
||||||
<Box paddingY={1}>
|
|
||||||
<SearchSelect
|
|
||||||
selected={grainType}
|
|
||||||
changeSelection={o => setGrainType(o ? o : undefined)}
|
|
||||||
label="Grain Type"
|
|
||||||
options={grainOptions}
|
|
||||||
group
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
<Box paddingY={1}>
|
|
||||||
<TextField
|
|
||||||
value={rawGrainMoisture}
|
|
||||||
onChange={event => setRawGrainMoisture(event.target.value)}
|
|
||||||
fullWidth
|
|
||||||
label="Grain Moisture"
|
|
||||||
variant="outlined"
|
|
||||||
error={invalidGrainMoisture}
|
|
||||||
helperText={invalidGrainMoisture ? "Invalid number" : ""}
|
|
||||||
InputProps={{
|
|
||||||
endAdornment: (
|
|
||||||
<InputAdornment position="end">
|
|
||||||
<InputAdornment position="end">% WB</InputAdornment>
|
|
||||||
</InputAdornment>
|
|
||||||
)
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const setupChart = () => {
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
<Typography variant="subtitle1" color="textSecondary" gutterBottom align="center">
|
|
||||||
Please select your plenum moisture sensor
|
|
||||||
</Typography>{" "}
|
|
||||||
<Grid container spacing={2}>
|
|
||||||
<Grid size={{ xs: 12 }}>
|
|
||||||
<SearchSelect
|
|
||||||
label="Device"
|
|
||||||
selected={device}
|
|
||||||
disabled={loading}
|
|
||||||
options={deviceOptions}
|
|
||||||
changeSelection={option => setDevice(option ? option : undefined)}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid size={{ xs: 12 }}>
|
|
||||||
<SearchSelect
|
|
||||||
label="Moisture Sensor"
|
|
||||||
selected={component}
|
|
||||||
options={componentOptions}
|
|
||||||
disabled={!device}
|
|
||||||
loading={componentsLoading}
|
|
||||||
changeSelection={option => setComponent(option ? option : undefined)}
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const analyzeChart = () => {
|
|
||||||
return (
|
|
||||||
<Box>
|
|
||||||
{samplesLoading ? (
|
|
||||||
<Skeleton variant="rectangular" />
|
|
||||||
) : chartData.length > 1 ? (
|
|
||||||
<GrainDryingChart data={chartData} />
|
|
||||||
) : (
|
|
||||||
<Alert severity="info" variant="outlined">
|
|
||||||
<AlertTitle>No data to display graph</AlertTitle>
|
|
||||||
<Box>Tips:</Box>
|
|
||||||
<Box> - increase the time range</Box>
|
|
||||||
<Box> - select an active moisture sensor</Box>
|
|
||||||
</Alert>
|
|
||||||
)}
|
|
||||||
<DateSelect
|
|
||||||
updateDateRange={(newStart: Moment, newEnd: Moment) =>
|
|
||||||
setDateRange({ start: newStart, end: newEnd })
|
|
||||||
}
|
|
||||||
startDate={dateRange.start}
|
|
||||||
endDate={dateRange.end}
|
|
||||||
/>
|
|
||||||
<Typography variant="caption" color="textSecondary">
|
|
||||||
Effective Vapor Pressure Deficit (VPD) represents the potential for moisture to be added
|
|
||||||
or removed
|
|
||||||
</Typography>
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const stepContent = () => {
|
|
||||||
switch (activeStep) {
|
|
||||||
case 1:
|
|
||||||
return setupChart();
|
|
||||||
case 2:
|
|
||||||
return analyzeChart();
|
|
||||||
default:
|
|
||||||
return initialSetup();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const stepComplete = (): boolean => {
|
|
||||||
switch (activeStep) {
|
|
||||||
case 0:
|
|
||||||
return grainType !== undefined && !grainMoistureInvalid();
|
|
||||||
case 1:
|
|
||||||
return device !== undefined && component !== undefined;
|
|
||||||
default:
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const actions = () => {
|
|
||||||
return (
|
|
||||||
<CardActions className={classes.actions}>
|
|
||||||
<Box display="flex" width="100%" justifyContent="space-between">
|
|
||||||
<Button
|
|
||||||
color="primary"
|
|
||||||
onClick={() => setActiveStep(activeStep - 1)}
|
|
||||||
disabled={activeStep <= 0}>
|
|
||||||
Back
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
color="primary"
|
|
||||||
onClick={() => setActiveStep(activeStep + 1)}
|
|
||||||
disabled={activeStep >= steps.length - 1 || !stepComplete()}>
|
|
||||||
Next
|
|
||||||
</Button>
|
|
||||||
</Box>
|
|
||||||
</CardActions>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (loading) return <Skeleton variant="rectangular" width="100%" height="300px" />;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Card elevation={4} className={classes.card}>
|
|
||||||
<CardHeader
|
|
||||||
title="Grain Drying Calculator"
|
|
||||||
subheader={
|
|
||||||
<Typography variant="body2" color="textSecondary">
|
|
||||||
Find out how well your grain is drying
|
|
||||||
</Typography>
|
|
||||||
}
|
|
||||||
className={classes.header}
|
|
||||||
/>
|
|
||||||
<CardContent className={classes.gutter}>
|
|
||||||
<Stepper activeStep={activeStep} className={classes.stepper} alternativeLabel>
|
|
||||||
<Step key={0}>
|
|
||||||
<StepLabel>Grain Moisture</StepLabel>
|
|
||||||
</Step>
|
|
||||||
<Step key={1}>
|
|
||||||
<StepLabel>Select Plenum</StepLabel>
|
|
||||||
</Step>
|
|
||||||
<Step key={2}>
|
|
||||||
<StepLabel>Analyze</StepLabel>
|
|
||||||
</Step>
|
|
||||||
</Stepper>
|
|
||||||
<Box paddingY={1}>
|
|
||||||
<Divider />
|
|
||||||
</Box>
|
|
||||||
<Box paddingTop={1}>{stepContent()}</Box>
|
|
||||||
</CardContent>
|
|
||||||
{actions()}
|
|
||||||
</Card>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
export * from "./GrainDescriber";
|
export * from "./GrainDescriber";
|
||||||
export * from "./GrainDryingCalculator";
|
|
||||||
export * from "./GrainMoisture";
|
export * from "./GrainMoisture";
|
||||||
export * from "./GrainUse";
|
export * from "./GrainUse";
|
||||||
export * from "./GrainUtils";
|
export * from "./GrainUtils";
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import { useDeviceAPI, useGroupAPI, usePrevious, useSnackbar } from "hooks";
|
||||||
import { Device, Group } from "models";
|
import { Device, Group } from "models";
|
||||||
import { filterDevices } from "pbHelpers/Device";
|
import { filterDevices } from "pbHelpers/Device";
|
||||||
import { groupsAreEqual } from "pbHelpers/Group";
|
import { groupsAreEqual } from "pbHelpers/Group";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
import React, { useCallback, useEffect, useState } from "react";
|
import React, { useCallback, useEffect, useState } from "react";
|
||||||
import RemoveGroup from "./RemoveGroup";
|
import RemoveGroup from "./RemoveGroup";
|
||||||
|
|
||||||
|
|
@ -76,6 +77,7 @@ export default function GroupSettings(props: Props) {
|
||||||
groupDevices,
|
groupDevices,
|
||||||
} = props;
|
} = props;
|
||||||
const prevInitialGroup = usePrevious(initialGroup);
|
const prevInitialGroup = usePrevious(initialGroup);
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const groupAPI = useGroupAPI();
|
const groupAPI = useGroupAPI();
|
||||||
const deviceAPI = useDeviceAPI();
|
const deviceAPI = useDeviceAPI();
|
||||||
const snackbar = useSnackbar()
|
const snackbar = useSnackbar()
|
||||||
|
|
@ -103,7 +105,7 @@ export default function GroupSettings(props: Props) {
|
||||||
const loadDevices = useCallback(() => {
|
const loadDevices = useCallback(() => {
|
||||||
setLoadingDevices(true);
|
setLoadingDevices(true);
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.list(1000000, 0, "asc")
|
.list(1000000, 0, "asc", undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,as)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
let rDevices: Device[] = response.data.devices
|
let rDevices: Device[] = response.data.devices
|
||||||
? response.data.devices.map((device: any) => Device.any(device))
|
? response.data.devices.map((device: any) => Device.any(device))
|
||||||
|
|
@ -115,7 +117,7 @@ export default function GroupSettings(props: Props) {
|
||||||
setDevices([]);
|
setDevices([]);
|
||||||
})
|
})
|
||||||
.finally(() => setLoadingDevices(false));
|
.finally(() => setLoadingDevices(false));
|
||||||
}, [deviceAPI]);
|
}, [deviceAPI, as]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (prevInitialGroup !== initialGroup) {
|
if (prevInitialGroup !== initialGroup) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import DeviceViewer from "device/DeviceViewer";
|
||||||
import MapMarkerSettings from "maps/MapMarkerSettings";
|
import MapMarkerSettings from "maps/MapMarkerSettings";
|
||||||
import { Device } from "models";
|
import { Device } from "models";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useDeviceAPI, useSnackbar } from "providers";
|
import { useDeviceAPI, useGlobalState, useSnackbar } from "providers";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -19,6 +19,7 @@ interface Props {
|
||||||
|
|
||||||
export default function DeviceDrawer(props: Props) {
|
export default function DeviceDrawer(props: Props) {
|
||||||
const { open, onClose, selectedDevice, devices, removeMarker, updateMarker, moveMap } = props;
|
const { open, onClose, selectedDevice, devices, removeMarker, updateMarker, moveMap } = props;
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const [device, setDevice] = useState<Device>(Device.create());
|
const [device, setDevice] = useState<Device>(Device.create());
|
||||||
const [openMarkerSettings, setOpenMarkerSettings] = useState(false);
|
const [openMarkerSettings, setOpenMarkerSettings] = useState(false);
|
||||||
const deviceAPI = useDeviceAPI();
|
const deviceAPI = useDeviceAPI();
|
||||||
|
|
@ -96,7 +97,7 @@ export default function DeviceDrawer(props: Props) {
|
||||||
settings.longitude = 0;
|
settings.longitude = 0;
|
||||||
settings.latitude = 0;
|
settings.latitude = 0;
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.update(device.id(), settings)
|
.update(device.id(), 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
|
||||||
|
|
@ -138,7 +139,7 @@ export default function DeviceDrawer(props: Props) {
|
||||||
let settings = device.settings;
|
let settings = device.settings;
|
||||||
settings.theme = newTheme;
|
settings.theme = newTheme;
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.update(device.id(), settings)
|
.update(device.id(), settings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("marker settings updated");
|
openSnack("marker settings updated");
|
||||||
updateMarker(device.id().toString(), settings);
|
updateMarker(device.id().toString(), settings);
|
||||||
|
|
|
||||||
|
|
@ -503,7 +503,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
|
|
||||||
const loadDevices = useCallback(() => {
|
const loadDevices = useCallback(() => {
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.list(500, 0, "asc", "name")
|
.list(500, 0, "asc", "name", undefined, undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
let map = new Map<string, DeviceModel>();
|
let map = new Map<string, DeviceModel>();
|
||||||
let newDevMarkers: Map<string, MarkerData> = new Map();
|
let newDevMarkers: Map<string, MarkerData> = new Map();
|
||||||
|
|
@ -557,7 +557,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
openSnack("Failed to load Devices");
|
openSnack("Failed to load Devices");
|
||||||
});
|
});
|
||||||
}, [deviceAPI, openSnack]); // eslint-disable-line react-hooks/exhaustive-deps
|
}, [deviceAPI, openSnack, as]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const fmIcon = (type: pond.FieldMarkerType, size: number) => {
|
const fmIcon = (type: pond.FieldMarkerType, size: number) => {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
@ -1042,7 +1042,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
device.settings.longitude = long;
|
device.settings.longitude = long;
|
||||||
device.settings.latitude = lat;
|
device.settings.latitude = lat;
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.update(device.id(), device.settings)
|
.update(device.id(), device.settings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Device location Updated");
|
openSnack("Device location Updated");
|
||||||
if (deviceOptions.includes(device)) {
|
if (deviceOptions.includes(device)) {
|
||||||
|
|
|
||||||
|
|
@ -194,7 +194,7 @@ export default function ConstructionMapController(props: Props) {
|
||||||
if (loadingDevices) return;
|
if (loadingDevices) return;
|
||||||
setLoadingDevices(true);
|
setLoadingDevices(true);
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.list(500, 0, "asc", "name", undefined, undefined, undefined, undefined, undefined, true)
|
.list(500, 0, "asc", "name", undefined, undefined, undefined, undefined, undefined, true, undefined, undefined,undefined,undefined,undefined,as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
let devOps: Device[] = []; //only devices that are not mapped
|
let devOps: Device[] = []; //only devices that are not mapped
|
||||||
let deviceMap: Map<string, Device> = new Map<string, Device>(); // all devices
|
let deviceMap: Map<string, Device> = new Map<string, Device>(); // all devices
|
||||||
|
|
@ -252,7 +252,7 @@ export default function ConstructionMapController(props: Props) {
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
openSnack("Failed to Load Devices");
|
openSnack("Failed to Load Devices");
|
||||||
});
|
});
|
||||||
}, [deviceAPI, openSnack]); // eslint-disable-line react-hooks/exhaustive-deps
|
}, [deviceAPI, openSnack, as]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const loadGroups = useCallback(() => {
|
const loadGroups = useCallback(() => {
|
||||||
groupAPI
|
groupAPI
|
||||||
|
|
@ -527,7 +527,7 @@ export default function ConstructionMapController(props: Props) {
|
||||||
device.settings.longitude = long;
|
device.settings.longitude = long;
|
||||||
device.settings.latitude = lat;
|
device.settings.latitude = lat;
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.update(device.id(), device.settings)
|
.update(device.id(), device.settings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Device location Updated");
|
openSnack("Device location Updated");
|
||||||
if (devOps.includes(device)) {
|
if (devOps.includes(device)) {
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ export default function ObjectHeaterCharts(props: Props) {
|
||||||
const now = moment();
|
const now = moment();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const [mutationData, setMutationData] = useState<MutationData[]>([]);
|
const [mutationData, setMutationData] = useState<MutationData[]>([]);
|
||||||
const [{ user }] = useGlobalState();
|
const [{ user, as }] = useGlobalState();
|
||||||
const themeType = useThemeType();
|
const themeType = useThemeType();
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [mutationsLoading, setMutationsLoading] = useState(false);
|
const [mutationsLoading, setMutationsLoading] = useState(false);
|
||||||
|
|
@ -165,7 +165,7 @@ export default function ObjectHeaterCharts(props: Props) {
|
||||||
setTempOnly(tempOnly);
|
setTempOnly(tempOnly);
|
||||||
setHeater(heater);
|
setHeater(heater);
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.listJSONMeasurements(dev.id(), measurementsFor, start, end, 0, 0, "asc", "timestamp")
|
.listJSONMeasurements(dev.id(), measurementsFor, start, end, 0, 0, "asc", "timestamp", as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
resp.data.components.forEach(comp => {
|
resp.data.components.forEach(comp => {
|
||||||
if (comp.componentId === tempHum?.key()) {
|
if (comp.componentId === tempHum?.key()) {
|
||||||
|
|
@ -192,7 +192,7 @@ export default function ObjectHeaterCharts(props: Props) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, [device, deviceAPI, start, end]); //eslint-disable-line react-hooks/exhaustive-deps
|
}, [device, deviceAPI, start, end, as]); //eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const updateDateRange = (newStartDate: any, newEndDate: any, live: boolean) => {
|
const updateDateRange = (newStartDate: any, newEndDate: any, live: boolean) => {
|
||||||
setStart(newStartDate);
|
setStart(newStartDate);
|
||||||
|
|
|
||||||
|
|
@ -414,7 +414,7 @@ export default function Bin(props: Props) {
|
||||||
const reLoadSingleComponent = (componentKey: string) => {
|
const reLoadSingleComponent = (componentKey: string) => {
|
||||||
let dev = componentDevices.get(componentKey);
|
let dev = componentDevices.get(componentKey);
|
||||||
if (dev) {
|
if (dev) {
|
||||||
componentAPI.get(dev, componentKey).then(resp => {
|
componentAPI.get(dev, componentKey, undefined, undefined, as).then(resp => {
|
||||||
let compMap = components;
|
let compMap = components;
|
||||||
let comp = Component.any(resp.data);
|
let comp = Component.any(resp.data);
|
||||||
compMap.set(comp.key(), comp);
|
compMap.set(comp.key(), comp);
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,7 @@ export default function DevicePage() {
|
||||||
// console.log("load device page data")
|
// console.log("load device page data")
|
||||||
if (loading) return
|
if (loading) return
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
deviceAPI.getPageData(deviceID, getContextKeys(), getContextTypes()).then(resp => {
|
deviceAPI.getPageData(deviceID, getContextKeys(), getContextTypes(), as).then(resp => {
|
||||||
let device = Device.any(resp.data.device)
|
let device = Device.any(resp.data.device)
|
||||||
// console.log(resp.data.device)
|
// console.log(resp.data.device)
|
||||||
setDevice(device)
|
setDevice(device)
|
||||||
|
|
@ -143,13 +143,13 @@ export default function DevicePage() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadDevice()
|
loadDevice()
|
||||||
}, [deviceID])
|
}, [deviceID, as])
|
||||||
|
|
||||||
const toggleNotificationPreference = () => {
|
const toggleNotificationPreference = () => {
|
||||||
let updatedPreferences = cloneDeep(preferences);
|
let updatedPreferences = cloneDeep(preferences);
|
||||||
updatedPreferences.notify = !preferences.notify;
|
updatedPreferences.notify = !preferences.notify;
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.updatePreferences(deviceID, updatedPreferences, getContextKeys(), getContextTypes())
|
.updatePreferences(deviceID, updatedPreferences, getContextKeys(), getContextTypes(), as)
|
||||||
.then(() => setPreferences(updatedPreferences))
|
.then(() => setPreferences(updatedPreferences))
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
snackbar.error(
|
snackbar.error(
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,8 @@ export default function DeviceComponent() {
|
||||||
false,
|
false,
|
||||||
getContextKeys(),
|
getContextKeys(),
|
||||||
getContextTypes(),
|
getContextTypes(),
|
||||||
showErrors
|
showErrors,
|
||||||
|
as
|
||||||
)
|
)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
if (resp.data.measurements) {
|
if (resp.data.measurements) {
|
||||||
|
|
@ -179,7 +180,7 @@ export default function DeviceComponent() {
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
setSampling(false);
|
setSampling(false);
|
||||||
});
|
});
|
||||||
}, [componentAPI, deviceID, componentID, user, startDate, endDate, showErrors]);
|
}, [componentAPI, deviceID, componentID, user, startDate, endDate, showErrors, as]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (live.current && liveSamples) {
|
if (live.current && liveSamples) {
|
||||||
|
|
@ -206,7 +207,7 @@ export default function DeviceComponent() {
|
||||||
if (user.settings.id === "") return;
|
if (user.settings.id === "") return;
|
||||||
setLoadingInitial(true);
|
setLoadingInitial(true);
|
||||||
deviceAPI
|
deviceAPI
|
||||||
.get(deviceID, false, getContextKeys().slice(0, -1), getContextTypes().slice(0, -1))
|
.get(deviceID, false, getContextKeys().slice(0, -1), getContextTypes().slice(0, -1), as)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
const rDevice = Device.any(response.data);
|
const rDevice = Device.any(response.data);
|
||||||
setDevice(rDevice);
|
setDevice(rDevice);
|
||||||
|
|
@ -215,10 +216,11 @@ export default function DeviceComponent() {
|
||||||
false,
|
false,
|
||||||
getContextKeys(),
|
getContextKeys(),
|
||||||
getContextTypes(),
|
getContextTypes(),
|
||||||
true
|
true,
|
||||||
|
as
|
||||||
);
|
);
|
||||||
let userPromise = userAPI.getUser(user.settings.id, deviceScope(deviceID.toString()));
|
let userPromise = userAPI.getUser(user.settings.id, deviceScope(deviceID.toString()));
|
||||||
let prefPromise = deviceAPI.listDeviceComponentPreferences(deviceID, getContextKeys().slice(0, -1), getContextTypes().slice(0, -1));
|
let prefPromise = deviceAPI.listDeviceComponentPreferences(deviceID, getContextKeys().slice(0, -1), getContextTypes().slice(0, -1), as);
|
||||||
Promise.all([componentsPromise, userPromise, prefPromise])
|
Promise.all([componentsPromise, userPromise, prefPromise])
|
||||||
.then((responses: any) => {
|
.then((responses: any) => {
|
||||||
const rawComponents: Array<any> = or(responses[0].data.components, []).sort(
|
const rawComponents: Array<any> = or(responses[0].data.components, []).sort(
|
||||||
|
|
@ -427,7 +429,8 @@ export default function DeviceComponent() {
|
||||||
undefined,
|
undefined,
|
||||||
getContextKeys(),
|
getContextKeys(),
|
||||||
getContextTypes(),
|
getContextTypes(),
|
||||||
showErrors
|
showErrors,
|
||||||
|
as
|
||||||
)
|
)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
let total: number = response.data.total ? response.data.total : 0;
|
let total: number = response.data.total ? response.data.total : 0;
|
||||||
|
|
@ -458,7 +461,7 @@ export default function DeviceComponent() {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
load()
|
load()
|
||||||
}, [page, pageSize])
|
}, [page, pageSize, as])
|
||||||
|
|
||||||
const columns = (): Column<convertedUnitMeasurement>[] => {
|
const columns = (): Column<convertedUnitMeasurement>[] => {
|
||||||
return [
|
return [
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import { useEffect, useState } from "react";
|
||||||
import { useParams } from "react-router";
|
import { useParams } from "react-router";
|
||||||
import DeviceHistory from "device/DeviceHistory";
|
import DeviceHistory from "device/DeviceHistory";
|
||||||
import { makeStyles } from "@mui/styles";
|
import { makeStyles } from "@mui/styles";
|
||||||
|
import { useGlobalState } from "providers";
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) => {
|
const useStyles = makeStyles((theme: Theme) => {
|
||||||
return ({
|
return ({
|
||||||
|
|
@ -24,6 +25,7 @@ interface Props {}
|
||||||
export default function DeviceHistoryPage(_props: Props) {
|
export default function DeviceHistoryPage(_props: Props) {
|
||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const { error } = useSnackbar();
|
const { error } = useSnackbar();
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const deviceAPI = useDeviceAPI();
|
const deviceAPI = useDeviceAPI();
|
||||||
const deviceID = useParams<{ deviceID: string }>()?.deviceID ?? "";
|
const deviceID = useParams<{ deviceID: string }>()?.deviceID ?? "";
|
||||||
const [device, setDevice] = useState(Device.any({ settings: { deviceId: deviceID } }));
|
const [device, setDevice] = useState(Device.any({ settings: { deviceId: deviceID } }));
|
||||||
|
|
@ -32,7 +34,7 @@ export default function DeviceHistoryPage(_props: Props) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
(async function load() {
|
(async function load() {
|
||||||
await deviceAPI
|
await deviceAPI
|
||||||
.get(deviceID)
|
.get(deviceID, undefined, undefined, undefined, as)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
setDevice(Device.any(response.data));
|
setDevice(Device.any(response.data));
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -213,6 +213,7 @@ export default function Devices() {
|
||||||
getTypes(),
|
getTypes(),
|
||||||
fieldContains,
|
fieldContains,
|
||||||
search,
|
search,
|
||||||
|
as
|
||||||
).then(resp => {
|
).then(resp => {
|
||||||
let newDevices: Device[] = []
|
let newDevices: Device[] = []
|
||||||
resp.data.devices.forEach(device => {
|
resp.data.devices.forEach(device => {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import { Device, Group } from "models"
|
||||||
import { useEffect, useState } from "react"
|
import { useEffect, useState } from "react"
|
||||||
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||||
import PageContainer from "./PageContainer";
|
import PageContainer from "./PageContainer";
|
||||||
import { useDeviceAPI, useGroupAPI } from "providers";
|
import { useDeviceAPI, useGlobalState, useGroupAPI } from "providers";
|
||||||
import GroupActions from "group/GroupActions";
|
import GroupActions from "group/GroupActions";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
|
import { getContextKeys, getContextTypes } from "pbHelpers/Context";
|
||||||
|
|
@ -66,6 +66,7 @@ export default function GroupPage() {
|
||||||
|
|
||||||
const groupID = parseInt(useParams<{ groupID: string }>()?.groupID ?? "0");
|
const groupID = parseInt(useParams<{ groupID: string }>()?.groupID ?? "0");
|
||||||
const { state } = useLocation();
|
const { state } = useLocation();
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
const [group, setGroup] = useState<Group>(state?.group ? Group.create(state.group) : Group.create())
|
const [group, setGroup] = useState<Group>(state?.group ? Group.create(state.group) : Group.create())
|
||||||
const [loadingGroup, setLoadingGroup] = useState(false)
|
const [loadingGroup, setLoadingGroup] = useState(false)
|
||||||
const [loadingDevices, setLoadingDevices] = useState(false)
|
const [loadingDevices, setLoadingDevices] = useState(false)
|
||||||
|
|
@ -131,7 +132,10 @@ export default function GroupPage() {
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
getKeys(),
|
getKeys(),
|
||||||
getTypes()
|
getTypes(),
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
as
|
||||||
).then(resp => {
|
).then(resp => {
|
||||||
let newDevices: Device[] = [];
|
let newDevices: Device[] = [];
|
||||||
resp.data.devices.forEach(device => {
|
resp.data.devices.forEach(device => {
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,10 @@ export default function Heater() {
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
[heaterID],
|
[heaterID],
|
||||||
["objectHeater"]
|
["objectHeater"],
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
as
|
||||||
)
|
)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
setLoadingDevs(false);
|
setLoadingDevs(false);
|
||||||
|
|
@ -185,7 +188,7 @@ export default function Heater() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [location, heaterAPI, heaterID, deviceAPI]); //eslint-disable-line react-hooks/exhaustive-deps
|
}, [location, heaterAPI, heaterID, deviceAPI, as]); //eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const disconnectDisplayDevice = () => {
|
const disconnectDisplayDevice = () => {
|
||||||
if (displayDevice) {
|
if (displayDevice) {
|
||||||
|
|
|
||||||
|
|
@ -18,36 +18,41 @@ export interface IComponentAPIContext {
|
||||||
url: string,
|
url: string,
|
||||||
componentKey: string
|
componentKey: string
|
||||||
) => Promise<any>;
|
) => Promise<any>;
|
||||||
add: (device: number, settings: pond.ComponentSettings) => Promise<AxiosResponse<pond.AddComponentResponse>>;
|
add: (device: number, settings: pond.ComponentSettings, as?: string) => Promise<AxiosResponse<pond.AddComponentResponse>>;
|
||||||
addMultiComponents: (
|
addMultiComponents: (
|
||||||
device: number,
|
device: number,
|
||||||
components: pond.MultiComponentSettings
|
components: pond.MultiComponentSettings,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.AddMultiComponentsResponse>>;
|
) => Promise<AxiosResponse<pond.AddMultiComponentsResponse>>;
|
||||||
update: (
|
update: (
|
||||||
device: number,
|
device: number,
|
||||||
settings: pond.ComponentSettings,
|
settings: pond.ComponentSettings,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.UpdateComponentResponse>>;
|
) => Promise<AxiosResponse<pond.UpdateComponentResponse>>;
|
||||||
remove: (device: number, component: string, keys?: string[], types?: string[]) => Promise<AxiosResponse<pond.RemoveComponentResponse>>;
|
remove: (device: number, component: string, keys?: string[], types?: string[], as?: string) => Promise<AxiosResponse<pond.RemoveComponentResponse>>;
|
||||||
get: (device: number, component: string, keys?: string[], types?: string[]) => Promise<AxiosResponse<pond.Component>>;
|
get: (device: number, component: string, keys?: string[], types?: string[], as?: string) => Promise<AxiosResponse<pond.Component>>;
|
||||||
list: (
|
list: (
|
||||||
device: number | string,
|
device: number | string,
|
||||||
demo?: boolean,
|
demo?: boolean,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
comprehensive?: boolean
|
comprehensive?: boolean,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.ListComponentsResponse>>;
|
) => Promise<AxiosResponse<pond.ListComponentsResponse>>;
|
||||||
listForObject: (
|
listForObject: (
|
||||||
keys: string[],
|
keys: string[],
|
||||||
types: string[]
|
types: string[],
|
||||||
|
as?:string
|
||||||
) => Promise<AxiosResponse<pond.ListComponentsResponse>>;
|
) => Promise<AxiosResponse<pond.ListComponentsResponse>>;
|
||||||
listComponentCardData: (
|
listComponentCardData: (
|
||||||
device: number | string,
|
device: number | string,
|
||||||
demo?: boolean,
|
demo?: boolean,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
comprehensive?: boolean
|
comprehensive?: boolean,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.ListComponentCardDataResponse>>;
|
) => Promise<AxiosResponse<pond.ListComponentCardDataResponse>>;
|
||||||
listHistory: (
|
listHistory: (
|
||||||
deviceId: string | number,
|
deviceId: string | number,
|
||||||
|
|
@ -57,30 +62,32 @@ export interface IComponentAPIContext {
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[]
|
||||||
) => Promise<AxiosResponse<pond.ListComponentHistoryResponse>>;
|
) => Promise<AxiosResponse<pond.ListComponentHistoryResponse>>;
|
||||||
listMeasurements: (
|
// Old measuremnt structure functions, no longer used in codebase
|
||||||
device: number,
|
// listMeasurements: (
|
||||||
component: string,
|
// device: number,
|
||||||
startDate: any,
|
// component: string,
|
||||||
endDate: any,
|
// startDate: any,
|
||||||
limit: number,
|
// endDate: any,
|
||||||
offset: number,
|
// limit: number,
|
||||||
order: string,
|
// offset: number,
|
||||||
orderBy: string,
|
// order: string,
|
||||||
demo?: boolean,
|
// orderBy: string,
|
||||||
keys?: string[],
|
// demo?: boolean,
|
||||||
types?: string[]
|
// keys?: string[],
|
||||||
) => //exportMeasurements?: boolean
|
// types?: string[]
|
||||||
Promise<AxiosResponse<pond.ListMeasurementsResponse>>;
|
// ) => //exportMeasurements?: boolean
|
||||||
sampleMeasurements: (
|
// Promise<AxiosResponse<pond.ListMeasurementsResponse>>;
|
||||||
device: number | string,
|
// sampleMeasurements: (
|
||||||
component: string,
|
// device: number | string,
|
||||||
startDate: any,
|
// component: string,
|
||||||
endDate: any,
|
// startDate: any,
|
||||||
sampleSize: number,
|
// endDate: any,
|
||||||
demo?: boolean,
|
// sampleSize: number,
|
||||||
keys?: string[],
|
// demo?: boolean,
|
||||||
types?: string[]
|
// keys?: string[],
|
||||||
) => Promise<AxiosResponse<pond.SampleMeasurementsResponse>>;
|
// types?: string[],
|
||||||
|
// as?: string
|
||||||
|
// ) => Promise<AxiosResponse<pond.SampleMeasurementsResponse>>;
|
||||||
sampleUnitMeasurements: (
|
sampleUnitMeasurements: (
|
||||||
device: number | string,
|
device: number | string,
|
||||||
component: string,
|
component: string,
|
||||||
|
|
@ -90,7 +97,8 @@ export interface IComponentAPIContext {
|
||||||
demo?: boolean,
|
demo?: boolean,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
showErrors?: boolean
|
showErrors?: boolean,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.SampleUnitMeasurementsResponse>>;
|
) => Promise<AxiosResponse<pond.SampleUnitMeasurementsResponse>>;
|
||||||
// possibly a deprecated function as it is not used anywhere
|
// possibly a deprecated function as it is not used anywhere
|
||||||
updateComponentPreferences: (
|
updateComponentPreferences: (
|
||||||
|
|
@ -111,7 +119,8 @@ export interface IComponentAPIContext {
|
||||||
measurementType?: number | quack.MeasurementType,
|
measurementType?: number | quack.MeasurementType,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
showErrors?: boolean
|
showErrors?: boolean,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.ListUnitMeasurementsResponse>>;
|
) => Promise<AxiosResponse<pond.ListUnitMeasurementsResponse>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +131,7 @@ interface Props {}
|
||||||
export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
const { get, post, put, del } = useHTTP();
|
const { get, post, put, del } = useHTTP();
|
||||||
const [{ as }] = useGlobalState();
|
//const [{ as }] = useGlobalState();
|
||||||
|
|
||||||
const newCron = (
|
const newCron = (
|
||||||
device: number,
|
device: number,
|
||||||
|
|
@ -147,7 +156,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const addComponent = (device: number, settings: pond.ComponentSettings) => {
|
const addComponent = (device: number, settings: pond.ComponentSettings, as?: string) => {
|
||||||
let url = "/devices/" + device + "/components"
|
let url = "/devices/" + device + "/components"
|
||||||
if (as) url = url + `?as=${as}`
|
if (as) url = url + `?as=${as}`
|
||||||
return new Promise<AxiosResponse<pond.AddComponentResponse>>((resolve, reject) => {
|
return new Promise<AxiosResponse<pond.AddComponentResponse>>((resolve, reject) => {
|
||||||
|
|
@ -160,7 +169,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const addMultiComponents = (device: number, components: pond.MultiComponentSettings) => {
|
const addMultiComponents = (device: number, components: pond.MultiComponentSettings, as?: string) => {
|
||||||
let url = "/devices/" + device + "/multiComponents"
|
let url = "/devices/" + device + "/multiComponents"
|
||||||
if (as) url = url + `?as=${as}`
|
if (as) url = url + `?as=${as}`
|
||||||
return new Promise<AxiosResponse<pond.AddMultiComponentsResponse>>((resolve, reject)=>{
|
return new Promise<AxiosResponse<pond.AddMultiComponentsResponse>>((resolve, reject)=>{
|
||||||
|
|
@ -177,7 +186,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
device: number,
|
device: number,
|
||||||
settings: pond.ComponentSettings,
|
settings: pond.ComponentSettings,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let k: string[] = keys ? keys : [];
|
let k: string[] = keys ? keys : [];
|
||||||
if (!k.includes(device.toString())) k.push(device.toString()); //if the device id is already in the keys do not add it again
|
if (!k.includes(device.toString())) k.push(device.toString()); //if the device id is already in the keys do not add it again
|
||||||
|
|
@ -207,7 +217,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
device: number,
|
device: number,
|
||||||
component: string,
|
component: string,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let k: string[] = keys ? keys : [];
|
let k: string[] = keys ? keys : [];
|
||||||
if (!k.includes(device.toString())) k.push(device.toString()); //if the device id is already in the keys do not add it again
|
if (!k.includes(device.toString())) k.push(device.toString()); //if the device id is already in the keys do not add it again
|
||||||
|
|
@ -232,7 +243,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const getComponent = (device: number, component: string, keys?: string[], types?: string[]) => {
|
const getComponent = (device: number, component: string, keys?: string[], types?: string[], as?: string) => {
|
||||||
let k: string[] = keys ? keys : [];
|
let k: string[] = keys ? keys : [];
|
||||||
if (!k.includes(device.toString())) k.push(device.toString()); //if the device id is already in the keys do not add it again
|
if (!k.includes(device.toString())) k.push(device.toString()); //if the device id is already in the keys do not add it again
|
||||||
let t: string[] = types ? types : [];
|
let t: string[] = types ? types : [];
|
||||||
|
|
@ -261,7 +272,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
demo: boolean = false,
|
demo: boolean = false,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
comprehensive?: boolean
|
comprehensive?: boolean,
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let k = keys ? keys : [];
|
let k = keys ? keys : [];
|
||||||
let t = types ? types : [];
|
let t = types ? types : [];
|
||||||
|
|
@ -291,7 +303,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const listComponentsForObject = (keys: string[], types: string[]) => {
|
const listComponentsForObject = (keys: string[], types: string[], as?: string) => {
|
||||||
let url = pondURL("/components/forObject?keys=" + keys + "&types=" + types + (as ? "&as=" + as : ""))
|
let url = pondURL("/components/forObject?keys=" + keys + "&types=" + types + (as ? "&as=" + as : ""))
|
||||||
return new Promise<AxiosResponse<pond.ListComponentsResponse>>((resolve, reject) => {
|
return new Promise<AxiosResponse<pond.ListComponentsResponse>>((resolve, reject) => {
|
||||||
get<pond.ListComponentsResponse>(url).then(resp => {
|
get<pond.ListComponentsResponse>(url).then(resp => {
|
||||||
|
|
@ -308,7 +320,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
demo: boolean = false,
|
demo: boolean = false,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
comprehensive = false
|
comprehensive = false,
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let url = pondURL(
|
let url = pondURL(
|
||||||
"/devices/" +
|
"/devices/" +
|
||||||
|
|
@ -368,84 +381,86 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const listMeasurements = (
|
// const listMeasurements = (
|
||||||
device: number,
|
// device: number,
|
||||||
component: string,
|
// component: string,
|
||||||
startDate: any,
|
// startDate: any,
|
||||||
endDate: any,
|
// endDate: any,
|
||||||
limit: number,
|
// limit: number,
|
||||||
offset: number,
|
// offset: number,
|
||||||
order: string,
|
// order: string,
|
||||||
orderBy: string,
|
// orderBy: string,
|
||||||
demo: boolean = false,
|
// demo: boolean = false,
|
||||||
keys?: string[],
|
// keys?: string[],
|
||||||
types?: string[]
|
// types?: string[],
|
||||||
// exportMeasurements: boolean = false
|
// as?: string
|
||||||
) => {
|
// // exportMeasurements: boolean = false
|
||||||
const url = pondURL(
|
// ) => {
|
||||||
"/devices/" +
|
// const url = pondURL(
|
||||||
device +
|
// "/devices/" +
|
||||||
"/components/" +
|
// device +
|
||||||
component +
|
// "/components/" +
|
||||||
"/measurements" +
|
// component +
|
||||||
//(exportMeasurements ? "/export" : "") +
|
// "/measurements" +
|
||||||
dateRange(startDate, endDate) +
|
// //(exportMeasurements ? "/export" : "") +
|
||||||
"&limit=" +
|
// dateRange(startDate, endDate) +
|
||||||
limit +
|
// "&limit=" +
|
||||||
"&offset=" +
|
// limit +
|
||||||
offset +
|
// "&offset=" +
|
||||||
"&order=" +
|
// offset +
|
||||||
order +
|
// "&order=" +
|
||||||
"&by=" +
|
// order +
|
||||||
orderBy +
|
// "&by=" +
|
||||||
(as ? "&as=" + as : "") +
|
// orderBy +
|
||||||
(keys ? "&keys=" + keys : "&keys=" + [device]) +
|
// (as ? "&as=" + as : "") +
|
||||||
(types ? "&types=" + types : "&types=" + ["device"]),
|
// (keys ? "&keys=" + keys : "&keys=" + [device]) +
|
||||||
demo
|
// (types ? "&types=" + types : "&types=" + ["device"]),
|
||||||
);
|
// demo
|
||||||
return new Promise<AxiosResponse<pond.ListMeasurementsResponse>>((resolve,reject) => {
|
// );
|
||||||
return get<pond.ListMeasurementsResponse>(url).then(resp => {
|
// return new Promise<AxiosResponse<pond.ListMeasurementsResponse>>((resolve,reject) => {
|
||||||
resp.data = pond.ListMeasurementsResponse.fromObject(resp.data)
|
// return get<pond.ListMeasurementsResponse>(url).then(resp => {
|
||||||
return resolve(resp)
|
// resp.data = pond.ListMeasurementsResponse.fromObject(resp.data)
|
||||||
}).catch(err => {
|
// return resolve(resp)
|
||||||
return reject(err)
|
// }).catch(err => {
|
||||||
})
|
// return reject(err)
|
||||||
})
|
// })
|
||||||
};
|
// })
|
||||||
|
// };
|
||||||
|
|
||||||
const sampleMeasurements = (
|
// const sampleMeasurements = (
|
||||||
device: number | string,
|
// device: number | string,
|
||||||
component: string,
|
// component: string,
|
||||||
startDate: any,
|
// startDate: any,
|
||||||
endDate: any,
|
// endDate: any,
|
||||||
sampleSize: number,
|
// sampleSize: number,
|
||||||
demo: boolean = false,
|
// demo: boolean = false,
|
||||||
keys?: string[],
|
// keys?: string[],
|
||||||
types?: string[]
|
// types?: string[],
|
||||||
) => {
|
// as?: string
|
||||||
const url = pondURL(
|
// ) => {
|
||||||
"/devices/" +
|
// const url = pondURL(
|
||||||
device +
|
// "/devices/" +
|
||||||
"/components/" +
|
// device +
|
||||||
component +
|
// "/components/" +
|
||||||
"/measurements/sample" +
|
// component +
|
||||||
dateRange(startDate, endDate) +
|
// "/measurements/sample" +
|
||||||
"&size=" +
|
// dateRange(startDate, endDate) +
|
||||||
sampleSize +
|
// "&size=" +
|
||||||
(as ? "&as=" + as : "") +
|
// sampleSize +
|
||||||
(keys ? "&keys=" + keys : "&keys=" + [device]) +
|
// (as ? "&as=" + as : "") +
|
||||||
(types ? "&types=" + types : "&types=" + ["device"]),
|
// (keys ? "&keys=" + keys : "&keys=" + [device]) +
|
||||||
demo
|
// (types ? "&types=" + types : "&types=" + ["device"]),
|
||||||
);
|
// demo
|
||||||
return new Promise<AxiosResponse<pond.SampleMeasurementsResponse>>((resolve, reject) => {
|
// );
|
||||||
get<pond.SampleMeasurementsResponse>(url).then(resp => {
|
// return new Promise<AxiosResponse<pond.SampleMeasurementsResponse>>((resolve, reject) => {
|
||||||
resp.data = pond.SampleMeasurementsResponse.fromObject(resp.data)
|
// get<pond.SampleMeasurementsResponse>(url).then(resp => {
|
||||||
return resolve(resp)
|
// resp.data = pond.SampleMeasurementsResponse.fromObject(resp.data)
|
||||||
}).catch(err => {
|
// return resolve(resp)
|
||||||
return reject(err)
|
// }).catch(err => {
|
||||||
})
|
// return reject(err)
|
||||||
})
|
// })
|
||||||
};
|
// })
|
||||||
|
// };
|
||||||
|
|
||||||
const sampleUnitMeasurements = (
|
const sampleUnitMeasurements = (
|
||||||
device: number | string,
|
device: number | string,
|
||||||
|
|
@ -456,7 +471,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
demo: boolean = false,
|
demo: boolean = false,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
showErrors: boolean = true
|
showErrors: boolean = true,
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
const url = pondURL(
|
const url = pondURL(
|
||||||
"/devices/" +
|
"/devices/" +
|
||||||
|
|
@ -519,7 +535,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
measurementType?: number | quack.MeasurementType,
|
measurementType?: number | quack.MeasurementType,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
showErrors?: boolean
|
showErrors?: boolean,
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
const url = pondURL(
|
const url = pondURL(
|
||||||
"/devices/" +
|
"/devices/" +
|
||||||
|
|
@ -563,8 +580,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||||
listForObject: listComponentsForObject,
|
listForObject: listComponentsForObject,
|
||||||
listComponentCardData: listComponentCardData,
|
listComponentCardData: listComponentCardData,
|
||||||
listHistory,
|
listHistory,
|
||||||
listMeasurements: listMeasurements,
|
//listMeasurements: listMeasurements,
|
||||||
sampleMeasurements: sampleMeasurements,
|
//sampleMeasurements: sampleMeasurements,
|
||||||
sampleUnitMeasurements,
|
sampleUnitMeasurements,
|
||||||
updateComponentPreferences: updateComponentPreferences,
|
updateComponentPreferences: updateComponentPreferences,
|
||||||
listUnitMeasurements
|
listUnitMeasurements
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { useHTTP, usePermissionAPI } from "hooks";
|
import { useHTTP, usePermissionAPI } from "hooks";
|
||||||
// import { useWebsocket } from "websocket";
|
// import { useWebsocket } from "websocket";
|
||||||
import { /*Component,*/ Component, deviceScope, User } from "models";
|
import { /*Component,*/ Component, deviceScope, Team, User } from "models";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { createContext, PropsWithChildren, useContext } from "react";
|
import { createContext, PropsWithChildren, useContext } from "react";
|
||||||
import { pondURL } from "./pond";
|
import { pondURL } from "./pond";
|
||||||
|
|
@ -12,18 +12,19 @@ import { dateRange } from "providers/http";
|
||||||
// import { reject, result } from "lodash";
|
// import { reject, result } from "lodash";
|
||||||
|
|
||||||
export interface IDeviceAPIContext {
|
export interface IDeviceAPIContext {
|
||||||
add: (name: string, description: string, backpack: pond.BackpackSettings) => Promise<AxiosResponse<pond.AddDeviceResponse>>;
|
add: (name: string, description: string, backpack: pond.BackpackSettings, as?: string) => Promise<AxiosResponse<pond.AddDeviceResponse>>;
|
||||||
update: (id: number, settings: pond.DeviceSettings) => Promise<AxiosResponse<pond.UpdateDeviceResponse>>;
|
update: (id: number, settings: pond.DeviceSettings, as?: string) => Promise<AxiosResponse<pond.UpdateDeviceResponse>>;
|
||||||
remove: (id: number) => Promise<AxiosResponse<pond.RemoveDeviceResponse>>;
|
remove: (id: number, as?: string) => Promise<AxiosResponse<pond.RemoveDeviceResponse>>;
|
||||||
get: (id: number | string, demo?: boolean, keys?: string[], types?: string[]) => Promise<AxiosResponse<pond.Device>>
|
get: (id: number | string, demo?: boolean, keys?: string[], types?: string[], as?: string) => Promise<AxiosResponse<pond.Device>>
|
||||||
getPageData: (
|
getPageData: (
|
||||||
id: number | string,
|
id: number | string,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.GetDevicePageDataResponse>>;
|
) => Promise<AxiosResponse<pond.GetDevicePageDataResponse>>;
|
||||||
getMulti: (ids: number[] | string[]) => Promise<AxiosResponse<pond.GetMultiDeviceResponse>>;
|
getMulti: (ids: number[] | string[], as?: string) => Promise<AxiosResponse<pond.GetMultiDeviceResponse>>;
|
||||||
getGeoJson: (id: number | string, demo?: boolean) => Promise<any>;
|
getGeoJson: (id: number | string, demo?: boolean, as?: string) => Promise<any>;
|
||||||
getMultiGeoJson: (ids: number[] | string[]) => Promise<any>;
|
getMultiGeoJson: (ids: number[] | string[], as?: string) => Promise<any>;
|
||||||
list: (
|
list: (
|
||||||
limit: number,
|
limit: number,
|
||||||
offset: number,
|
offset: number,
|
||||||
|
|
@ -40,6 +41,7 @@ export interface IDeviceAPIContext {
|
||||||
types?: string[],
|
types?: string[],
|
||||||
fieldContains?: Map<string, string>,
|
fieldContains?: Map<string, string>,
|
||||||
prefixSearch?: string,
|
prefixSearch?: string,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.ListDevicesResponse>>;
|
) => Promise<AxiosResponse<pond.ListDevicesResponse>>;
|
||||||
listForUser: (
|
listForUser: (
|
||||||
asRoot: boolean,
|
asRoot: boolean,
|
||||||
|
|
@ -62,19 +64,22 @@ export interface IDeviceAPIContext {
|
||||||
id: number | string,
|
id: number | string,
|
||||||
preferences: pond.DevicePreferences,
|
preferences: pond.DevicePreferences,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => Promise<any>;
|
) => Promise<any>;
|
||||||
updateComponentPreferences: (
|
updateComponentPreferences: (
|
||||||
id: number | string,
|
id: number | string,
|
||||||
component: string,
|
component: string,
|
||||||
preferences: pond.DeviceComponentPreferences,
|
preferences: pond.DeviceComponentPreferences,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.UpdateDeviceComponentPreferencesResponse>>;
|
) => Promise<AxiosResponse<pond.UpdateDeviceComponentPreferencesResponse>>;
|
||||||
listDeviceComponentPreferences: (
|
listDeviceComponentPreferences: (
|
||||||
id: number | string,
|
id: number | string,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.ListDeviceComponentPreferencesResponse>>;
|
) => Promise<AxiosResponse<pond.ListDeviceComponentPreferencesResponse>>;
|
||||||
updateStatus: (
|
updateStatus: (
|
||||||
id: number | string,
|
id: number | string,
|
||||||
|
|
@ -94,7 +99,7 @@ export interface IDeviceAPIContext {
|
||||||
newCap: number
|
newCap: number
|
||||||
) => Promise<AxiosResponse<pond.BulkChangeDataCapsResponse>>;
|
) => Promise<AxiosResponse<pond.BulkChangeDataCapsResponse>>;
|
||||||
resume: (id: number) => Promise<any>;
|
resume: (id: number) => Promise<any>;
|
||||||
getUpgradeStatus: (id: number, keys?: string[], types?: string[]) => Promise<any>;
|
getUpgradeStatus: (id: number, keys?: string[], types?: string[], as?: string) => Promise<any>;
|
||||||
loadBackpack: (id: number, backpack: number) => Promise<any>;
|
loadBackpack: (id: number, backpack: number) => Promise<any>;
|
||||||
setTags: (id: number, tags: string[]) => Promise<any>;
|
setTags: (id: number, tags: string[]) => Promise<any>;
|
||||||
setWifi: (
|
setWifi: (
|
||||||
|
|
@ -102,7 +107,8 @@ export interface IDeviceAPIContext {
|
||||||
gateway: string,
|
gateway: string,
|
||||||
password: string,
|
password: string,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => Promise<any>;
|
) => Promise<any>;
|
||||||
statistics: (
|
statistics: (
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
|
|
@ -122,7 +128,8 @@ export interface IDeviceAPIContext {
|
||||||
limit: number,
|
limit: number,
|
||||||
offset: number,
|
offset: number,
|
||||||
order: string,
|
order: string,
|
||||||
orderBy: string
|
orderBy: string,
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.ListDeviceExportedMeasurementsResponse>>;
|
) => Promise<AxiosResponse<pond.ListDeviceExportedMeasurementsResponse>>;
|
||||||
listSimpleJSON: (device: number) => Promise<any>;
|
listSimpleJSON: (device: number) => Promise<any>;
|
||||||
resetQuackCount: (id: number) => Promise<any>;
|
resetQuackCount: (id: number) => Promise<any>;
|
||||||
|
|
@ -150,9 +157,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
const { children } = props;
|
const { children } = props;
|
||||||
const { get, post, put, del } = useHTTP();
|
const { get, post, put, del } = useHTTP();
|
||||||
const permissionAPI = usePermissionAPI();
|
const permissionAPI = usePermissionAPI();
|
||||||
const [{ as, team }] = useGlobalState();
|
//const [{ as, team }] = useGlobalState();
|
||||||
|
|
||||||
const add = (name: string, description: string, backpack: pond.BackpackSettings) => {
|
const add = (name: string, description: string, backpack: pond.BackpackSettings, as?: string) => {
|
||||||
let url = pondURL("/devices")
|
let url = pondURL("/devices")
|
||||||
if (as) url = pondURL("/devices?as=" + as)
|
if (as) url = pondURL("/devices?as=" + as)
|
||||||
return new Promise<AxiosResponse<pond.AddDeviceResponse>>((resolve, reject) => {
|
return new Promise<AxiosResponse<pond.AddDeviceResponse>>((resolve, reject) => {
|
||||||
|
|
@ -169,7 +176,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
id: number | string,
|
id: number | string,
|
||||||
demo: boolean = false,
|
demo: boolean = false,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let url = pondURL(
|
let url = pondURL(
|
||||||
"/devices/" +
|
"/devices/" +
|
||||||
|
|
@ -222,7 +230,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
const getDevicePageData = (
|
const getDevicePageData = (
|
||||||
id: number | string,
|
id: number | string,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
): Promise<AxiosResponse<pond.GetDevicePageDataResponse>> => {
|
): Promise<AxiosResponse<pond.GetDevicePageDataResponse>> => {
|
||||||
let url = pondURL(
|
let url = pondURL(
|
||||||
"/devicePageData/" +
|
"/devicePageData/" +
|
||||||
|
|
@ -250,7 +259,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const getDeviceGeoJSON = (id: number | string, demo: boolean = false) => {
|
const getDeviceGeoJSON = (id: number | string, demo: boolean = false, as?: string) => {
|
||||||
let url = pondURL("/devices/" + id + "/geojson", demo);
|
let url = pondURL("/devices/" + id + "/geojson", demo);
|
||||||
if (as) url = pondURL("/devices/" + id + "/geojson?as=" + as, demo)
|
if (as) url = pondURL("/devices/" + id + "/geojson?as=" + as, demo)
|
||||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||||
|
|
@ -262,7 +271,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMulti = (ids: number[] | string[]) => {
|
const getMulti = (ids: number[] | string[], as?: string) => {
|
||||||
let idString = "";
|
let idString = "";
|
||||||
ids.forEach((id: number | string, i: number) => {
|
ids.forEach((id: number | string, i: number) => {
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
|
|
@ -282,7 +291,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const getMultiDevicesGeoJSON = (ids: number[] | string[]) => {
|
const getMultiDevicesGeoJSON = (ids: number[] | string[], as?: string) => {
|
||||||
let idString = "";
|
let idString = "";
|
||||||
ids.forEach((id: number | string, i: number) => {
|
ids.forEach((id: number | string, i: number) => {
|
||||||
if (i === 0) {
|
if (i === 0) {
|
||||||
|
|
@ -317,6 +326,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
types?: string[],
|
types?: string[],
|
||||||
fieldContains?: Map<string, string>,
|
fieldContains?: Map<string, string>,
|
||||||
prefixSearch?: string,
|
prefixSearch?: string,
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
const url = pondURL(
|
const url = pondURL(
|
||||||
"/devices" +
|
"/devices" +
|
||||||
|
|
@ -375,7 +385,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const remove = (id: number) => {
|
const remove = (id: number, as?: string) => {
|
||||||
const url = pondURL("/devices/" + id + (as ? "?as=" + as : ""))
|
const url = pondURL("/devices/" + id + (as ? "?as=" + as : ""))
|
||||||
return new Promise<AxiosResponse<pond.RemoveDeviceResponse>>((resolve, reject) => {
|
return new Promise<AxiosResponse<pond.RemoveDeviceResponse>>((resolve, reject) => {
|
||||||
del<pond.RemoveDeviceResponse>(url).then(resp => {
|
del<pond.RemoveDeviceResponse>(url).then(resp => {
|
||||||
|
|
@ -387,7 +397,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const update = (id: number, settings: pond.DeviceSettings) => {
|
const update = (id: number, settings: pond.DeviceSettings, as?: string) => {
|
||||||
const url = pondURL("/devices/" + id + "/update" + (as ? "?as=" + as : ""));
|
const url = pondURL("/devices/" + id + "/update" + (as ? "?as=" + as : ""));
|
||||||
return new Promise<AxiosResponse<pond.UpdateDeviceResponse>>((resolve, reject) => {
|
return new Promise<AxiosResponse<pond.UpdateDeviceResponse>>((resolve, reject) => {
|
||||||
put<pond.UpdateDeviceResponse>(url, settings).then(resp => {
|
put<pond.UpdateDeviceResponse>(url, settings).then(resp => {
|
||||||
|
|
@ -452,7 +462,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
id: number | string,
|
id: number | string,
|
||||||
preferences: pond.DevicePreferences,
|
preferences: pond.DevicePreferences,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let url = pondURL(
|
let url = pondURL(
|
||||||
"/devices/" +
|
"/devices/" +
|
||||||
|
|
@ -477,7 +488,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
component: string,
|
component: string,
|
||||||
preferences: pond.DeviceComponentPreferences,
|
preferences: pond.DeviceComponentPreferences,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let url = pondURL(
|
let url = pondURL(
|
||||||
"/devices/" +
|
"/devices/" +
|
||||||
|
|
@ -503,7 +515,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
const listDeviceComponentPreferences = (
|
const listDeviceComponentPreferences = (
|
||||||
id: number | string,
|
id: number | string,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let url = pondURL(
|
let url = pondURL(
|
||||||
"/devices/" +
|
"/devices/" +
|
||||||
|
|
@ -535,7 +548,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
id: number | string,
|
id: number | string,
|
||||||
status: pond.DeviceStatus,
|
status: pond.DeviceStatus,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let url = pondURL(
|
let url = pondURL(
|
||||||
"/devices/" +
|
"/devices/" +
|
||||||
|
|
@ -626,7 +640,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
const getUpgradeStatus = (id: number, keys?: string[], types?: string[]) => {
|
const getUpgradeStatus = (id: number, keys?: string[], types?: string[], as?: string) => {
|
||||||
let a = as ? "?as=" + as : "";
|
let a = as ? "?as=" + as : "";
|
||||||
if (keys && keys.length > 0 && types && types.length > 0) {
|
if (keys && keys.length > 0 && types && types.length > 0) {
|
||||||
a = as ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types;
|
a = as ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types;
|
||||||
|
|
@ -666,7 +680,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
gateway: string,
|
gateway: string,
|
||||||
password: string,
|
password: string,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let a = as ? "?as=" + as : "";
|
let a = as ? "?as=" + as : "";
|
||||||
if (keys && keys.length > 0 && types && types.length > 0) {
|
if (keys && keys.length > 0 && types && types.length > 0) {
|
||||||
|
|
@ -764,7 +779,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
limit: number,
|
limit: number,
|
||||||
offset: number,
|
offset: number,
|
||||||
order: string,
|
order: string,
|
||||||
orderBy: string
|
orderBy: string,
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let keyString = "";
|
let keyString = "";
|
||||||
components.forEach((comp, i) => {
|
components.forEach((comp, i) => {
|
||||||
|
|
@ -875,10 +891,12 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
MB: number,
|
MB: number,
|
||||||
source?: string,
|
source?: string,
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[]
|
types?: string[],
|
||||||
|
as?: string,
|
||||||
|
team?: Team
|
||||||
) => {
|
) => {
|
||||||
let url = "/devices/" + id + "/buyData?MB=" + MB;
|
let url = "/devices/" + id + "/buyData?MB=" + MB;
|
||||||
if (as === team.key()) url = url + "&team=" + team.key();
|
if (as === team?.key()) url = url + "&team=" + team?.key();
|
||||||
if (source) url = url + "&source=" + source;
|
if (source) url = url + "&source=" + source;
|
||||||
if (keys) url = url + "&keys=" + keys;
|
if (keys) url = url + "&keys=" + keys;
|
||||||
if (types) url = url + "&types=" + types;
|
if (types) url = url + "&types=" + types;
|
||||||
|
|
@ -936,7 +954,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
||||||
getDataUsage,
|
getDataUsage,
|
||||||
buyData,
|
buyData,
|
||||||
updateComponentPreferences,
|
updateComponentPreferences,
|
||||||
listDeviceComponentPreferences
|
listDeviceComponentPreferences//as
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</DeviceAPIContext.Provider>
|
</DeviceAPIContext.Provider>
|
||||||
|
|
|
||||||
|
|
@ -47,7 +47,7 @@ interface Props {
|
||||||
const REQUEST_LIMIT = 25;
|
const REQUEST_LIMIT = 25;
|
||||||
|
|
||||||
export default function AccessObject(props: Props) {
|
export default function AccessObject(props: Props) {
|
||||||
const [{ user }, dispatch] = useGlobalState();
|
const [{ user, as }, dispatch] = useGlobalState();
|
||||||
// const history = useHistory();
|
// const history = useHistory();
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
const isMobile = useMobile();
|
const isMobile = useMobile();
|
||||||
|
|
@ -152,7 +152,14 @@ export default function AccessObject(props: Props) {
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
true
|
true,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
as
|
||||||
)
|
)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
let rDevicesOffset: number = response.data.nextOffset ? response.data.nextOffset : 0;
|
let rDevicesOffset: number = response.data.nextOffset ? response.data.nextOffset : 0;
|
||||||
|
|
@ -170,7 +177,7 @@ export default function AccessObject(props: Props) {
|
||||||
setDevicesTotal(0);
|
setDevicesTotal(0);
|
||||||
})
|
})
|
||||||
.finally(() => setLoading(false));
|
.finally(() => setLoading(false));
|
||||||
}, [deviceAPI, groupAPI, teamAPI, kind, searchValue]);
|
}, [deviceAPI, groupAPI, teamAPI, kind, searchValue, as]);
|
||||||
|
|
||||||
const loadMoreDevices = useCallback(() => {
|
const loadMoreDevices = useCallback(() => {
|
||||||
deviceAPI
|
deviceAPI
|
||||||
|
|
@ -183,7 +190,14 @@ export default function AccessObject(props: Props) {
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
true
|
true,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
as
|
||||||
)
|
)
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
let rDevicesOffset: number = response.data.nextOffset ? response.data.nextOffset : 0;
|
let rDevicesOffset: number = response.data.nextOffset ? response.data.nextOffset : 0;
|
||||||
|
|
@ -200,7 +214,7 @@ export default function AccessObject(props: Props) {
|
||||||
setDevicesOffset(0);
|
setDevicesOffset(0);
|
||||||
setDevicesTotal(0);
|
setDevicesTotal(0);
|
||||||
});
|
});
|
||||||
}, [deviceAPI, devicesOffset, searchValue, devices]);
|
}, [deviceAPI, devicesOffset, searchValue, devices, as]);
|
||||||
|
|
||||||
const loadMoreGroups = useCallback(() => {
|
const loadMoreGroups = useCallback(() => {
|
||||||
groupAPI
|
groupAPI
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ export default function ComponentCards(props: Props) {
|
||||||
t.push("device");
|
t.push("device");
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
componentAPI
|
componentAPI
|
||||||
.list(deviceId, false, k, t, true)
|
.list(deviceId, false, k, t, true, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
if (loading) return;
|
if (loading) return;
|
||||||
if (!resp.data.components) return;
|
if (!resp.data.components) return;
|
||||||
|
|
@ -342,7 +342,7 @@ export default function ComponentCards(props: Props) {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [deviceId, componentAPI, showMobile, keys, types]);
|
}, [deviceId, componentAPI, showMobile, keys, types, as]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Grid container direction="row" justifyContent="flex-start" spacing={2}>
|
<Grid container direction="row" justifyContent="flex-start" spacing={2}>
|
||||||
|
|
|
||||||
|
|
@ -126,13 +126,13 @@ export default function DeviceDrawer(props: Props) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
deviceAPI.list(limit, offset).then(resp => {
|
deviceAPI.list(limit, offset, undefined, undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,as).then(resp => {
|
||||||
setDevices(resp.data.devices);
|
setDevices(resp.data.devices);
|
||||||
setTotal(resp.data.total);
|
setTotal(resp.data.total);
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
});
|
});
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||||
}, [limit, offset, deviceAPI]);
|
}, [limit, offset, deviceAPI, as]);
|
||||||
|
|
||||||
const back = () => {
|
const back = () => {
|
||||||
if (offset - limit < 0) {
|
if (offset - limit < 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue