update to mine api for as to be passed in to the functions
This commit is contained in:
parent
022837de87
commit
9b9f4cdf63
9 changed files with 50 additions and 34 deletions
|
|
@ -13,6 +13,7 @@ import { LibraryAdd } from "@mui/icons-material";
|
|||
import ResponsiveTable, { Column } from "common/ResponsiveTable";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { or } from "utils";
|
||||
import { useGlobalState } from "providers";
|
||||
|
||||
interface MineRow {
|
||||
mine: pond.Mine;
|
||||
|
|
@ -44,11 +45,12 @@ export default function Mines() {
|
|||
const [pageSize, setPageSize] = useState(10);
|
||||
const [mineDialog, setMineDialog] = useState(false);
|
||||
const [searchValue, setSearchValue] = useState("");
|
||||
const [{as}] = useGlobalState();
|
||||
|
||||
const load = useCallback(() => {
|
||||
setIsLoading(true);
|
||||
mineAPI
|
||||
.listMines(pageSize, pageSize * page, "desc", undefined, searchValue, false)
|
||||
.listMines(pageSize, pageSize * page, "desc", undefined, searchValue, false, as)
|
||||
.then(resp => {
|
||||
let mineData: MineRow[] = [];
|
||||
resp.data.mines.forEach(mine => {
|
||||
|
|
@ -62,7 +64,7 @@ export default function Mines() {
|
|||
.finally(() => {
|
||||
setIsLoading(false);
|
||||
});
|
||||
}, [pageSize, page, mineAPI, setIsLoading, searchValue]);
|
||||
}, [pageSize, page, mineAPI, setIsLoading, searchValue, as]);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import { useMineAPI } from "hooks";
|
|||
import { Sensor } from "ventilation/drawable/Sensor";
|
||||
import { useParams } from "react-router-dom";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
import { useGlobalState } from "providers";
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => {
|
||||
return ({
|
||||
|
|
@ -78,6 +79,7 @@ export default function Ventilation() {
|
|||
>(new Map());
|
||||
const [sensors, setSensors] = useState<Sensor[]>([]);
|
||||
const [componentDevices, setComponentDevices] = useState<Map<string, number>>(new Map());
|
||||
const [{as}] = useGlobalState();
|
||||
|
||||
const handleResize = (node: any) => {
|
||||
setHeight(node.getBoundingClientRect().height);
|
||||
|
|
@ -96,7 +98,7 @@ export default function Ventilation() {
|
|||
if (!mineKey) return;
|
||||
setLoading(true);
|
||||
mineAPI
|
||||
.getMine(mineKey)
|
||||
.getMine(mineKey, as)
|
||||
.then((resp: { data: pond.IGetMineResponse | undefined; }) => {
|
||||
if (resp.data && resp.data.mine && resp.data.mine.settings) {
|
||||
let data = pond.GetMineResponse.create(resp.data);
|
||||
|
|
|
|||
|
|
@ -7,14 +7,15 @@ import { createContext, PropsWithChildren, useContext } from "react";
|
|||
import { pondURL } from "./pond";
|
||||
|
||||
export interface IMineAPIContext {
|
||||
addMine: (mine: pond.MineSettings) => Promise<AxiosResponse<pond.AddMineResponse>>;
|
||||
getMine: (key: string) => Promise<AxiosResponse<pond.GetMineResponse>>;
|
||||
addDevice: (key: string, deviceID: string, permissions: pond.Permission[]) => Promise<any>;
|
||||
addMine: (mine: pond.MineSettings, as?: string) => Promise<AxiosResponse<pond.AddMineResponse>>;
|
||||
getMine: (key: string, as?: string) => Promise<AxiosResponse<pond.GetMineResponse>>;
|
||||
addDevice: (key: string, deviceID: string, permissions: pond.Permission[], as?: string) => Promise<any>;
|
||||
addComponent: (
|
||||
key: string,
|
||||
deviceID: string,
|
||||
componentKey: string,
|
||||
permissions: pond.Permission[]
|
||||
permissions: pond.Permission[],
|
||||
as?: string
|
||||
) => Promise<any>;
|
||||
listMines: (
|
||||
limit: number,
|
||||
|
|
@ -22,7 +23,8 @@ export interface IMineAPIContext {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListMinesResponse>>;
|
||||
listMinesSimple: (
|
||||
limit: number,
|
||||
|
|
@ -30,9 +32,10 @@ export interface IMineAPIContext {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListMinesSimpleResponse>>;
|
||||
removeMine: (key: string) => Promise<AxiosResponse<pond.RemoveMineResponse>>;
|
||||
removeMine: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveMineResponse>>;
|
||||
updateMine: (
|
||||
mine: pond.MineSettings,
|
||||
componentPreferences: Map<string, pond.MineComponentPreferences>
|
||||
|
|
@ -46,13 +49,13 @@ interface Props {}
|
|||
export default function MineProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
const [{ as }] = useGlobalState();
|
||||
//const [{ as }] = useGlobalState();
|
||||
|
||||
const addMine = (mine: pond.MineSettings) => {
|
||||
const addMine = (mine: pond.MineSettings, as?: string) => {
|
||||
return post<pond.AddMineResponse>(pondURL("/mines" + (as ? "?as=" + as : "")), mine);
|
||||
};
|
||||
|
||||
const getMine = (key: string) => {
|
||||
const getMine = (key: string, as?: string) => {
|
||||
return get<pond.GetMineResponse>(pondURL("/mines/" + key + (as ? "?as=" + as : "")));
|
||||
};
|
||||
|
||||
|
|
@ -64,7 +67,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
search?: string,
|
||||
asRoot?: boolean,
|
||||
keys?: string,
|
||||
types?: string
|
||||
types?: string,
|
||||
as?: string
|
||||
) => {
|
||||
const url = pondURL(
|
||||
"/mines" +
|
||||
|
|
@ -89,7 +93,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
) => {
|
||||
const url = pondURL(
|
||||
"/minesSimple" +
|
||||
|
|
@ -106,7 +111,7 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
return get<pond.ListMinesSimpleResponse>(url);
|
||||
};
|
||||
|
||||
const removeMine = (key: string) => {
|
||||
const removeMine = (key: string, as?: string) => {
|
||||
return del<pond.RemoveMineResponse>(pondURL("/mines/" + key + (as ? "?as=" + as : "")));
|
||||
};
|
||||
|
||||
|
|
@ -127,7 +132,7 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
return put<pond.AddMineResponse>(pondURL("/mines"), request);
|
||||
};
|
||||
|
||||
const addDevice = (key: string, deviceID: string, permissions: pond.Permission[]) => {
|
||||
const addDevice = (key: string, deviceID: string, permissions: pond.Permission[], as?: string) => {
|
||||
if (as)
|
||||
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID + `?as=${as}`), {
|
||||
permissions: permissions.map(permission => permissionToString(permission))
|
||||
|
|
@ -141,7 +146,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
key: string,
|
||||
deviceID: string,
|
||||
componentKey: string,
|
||||
permissions: pond.Permission[]
|
||||
permissions: pond.Permission[],
|
||||
as?: string
|
||||
) => {
|
||||
if (as)
|
||||
return post(
|
||||
|
|
@ -163,8 +169,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
addDevice,
|
||||
addComponent,
|
||||
listMines,
|
||||
listMinesSimple,
|
||||
removeMine,
|
||||
listMinesSimple,//
|
||||
removeMine,//
|
||||
updateMine
|
||||
}}>
|
||||
{children}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import {
|
|||
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||
import { useMineAPI } from "hooks";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useGlobalState } from "providers";
|
||||
import { useState } from "react";
|
||||
|
||||
interface Props {
|
||||
|
|
@ -20,11 +21,12 @@ export default function AddMine(props: Props) {
|
|||
const { open, closeCallback, refreshCallback } = props;
|
||||
const [name, setName] = useState("");
|
||||
const mineAPI = useMineAPI();
|
||||
const [{as}] = useGlobalState();
|
||||
|
||||
const addMine = () => {
|
||||
let newMine = pond.MineSettings.create();
|
||||
newMine.name = name;
|
||||
mineAPI.addMine(newMine).finally(() => {
|
||||
mineAPI.addMine(newMine, as).finally(() => {
|
||||
closeCallback();
|
||||
refreshCallback();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -111,14 +111,14 @@ export default function Editor(props: Props) {
|
|||
undefined | Map<string, UnitMeasurement[]>
|
||||
>(undefined);
|
||||
|
||||
const [{ user }] = useGlobalState();
|
||||
const [{ user, as }] = useGlobalState();
|
||||
|
||||
const save = () => {
|
||||
let settings = pond.MineSettings.create();
|
||||
props.devices.forEach(device => {
|
||||
if (device.settings) settings.devices.push(device.settings?.deviceId);
|
||||
});
|
||||
mineAPI.addMine(settings).then((resp: any) => {
|
||||
mineAPI.addMine(settings, as).then((resp: any) => {
|
||||
console.log(resp);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import CursorIcon from "assets/editor/cursor.png";
|
|||
import DeleteIcon from "assets/editor/delete.png";
|
||||
import { ImgIcon } from "common/ImgIcon";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useMineAPI, useSnackbar } from "providers";
|
||||
import { useGlobalState, useMineAPI, useSnackbar } from "providers";
|
||||
import { Save, CloudDownload } from "@mui/icons-material";
|
||||
import { Placeable } from "./drawable/Placeable";
|
||||
import { Component } from "models";
|
||||
|
|
@ -107,6 +107,7 @@ export default function EditorHeader(props: Props) {
|
|||
const snackbar = useSnackbar();
|
||||
const theme = useTheme();
|
||||
const [loadDialog, setLoadDialog] = useState(false);
|
||||
const [{as}] = useGlobalState();
|
||||
|
||||
const save = () => {
|
||||
let settings = pond.MineSettings.create();
|
||||
|
|
@ -141,7 +142,7 @@ export default function EditorHeader(props: Props) {
|
|||
});
|
||||
} else {
|
||||
mineAPI
|
||||
.addMine(settings)
|
||||
.addMine(settings, as)
|
||||
.then(resp => {
|
||||
if (resp.status === 200) {
|
||||
snackbar.success("New mine successfully saved!");
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import {
|
|||
Typography
|
||||
} from "@mui/material";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useMineAPI, useSnackbar } from "providers";
|
||||
import { useGlobalState, useMineAPI, useSnackbar } from "providers";
|
||||
import React, { useEffect, useState } from "react";
|
||||
import { or } from "utils";
|
||||
import { loadPlaceable, Placeable } from "./drawable/Placeable";
|
||||
|
|
@ -80,11 +80,12 @@ export default function LoadMine(props: Props) {
|
|||
const [offset, setOffset] = useState(0);
|
||||
const classes = useStyles();
|
||||
const isMobile = useMobile();
|
||||
const [{as}] = useGlobalState();
|
||||
|
||||
const load = (key: string) => {
|
||||
setLoading(true);
|
||||
mineAPI
|
||||
.getMine(key)
|
||||
.getMine(key, as)
|
||||
.then(resp => {
|
||||
let newBlocks: Placeable[] = [];
|
||||
if (resp.data.mine?.settings?.placeables)
|
||||
|
|
@ -117,13 +118,13 @@ export default function LoadMine(props: Props) {
|
|||
useEffect(() => {
|
||||
if (open) {
|
||||
setLoading(true);
|
||||
mineAPI.listMinesSimple(limit, offset).then(resp => {
|
||||
mineAPI.listMinesSimple(limit, offset, undefined, undefined, undefined, false, as).then(resp => {
|
||||
setMines(resp.data.mines);
|
||||
setLoading(false);
|
||||
setTotal(resp.data.total);
|
||||
});
|
||||
}
|
||||
}, [mineAPI, open, limit, offset]);
|
||||
}, [mineAPI, open, limit, offset, as]);
|
||||
|
||||
const back = () => {
|
||||
if (offset - limit < 0) {
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ export default function ComponentCards(props: Props) {
|
|||
const [firstLoad, setFirstLoad] = useState(true);
|
||||
const themeType = useThemeType();
|
||||
const classes = useStyles();
|
||||
const [{ user }] = useGlobalState();
|
||||
const [{ user, as }] = useGlobalState();
|
||||
const theme = useTheme();
|
||||
const navigate = useNavigate()
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ export default function ComponentCards(props: Props) {
|
|||
types.forEach((type, index) => {
|
||||
if (type === "mine") mine = keys[index];
|
||||
});
|
||||
mineAPI.addComponent(mine, device, component.key(), [pond.Permission.PERMISSION_INVALID]);
|
||||
mineAPI.addComponent(mine, device, component.key(), [pond.Permission.PERMISSION_INVALID], as);
|
||||
};
|
||||
|
||||
const addComponent = (device: string, component: Component) => {
|
||||
|
|
@ -110,7 +110,7 @@ export default function ComponentCards(props: Props) {
|
|||
pond.Permission.PERMISSION_SHARE,
|
||||
pond.Permission.PERMISSION_WRITE,
|
||||
pond.Permission.PERMISSION_USERS
|
||||
])
|
||||
], as)
|
||||
.then(() => {
|
||||
let prefs = getPreferences(component);
|
||||
mineComponentPreferences.set(component.key(), prefs);
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { useDeviceAPI, useMineAPI } from "hooks";
|
|||
import LeftIcon from "@mui/icons-material/KeyboardArrowLeft";
|
||||
import RightIcon from "@mui/icons-material/KeyboardArrowRight";
|
||||
import { makeStyles } from "@mui/styles";
|
||||
import { useGlobalState } from "providers";
|
||||
|
||||
const useStyles = makeStyles((theme: Theme) => {
|
||||
return ({
|
||||
|
|
@ -111,6 +112,7 @@ export default function DeviceDrawer(props: Props) {
|
|||
const deviceAPI = useDeviceAPI();
|
||||
const mineAPI = useMineAPI();
|
||||
const [tab, setTab] = React.useState(0);
|
||||
const [{as}] = useGlobalState();
|
||||
|
||||
useEffect(() => {
|
||||
let ids: number[] = [];
|
||||
|
|
@ -153,7 +155,7 @@ export default function DeviceDrawer(props: Props) {
|
|||
const index = selectedIDs.indexOf(id);
|
||||
if (index > -1) {
|
||||
if (device.settings && mine.name !== "") {
|
||||
mineAPI.addDevice(mine.key, device.settings.deviceId.toString(), []).then(resp => {
|
||||
mineAPI.addDevice(mine.key, device.settings.deviceId.toString(), [], as).then(resp => {
|
||||
selectedIDs.splice(index, 1);
|
||||
let d = selectedDevices;
|
||||
let deviceIndex = 0;
|
||||
|
|
@ -175,7 +177,7 @@ export default function DeviceDrawer(props: Props) {
|
|||
pond.Permission.PERMISSION_SHARE,
|
||||
pond.Permission.PERMISSION_WRITE,
|
||||
pond.Permission.PERMISSION_USERS
|
||||
])
|
||||
], as)
|
||||
.then(resp => {
|
||||
selectedIDs.push(id);
|
||||
let d = selectedDevices;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue