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
|
|
@ -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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue