updated all uses of as in the api files to use the global state as well as a passed in value, will give priority to the passed in value and fall back to the state if it is undefined.
This commit is contained in:
parent
b404c45a4f
commit
59f7f7f4e1
25 changed files with 673 additions and 535 deletions
|
|
@ -344,7 +344,7 @@ export default function BinSettings(props: Props) {
|
|||
setBinYardOptions(y);
|
||||
} else {
|
||||
binYardAPI
|
||||
.listBinYards(350, 0, "desc", as ? as : userID, undefined, undefined, undefined, as)
|
||||
.listBinYards(350, 0, "desc", as ? as : userID, undefined, undefined, as)
|
||||
.then(resp => {
|
||||
let data = resp.data.yard ? resp.data.yard : [];
|
||||
let yards: Option[] = data.map((yard: pond.BinYard) => {
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ export default function GrainTransaction(props: Props) {
|
|||
if (!bagsLoading) {
|
||||
setBagsLoading(true);
|
||||
grainBagAPI
|
||||
.listGrainBags(0, 0, undefined, undefined, undefined, undefined, undefined, undefined, undefined, as)
|
||||
.listGrainBags(0, 0, undefined, undefined, undefined, undefined, undefined, undefined, as)
|
||||
.then(resp => {
|
||||
//let sourceOps: Option[] = sourceOptions
|
||||
let bagOps: Option[] = [];
|
||||
|
|
|
|||
|
|
@ -304,7 +304,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
|||
|
||||
const loadGrainBags = useCallback(() => {
|
||||
grainBagAPI
|
||||
.listGrainBags(100, 0, undefined, undefined, undefined, undefined, undefined, undefined, undefined, as)
|
||||
.listGrainBags(100, 0, undefined, undefined, undefined, undefined, undefined, undefined, as)
|
||||
.then(resp => {
|
||||
let bags: Map<string, BagModel> = new Map();
|
||||
let bagOp: BagModel[] = [];
|
||||
|
|
@ -376,7 +376,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
|||
let yardEntries: Result[] = [];
|
||||
|
||||
binYardAPI
|
||||
.listBinYards(400, 0, "asc", undefined, undefined, undefined, undefined, as)
|
||||
.listBinYards(400, 0, "asc", undefined, undefined, undefined, as)
|
||||
.then(resp => {
|
||||
resp.data.yard.forEach(yard => {
|
||||
if (yard.settings) {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ export default function Contracts() {
|
|||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
year,
|
||||
as
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,9 +10,9 @@ export interface IObjectHeaterAPIContext {
|
|||
addObjectHeater: (
|
||||
name: string,
|
||||
heater: pond.ObjectHeaterSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddObjectHeaterResponse>>;
|
||||
getObjectHeater: (key: string, as?: string) => Promise<AxiosResponse<pond.GetObjectHeaterResponse>>;
|
||||
getObjectHeater: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetObjectHeaterResponse>>;
|
||||
listObjectHeaters: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
|
|
@ -20,17 +20,17 @@ export interface IObjectHeaterAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
numerical?: boolean
|
||||
) => Promise<AxiosResponse<pond.ListObjectHeatersResponse>>;
|
||||
removeObjectHeater: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveObjectHeaterResponse>>;
|
||||
removeObjectHeater: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveObjectHeaterResponse>>;
|
||||
updateObjectHeater: (
|
||||
key: string,
|
||||
name: string,
|
||||
settings: pond.ObjectHeaterSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateObjectHeaterResponse>>;
|
||||
updateLink: (
|
||||
parentKey: string,
|
||||
|
|
@ -38,7 +38,7 @@ export interface IObjectHeaterAPIContext {
|
|||
objectID: string,
|
||||
objectType: string,
|
||||
permissions: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<any>;
|
||||
listObjectHeatersPageData: (
|
||||
limit: number,
|
||||
|
|
@ -46,7 +46,7 @@ export interface IObjectHeaterAPIContext {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => Promise<AxiosResponse<pond.ListObjectHeatersPageDataResponse>>;
|
||||
}
|
||||
|
|
@ -60,27 +60,30 @@ interface Props {}
|
|||
export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addObjectHeater = (name: string, settings: pond.ObjectHeaterSettings, as?: string) => {
|
||||
if (as)
|
||||
const addObjectHeater = (name: string, settings: pond.ObjectHeaterSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post<pond.AddObjectHeaterResponse>(
|
||||
pondURL("/objectHeaters?name=" + name + "&as=" + as),
|
||||
pondURL("/objectHeaters?name=" + name + "&as=" + view),
|
||||
settings
|
||||
);
|
||||
return post<pond.AddObjectHeaterResponse>(pondURL("/objectHeaters?name=" + name), settings);
|
||||
};
|
||||
|
||||
const getObjectHeater = (key: string, as?: string) => {
|
||||
if (as) {
|
||||
return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + as));
|
||||
const getObjectHeater = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + view));
|
||||
}
|
||||
return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key));
|
||||
};
|
||||
|
||||
const removeObjectHeater = (key: string, as?: string) => {
|
||||
if (as)
|
||||
return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + as));
|
||||
const removeObjectHeater = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + view));
|
||||
return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key));
|
||||
};
|
||||
|
||||
|
|
@ -91,11 +94,12 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
numerical?: boolean
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.ListObjectHeatersResponse>(
|
||||
pondURL(
|
||||
"/objectHeaters" +
|
||||
|
|
@ -108,17 +112,18 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
|
|||
(search ? "&search=" + search : "") +
|
||||
(numerical ? "&numerical=true" : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const updateObjectHeater = (key: string, name: string, settings: pond.ObjectHeaterSettings, as?: string) => {
|
||||
if (as) {
|
||||
const updateObjectHeater = (key: string, name: string, settings: pond.ObjectHeaterSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return put<pond.UpdateObjectHeaterResponse>(
|
||||
pondURL("/objectHeaters/" + key + "?as=" + as + "&name=" + name),
|
||||
pondURL("/objectHeaters/" + key + "?as=" + view + "&name=" + name),
|
||||
settings
|
||||
);
|
||||
}
|
||||
|
|
@ -134,10 +139,11 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
|
|||
objectID: string,
|
||||
objectType: string,
|
||||
permissions: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
if (as)
|
||||
return post(pondURL(`/objectHeaters/` + parentID + `/link?as=${as}`), {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post(pondURL(`/objectHeaters/` + parentID + `/link?as=${view}`), {
|
||||
Key: objectID,
|
||||
Type: objectType,
|
||||
Parent: parentID,
|
||||
|
|
@ -159,9 +165,10 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.ListObjectHeatersPageDataResponse>(
|
||||
pondURL(
|
||||
"/objectHeatersWithData" +
|
||||
|
|
@ -171,7 +178,7 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
|
|||
offset +
|
||||
("&order=" + or(order, "asc")) +
|
||||
("&by=" + or(orderBy, "key")) +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(search ? "&search=" + search : "")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -10,43 +10,43 @@ import { useGlobalState } from "providers";
|
|||
import { quack } from "protobuf-ts/quack";
|
||||
|
||||
export interface IBinAPIContext {
|
||||
addBin: (bin: pond.BinSettings, as?: string) => Promise<AxiosResponse<pond.AddBinResponse>>;
|
||||
updateBin: (key: string, bin: pond.BinSettings, as?: string) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
|
||||
bulkBinUpdate: (bins: pond.BinSettings[], as?: string) => Promise<AxiosResponse<pond.BulkBinUpdateResponse>>;
|
||||
addBin: (bin: pond.BinSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddBinResponse>>;
|
||||
updateBin: (key: string, bin: pond.BinSettings, otherTeam?: string) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
|
||||
bulkBinUpdate: (bins: pond.BinSettings[], otherTeam?: string) => Promise<AxiosResponse<pond.BulkBinUpdateResponse>>;
|
||||
updateBinStatus: (
|
||||
key: string,
|
||||
binStatus: pond.BinStatus,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
|
||||
removeBin: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveBinResponse>>;
|
||||
getBin: (key: string, as?: string) => Promise<AxiosResponse<pond.Bin>>;
|
||||
removeBin: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveBinResponse>>;
|
||||
getBin: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.Bin>>;
|
||||
addComponent: (
|
||||
bin: string,
|
||||
device: number,
|
||||
component: string,
|
||||
preferences?: pond.BinComponentPreferences,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddBinComponentResponse>>;
|
||||
removeComponent: (
|
||||
bin: string,
|
||||
component: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.RemoveBinComponentResponse>>;
|
||||
removeAllComponents: (bin: string, as?: string) => Promise<AxiosResponse<pond.RemoveAllBinComponentsResponse>>;
|
||||
removeAllComponents: (bin: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveAllBinComponentsResponse>>;
|
||||
updateComponentPreferences: (
|
||||
bin: string,
|
||||
component: string,
|
||||
preferences: pond.BinComponentPreferences,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateBinComponentPreferencesResponse>>;
|
||||
getBinPageData: (binKey: string, userKey: string, showErrors?: boolean, as?: string) => Promise<AxiosResponse<pond.GetBinPageDataResponse>>;
|
||||
getBinPageData: (binKey: string, userKey: string, showErrors?: boolean, otherTeam?: string) => Promise<AxiosResponse<pond.GetBinPageDataResponse>>;
|
||||
listBins: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean,
|
||||
numerical?: boolean,
|
||||
keys?: string[],
|
||||
|
|
@ -58,7 +58,7 @@ export interface IBinAPIContext {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
|
|
@ -89,13 +89,13 @@ export interface IBinAPIContext {
|
|||
start: string,
|
||||
end: string,
|
||||
showErrors?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListBinComponentsMeasurementsResponse>>;
|
||||
updateBinPermissions: (
|
||||
key: string,
|
||||
users: User[]
|
||||
) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
|
||||
getBinMetrics: (search?: string, as?: string) => Promise<AxiosResponse<pond.GetBinMetricsResponse>>;
|
||||
getBinMetrics: (search?: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetBinMetricsResponse>>;
|
||||
listBinLiters: (
|
||||
key: string,
|
||||
start: string,
|
||||
|
|
@ -105,13 +105,13 @@ export interface IBinAPIContext {
|
|||
cable: string,
|
||||
pressure: string,
|
||||
fan?: string, // the fan controller is optional so that if they don't have one the fan is assumed on
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListBinLiterResponse>>;
|
||||
listBinPrefs: (key: string) => Promise<AxiosResponse<pond.ListBinComponentPreferencesResponse>>;
|
||||
updateTopNodes: (
|
||||
key: string,
|
||||
newTopNodes: pond.NewTopNode[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateTopNodesResponse>>;
|
||||
listBinMeasurements: (
|
||||
key: string,
|
||||
|
|
@ -124,7 +124,7 @@ export interface IBinAPIContext {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
showErrors?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListObjectMeasurementsResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -136,10 +136,11 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
const { children } = props;
|
||||
const { get, post, put, del } = useHTTP();
|
||||
const permissionAPI = usePermissionAPI();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addBin = (bin: pond.BinSettings, as?: string) => {
|
||||
const url = "/bins" + (as ? "?as=" + as : "")
|
||||
const addBin = (bin: pond.BinSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = "/bins" + (view ? "?as=" + view : "")
|
||||
return new Promise<AxiosResponse<pond.AddBinResponse>>((resolve, reject)=>{
|
||||
post<pond.AddBinResponse>(pondURL(url), bin).then(resp => {
|
||||
resp.data = pond.AddBinResponse.fromObject(resp.data)
|
||||
|
|
@ -150,8 +151,9 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const updateBin = (key: string, bin: pond.BinSettings, as?: string) => {
|
||||
const url = "/bins/" + key + (as ? "?as=" + as : "")
|
||||
const updateBin = (key: string, bin: pond.BinSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = "/bins/" + key + (view ? "?as=" + view : "")
|
||||
return new Promise<AxiosResponse<pond.UpdateBinResponse>>((resolve, reject)=>{
|
||||
put<pond.UpdateBinResponse>(pondURL(url), bin).then(resp => {
|
||||
resp.data = pond.UpdateBinResponse.fromObject(resp.data)
|
||||
|
|
@ -162,9 +164,10 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const bulkBinUpdate = (bins: pond.BinSettings[], as?: string) => {
|
||||
const bulkBinUpdate = (bins: pond.BinSettings[], otherTeam?: string) => {
|
||||
let url = "/bulkBins/update"
|
||||
if (as) url = url + "?as=" + as
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) url = url + "?as=" + view
|
||||
return new Promise<AxiosResponse<pond.BulkBinUpdateResponse>>((resolve, reject)=>{
|
||||
put<pond.BulkBinUpdateResponse>(pondURL(url), { bins: bins }).then(resp => {
|
||||
resp.data = pond.BulkBinUpdateResponse.fromObject(resp.data)
|
||||
|
|
@ -175,9 +178,10 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const updateBinStatus = (key: string, binStatus: pond.BinStatus, as?: string) => {
|
||||
const updateBinStatus = (key: string, binStatus: pond.BinStatus, otherTeam?: string) => {
|
||||
let url = "/bins/" + key + "/status"
|
||||
if (as) url = url + "?as=" + as
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) url = url + "?as=" + view
|
||||
return new Promise<AxiosResponse<pond.UpdateBinStatusResponse>>((resolve, reject)=>{
|
||||
put<pond.UpdateBinStatusResponse>(pondURL(url), binStatus).then(resp=>{
|
||||
resp.data = pond.UpdateBinStatusResponse.fromObject(resp.data)
|
||||
|
|
@ -188,9 +192,10 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const removeBin = (key: string, as?: string) => {
|
||||
const removeBin = (key: string, otherTeam?: string) => {
|
||||
let url = "/bins/" + key
|
||||
if (as) url = url + "?as=" + as
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) url = url + "?as=" + view
|
||||
return new Promise<AxiosResponse<pond.RemoveBinResponse>>((resolve, reject) => {
|
||||
del<pond.RemoveBinResponse>(pondURL(url)).then(resp => {
|
||||
resp.data = pond.RemoveBinResponse.fromObject(resp.data)
|
||||
|
|
@ -201,8 +206,9 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getBin = (key: string, as?: string) => {
|
||||
const url = "/bins/" + key + (as ? "?as=" + as : "")
|
||||
const getBin = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = "/bins/" + key + (view ? "?as=" + view : "")
|
||||
return new Promise<AxiosResponse<pond.Bin>>((resolve, reject)=>{
|
||||
get<pond.Bin>(pondURL(url))
|
||||
.then(resp => {
|
||||
|
|
@ -220,14 +226,15 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
device: number,
|
||||
component: string,
|
||||
preferences?: pond.BinComponentPreferences,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = "/bins/" + bin + "/addComponent/" + device + "/" + component;
|
||||
if (as) {
|
||||
if (view) {
|
||||
url =
|
||||
url +
|
||||
"?as=" +
|
||||
as +
|
||||
view +
|
||||
(preferences ? "&binPref=" + preferences.type + "&fillNode=" + preferences.node : "");
|
||||
} else if (preferences) {
|
||||
url = url + "?binPref=" + preferences.type + "&fillNode=" + preferences.node;
|
||||
|
|
@ -242,9 +249,10 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const removeComponent = (bin: string, component: string, as?: string) => {
|
||||
const removeComponent = (bin: string, component: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = "/bins/" + bin + "/removeComponent/" + component;
|
||||
if (as) url = url + "?as=" + as;
|
||||
if (view) url = url + "?as=" + view;
|
||||
return new Promise<AxiosResponse<pond.RemoveBinComponentResponse>>((resolve, reject)=>{
|
||||
post<pond.RemoveBinComponentResponse>(pondURL(url)).then(resp => {
|
||||
resp.data = pond.RemoveBinComponentResponse.fromObject(resp.data)
|
||||
|
|
@ -255,9 +263,10 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const removeAllComponents = (bin: string, as?: string) => {
|
||||
const removeAllComponents = (bin: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = "/bins/" + bin + "/removeAllComponents";
|
||||
if (as) url = url + "?as=" + as;
|
||||
if (view) url = url + "?as=" + view;
|
||||
return new Promise<AxiosResponse<pond.RemoveAllBinComponentsResponse>>((resolve, reject)=>{
|
||||
post<pond.RemoveAllBinComponentsResponse>(pondURL(url)).then(resp => {
|
||||
resp.data = pond.RemoveAllBinComponentsResponse.fromObject(resp.data)
|
||||
|
|
@ -272,10 +281,11 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
bin: string,
|
||||
component: string,
|
||||
preferences: pond.BinComponentPreferences,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = "/bins/" + bin + "/updateComponent/" + component + "/preferences";
|
||||
if (as) url = url + "/?as=" + as;
|
||||
if (view) url = url + "/?as=" + view;
|
||||
interface request {
|
||||
preferences: Object;
|
||||
}
|
||||
|
|
@ -290,13 +300,14 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getBinPageData = (binKey: string, userKey: string, showErrors = true, as?: string) => {
|
||||
const getBinPageData = (binKey: string, userKey: string, showErrors = true, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = "/bins/" +
|
||||
binKey +
|
||||
"/users/" +
|
||||
userKey +
|
||||
(showErrors ? "?showErrors=true" : "?showErrors=false") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
return new Promise<AxiosResponse<pond.GetBinPageDataResponse>>((resolve, reject)=>{
|
||||
get<pond.GetBinPageDataResponse>(pondURL(url))
|
||||
.then(resp => {
|
||||
|
|
@ -315,13 +326,14 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean,
|
||||
numerical?: boolean,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
) => {
|
||||
return new Promise<AxiosResponse<pond.ListBinsResponse>>((resolve, reject)=>{
|
||||
const view = otherTeam ? otherTeam : as
|
||||
get<pond.ListBinsResponse>(
|
||||
pondURL(
|
||||
"/bins" +
|
||||
|
|
@ -332,7 +344,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
("&order=" + or(order, "asc")) +
|
||||
("&by=" + or(orderBy, "key")) +
|
||||
(numerical ? "&numerical=true" : "") +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(search ? "&search=" + search : "") +
|
||||
(keys ? "&keys=" + keys.join(",") : "") +
|
||||
|
|
@ -353,11 +365,12 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = "/binsAndData" +
|
||||
"?limit=" +
|
||||
limit +
|
||||
|
|
@ -365,7 +378,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
offset +
|
||||
("&order=" + or(order, "asc")) +
|
||||
("&by=" + or(orderBy, "key")) +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(search ? "&search=" + search : "") +
|
||||
(keys ? "&keys=" + keys.join(",") : "") +
|
||||
|
|
@ -430,15 +443,16 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
start: string,
|
||||
end: string,
|
||||
showErrors = false,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = "/bins/" +
|
||||
key +
|
||||
"/components/measurements?start=" +
|
||||
start +
|
||||
"&end=" +
|
||||
end +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(showErrors ? "&showErrors=true" : "&showErrors=false")
|
||||
|
||||
return new Promise<AxiosResponse<pond.ListBinComponentsMeasurementsResponse>>((resolve, reject) => {
|
||||
|
|
@ -486,13 +500,14 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
return permissionAPI.updatePermissions(binScope(key.toString()), users);
|
||||
};
|
||||
|
||||
const getBinMetrics = (search?: string, as?: string) => {
|
||||
const getBinMetrics = (search?: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = "/metrics/bins" + (search ? "?search=" + search : "")
|
||||
if (as) {
|
||||
if (view) {
|
||||
if (search){
|
||||
url = "/metrics/bins/?search=" + search + "&as=" + as
|
||||
url = "/metrics/bins/?search=" + search + "&as=" + view
|
||||
}
|
||||
url = "/metrics/bins/?as=" + as;
|
||||
url = "/metrics/bins/?as=" + view;
|
||||
}
|
||||
return new Promise<AxiosResponse<pond.GetBinMetricsResponse>>((resolve, reject)=>{
|
||||
get<pond.GetBinMetricsResponse>(pondURL(url)).then(resp => {
|
||||
|
|
@ -513,8 +528,9 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
cable: string,
|
||||
pressure: string,
|
||||
fan?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = "/bins/" +
|
||||
key +
|
||||
"/liters?start=" +
|
||||
|
|
@ -530,7 +546,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
"&pressure=" +
|
||||
pressure +
|
||||
(fan ? "&fan=" + fan : "") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
|
||||
return new Promise<AxiosResponse<pond.ListBinLiterResponse>>((resolve, reject)=>{
|
||||
get<pond.ListBinLiterResponse>(pondURL(url))
|
||||
|
|
@ -543,8 +559,9 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const listBinPrefs = (key: string, as?: string) => {
|
||||
const url = "/bins/" + key + "/componentPreferences?as=" + as
|
||||
const listBinPrefs = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = "/bins/" + key + "/componentPreferences?as=" + view
|
||||
return new Promise<AxiosResponse<pond.ListBinComponentPreferencesResponse>>((resolve, reject)=>{
|
||||
get<pond.ListBinComponentPreferencesResponse>(pondURL(url))
|
||||
.then(resp => {
|
||||
|
|
@ -556,9 +573,10 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const updateTopNodes = (key: string, newTopNodes: pond.NewTopNode[], as?: string) => {
|
||||
const updateTopNodes = (key: string, newTopNodes: pond.NewTopNode[], otherTeam?: string) => {
|
||||
let body: pond.TopNodeList = pond.TopNodeList.create({ newTopNodes: newTopNodes });
|
||||
let url = "/bins/" + key + "/updateTopNodes" + (as ? "?as=" + as : "")
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = "/bins/" + key + "/updateTopNodes" + (view ? "?as=" + view : "")
|
||||
return new Promise<AxiosResponse<pond.UpdateTopNodesResponse>>((resolve,response) => {
|
||||
post<pond.UpdateTopNodesResponse>(pondURL(url),body).then(resp => {
|
||||
resp.data = pond.UpdateTopNodesResponse.fromObject(resp.data)
|
||||
|
|
@ -580,8 +598,9 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
showErrors?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/objects/" +
|
||||
key +
|
||||
|
|
@ -594,7 +613,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
|
|||
"&order=" +
|
||||
order +
|
||||
(measurementType ? "&type=" + measurementType : "") +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(keys ? "&keys=" + keys : "") +
|
||||
(types ? "&types=" + types : "") +
|
||||
(showErrors ? "&showErrors=true" : "&showErrors=false")
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ import { AxiosResponse } from "axios";
|
|||
import { useGlobalState } from "providers";
|
||||
|
||||
export interface IBinYardAPIContext {
|
||||
addBinYard: (bin: pond.BinYardSettings, as?: string) => Promise<AxiosResponse<pond.AddBinYardResponse>>;
|
||||
addBinYard: (bin: pond.BinYardSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddBinYardResponse>>;
|
||||
updateBinYard: (
|
||||
key: string,
|
||||
binYard: pond.BinYardSettings,
|
||||
asRoot?: true,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateBinYardResponse>>;
|
||||
removeBinYard: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveBinYardResponse>>;
|
||||
getBinYard: (key: string, as?: string) => Promise<AxiosResponse<pond.BinYard>>;
|
||||
removeBinYard: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveBinYardResponse>>;
|
||||
getBinYard: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.BinYard>>;
|
||||
listBinYards: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
|
|
@ -23,8 +23,7 @@ export interface IBinYardAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListBinYardsResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -35,24 +34,26 @@ interface Props {}
|
|||
export default function BinYardProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, post, put, del } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addBinYard = (binYard: pond.BinYardSettings, as?: string) => {
|
||||
if (as) return post<pond.AddBinYardResponse>(pondURL(`/binyard?as=${as}`), binYard);
|
||||
const addBinYard = (binYard: pond.BinYardSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (as) return post<pond.AddBinYardResponse>(pondURL(`/binyard?as=${view}`), binYard);
|
||||
return post<pond.AddBinYardResponse>(pondURL("/binyard"), binYard);
|
||||
};
|
||||
|
||||
const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean, as?: string) => {
|
||||
if (as) {
|
||||
const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
if (asRoot) {
|
||||
return put<pond.UpdateBinYardResponse>(
|
||||
pondURL(
|
||||
"/binyards/" + key + (asRoot ? "?asRoot=" + asRoot.toString() : "") + "&as=" + as
|
||||
"/binyards/" + key + (asRoot ? "?asRoot=" + asRoot.toString() : "") + "&as=" + view
|
||||
),
|
||||
binYard
|
||||
);
|
||||
}
|
||||
return put<pond.UpdateBinYardResponse>(pondURL("/binyards/" + key + "?as=" + as), binYard);
|
||||
return put<pond.UpdateBinYardResponse>(pondURL("/binyards/" + key + "?as=" + view), binYard);
|
||||
}
|
||||
return put<pond.UpdateBinYardResponse>(
|
||||
pondURL("/binyards/" + key + (asRoot ? "?asRoot=" + asRoot.toString() : "")),
|
||||
|
|
@ -60,13 +61,15 @@ export default function BinYardProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const removeBinYard = (key: string, as?: string) => {
|
||||
if (as) return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key + "?as=" + as));
|
||||
const removeBinYard = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key + "?as=" + view));
|
||||
return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key));
|
||||
};
|
||||
|
||||
const getBinYard = (key: string, as?: string) => {
|
||||
if (as) return get<pond.BinYard>(pondURL("/binYard/" + key + "?as=" + as));
|
||||
const getBinYard = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return get<pond.BinYard>(pondURL("/binYard/" + key + "?as=" + view));
|
||||
return get<pond.BinYard>(pondURL("/binYard/" + key));
|
||||
};
|
||||
|
||||
|
|
@ -77,12 +80,11 @@ export default function BinYardProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
let asText = "";
|
||||
if (as) asText = "&as=" + as;
|
||||
if (specificUser) asText = "&as=" + specificUser;
|
||||
let asText = ""
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) asText = "&as=" + view;
|
||||
return get<pond.ListBinYardsResponse>(
|
||||
pondURL(
|
||||
"/binYards" +
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { useHTTP } from "hooks";
|
||||
// import { useWebsocket } from "websocket";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import React, { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { dateRange } from "providers/http";
|
||||
import { getComponentIDString } from "pbHelpers/Component";
|
||||
import { Component } from "models";
|
||||
|
|
@ -18,33 +18,33 @@ export interface IComponentAPIContext {
|
|||
url: string,
|
||||
componentKey: string
|
||||
) => Promise<any>;
|
||||
add: (device: number, settings: pond.ComponentSettings, as?: string) => Promise<AxiosResponse<pond.AddComponentResponse>>;
|
||||
add: (device: number, settings: pond.ComponentSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddComponentResponse>>;
|
||||
addMultiComponents: (
|
||||
device: number,
|
||||
components: pond.MultiComponentSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddMultiComponentsResponse>>;
|
||||
update: (
|
||||
device: number,
|
||||
settings: pond.ComponentSettings,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateComponentResponse>>;
|
||||
remove: (device: number, component: string, keys?: string[], types?: string[], as?: string) => Promise<AxiosResponse<pond.RemoveComponentResponse>>;
|
||||
get: (device: number, component: string, keys?: string[], types?: string[], as?: string) => Promise<AxiosResponse<pond.Component>>;
|
||||
remove: (device: number, component: string, keys?: string[], types?: string[], otherTeam?: string) => Promise<AxiosResponse<pond.RemoveComponentResponse>>;
|
||||
get: (device: number, component: string, keys?: string[], types?: string[], otherTeam?: string) => Promise<AxiosResponse<pond.Component>>;
|
||||
list: (
|
||||
device: number | string,
|
||||
demo?: boolean,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
comprehensive?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListComponentsResponse>>;
|
||||
listForObject: (
|
||||
keys: string[],
|
||||
types: string[],
|
||||
as?:string
|
||||
otherTeam?:string
|
||||
) => Promise<AxiosResponse<pond.ListComponentsResponse>>;
|
||||
listComponentCardData: (
|
||||
device: number | string,
|
||||
|
|
@ -52,7 +52,7 @@ export interface IComponentAPIContext {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
comprehensive?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListComponentCardDataResponse>>;
|
||||
listHistory: (
|
||||
deviceId: string | number,
|
||||
|
|
@ -86,7 +86,7 @@ export interface IComponentAPIContext {
|
|||
// demo?: boolean,
|
||||
// keys?: string[],
|
||||
// types?: string[],
|
||||
// as?: string
|
||||
// otherTeam?: string
|
||||
// ) => Promise<AxiosResponse<pond.SampleMeasurementsResponse>>;
|
||||
sampleUnitMeasurements: (
|
||||
device: number | string,
|
||||
|
|
@ -98,7 +98,7 @@ export interface IComponentAPIContext {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
showErrors?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.SampleUnitMeasurementsResponse>>;
|
||||
// possibly a deprecated function as it is not used anywhere
|
||||
updateComponentPreferences: (
|
||||
|
|
@ -120,7 +120,7 @@ export interface IComponentAPIContext {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
showErrors?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListUnitMeasurementsResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -131,7 +131,7 @@ interface Props {}
|
|||
export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, post, put, del } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const newCron = (
|
||||
device: number,
|
||||
|
|
@ -156,9 +156,10 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const addComponent = (device: number, settings: pond.ComponentSettings, as?: string) => {
|
||||
const addComponent = (device: number, settings: pond.ComponentSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = "/devices/" + device + "/components"
|
||||
if (as) url = url + `?as=${as}`
|
||||
if (view) url = url + `?as=${view}`
|
||||
return new Promise<AxiosResponse<pond.AddComponentResponse>>((resolve, reject) => {
|
||||
post<pond.AddComponentResponse>(pondURL(url), settings).then(resp => {
|
||||
resp.data = pond.AddComponentResponse.fromObject(resp.data)
|
||||
|
|
@ -169,9 +170,10 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const addMultiComponents = (device: number, components: pond.MultiComponentSettings, as?: string) => {
|
||||
const addMultiComponents = (device: number, components: pond.MultiComponentSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = "/devices/" + device + "/multiComponents"
|
||||
if (as) url = url + `?as=${as}`
|
||||
if (view) url = url + `?as=${view}`
|
||||
return new Promise<AxiosResponse<pond.AddMultiComponentsResponse>>((resolve, reject)=>{
|
||||
post<pond.AddMultiComponentsResponse>(pondURL(url), components).then(resp => {
|
||||
resp.data = pond.AddMultiComponentsResponse.fromObject(resp.data)
|
||||
|
|
@ -187,12 +189,13 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
settings: pond.ComponentSettings,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
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
|
||||
let t: string[] = types ? types : [];
|
||||
if (!t.includes("device")) t.push("device"); // if "device" is already in the types do not add it again
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
|
|
@ -201,7 +204,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
"/update" +
|
||||
("?keys=" + k) +
|
||||
("&types=" + t) +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
);
|
||||
return new Promise<AxiosResponse<pond.UpdateComponentResponse>>((resolve, reject)=>{
|
||||
put<pond.UpdateComponentResponse>(url, settings).then(resp => {
|
||||
|
|
@ -218,12 +221,13 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
component: string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
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
|
||||
let t: string[] = types ? types : [];
|
||||
if (!t.includes("device")) t.push("device"); // if "device" is already in the types do not add it again
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
|
|
@ -231,7 +235,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
component +
|
||||
("?keys=" + k) +
|
||||
("&types=" + t) +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
);
|
||||
return new Promise<AxiosResponse<pond.RemoveComponentResponse>>((resolve, reject) => {
|
||||
del<pond.RemoveComponentResponse>(url).then(resp => {
|
||||
|
|
@ -243,11 +247,12 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getComponent = (device: number, component: string, keys?: string[], types?: string[], as?: string) => {
|
||||
const getComponent = (device: number, component: string, keys?: string[], types?: string[], otherTeam?: string) => {
|
||||
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
|
||||
let t: string[] = types ? types : [];
|
||||
if (!t.includes("device")) t.push("device"); // if "device" is already in the types do not add it again
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
|
|
@ -255,7 +260,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
component +
|
||||
("?keys=" + k) +
|
||||
("&types=" + t) +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
);
|
||||
return new Promise<AxiosResponse<pond.Component>>((resolve, reject) => {
|
||||
get<pond.Component>(url).then(resp => {
|
||||
|
|
@ -273,10 +278,11 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
comprehensive?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
let k = keys ? keys : [];
|
||||
let t = types ? types : [];
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
|
|
@ -287,9 +293,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
(comprehensive ? "&comprehensive=" + comprehensive.toString() : ""),
|
||||
demo
|
||||
);
|
||||
if (as)
|
||||
if (view)
|
||||
url = pondURL(
|
||||
`/devices/${device}/components?as=${as}&keys=${k}&types=${t}` +
|
||||
`/devices/${device}/components?as=${view}&keys=${k}&types=${t}` +
|
||||
(comprehensive ? "&comprehensive=" + comprehensive.toString() : ""),
|
||||
demo
|
||||
);
|
||||
|
|
@ -303,8 +309,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const listComponentsForObject = (keys: string[], types: string[], as?: string) => {
|
||||
let url = pondURL("/components/forObject?keys=" + keys + "&types=" + types + (as ? "&as=" + as : ""))
|
||||
const listComponentsForObject = (keys: string[], types: string[], otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/components/forObject?keys=" + keys + "&types=" + types + (view ? "&as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.ListComponentsResponse>>((resolve, reject) => {
|
||||
get<pond.ListComponentsResponse>(url).then(resp => {
|
||||
resp.data = pond.ListComponentsResponse.fromObject(resp.data)
|
||||
|
|
@ -321,8 +328,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
comprehensive = false,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
|
|
@ -334,9 +342,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
|
||||
demo
|
||||
);
|
||||
if (as)
|
||||
if (view)
|
||||
url = pondURL(
|
||||
`/devices/${device}/componentCards?as=${as}` +
|
||||
`/devices/${device}/componentCards?as=${view}` +
|
||||
(keys ? "&keys=" + keys : "&keys=" + [device.toString()]) +
|
||||
(types ? "&types=" + types : "&types=" + ["device"]),
|
||||
demo
|
||||
|
|
@ -393,7 +401,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
// demo: boolean = false,
|
||||
// keys?: string[],
|
||||
// types?: string[],
|
||||
// as?: string
|
||||
// otherTeam?: string
|
||||
// // exportMeasurements: boolean = false
|
||||
// ) => {
|
||||
// const url = pondURL(
|
||||
|
|
@ -436,7 +444,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
// demo: boolean = false,
|
||||
// keys?: string[],
|
||||
// types?: string[],
|
||||
// as?: string
|
||||
// otherTeam?: string
|
||||
// ) => {
|
||||
// const url = pondURL(
|
||||
// "/devices/" +
|
||||
|
|
@ -472,8 +480,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
showErrors: boolean = true,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
|
|
@ -483,7 +492,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
dateRange(startDate, endDate) +
|
||||
"&size=" +
|
||||
sampleSize +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(keys ? "&keys=" + keys : "&keys=" + [device]) +
|
||||
(types ? "&types=" + types : "&types=" + ["device"]) +
|
||||
(showErrors ? "&showErrors=true" : "&showErrors=false"),
|
||||
|
|
@ -536,8 +545,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
showErrors?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
|
|
@ -552,7 +562,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
"&order=" +
|
||||
order +
|
||||
(measurementType ? "&type=" + measurementType : "") +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(keys ? "&keys=" + keys : "&keys=" + [device]) +
|
||||
(types ? "&types=" + types : "&types=" + ["device"]) +
|
||||
(showErrors ? "&showErrors=true" : "&showErrors=false")
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { useHTTP } from "hooks";
|
||||
import React, { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { pondURL } from "./pond";
|
||||
import { AxiosResponse } from "axios";
|
||||
|
|
@ -9,7 +9,7 @@ export interface IContractInterface {
|
|||
addContract: (
|
||||
name: string,
|
||||
settings: pond.ContractSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddContractResponse>>;
|
||||
listContracts: (
|
||||
limit: number,
|
||||
|
|
@ -21,15 +21,15 @@ export interface IContractInterface {
|
|||
types?: string[],
|
||||
numerical?: boolean,
|
||||
specificUser?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
) => Promise<AxiosResponse<pond.ListContractsResponse>>;
|
||||
updateContract: (
|
||||
key: string,
|
||||
name: string,
|
||||
settings: pond.ContractSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateContractResponse>>;
|
||||
removeContract: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveContractResponse>>;
|
||||
removeContract: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveContractResponse>>;
|
||||
listContractsByYear: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
|
|
@ -41,10 +41,10 @@ export interface IContractInterface {
|
|||
numerical?: boolean,
|
||||
specificUser?: string,
|
||||
contractYear?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListContractsByYearResponse>>;
|
||||
//list contract page data
|
||||
getContractPageData: (key: string, as?: string) => Promise<AxiosResponse<pond.GetContractPageDataResponse>>;
|
||||
getContractPageData: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetContractPageDataResponse>>;
|
||||
//for the moment however simply passing the contract from the earlier list is sufficient
|
||||
}
|
||||
|
||||
|
|
@ -55,13 +55,14 @@ interface Props {}
|
|||
export default function ContractProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
//add
|
||||
const addContract = (name: string, settings: pond.ContractSettings, as?: string) => {
|
||||
if (as) {
|
||||
const addContract = (name: string, settings: pond.ContractSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return post<pond.AddContractResponse>(
|
||||
pondURL("/contracts?name=" + name + "&as=" + as),
|
||||
pondURL("/contracts?name=" + name + "&as=" + view),
|
||||
settings
|
||||
);
|
||||
}
|
||||
|
|
@ -77,12 +78,11 @@ export default function ContractProvider(props: PropsWithChildren<Props>) {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
numerical?: boolean,
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
let asText = "";
|
||||
if (as) asText = "&as=" + as;
|
||||
if (specificUser) asText = "&as=" + specificUser;
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) asText = "&as=" + view;
|
||||
return get<pond.ListContractsResponse>(
|
||||
pondURL(
|
||||
"/contracts?limit=" +
|
||||
|
|
@ -108,13 +108,12 @@ export default function ContractProvider(props: PropsWithChildren<Props>) {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
numerical?: boolean,
|
||||
specificUser?: string,
|
||||
contractYear?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
) => {
|
||||
let asText = "";
|
||||
if (as) asText = "&as=" + as;
|
||||
if (specificUser) asText = "&as=" + specificUser;
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) asText = "&as=" + view;
|
||||
return get<pond.ListContractsByYearResponse>(
|
||||
pondURL(
|
||||
"/contractsByYear?limit=" +
|
||||
|
|
@ -133,10 +132,11 @@ export default function ContractProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
//update
|
||||
const updateContract = (key: string, name: string, settings: pond.ContractSettings, as?: string) => {
|
||||
if (as) {
|
||||
const updateContract = (key: string, name: string, settings: pond.ContractSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return put<pond.UpdateContractResponse>(
|
||||
pondURL("/contracts/" + key + "?as=" + as + "&name=" + name),
|
||||
pondURL("/contracts/" + key + "?as=" + view + "&name=" + name),
|
||||
settings
|
||||
);
|
||||
}
|
||||
|
|
@ -146,16 +146,18 @@ export default function ContractProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
//remove
|
||||
const removeContract = (key: string, as?: string) => {
|
||||
if (as) {
|
||||
return del<pond.RemoveContractResponse>(pondURL("/contracts/" + key + "?as=" + as));
|
||||
const removeContract = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return del<pond.RemoveContractResponse>(pondURL("/contracts/" + key + "?as=" + view));
|
||||
}
|
||||
return del<pond.RemoveContractResponse>(pondURL("/contracts/" + key + "?as=" + as));
|
||||
return del<pond.RemoveContractResponse>(pondURL("/contracts/" + key));
|
||||
};
|
||||
|
||||
const getContractPageData = (key: string, as?: string) => {
|
||||
if (as) {
|
||||
return get<pond.GetContractPageDataResponse>(pondURL("/contractsPage/" + key + "?as=" + as));
|
||||
const getContractPageData = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return get<pond.GetContractPageDataResponse>(pondURL("/contractsPage/" + key + "?as=" + view));
|
||||
}
|
||||
|
||||
return get<pond.GetContractPageDataResponse>(pondURL("/contractsPage/" + key));
|
||||
|
|
|
|||
|
|
@ -12,19 +12,19 @@ import { dateRange } from "providers/http";
|
|||
// import { reject, result } from "lodash";
|
||||
|
||||
export interface IDeviceAPIContext {
|
||||
add: (name: string, description: string, backpack: pond.BackpackSettings, as?: string) => Promise<AxiosResponse<pond.AddDeviceResponse>>;
|
||||
update: (id: number, settings: pond.DeviceSettings, as?: string) => Promise<AxiosResponse<pond.UpdateDeviceResponse>>;
|
||||
remove: (id: number, as?: string) => Promise<AxiosResponse<pond.RemoveDeviceResponse>>;
|
||||
get: (id: number | string, demo?: boolean, keys?: string[], types?: string[], as?: string) => Promise<AxiosResponse<pond.Device>>
|
||||
add: (name: string, description: string, backpack: pond.BackpackSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddDeviceResponse>>;
|
||||
update: (id: number, settings: pond.DeviceSettings, otherTeam?: string) => Promise<AxiosResponse<pond.UpdateDeviceResponse>>;
|
||||
remove: (id: number, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveDeviceResponse>>;
|
||||
get: (id: number | string, demo?: boolean, keys?: string[], types?: string[], otherTeam?: string) => Promise<AxiosResponse<pond.Device>>
|
||||
getPageData: (
|
||||
id: number | string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.GetDevicePageDataResponse>>;
|
||||
getMulti: (ids: number[] | string[], as?: string) => Promise<AxiosResponse<pond.GetMultiDeviceResponse>>;
|
||||
getGeoJson: (id: number | string, demo?: boolean, as?: string) => Promise<any>;
|
||||
getMultiGeoJson: (ids: number[] | string[], as?: string) => Promise<any>;
|
||||
getMulti: (ids: number[] | string[], otherTeam?: string) => Promise<AxiosResponse<pond.GetMultiDeviceResponse>>;
|
||||
getGeoJson: (id: number | string, demo?: boolean, otherTeam?: string) => Promise<any>;
|
||||
getMultiGeoJson: (ids: number[] | string[], otherTeam?: string) => Promise<any>;
|
||||
list: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
|
|
@ -41,7 +41,7 @@ export interface IDeviceAPIContext {
|
|||
types?: string[],
|
||||
fieldContains?: Map<string, string>,
|
||||
prefixSearch?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListDevicesResponse>>;
|
||||
listForUser: (
|
||||
asRoot: boolean,
|
||||
|
|
@ -65,7 +65,7 @@ export interface IDeviceAPIContext {
|
|||
preferences: pond.DevicePreferences,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<any>;
|
||||
updateComponentPreferences: (
|
||||
id: number | string,
|
||||
|
|
@ -73,13 +73,13 @@ export interface IDeviceAPIContext {
|
|||
preferences: pond.DeviceComponentPreferences,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateDeviceComponentPreferencesResponse>>;
|
||||
listDeviceComponentPreferences: (
|
||||
id: number | string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListDeviceComponentPreferencesResponse>>;
|
||||
updateStatus: (
|
||||
id: number | string,
|
||||
|
|
@ -99,7 +99,7 @@ export interface IDeviceAPIContext {
|
|||
newCap: number
|
||||
) => Promise<AxiosResponse<pond.BulkChangeDataCapsResponse>>;
|
||||
resume: (id: number) => Promise<any>;
|
||||
getUpgradeStatus: (id: number, keys?: string[], types?: string[], as?: string) => Promise<any>;
|
||||
getUpgradeStatus: (id: number, keys?: string[], types?: string[], otherTeam?: string) => Promise<any>;
|
||||
loadBackpack: (id: number, backpack: number) => Promise<any>;
|
||||
setTags: (id: number, tags: string[]) => Promise<any>;
|
||||
setWifi: (
|
||||
|
|
@ -108,7 +108,7 @@ export interface IDeviceAPIContext {
|
|||
password: string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<any>;
|
||||
statistics: (
|
||||
keys?: string[],
|
||||
|
|
@ -129,9 +129,9 @@ export interface IDeviceAPIContext {
|
|||
offset: number,
|
||||
order: string,
|
||||
orderBy: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListDeviceExportedMeasurementsResponse>>;
|
||||
listSimpleJSON: (device: number, as?: string) => Promise<any>;
|
||||
listSimpleJSON: (device: number, otherTeam?: string) => Promise<any>;
|
||||
resetQuackCount: (id: number) => Promise<any>;
|
||||
resetQuackCountTx: (id: number) => Promise<any>;
|
||||
resetQuackCountTx1000: (id: number) => Promise<any>;
|
||||
|
|
@ -157,11 +157,12 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
const { children } = props;
|
||||
const { get, post, put, del } = useHTTP();
|
||||
const permissionAPI = usePermissionAPI();
|
||||
//const [{ as, team }] = useGlobalState();
|
||||
const [{ as, team }] = useGlobalState();
|
||||
|
||||
const add = (name: string, description: string, backpack: pond.BackpackSettings, as?: string) => {
|
||||
const add = (name: string, description: string, backpack: pond.BackpackSettings, otherTeam?: string) => {
|
||||
let url = pondURL("/devices")
|
||||
if (as) url = pondURL("/devices?as=" + as)
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) url = pondURL("/devices?as=" + view)
|
||||
return new Promise<AxiosResponse<pond.AddDeviceResponse>>((resolve, reject) => {
|
||||
post<pond.AddDeviceResponse>(url, { name, description, backpack }).then(resp => {
|
||||
resp.data = pond.AddDeviceResponse.fromObject(resp.data)
|
||||
|
|
@ -177,8 +178,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
demo: boolean = false,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
id +
|
||||
|
|
@ -186,11 +188,11 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
(types ? "&types=" + types.toString() : ""),
|
||||
demo
|
||||
);
|
||||
if (as) {
|
||||
if (view) {
|
||||
url = pondURL(
|
||||
"/devices/" +
|
||||
id +
|
||||
"?as=" + as +
|
||||
"?as=" + view +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : ""),
|
||||
demo
|
||||
|
|
@ -231,20 +233,21 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
id: number | string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
): Promise<AxiosResponse<pond.GetDevicePageDataResponse>> => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/devicePageData/" +
|
||||
id +
|
||||
(keys ? "?keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
);
|
||||
if (as && !(types && types.length > 0 && types[0] === "team")) {
|
||||
if (view && !(types && types.length > 0 && types[0] === "team")) {
|
||||
url = pondURL(
|
||||
"/devicePageData/" +
|
||||
id +
|
||||
"?as=" +
|
||||
as +
|
||||
view +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
)
|
||||
|
|
@ -259,9 +262,10 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getDeviceGeoJSON = (id: number | string, demo: boolean = false, as?: string) => {
|
||||
const getDeviceGeoJSON = (id: number | string, demo: boolean = false, otherTeam?: string) => {
|
||||
let url = pondURL("/devices/" + id + "/geojson", demo);
|
||||
if (as) url = pondURL("/devices/" + id + "/geojson?as=" + as, demo)
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) url = pondURL("/devices/" + id + "/geojson?as=" + view, demo)
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
get(url).catch(resp => {
|
||||
return resolve(resp)
|
||||
|
|
@ -271,7 +275,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getMulti = (ids: number[] | string[], as?: string) => {
|
||||
const getMulti = (ids: number[] | string[], otherTeam?: string) => {
|
||||
let idString = "";
|
||||
ids.forEach((id: number | string, i: number) => {
|
||||
if (i === 0) {
|
||||
|
|
@ -280,7 +284,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
idString = idString + "," + id;
|
||||
}
|
||||
});
|
||||
let url = pondURL("/multidevices?devices=" + idString + (as ? "&as=" + as : ""))
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/multidevices?devices=" + idString + (view ? "&as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.GetMultiDeviceResponse>>((resolve, reject) => {
|
||||
get<pond.GetMultiDeviceResponse>(url).then(resp => {
|
||||
resp.data = pond.GetMultiDeviceResponse.fromObject(resp.data)
|
||||
|
|
@ -291,7 +296,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getMultiDevicesGeoJSON = (ids: number[] | string[], as?: string) => {
|
||||
const getMultiDevicesGeoJSON = (ids: number[] | string[], otherTeam?: string) => {
|
||||
let idString = "";
|
||||
ids.forEach((id: number | string, i: number) => {
|
||||
if (i === 0) {
|
||||
|
|
@ -300,7 +305,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
idString = idString + "," + id;
|
||||
}
|
||||
});
|
||||
let url = pondURL("/geojson/devices?devices=" + idString + (as ? "&as=" + as : ""))
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/geojson/devices?devices=" + idString + (view ? "&as=" + view : ""))
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
get(url).then(resp => {
|
||||
return resolve(resp)
|
||||
|
|
@ -326,8 +332,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
types?: string[],
|
||||
fieldContains?: Map<string, string>,
|
||||
prefixSearch?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/devices" +
|
||||
"?limit=" +
|
||||
|
|
@ -341,7 +348,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
(status ? "&status=" + status : "") +
|
||||
(ids ? "&ids=" + ids.join(",") : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as && !(types && types.length > 0 && types[0] === "team") ? "&as=" + as : "") +
|
||||
(view && !(types && types.length > 0 && types[0] === "team") ? "&as=" + view : "") +
|
||||
(comprehensive ? "&comprehensive=" + comprehensive.toString() : "") +
|
||||
(withMeasurements ? "&measurements=" + withMeasurements.toString() : "") +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
|
|
@ -385,8 +392,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const remove = (id: number, as?: string) => {
|
||||
const url = pondURL("/devices/" + id + (as ? "?as=" + as : ""))
|
||||
const remove = (id: number, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL("/devices/" + id + (view ? "?as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.RemoveDeviceResponse>>((resolve, reject) => {
|
||||
del<pond.RemoveDeviceResponse>(url).then(resp => {
|
||||
resp.data = pond.RemoveDeviceResponse.fromObject(resp.data)
|
||||
|
|
@ -397,8 +405,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const update = (id: number, settings: pond.DeviceSettings, as?: string) => {
|
||||
const url = pondURL("/devices/" + id + "/update" + (as ? "?as=" + as : ""));
|
||||
const update = (id: number, settings: pond.DeviceSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL("/devices/" + id + "/update" + (view ? "?as=" + view : ""));
|
||||
return new Promise<AxiosResponse<pond.UpdateDeviceResponse>>((resolve, reject) => {
|
||||
put<pond.UpdateDeviceResponse>(url, settings).then(resp => {
|
||||
resp.data = pond.UpdateDeviceResponse.fromObject(resp)
|
||||
|
|
@ -463,14 +472,15 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
preferences: pond.DevicePreferences,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
id +
|
||||
"/preferences" +
|
||||
"?as=" +
|
||||
or(as, "") +
|
||||
or(view, "") +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
)
|
||||
|
|
@ -489,8 +499,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
preferences: pond.DeviceComponentPreferences,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
id +
|
||||
|
|
@ -498,7 +509,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
component +
|
||||
"/componentPreferences" +
|
||||
"?as=" +
|
||||
as +
|
||||
view +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
)
|
||||
|
|
@ -516,8 +527,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
id: number | string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
id +
|
||||
|
|
@ -525,11 +537,11 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
(keys ? "?keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
)
|
||||
if (as) {
|
||||
if (view) {
|
||||
url = pondURL(
|
||||
"/devices/" +
|
||||
id +
|
||||
"/componentPreferences?as=" + as +
|
||||
"/componentPreferences?as=" + view +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
)
|
||||
|
|
@ -549,14 +561,15 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
status: pond.DeviceStatus,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
id +
|
||||
"/updateStatus" +
|
||||
"?as=" +
|
||||
as +
|
||||
view +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
)
|
||||
|
|
@ -640,10 +653,11 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getUpgradeStatus = (id: number, keys?: string[], types?: string[], as?: string) => {
|
||||
let a = as ? "?as=" + as : "";
|
||||
const getUpgradeStatus = (id: number, keys?: string[], types?: string[], otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let a = view ? "?as=" + view : "";
|
||||
if (keys && keys.length > 0 && types && types.length > 0) {
|
||||
a = as ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types;
|
||||
a = view ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types;
|
||||
}
|
||||
let url = pondURL("/devices/" + id + "/firmware" + a);
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
|
|
@ -681,11 +695,12 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
password: string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
let a = as ? "?as=" + as : "";
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let a = view ? "?as=" + view : "";
|
||||
if (keys && keys.length > 0 && types && types.length > 0) {
|
||||
a = as ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types;
|
||||
a = view ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types;
|
||||
}
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
put(pondURL("/devices/" + id + "/wifi" + a), { gateway, password }).then(resp => {
|
||||
|
|
@ -780,7 +795,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
offset: number,
|
||||
order: string,
|
||||
orderBy: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
let keyString = "";
|
||||
components.forEach((comp, i) => {
|
||||
|
|
@ -790,7 +805,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
keyString = keyString + "," + comp.key();
|
||||
}
|
||||
});
|
||||
if (as) {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return get<pond.ListDeviceExportedMeasurementsResponse>(
|
||||
pondURL(
|
||||
"/devices/" +
|
||||
|
|
@ -808,7 +824,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
"&orderBy=" +
|
||||
orderBy +
|
||||
"&as=" +
|
||||
as
|
||||
view
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -832,9 +848,10 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const listSimpleJSON = (device: number, as?: string) => {
|
||||
const listSimpleJSON = (device: number, otherTeam?: string) => {
|
||||
let url = "/devices/" + device + "/measurements/exportSimple"
|
||||
if(as) url = url + "?as=" + as
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if(view) url = url + "?as=" + view
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
get(pondURL(url)).then(resp => {
|
||||
return resolve(resp)
|
||||
|
|
@ -894,11 +911,11 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
source?: string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string,
|
||||
team?: Team
|
||||
otherTeam?: string
|
||||
) => {
|
||||
let url = "/devices/" + id + "/buyData?MB=" + MB;
|
||||
if (as === team?.key()) url = url + "&team=" + team?.key();
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view === team?.key()) url = url + "&team=" + team?.key();
|
||||
if (source) url = url + "&source=" + source;
|
||||
if (keys) url = url + "&keys=" + keys;
|
||||
if (types) url = url + "&types=" + types;
|
||||
|
|
@ -956,7 +973,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
getDataUsage,
|
||||
buyData,
|
||||
updateComponentPreferences,
|
||||
listDeviceComponentPreferences//as
|
||||
listDeviceComponentPreferences
|
||||
}}>
|
||||
{children}
|
||||
</DeviceAPIContext.Provider>
|
||||
|
|
|
|||
|
|
@ -7,23 +7,23 @@ import { or } from "utils";
|
|||
import { pondURL } from "./pond";
|
||||
|
||||
export interface IFieldAPIContext {
|
||||
addField: (field: pond.FieldSettings, as?: string) => Promise<any>;
|
||||
getField: (fieldId: string, as?: string) => Promise<any>;
|
||||
addField: (field: pond.FieldSettings, otherTeam?: string) => Promise<any>;
|
||||
getField: (fieldId: string, otherTeam?: string) => Promise<any>;
|
||||
listFields: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => Promise<AxiosResponse<pond.ListFieldsResponse>>;
|
||||
removeField: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveFieldResponse>>;
|
||||
removeField: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveFieldResponse>>;
|
||||
updateField: (
|
||||
key: string,
|
||||
field: pond.FieldSettings,
|
||||
asRoot?: true,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateSiteResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -34,20 +34,23 @@ interface Props {}
|
|||
export default function FieldProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addField = (field: pond.FieldSettings, as?: string) => {
|
||||
if (as) return post<pond.AddFieldResponse>(pondURL("/fields?as=" + as), field);
|
||||
const addField = (field: pond.FieldSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return post<pond.AddFieldResponse>(pondURL("/fields?as=" + view), field);
|
||||
return post(pondURL("/fields"), field);
|
||||
};
|
||||
|
||||
const getField = (fieldId: string, as?: string) => {
|
||||
if (as) return get(pondURL("/field/" + fieldId + "?as=" + as));
|
||||
const getField = (fieldId: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return get(pondURL("/field/" + fieldId + "?as=" + view));
|
||||
return get(pondURL("/field/" + fieldId));
|
||||
};
|
||||
|
||||
const removeField = (key: string, as?: string) => {
|
||||
if (as) return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key + "?as=" + as));
|
||||
const removeField = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key + "?as=" + view));
|
||||
return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key));
|
||||
};
|
||||
|
||||
|
|
@ -57,9 +60,10 @@ export default function FieldProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.ListFieldsResponse>(
|
||||
pondURL(
|
||||
"/fields" +
|
||||
|
|
@ -69,17 +73,18 @@ export default function FieldProvider(props: PropsWithChildren<Props>) {
|
|||
offset +
|
||||
("&order=" + or(order, "asc")) +
|
||||
("&by=" + or(orderBy, "key")) +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(search ? "&search=" + search : "")
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const updateField = (key: string, field: pond.FieldSettings, asRoot?: boolean, as?: string) => {
|
||||
if (as)
|
||||
const updateField = (key: string, field: pond.FieldSettings, asRoot?: boolean, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return put<pond.UpdateFieldResponse>(
|
||||
pondURL("/fields/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "")),
|
||||
pondURL("/fields/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")),
|
||||
field
|
||||
);
|
||||
return put<pond.UpdateFieldResponse>(
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import { pondURL } from "./pond";
|
|||
export interface IFieldMarkerAPIContext {
|
||||
addFieldMarker: (
|
||||
fieldMarker: pond.FieldMarkerSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddFieldMarkerResponse>>;
|
||||
getFieldMarker: (fieldMarkerID: string) => Promise<AxiosResponse<pond.FieldMarker>>;
|
||||
getFieldMarker: (fieldMarkerID: string, otherTeam?: string) => Promise<AxiosResponse<pond.FieldMarker>>;
|
||||
listFieldMarkers: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
|
|
@ -18,17 +18,17 @@ export interface IFieldMarkerAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListFieldMarkersResponse>>;
|
||||
removeFieldMarker: (
|
||||
fieldMarkerID: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.RemoveFieldMarkerResponse>>;
|
||||
updateFieldMarker: (
|
||||
key: string,
|
||||
fieldMarker: pond.FieldMarkerSettings,
|
||||
asRoot?: true,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateFieldMarkerResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -41,22 +41,25 @@ interface Props {}
|
|||
export default function FieldMarkerProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addFieldMarker = (fieldMarker: pond.FieldMarkerSettings, as?: string) => {
|
||||
if (as)
|
||||
return post<pond.AddFieldMarkerResponse>(pondURL("/fieldMarkers?as=" + as), fieldMarker);
|
||||
const addFieldMarker = (fieldMarker: pond.FieldMarkerSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post<pond.AddFieldMarkerResponse>(pondURL("/fieldMarkers?as=" + view), fieldMarker);
|
||||
return post<pond.AddFieldMarkerResponse>(pondURL("/fieldMarkers"), fieldMarker);
|
||||
};
|
||||
|
||||
const getFieldMarker = (fieldMarkerId: string, as?: string) => {
|
||||
if (as) return get<pond.FieldMarker>(pondURL("/fieldMarkers/" + fieldMarkerId + "?as=" + as));
|
||||
const getFieldMarker = (fieldMarkerId: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return get<pond.FieldMarker>(pondURL("/fieldMarkers/" + fieldMarkerId + "?as=" + view));
|
||||
return get<pond.FieldMarker>(pondURL("/fieldMarkers/" + fieldMarkerId));
|
||||
};
|
||||
|
||||
const removeFieldMarker = (key: string, as?: string) => {
|
||||
if (as)
|
||||
return del<pond.RemoveFieldMarkerResponse>(pondURL("/fieldMarkers/" + key + "?as=" + as));
|
||||
const removeFieldMarker = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return del<pond.RemoveFieldMarkerResponse>(pondURL("/fieldMarkers/" + key + "?as=" + view));
|
||||
return del<pond.RemoveFieldMarkerResponse>(pondURL("/fieldMarkers/" + key));
|
||||
};
|
||||
|
||||
|
|
@ -67,8 +70,9 @@ export default function FieldMarkerProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.ListFieldMarkersResponse>(
|
||||
pondURL(
|
||||
"/fieldMarkers" +
|
||||
|
|
@ -80,16 +84,17 @@ export default function FieldMarkerProvider(props: PropsWithChildren<Props>) {
|
|||
("&by=" + (orderBy ? orderBy : "key")) +
|
||||
(search ? "&search=" + search : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const updateFieldMarker = (key: string, hm: pond.FieldMarkerSettings, asRoot?: boolean, as?: string) => {
|
||||
if (as)
|
||||
const updateFieldMarker = (key: string, hm: pond.FieldMarkerSettings, asRoot?: boolean, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return put<pond.UpdateFieldMarkerResponse>(
|
||||
pondURL(
|
||||
"/fieldMarkers/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "")
|
||||
"/fieldMarkers/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")
|
||||
),
|
||||
hm
|
||||
);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export interface IGateInterface {
|
|||
addGate: (
|
||||
name: string,
|
||||
settings: pond.GateSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddGateResponse>>;
|
||||
listGates: (
|
||||
limit: number,
|
||||
|
|
@ -22,23 +22,23 @@ export interface IGateInterface {
|
|||
types?: string[],
|
||||
numerical?: boolean,
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListGatesResponse>>;
|
||||
updateGate: (
|
||||
key: string,
|
||||
name: string,
|
||||
settings: pond.GateSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateGateResponse>>;
|
||||
getGate: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGateResponse>>;
|
||||
removeGate: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveGateResponse>>;
|
||||
getGate: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetGateResponse>>;
|
||||
removeGate: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveGateResponse>>;
|
||||
updateLink: (
|
||||
parentKey: string,
|
||||
parentType: string,
|
||||
objectID: string,
|
||||
objectType: string,
|
||||
permissions: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<any>;
|
||||
updatePrefs: (
|
||||
gateKey: string,
|
||||
|
|
@ -47,9 +47,9 @@ export interface IGateInterface {
|
|||
gatePref: pond.GateComponentType | pond.GateDeviceType,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateGatePreferencesResponse>>;
|
||||
getGatePageData: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGatePageDataResponse>>;
|
||||
getGatePageData: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetGatePageDataResponse>>;
|
||||
listGateAirflow: (
|
||||
gate: string,
|
||||
device: number | string,
|
||||
|
|
@ -59,7 +59,7 @@ export interface IGateInterface {
|
|||
end: string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListGateAirflowResponse>>;
|
||||
listGateFlowEvents: (
|
||||
gate: string,
|
||||
|
|
@ -72,13 +72,13 @@ export interface IGateInterface {
|
|||
flowVariance: number,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListGateFlowEventsResponse>>;
|
||||
listGateMeasurements: (
|
||||
key: string,
|
||||
start: string,
|
||||
end: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -89,10 +89,11 @@ interface Props {}
|
|||
export default function GateProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addGate = (name: string, settings: pond.GateSettings, as?: string) => {
|
||||
let url = pondURL("/gates?name=" + name + (as ? "&as=" + as : ""))
|
||||
const addGate = (name: string, settings: pond.GateSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/gates?name=" + name + (view ? "&as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.AddGateResponse>>((resolve, reject) => {
|
||||
post<pond.AddGateResponse>(url, settings).then(resp => {
|
||||
resp.data = pond.AddGateResponse.fromObject(resp.data)
|
||||
|
|
@ -114,10 +115,11 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
types?: string[],
|
||||
numerical?: boolean,
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
let asText = "";
|
||||
if (as) asText = "&as=" + as;
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) asText = "&as=" + view;
|
||||
if (specificUser) asText = "&as=" + specificUser;
|
||||
let url = pondURL(
|
||||
"/gates?limit=" +
|
||||
|
|
@ -143,8 +145,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const updateGate = (key: string, name: string, settings: pond.GateSettings, as?: string) => {
|
||||
let url = pondURL("/gates/" + key + "?name=" + name + (as ? "&as=" + as : ""))
|
||||
const updateGate = (key: string, name: string, settings: pond.GateSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/gates/" + key + "?name=" + name + (view ? "&as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.UpdateGateResponse>>((resolve, reject) => {
|
||||
put<pond.UpdateGateResponse>(url, settings).then(resp => {
|
||||
resp.data = pond.UpdateGateResponse.fromObject(resp.data)
|
||||
|
|
@ -155,8 +158,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const removeGate = (key: string, as?: string) => {
|
||||
let url = pondURL("/gates/" + key + (as ? "?as=" + as : ""))
|
||||
const removeGate = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/gates/" + key + (view ? "?as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.RemoveGateResponse>>((resolve, reject) => {
|
||||
del<pond.RemoveGateResponse>(url).then(resp => {
|
||||
resp.data = pond.RemoveGateResponse.fromObject(resp.data)
|
||||
|
|
@ -167,8 +171,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getGate = (key: string, as?: string) => {
|
||||
let url = pondURL("/gates/" + key + (as ? "?as=" + as : ""))
|
||||
const getGate = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/gates/" + key + (view ? "?as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.GetGateResponse>>((resolve, reject) => {
|
||||
get<pond.GetGateResponse>(url).then(resp => {
|
||||
resp.data = pond.GetGateResponse.fromObject(resp.data)
|
||||
|
|
@ -179,8 +184,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getGatePageData = (key: string, as?: string) => {
|
||||
let url = pondURL("/gatePage/" + key + (as ? "?as=" + as : ""))
|
||||
const getGatePageData = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/gatePage/" + key + (view ? "?as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.GetGatePageDataResponse>>((resolve, reject) => {
|
||||
get<pond.GetGatePageDataResponse>(url).then(resp => {
|
||||
resp.data = pond.GetGatePageDataResponse.fromObject(resp.data)
|
||||
|
|
@ -197,9 +203,10 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
objectID: string,
|
||||
objectType: string,
|
||||
permissions: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
let url = pondURL(`/gates/` + parentID + "/link" + (as ? `?as=${as}` : ""))
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(`/gates/` + parentID + "/link" + (view ? `?as=${view}` : ""))
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
post(url, {
|
||||
Key: objectID,
|
||||
|
|
@ -223,8 +230,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
gatePref: pond.GateComponentType | pond.GateDeviceType,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
`/gatePrefs/` +
|
||||
gateKey +
|
||||
|
|
@ -234,7 +242,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
childKey +
|
||||
"&gatePreference=" +
|
||||
gatePref +
|
||||
(as ? `&as=` + as : "") +
|
||||
(view ? `&as=` + view : "") +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
)
|
||||
|
|
@ -257,8 +265,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
end: string,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/gates/" +
|
||||
gate +
|
||||
|
|
@ -272,7 +281,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
start +
|
||||
"&end=" +
|
||||
end +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
)
|
||||
|
|
@ -286,8 +295,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const listGateMeasurements = (key: string, start: string, end: string, as?: string) => {
|
||||
let url = pondURL("/gates/" + key + "/measurements?start=" + start + "&end=" + end + "&as=" + as)
|
||||
const listGateMeasurements = (key: string, start: string, end: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/gates/" + key + "/measurements?start=" + start + "&end=" + end + "&as=" + view)
|
||||
return new Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>((resolve, reject) => {
|
||||
get<pond.ListGateMeasurementsResponse>(url).then(resp => {
|
||||
resp.data = pond.ListGateMeasurementsResponse.fromObject(resp.data)
|
||||
|
|
@ -309,8 +319,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
flowVariance: number,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.ListGateFlowEventsResponse>(
|
||||
pondURL(
|
||||
"/gates/" +
|
||||
|
|
@ -329,7 +340,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
|
|||
idleFlow +
|
||||
"&variance=" +
|
||||
flowVariance +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(keys ? "&keys=" + keys.toString() : "") +
|
||||
(types ? "&types=" + types.toString() : "")
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,13 +4,12 @@ import { pond } from "protobuf-ts/pond";
|
|||
import { pondURL } from "./pond";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { useGlobalState } from "providers";
|
||||
import { GrainBag } from "models/GrainBag";
|
||||
|
||||
export interface IGrainBagInterface {
|
||||
addGrainBag: (
|
||||
name: string,
|
||||
settings: pond.GrainBagSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddGrainBagResponse>>;
|
||||
listGrainBags: (
|
||||
limit: number,
|
||||
|
|
@ -21,28 +20,27 @@ export interface IGrainBagInterface {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
numerical?: boolean,
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListGrainBagsResponse>>;
|
||||
updateGrainBag: (
|
||||
key: string,
|
||||
name: string,
|
||||
settings: pond.GrainBagSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateGrainBagResponse>>;
|
||||
bulkUpdateGrainBags: (
|
||||
bags: pond.GrainBag[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.BulkGrainBagUpdateResponse>>;
|
||||
getGrainBag: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGrainBagResponse>>;
|
||||
removeGrainBag: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveGrainBagResponse>>;
|
||||
getGrainBag: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetGrainBagResponse>>;
|
||||
removeGrainBag: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveGrainBagResponse>>;
|
||||
listHistory: (
|
||||
id: string,
|
||||
limit: number,
|
||||
offset: number,
|
||||
start?: string,
|
||||
end?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListGrainBagHistoryResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -53,12 +51,13 @@ interface Props {}
|
|||
export default function GrainBagProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addGrainBag = (name: string, settings: pond.GrainBagSettings, as?: string) => {
|
||||
if (as) {
|
||||
const addGrainBag = (name: string, settings: pond.GrainBagSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return post<pond.AddGrainBagResponse>(
|
||||
pondURL("/grainbags?name=" + name + "&as=" + as),
|
||||
pondURL("/grainbags?name=" + name + "&as=" + view),
|
||||
settings
|
||||
);
|
||||
}
|
||||
|
|
@ -74,12 +73,11 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
|
|||
keys?: string[],
|
||||
types?: string[],
|
||||
numerical?: boolean,
|
||||
specificUser?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
let asText = "";
|
||||
if (as) asText = "&as=" + as;
|
||||
if (specificUser) asText = "&as=" + specificUser;
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) asText = "&as=" + view;
|
||||
return get<pond.ListGrainBagsResponse>(
|
||||
pondURL(
|
||||
"/grainbags?limit=" +
|
||||
|
|
@ -97,10 +95,11 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const updateGrainBag = (key: string, name: string, settings: pond.GrainBagSettings, as?: string) => {
|
||||
if (as) {
|
||||
const updateGrainBag = (key: string, name: string, settings: pond.GrainBagSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return put<pond.UpdateGrainBagResponse>(
|
||||
pondURL("/grainbags/" + key + "?as=" + as + "&name=" + name),
|
||||
pondURL("/grainbags/" + key + "?as=" + view + "&name=" + name),
|
||||
settings
|
||||
);
|
||||
}
|
||||
|
|
@ -110,29 +109,33 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const bulkUpdateGrainBags = (bags: pond.GrainBag[], as?: string) => {
|
||||
if (as)
|
||||
return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update?as=" + as), {
|
||||
const bulkUpdateGrainBags = (bags: pond.GrainBag[], otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update?as=" + view), {
|
||||
bags: bags
|
||||
});
|
||||
return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update"), { bags: bags });
|
||||
};
|
||||
|
||||
const removeGrainBag = (key: string, as?: string) => {
|
||||
if (as) {
|
||||
return del<pond.RemoveGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + as));
|
||||
const removeGrainBag = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return del<pond.RemoveGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + view));
|
||||
}
|
||||
return del<pond.RemoveGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + as));
|
||||
return del<pond.RemoveGrainBagResponse>(pondURL("/grainbags/" + key));
|
||||
};
|
||||
|
||||
const getGrainBag = (key: string, as?: string) => {
|
||||
if (as) {
|
||||
return get<pond.GetGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + as));
|
||||
const getGrainBag = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return get<pond.GetGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + view));
|
||||
}
|
||||
return get<pond.GetGrainBagResponse>(pondURL("/grainbags/" + key));
|
||||
};
|
||||
|
||||
const listHistory = (id: string, limit: number, offset: number, start?: string, end?: string, as?: string) => {
|
||||
const listHistory = (id: string, limit: number, offset: number, start?: string, end?: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/grainbags/" +
|
||||
id +
|
||||
|
|
@ -143,8 +146,8 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
|
|||
(start && "&start=" + start) +
|
||||
(end && "&end=" + end)
|
||||
)
|
||||
if (as) {
|
||||
url = url + "?as=" + as
|
||||
if (view) {
|
||||
url = url + "?as=" + view
|
||||
}
|
||||
return get<pond.ListGrainBagHistoryResponse>(url);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ import { or } from "utils";
|
|||
import { pondURL } from "./pond";
|
||||
|
||||
export interface IHarvestPlanAPIContext {
|
||||
addHarvestPlan: (harvestPlan: pond.HarvestPlanSettings, as?: string) => Promise<any>;
|
||||
getHarvestPlan: (harvestPlanId: string, as?: string) => Promise<any>;
|
||||
addHarvestPlan: (harvestPlan: pond.HarvestPlanSettings, otherTeam?: string) => Promise<any>;
|
||||
getHarvestPlan: (harvestPlanId: string, otherTeam?: string) => Promise<any>;
|
||||
listHarvestPlans: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => Promise<AxiosResponse<pond.ListHarvestPlansResponse>>;
|
||||
listHistory: (
|
||||
|
|
@ -25,13 +25,13 @@ export interface IHarvestPlanAPIContext {
|
|||
) => Promise<AxiosResponse<pond.ListHarvestPlanHistoryResponse>>;
|
||||
removeHarvestPlan: (
|
||||
harvestPlanId: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.RemoveHarvestPlanResponse>>;
|
||||
updateHarvestPlan: (
|
||||
key: string,
|
||||
harvestPlan: pond.HarvestPlanSettings,
|
||||
asRoot?: true,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateHarvestPlanResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -44,21 +44,24 @@ interface Props {}
|
|||
export default function HarvestPlanProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addHarvestPlan = (harvestPlan: pond.HarvestPlanSettings, as?: string) => {
|
||||
if (as) return post(pondURL("/harvestPlans?as=" + as), harvestPlan);
|
||||
const addHarvestPlan = (harvestPlan: pond.HarvestPlanSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return post(pondURL("/harvestPlans?as=" + view), harvestPlan);
|
||||
return post(pondURL("/harvestPlans"), harvestPlan);
|
||||
};
|
||||
|
||||
const getHarvestPlan = (harvestPlanId: string, as?: string) => {
|
||||
if (as) return get(pondURL("/harvestPlans/" + harvestPlanId + "?as=" + as));
|
||||
const getHarvestPlan = (harvestPlanId: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return get(pondURL("/harvestPlans/" + harvestPlanId + "?as=" + view));
|
||||
return get(pondURL("/harvestPlans/" + harvestPlanId));
|
||||
};
|
||||
|
||||
const removeHarvestPlan = (key: string, as?: string) => {
|
||||
if (as)
|
||||
return del<pond.RemoveHarvestPlanResponse>(pondURL("/harvestPlans/" + key + "?as=" + as));
|
||||
const removeHarvestPlan = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return del<pond.RemoveHarvestPlanResponse>(pondURL("/harvestPlans/" + key + "?as=" + view));
|
||||
return del<pond.RemoveHarvestPlanResponse>(pondURL("/harvestPlans/" + key));
|
||||
};
|
||||
|
||||
|
|
@ -68,9 +71,10 @@ export default function HarvestPlanProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.ListHarvestPlansResponse>(
|
||||
pondURL(
|
||||
"/harvestPlans" +
|
||||
|
|
@ -82,7 +86,7 @@ export default function HarvestPlanProvider(props: PropsWithChildren<Props>) {
|
|||
("&by=" + or(orderBy, "key")) +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(search ? "&search=" + search : "") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
)
|
||||
);
|
||||
};
|
||||
|
|
@ -97,14 +101,15 @@ export default function HarvestPlanProvider(props: PropsWithChildren<Props>) {
|
|||
key: string,
|
||||
harvestPlan: pond.HarvestPlanSettings,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
if (as)
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return put<pond.UpdateHarvestPlanResponse>(
|
||||
pondURL(
|
||||
"/harvestPlans/" +
|
||||
key +
|
||||
(as ? "?as=" + as : "") +
|
||||
(view ? "?as=" + view : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "")
|
||||
),
|
||||
harvestPlan
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { pondURL } from "./pond";
|
|||
export interface IHomeMarkerAPIContext {
|
||||
addHomeMarker: (
|
||||
homeMarker: pond.HomeMarkerSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddHomeMarkerResponse>>;
|
||||
getHomeMarker: (homeMarkerID: string) => Promise<AxiosResponse<pond.HomeMarker>>;
|
||||
listHomeMarkers: (
|
||||
|
|
@ -18,14 +18,14 @@ export interface IHomeMarkerAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListHomeMarkersResponse>>;
|
||||
removeHomeMarker: (homeMarkerID: string) => Promise<AxiosResponse<pond.RemoveHomeMarkerResponse>>;
|
||||
updateHomeMarker: (
|
||||
key: string,
|
||||
homeMarker: pond.HomeMarkerSettings,
|
||||
asRoot?: true,
|
||||
as?:string
|
||||
otherTeam?:string
|
||||
) => Promise<AxiosResponse<pond.UpdateHomeMarkerResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -38,10 +38,11 @@ interface Props {}
|
|||
export default function HomeMarkerProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addHomeMarker = (homeMarker: pond.HomeMarkerSettings, as?: string) => {
|
||||
if (as) return post<pond.AddHomeMarkerResponse>(pondURL("/homeMarkers?as=" + as), homeMarker);
|
||||
const addHomeMarker = (homeMarker: pond.HomeMarkerSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return post<pond.AddHomeMarkerResponse>(pondURL("/homeMarkers?as=" + view), homeMarker);
|
||||
return post<pond.AddHomeMarkerResponse>(pondURL("/homeMarkers"), homeMarker);
|
||||
};
|
||||
|
||||
|
|
@ -60,8 +61,9 @@ export default function HomeMarkerProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.ListHomeMarkersResponse>(
|
||||
pondURL(
|
||||
"/homeMarkers" +
|
||||
|
|
@ -73,16 +75,17 @@ export default function HomeMarkerProvider(props: PropsWithChildren<Props>) {
|
|||
("&by=" + (orderBy ? orderBy : "key")) +
|
||||
(search ? "&search=" + search : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const updateHomeMarker = (key: string, hm: pond.HomeMarkerSettings, asRoot?: boolean, as?: string) => {
|
||||
if (as)
|
||||
const updateHomeMarker = (key: string, hm: pond.HomeMarkerSettings, asRoot?: boolean, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return put<pond.UpdateHomeMarkerResponse>(
|
||||
pondURL(
|
||||
"/homeMarkers/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "")
|
||||
"/homeMarkers/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")
|
||||
),
|
||||
hm
|
||||
);
|
||||
|
|
|
|||
|
|
@ -10,31 +10,31 @@ import { has } from "utils/types";
|
|||
import { pondURL } from "./pond";
|
||||
|
||||
export interface IInteractionsAPIContext {
|
||||
addInteraction: (device: number, settings: pond.IInteractionSettings, as?: string) => Promise<AxiosResponse<pond.AddInteractionResponse>>;
|
||||
addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings, as?: string) => Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>;
|
||||
addInteraction: (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddInteractionResponse>>;
|
||||
addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>;
|
||||
addInteractionToComponents: (
|
||||
fullComponentLocations: string[],
|
||||
settings: pond.IInteractionSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddInteractionToComponentsResponse>>;
|
||||
updateInteraction: (device: number, settings: pond.IInteractionSettings, as?: string) => Promise<AxiosResponse<pond.UpdateInteractionResponse>>;
|
||||
updateInteraction: (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => Promise<AxiosResponse<pond.UpdateInteractionResponse>>;
|
||||
updateInteractionPondSettings: (
|
||||
device: number,
|
||||
interaction: string,
|
||||
settings: pond.IInteractionPondSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>;
|
||||
removeInteraction: (device: number, interaction: string, as?: string) => Promise<AxiosResponse<pond.RemoveInteractionResponse>>;
|
||||
listInteractionsByDevice: (device: number | string, demo?: boolean, as?: string) => Promise<Interaction[]>;
|
||||
removeInteraction: (device: number, interaction: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveInteractionResponse>>;
|
||||
listInteractionsByDevice: (device: number | string, demo?: boolean, otherTeam?: string) => Promise<Interaction[]>;
|
||||
listInteractionsByComponent: (
|
||||
device: number,
|
||||
component: quack.ComponentID,
|
||||
demo?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<Interaction[]>;
|
||||
setAlertInteractions: (
|
||||
alerts: pond.AlertData[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.SetAlertInteractionsResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -60,12 +60,13 @@ function sanitizeInteraction(interaction: pond.IInteractionSettings): pond.IInte
|
|||
export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, post, put, del } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addInteraction = (device: number, settings: pond.IInteractionSettings, as?: string) => {
|
||||
const addInteraction = (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return new Promise<AxiosResponse<pond.AddInteractionResponse>>((resolve, reject) => {
|
||||
post<pond.AddInteractionResponse>(
|
||||
pondURL("/devices/" + device + "/interactions" + (as ? "?as=" + as : "")),
|
||||
pondURL("/devices/" + device + "/interactions" + (view ? "?as=" + view : "")),
|
||||
sanitizeInteraction(settings)
|
||||
).then(resp => {
|
||||
resp.data = pond.AddInteractionResponse.fromObject(resp)
|
||||
|
|
@ -85,13 +86,14 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
const addInteractionToComponents = (
|
||||
fullComponentLocations: string[],
|
||||
settings: pond.IInteractionSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/interactions/forComponents/" +
|
||||
"?componentIds=" +
|
||||
fullComponentLocations.toString() +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
)
|
||||
return new Promise<AxiosResponse<pond.AddInteractionToComponentsResponse>>((resolve, reject) => {
|
||||
post<pond.AddInteractionToComponentsResponse>(url,sanitizeInteraction(settings)).then(resp => {
|
||||
|
|
@ -103,8 +105,9 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const addMultiInteractions = (device: number, settings: pond.MultiInteractionSettings, as?: string) => {
|
||||
let url = pondURL("/devices/" + device + "/interactions/multi" + (as ? "?as=" + as : ""))
|
||||
const addMultiInteractions = (device: number, settings: pond.MultiInteractionSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/devices/" + device + "/interactions/multi" + (view ? "?as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>((resolve, reject) => {
|
||||
post<pond.AddMultiInteractionsResponse>(url,settings).then(resp => {
|
||||
resp.data = pond.AddMultiInteractionsResponse.fromObject(resp.data)
|
||||
|
|
@ -115,7 +118,8 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const updateInteraction = (device: number, settings: pond.IInteractionSettings, as?: string) => {
|
||||
const updateInteraction = (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
|
|
@ -123,7 +127,7 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
[device] +
|
||||
"&types=" +
|
||||
["device"] +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
)
|
||||
return new Promise<AxiosResponse<pond.UpdateInteractionResponse>>((resolve, reject) => {
|
||||
put<pond.UpdateInteractionResponse>(url,sanitizeInteraction(settings)).then(resp => {
|
||||
|
|
@ -139,8 +143,9 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
device: number,
|
||||
interaction: string,
|
||||
settings: pond.IInteractionPondSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
|
|
@ -150,7 +155,7 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
[device] +
|
||||
"&types=" +
|
||||
["device"] +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
)
|
||||
return new Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>((resolve, reject) => {
|
||||
put<pond.UpdateInteractionPondSettingsResponse>(url, sanitizeInteraction(settings)).then(resp => {
|
||||
|
|
@ -162,8 +167,9 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const removeInteraction = (device: number, interaction: string, as?: string) => {
|
||||
let url = pondURL("/devices/" + device + "/interactions/" + interaction + (as ? "?as=" + as : ""))
|
||||
const removeInteraction = (device: number, interaction: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/devices/" + device + "/interactions/" + interaction + (view ? "?as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.RemoveInteractionResponse>>((resolve, reject) => {
|
||||
del<pond.RemoveInteractionResponse>(url).then(resp => {
|
||||
resp.data = pond.RemoveInteractionResponse.fromObject(resp.data)
|
||||
|
|
@ -178,10 +184,11 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
const listInteractionsByDevice = (
|
||||
device: number | string,
|
||||
demo: boolean = false,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
): Promise<Interaction[]> => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return new Promise((resolve, reject) => {
|
||||
get(pondURL("/devices/" + device + "/interactions" + (as ? "?as=" + as : ""), demo))
|
||||
get(pondURL("/devices/" + device + "/interactions" + (view ? "?as=" + view : ""), demo))
|
||||
.then((response: any) => {
|
||||
if (!has(response, "data.interactions")) {
|
||||
return resolve([]);
|
||||
|
|
@ -217,8 +224,9 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
device: number,
|
||||
component: quack.ComponentID,
|
||||
demo: boolean = false,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
): Promise<Interaction[]> => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return new Promise((resolve, reject) => {
|
||||
get(
|
||||
pondURL(
|
||||
|
|
@ -227,7 +235,7 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
"/components/" +
|
||||
componentIDToString(component) +
|
||||
"/interactions" +
|
||||
(as ? "?as=" + as : ""),
|
||||
(view ? "?as=" + view : ""),
|
||||
demo
|
||||
)
|
||||
)
|
||||
|
|
@ -264,9 +272,10 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
|
|||
|
||||
const setAlertInteractions = (
|
||||
alerts: pond.AlertData[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
): Promise<AxiosResponse<pond.SetAlertInteractionsResponse>> => {
|
||||
let url = pondURL("/interactions/setAlerts" + (as ? "?as=" + as : ""))
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL("/interactions/setAlerts" + (view ? "?as=" + view : ""))
|
||||
return new Promise<AxiosResponse<pond.SetAlertInteractionsResponse>>((resolve, reject) => {
|
||||
post<pond.SetAlertInteractionsResponse>(url, { data: alerts }).then(resp => {
|
||||
resp.data = pond.SetAlertInteractionsResponse.fromObject(resp.data)
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ import { createContext, PropsWithChildren, useContext } from "react";
|
|||
import { pondURL } from "./pond";
|
||||
|
||||
export interface IMineAPIContext {
|
||||
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>;
|
||||
addMine: (mine: pond.MineSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddMineResponse>>;
|
||||
getMine: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetMineResponse>>;
|
||||
addDevice: (key: string, deviceID: string, permissions: pond.Permission[], otherTeam?: string) => Promise<any>;
|
||||
addComponent: (
|
||||
key: string,
|
||||
deviceID: string,
|
||||
componentKey: string,
|
||||
permissions: pond.Permission[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<any>;
|
||||
listMines: (
|
||||
limit: number,
|
||||
|
|
@ -24,7 +24,7 @@ export interface IMineAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListMinesResponse>>;
|
||||
listMinesSimple: (
|
||||
limit: number,
|
||||
|
|
@ -33,9 +33,9 @@ export interface IMineAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListMinesSimpleResponse>>;
|
||||
removeMine: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveMineResponse>>;
|
||||
removeMine: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveMineResponse>>;
|
||||
updateMine: (
|
||||
mine: pond.MineSettings,
|
||||
componentPreferences: Map<string, pond.MineComponentPreferences>
|
||||
|
|
@ -49,14 +49,16 @@ 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, as?: string) => {
|
||||
return post<pond.AddMineResponse>(pondURL("/mines" + (as ? "?as=" + as : "")), mine);
|
||||
const addMine = (mine: pond.MineSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return post<pond.AddMineResponse>(pondURL("/mines" + (view ? "?as=" + view : "")), mine);
|
||||
};
|
||||
|
||||
const getMine = (key: string, as?: string) => {
|
||||
return get<pond.GetMineResponse>(pondURL("/mines/" + key + (as ? "?as=" + as : "")));
|
||||
const getMine = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.GetMineResponse>(pondURL("/mines/" + key + (view ? "?as=" + view : "")));
|
||||
};
|
||||
|
||||
const listMines = (
|
||||
|
|
@ -68,8 +70,9 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
asRoot?: boolean,
|
||||
keys?: string,
|
||||
types?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/mines" +
|
||||
"?limit=" +
|
||||
|
|
@ -80,7 +83,7 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
("&by=" + (orderBy ? orderBy : "deviceId")) +
|
||||
(search ? "&search=" + search : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(keys ? "&keys=" + keys : "") +
|
||||
(types ? "&types=" + types : "")
|
||||
);
|
||||
|
|
@ -94,8 +97,9 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
const url = pondURL(
|
||||
"/minesSimple" +
|
||||
"?limit=" +
|
||||
|
|
@ -106,13 +110,14 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
("&by=" + (orderBy ? orderBy : "deviceId")) +
|
||||
(search ? "&search=" + search : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
);
|
||||
return get<pond.ListMinesSimpleResponse>(url);
|
||||
};
|
||||
|
||||
const removeMine = (key: string, as?: string) => {
|
||||
return del<pond.RemoveMineResponse>(pondURL("/mines/" + key + (as ? "?as=" + as : "")));
|
||||
const removeMine = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return del<pond.RemoveMineResponse>(pondURL("/mines/" + key + (view ? "?as=" + view : "")));
|
||||
};
|
||||
|
||||
const updateMine = (
|
||||
|
|
@ -132,9 +137,10 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
return put<pond.AddMineResponse>(pondURL("/mines"), request);
|
||||
};
|
||||
|
||||
const addDevice = (key: string, deviceID: string, permissions: pond.Permission[], as?: string) => {
|
||||
if (as)
|
||||
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID + `?as=${as}`), {
|
||||
const addDevice = (key: string, deviceID: string, permissions: pond.Permission[], otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID + `?as=${view}`), {
|
||||
permissions: permissions.map(permission => permissionToString(permission))
|
||||
});
|
||||
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID), {
|
||||
|
|
@ -147,11 +153,12 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
deviceID: string,
|
||||
componentKey: string,
|
||||
permissions: pond.Permission[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
if (as)
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post(
|
||||
pondURL(`/mines/` + key + `/addComponent/` + deviceID + "/" + componentKey + `?as=${as}`),
|
||||
pondURL(`/mines/` + key + `/addComponent/` + deviceID + "/" + componentKey + `?as=${view}`),
|
||||
{
|
||||
permissions: permissions.map(permission => permissionToString(permission))
|
||||
}
|
||||
|
|
@ -169,8 +176,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
|
|||
addDevice,
|
||||
addComponent,
|
||||
listMines,
|
||||
listMinesSimple,//
|
||||
removeMine,//
|
||||
listMinesSimple,
|
||||
removeMine,
|
||||
updateMine
|
||||
}}>
|
||||
{children}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { AxiosResponse } from "axios";
|
||||
import { useHTTP } from "hooks";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useGlobalState } from "providers";
|
||||
import { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { pondURL } from "./pond";
|
||||
|
||||
|
|
@ -15,7 +16,7 @@ export interface INoteAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListNotesResponse>>;
|
||||
listChats: (
|
||||
limit: number,
|
||||
|
|
@ -24,7 +25,7 @@ export interface INoteAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListChatsResponse>>;
|
||||
removeNote: (noteID: string) => Promise<AxiosResponse<pond.RemoveBinResponse>>;
|
||||
}
|
||||
|
|
@ -36,6 +37,7 @@ interface Props {}
|
|||
export default function NoteProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
const [{as}] = useGlobalState()
|
||||
|
||||
const addNote = (note: pond.NoteSettings, attachments?: string[]) => {
|
||||
let url = pondURL("/notes" + (attachments ? "?attachments=" + attachments.toString() : ""))
|
||||
|
|
@ -86,8 +88,9 @@ export default function NoteProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/notes" +
|
||||
"?limit=" +
|
||||
|
|
@ -98,7 +101,7 @@ export default function NoteProvider(props: PropsWithChildren<Props>) {
|
|||
("&by=" + (orderBy ? orderBy : "key")) +
|
||||
(search ? "&search=" + search : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
)
|
||||
return new Promise<AxiosResponse<pond.ListNotesResponse>>((resolve, reject) => {
|
||||
get<pond.ListNotesResponse>(url).then(resp => {
|
||||
|
|
@ -117,8 +120,9 @@ export default function NoteProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/chats" +
|
||||
"?limit=" +
|
||||
|
|
@ -129,7 +133,7 @@ export default function NoteProvider(props: PropsWithChildren<Props>) {
|
|||
("&by=" + (orderBy ? orderBy : "key")) +
|
||||
(search ? "&search=" + search : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
)
|
||||
return new Promise<AxiosResponse<pond.ListChatsResponse>>((resolve, reject) => {
|
||||
get<pond.ListChatsResponse>(url).then(resp => {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import { pond } from "protobuf-ts/pond";
|
|||
import { or } from "utils/types";
|
||||
import { pondURL } from "./pond";
|
||||
import { AxiosResponse } from "axios";
|
||||
import { useGlobalState } from "providers";
|
||||
|
||||
export interface INotificationAPIContext {
|
||||
listNotifications: (
|
||||
|
|
@ -12,7 +13,7 @@ export interface INotificationAPIContext {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => Promise<AxiosResponse<pond.ListNotificationsResponse>>;
|
||||
hideNotification: (keys: string[]) => Promise<AxiosResponse<pond.HideNotificationResponse>>;
|
||||
|
|
@ -24,7 +25,7 @@ export interface INotificationAPIContext {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListObjectNotificationsResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -37,6 +38,7 @@ interface Props {}
|
|||
export default function NotificationProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, put } = useHTTP();
|
||||
const [{as}] = useGlobalState();
|
||||
|
||||
const listNotifications = (
|
||||
limit: number,
|
||||
|
|
@ -44,9 +46,10 @@ export default function NotificationProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/notifications" +
|
||||
"?limit=" +
|
||||
|
|
@ -55,7 +58,7 @@ export default function NotificationProvider(props: PropsWithChildren<Props>) {
|
|||
offset +
|
||||
("&order=" + or(order, "asc")) +
|
||||
("&by=" + or(orderBy, "key")) +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(search ? "&search=" + search : "")
|
||||
)
|
||||
|
|
@ -77,8 +80,9 @@ export default function NotificationProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/object/notifications" +
|
||||
"?objectKey=" +
|
||||
|
|
@ -92,7 +96,7 @@ export default function NotificationProvider(props: PropsWithChildren<Props>) {
|
|||
("&order=" + or(order, "asc")) +
|
||||
("&by=" + or(orderBy, "key")) +
|
||||
(search ? "&search=" + search : "") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
)
|
||||
return new Promise<AxiosResponse<pond.ListObjectNotificationsResponse>>((resolve, reject) => {
|
||||
get<pond.ListObjectNotificationsResponse>(url).then(resp => {
|
||||
|
|
|
|||
|
|
@ -2,21 +2,21 @@ import { AxiosResponse } from "axios";
|
|||
import { useHTTP } from "hooks";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useGlobalState } from "providers/StateContainer";
|
||||
import React, { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { or } from "utils";
|
||||
import { pondURL } from "./pond";
|
||||
|
||||
export interface ISiteAPIContext {
|
||||
addSite: (site: pond.SiteSettings, as?: string) => Promise<any>;
|
||||
getSite: (siteID: string, as?: string) => Promise<any>;
|
||||
getSitePage: (siteID: string, as?: string) => Promise<any>;
|
||||
addSite: (site: pond.SiteSettings, otherTeam?: string) => Promise<any>;
|
||||
getSite: (siteID: string, otherTeam?: string) => Promise<any>;
|
||||
getSitePage: (siteID: string, otherTeam?: string) => Promise<any>;
|
||||
listSites: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => Promise<AxiosResponse<pond.ListSitesResponse>>;
|
||||
listSitesPageData: (
|
||||
|
|
@ -25,7 +25,7 @@ export interface ISiteAPIContext {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => Promise<AxiosResponse<pond.ListSitesPageDataResponse>>;
|
||||
removeSite: (siteID: string) => Promise<AxiosResponse<pond.RemoveSiteResponse>>;
|
||||
|
|
@ -33,7 +33,7 @@ export interface ISiteAPIContext {
|
|||
key: string,
|
||||
site: pond.SiteSettings,
|
||||
asRoot?: true,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateSiteResponse>>;
|
||||
updateLink: (
|
||||
parentKey: string,
|
||||
|
|
@ -41,7 +41,7 @@ export interface ISiteAPIContext {
|
|||
objectID: string,
|
||||
objectType: string,
|
||||
permissions: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<any>;
|
||||
}
|
||||
|
||||
|
|
@ -52,20 +52,23 @@ interface Props {}
|
|||
export default function SiteProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const getSitePage = (siteID: string, as?: string) => {
|
||||
if (as) return get(pondURL("/sitePage/" + siteID + "?as=" + as));
|
||||
const getSitePage = (siteID: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return get(pondURL("/sitePage/" + siteID + "?as=" + view));
|
||||
return get(pondURL("/sitePage/" + siteID));
|
||||
};
|
||||
|
||||
const addSite = (site: pond.SiteSettings, as?: string) => {
|
||||
if (as) return post(pondURL("/sites?as=" + as), site);
|
||||
const addSite = (site: pond.SiteSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return post(pondURL("/sites?as=" + view), site);
|
||||
return post(pondURL("/sites"), site);
|
||||
};
|
||||
|
||||
const getSite = (siteID: string, as?: string) => {
|
||||
if (as) return get(pondURL("/site/" + siteID + "?as=" + as));
|
||||
const getSite = (siteID: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return get(pondURL("/site/" + siteID + "?as=" + view));
|
||||
return get(pondURL("/site/" + siteID));
|
||||
};
|
||||
|
||||
|
|
@ -79,9 +82,10 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.ListSitesResponse>(
|
||||
pondURL(
|
||||
"/sites" +
|
||||
|
|
@ -91,7 +95,7 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
|
|||
offset +
|
||||
("&order=" + or(order, "asc")) +
|
||||
("&by=" + or(orderBy, "key")) +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(search ? "&search=" + search : "")
|
||||
)
|
||||
|
|
@ -104,9 +108,10 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
asRoot?: boolean
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.ListSitesPageDataResponse>(
|
||||
pondURL(
|
||||
"/sitesWithData" +
|
||||
|
|
@ -116,18 +121,19 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
|
|||
offset +
|
||||
("&order=" + or(order, "asc")) +
|
||||
("&by=" + or(orderBy, "key")) +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(search ? "&search=" + search : "")
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const updateSite = (key: string, site: pond.SiteSettings, asRoot?: boolean, as?: string) => {
|
||||
if (as)
|
||||
const updateSite = (key: string, site: pond.SiteSettings, asRoot?: boolean, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return put<pond.UpdateSiteResponse>(
|
||||
pondURL(
|
||||
"/sites/" + key + (as ? "?as=" + as : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "")
|
||||
"/sites/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")
|
||||
),
|
||||
site
|
||||
);
|
||||
|
|
@ -143,10 +149,11 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
|
|||
objectID: string,
|
||||
objectType: string,
|
||||
permissions: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
if (as)
|
||||
return post(pondURL(`/sites/` + parentID + `/link?as=${as}`), {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post(pondURL(`/sites/` + parentID + `/link?as=${view}`), {
|
||||
Key: objectID,
|
||||
Type: objectType,
|
||||
Parent: parentID,
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import { createContext, PropsWithChildren, useContext } from "react";
|
|||
import { pondURL } from "./pond";
|
||||
|
||||
export interface ITaskAPIContext {
|
||||
addTask: (task: pond.TaskSettings, as?: string) => Promise<AxiosResponse<pond.AddTaskResponse>>;
|
||||
getTask: (taskID: string, as?: string) => Promise<AxiosResponse<pond.Task>>;
|
||||
addTask: (task: pond.TaskSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddTaskResponse>>;
|
||||
getTask: (taskID: string, otherTeam?: string) => Promise<AxiosResponse<pond.Task>>;
|
||||
listTasks: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
|
|
@ -15,18 +15,18 @@ export interface ITaskAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
from?: string,
|
||||
to?: string
|
||||
) => Promise<AxiosResponse<pond.ListTasksResponse>>;
|
||||
removeTask: (taskID: string, as?: string) => Promise<AxiosResponse<pond.RemoveTaskResponse>>;
|
||||
removeTask: (taskID: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveTaskResponse>>;
|
||||
updateTask: (
|
||||
key: string,
|
||||
task: pond.TaskSettings,
|
||||
asRoot?: true,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateTaskResponse>>;
|
||||
getMultiTasks: (objectKeys: string[], as?: string) => Promise<AxiosResponse<pond.GetMultiTasksResponse>>;
|
||||
getMultiTasks: (objectKeys: string[], otherTeam?: string) => Promise<AxiosResponse<pond.GetMultiTasksResponse>>;
|
||||
}
|
||||
|
||||
export const TaskAPIContext = createContext<ITaskAPIContext>({} as ITaskAPIContext);
|
||||
|
|
@ -36,20 +36,23 @@ interface Props {}
|
|||
export default function TaskProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addTask = (task: pond.TaskSettings, as?: string) => {
|
||||
if (as) return post<pond.AddTaskResponse>(pondURL("/tasks?as=" + as), task);
|
||||
const addTask = (task: pond.TaskSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return post<pond.AddTaskResponse>(pondURL("/tasks?as=" + view), task);
|
||||
return post<pond.AddTaskResponse>(pondURL("/tasks"), task);
|
||||
};
|
||||
|
||||
const getTask = (taskID: string, as?: string) => {
|
||||
if (as) return get<pond.Task>(pondURL("/task/" + taskID + "?as=" + as));
|
||||
const getTask = (taskID: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return get<pond.Task>(pondURL("/task/" + taskID + "?as=" + view));
|
||||
return get<pond.Task>(pondURL("/task/" + taskID));
|
||||
};
|
||||
|
||||
const removeTask = (key: string, as?: string) => {
|
||||
if (as) return del<pond.RemoveTaskResponse>(pondURL("/tasks/" + key + "?as=" + as));
|
||||
const removeTask = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) return del<pond.RemoveTaskResponse>(pondURL("/tasks/" + key + "?as=" + view));
|
||||
return del<pond.RemoveTaskResponse>(pondURL("/tasks/" + key));
|
||||
};
|
||||
|
||||
|
|
@ -60,10 +63,11 @@ export default function TaskProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
from?: string,
|
||||
to?: string
|
||||
) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
return get<pond.ListTasksResponse>(
|
||||
pondURL(
|
||||
"/tasks" +
|
||||
|
|
@ -75,17 +79,18 @@ export default function TaskProvider(props: PropsWithChildren<Props>) {
|
|||
("&by=" + (orderBy ? orderBy : "key")) +
|
||||
(search ? "&search=" + search : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "") +
|
||||
(view ? "&as=" + view : "") +
|
||||
(from ? "&from=" + from : "") +
|
||||
(to ? "&to=" + to : "")
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const updateTask = (key: string, task: pond.TaskSettings, asRoot?: boolean, as?: string) => {
|
||||
if (as)
|
||||
const updateTask = (key: string, task: pond.TaskSettings, asRoot?: boolean, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return put<pond.UpdateTaskResponse>(
|
||||
pondURL("/tasks/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "")),
|
||||
pondURL("/tasks/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")),
|
||||
task
|
||||
);
|
||||
return put<pond.UpdateTaskResponse>(
|
||||
|
|
@ -94,10 +99,11 @@ export default function TaskProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const getMultiTasks = (objectKeys: string[], as?: string) => {
|
||||
if (as)
|
||||
const getMultiTasks = (objectKeys: string[], otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return get<pond.GetMultiTasksResponse>(
|
||||
pondURL("/multitasks?objectKeys=" + objectKeys.join(",") + "&as=" + as)
|
||||
pondURL("/multitasks?objectKeys=" + objectKeys.join(",") + "&as=" + view)
|
||||
);
|
||||
return get<pond.GetMultiTasksResponse>(
|
||||
pondURL("/multitasks?objectKeys=" + objectKeys.join(","))
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import { pond } from "protobuf-ts/pond";
|
|||
import { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { or } from "utils/types";
|
||||
import { pondURL } from "./pond";
|
||||
import { useGlobalState } from "providers";
|
||||
|
||||
export interface ITeamAPIContext {
|
||||
addTeam: (team: pond.TeamSettings) => Promise<AxiosResponse<pond.AddTeamResponse>>;
|
||||
|
|
@ -27,11 +28,11 @@ export interface ITeamAPIContext {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
prefixSearch?: string,
|
||||
) => Promise<AxiosResponse<pond.ListTeamsResponse>>;
|
||||
listAllTeams: () => Promise<AxiosResponse<pond.ListTeamsResponse>>;
|
||||
listObjectTeams: (scope: Scope, as?: string) => Promise<any>;
|
||||
listObjectTeams: (scope: Scope, otherTeam?: string) => Promise<any>;
|
||||
removeTeam: (key: string) => Promise<AxiosResponse<pond.RemoveTeamResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -42,7 +43,7 @@ interface Props {}
|
|||
export default function TeamProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ team }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addTeam = (team: pond.TeamSettings) => {
|
||||
return new Promise<AxiosResponse<pond.AddTeamResponse>>((resolve, reject) => {
|
||||
|
|
@ -114,10 +115,11 @@ export default function TeamProvider(props: PropsWithChildren<Props>) {
|
|||
orderBy?: string,
|
||||
search?: string,
|
||||
asRoot?: boolean,
|
||||
as?: string,
|
||||
otherTeam?: string,
|
||||
prefixSearch?: string,
|
||||
) => {
|
||||
//let asText = team ? "&as=" + team.key() : "";
|
||||
const view = otherTeam ? otherTeam : as
|
||||
let url = pondURL(
|
||||
"/teams" +
|
||||
"?limit=" +
|
||||
|
|
@ -129,7 +131,7 @@ export default function TeamProvider(props: PropsWithChildren<Props>) {
|
|||
(search ? "&search=" + search : "") +
|
||||
(prefixSearch ? "&prefixSearch=" + prefixSearch : "") +
|
||||
(asRoot ? "&asRoot=" + asRoot.toString() : "") +
|
||||
(as ? "&as=" + as : "")
|
||||
(view ? "&as=" + view : "")
|
||||
)
|
||||
return new Promise<AxiosResponse<pond.ListTeamsResponse>>((resolve, reject)=>{
|
||||
get<pond.ListTeamsResponse>(url).then(resp => {
|
||||
|
|
@ -152,9 +154,10 @@ export default function TeamProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const listObjectTeams = (scope: Scope, as?: string) => {
|
||||
const listObjectTeams = (scope: Scope, otherTeam?: string) => {
|
||||
let url = "/" + scope.kind + "s/" + scope.key + "/teams"
|
||||
if (as) url = `/${scope.kind}s/${scope.key}/teams?as=${as}`
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) url = `/${scope.kind}s/${scope.key}/teams?as=${view}`
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
get(pondURL(url)).then(resp => {
|
||||
return resolve(resp)
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ export interface ITerminalAPIContext {
|
|||
addTerminal: (
|
||||
name: string,
|
||||
terminal: pond.TerminalSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddTerminalResponse>>;
|
||||
listTerminals: (
|
||||
limit: number,
|
||||
|
|
@ -17,7 +17,7 @@ export interface ITerminalAPIContext {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListTerminalsResponse>>;
|
||||
listTerminalsAndGates: (
|
||||
limit: number,
|
||||
|
|
@ -25,15 +25,15 @@ export interface ITerminalAPIContext {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListTerminalsAndGatesResponse>>;
|
||||
updateTerminal: (
|
||||
key: string,
|
||||
name: string,
|
||||
settings: pond.TerminalSettings,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateTerminalResponse>>;
|
||||
removeTerminal: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveTerminalResponse>>;
|
||||
removeTerminal: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveTerminalResponse>>;
|
||||
}
|
||||
|
||||
export const TerminalAPIContext = createContext<ITerminalAPIContext>({} as ITerminalAPIContext);
|
||||
|
|
@ -43,12 +43,13 @@ interface Props {}
|
|||
export default function TerminalProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, del, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addTerminal = (name: string, terminal: pond.TerminalSettings, as?: string) => {
|
||||
if (as)
|
||||
const addTerminal = (name: string, terminal: pond.TerminalSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post<pond.AddTerminalResponse>(
|
||||
pondURL("/terminals?name=" + name + "&as=" + as),
|
||||
pondURL("/terminals?name=" + name + "&as=" + view),
|
||||
terminal
|
||||
);
|
||||
return post<pond.AddTerminalResponse>(pondURL("/terminals?name=" + name), terminal);
|
||||
|
|
@ -60,13 +61,14 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
if (as)
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return get<pond.ListTerminalsResponse>(
|
||||
pondURL(
|
||||
"/terminals?as=" +
|
||||
as +
|
||||
view +
|
||||
"&limit=" +
|
||||
limit +
|
||||
"&offset=" +
|
||||
|
|
@ -95,13 +97,14 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
|
|||
order?: "asc" | "desc",
|
||||
orderBy?: string,
|
||||
search?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
if (as)
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return get<pond.ListTerminalsAndGatesResponse>(
|
||||
pondURL(
|
||||
"/terminalsAndGates?as=" +
|
||||
as +
|
||||
view +
|
||||
"&limit=" +
|
||||
limit +
|
||||
"&offset=" +
|
||||
|
|
@ -124,10 +127,11 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const updateTerminal = (key: string, name: string, settings: pond.TerminalSettings, as?: string) => {
|
||||
if (as) {
|
||||
const updateTerminal = (key: string, name: string, settings: pond.TerminalSettings, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return put<pond.UpdateTerminalResponse>(
|
||||
pondURL("/terminals/" + key + "?as=" + as + "&name=" + name),
|
||||
pondURL("/terminals/" + key + "?as=" + view + "&name=" + name),
|
||||
settings
|
||||
);
|
||||
}
|
||||
|
|
@ -137,9 +141,10 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const removeTerminal = (key: string, as?: string) => {
|
||||
if (as) {
|
||||
return del<pond.RemoveTerminalResponse>(pondURL("/terminals/" + key + "?as=" + as));
|
||||
const removeTerminal = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return del<pond.RemoveTerminalResponse>(pondURL("/terminals/" + key + "?as=" + view));
|
||||
}
|
||||
return del<pond.RemoveTerminalResponse>(pondURL("/terminals/" + key));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { useHTTP } from "hooks";
|
||||
import React, { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { pondURL } from "./pond";
|
||||
import { AxiosResponse } from "axios";
|
||||
|
|
@ -9,12 +9,12 @@ export interface ITransactionAPIContext {
|
|||
addTransaction: (
|
||||
transaction: pond.Transaction,
|
||||
fileIDs?: string[],
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.AddTransactionResponse>>;
|
||||
transactionPageData: (
|
||||
start: string,
|
||||
end: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.TransactionPageDataResponse>>;
|
||||
listTransactions: (
|
||||
start: string,
|
||||
|
|
@ -23,13 +23,13 @@ export interface ITransactionAPIContext {
|
|||
toObject?: pond.ObjectType,
|
||||
fromKey?: string,
|
||||
toKey?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.ListTransactionsResponse>>;
|
||||
revokeTransaction: (key: string, as?: string) => Promise<AxiosResponse<pond.RevokeTransactionResponse>>;
|
||||
revokeTransaction: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RevokeTransactionResponse>>;
|
||||
updateTransaction: (
|
||||
key: string,
|
||||
data: pond.TransactionData,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateTransactionResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -42,13 +42,14 @@ interface Props {}
|
|||
export default function TransactionProvider(props: PropsWithChildren<Props>) {
|
||||
const { children } = props;
|
||||
const { get, post, put } = useHTTP();
|
||||
//const [{ as }] = useGlobalState();
|
||||
const [{ as }] = useGlobalState();
|
||||
|
||||
const addTransaction = (transaction: pond.Transaction, fileIDs?: string[], as?: string) => {
|
||||
if (as)
|
||||
const addTransaction = (transaction: pond.Transaction, fileIDs?: string[], otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post<pond.AddTransactionResponse>(
|
||||
pondURL(
|
||||
"/transactions?as=" + as + (fileIDs ? "&fileAttachments=" + fileIDs.toString() : "")
|
||||
"/transactions?as=" + view + (fileIDs ? "&fileAttachments=" + fileIDs.toString() : "")
|
||||
),
|
||||
transaction
|
||||
);
|
||||
|
|
@ -65,11 +66,12 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
|
|||
toObject?: pond.ObjectType,
|
||||
fromKey?: string,
|
||||
toKey?: string,
|
||||
as?: string
|
||||
otherTeam?: string
|
||||
) => {
|
||||
if (as) {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return get<pond.ListTransactionsResponse>(
|
||||
pondURL("/transactions?as=" + as + "&start=" + start + "&end=" + end)
|
||||
pondURL("/transactions?as=" + view + "&start=" + start + "&end=" + end)
|
||||
);
|
||||
}
|
||||
return get<pond.ListTransactionsResponse>(
|
||||
|
|
@ -86,19 +88,21 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const updateTransaction = (key: string, data: pond.TransactionData, as?: string) => {
|
||||
if (as)
|
||||
const updateTransaction = (key: string, data: pond.TransactionData, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view)
|
||||
return post<pond.UpdateTransactionResponse>(
|
||||
pondURL("/transactions/" + key + "/update?as=" + as),
|
||||
pondURL("/transactions/" + key + "/update?as=" + view),
|
||||
data
|
||||
);
|
||||
return post<pond.UpdateTransactionResponse>(pondURL("/transactions/" + key + "/update"), data);
|
||||
};
|
||||
|
||||
const transactionPageData = (start: string, end: string, as?: string) => {
|
||||
if (as) {
|
||||
const transactionPageData = (start: string, end: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return get<pond.TransactionPageDataResponse>(
|
||||
pondURL("/transactionsPage?as=" + as + "&start=" + start + "&end=" + end)
|
||||
pondURL("/transactionsPage?as=" + view + "&start=" + start + "&end=" + end)
|
||||
);
|
||||
}
|
||||
return get<pond.TransactionPageDataResponse>(
|
||||
|
|
@ -106,10 +110,11 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const revokeTransaction = (key: string, as?: string) => {
|
||||
if (as) {
|
||||
const revokeTransaction = (key: string, otherTeam?: string) => {
|
||||
const view = otherTeam ? otherTeam : as
|
||||
if (view) {
|
||||
return put<pond.RevokeTransactionResponse>(
|
||||
pondURL("/transactions/" + key + "/revoke?as=" + as)
|
||||
pondURL("/transactions/" + key + "/revoke?as=" + view)
|
||||
);
|
||||
}
|
||||
return put<pond.TransactionPageDataResponse>(pondURL("/transactions/" + key + "/revoke"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue