updated the component and device api's to have as be a parameter for the function
This commit is contained in:
parent
c617ebf868
commit
b62c7dbe5c
39 changed files with 346 additions and 651 deletions
|
|
@ -18,36 +18,41 @@ export interface IComponentAPIContext {
|
|||
url: string,
|
||||
componentKey: string
|
||||
) => Promise<any>;
|
||||
add: (device: number, settings: pond.ComponentSettings) => Promise<AxiosResponse<pond.AddComponentResponse>>;
|
||||
add: (device: number, settings: pond.ComponentSettings, as?: string) => Promise<AxiosResponse<pond.AddComponentResponse>>;
|
||||
addMultiComponents: (
|
||||
device: number,
|
||||
components: pond.MultiComponentSettings
|
||||
components: pond.MultiComponentSettings,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.AddMultiComponentsResponse>>;
|
||||
update: (
|
||||
device: number,
|
||||
settings: pond.ComponentSettings,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateComponentResponse>>;
|
||||
remove: (device: number, component: string, keys?: string[], types?: string[]) => Promise<AxiosResponse<pond.RemoveComponentResponse>>;
|
||||
get: (device: number, component: string, keys?: string[], types?: string[]) => Promise<AxiosResponse<pond.Component>>;
|
||||
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>>;
|
||||
list: (
|
||||
device: number | string,
|
||||
demo?: boolean,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
comprehensive?: boolean
|
||||
comprehensive?: boolean,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListComponentsResponse>>;
|
||||
listForObject: (
|
||||
keys: string[],
|
||||
types: string[]
|
||||
types: string[],
|
||||
as?:string
|
||||
) => Promise<AxiosResponse<pond.ListComponentsResponse>>;
|
||||
listComponentCardData: (
|
||||
device: number | string,
|
||||
demo?: boolean,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
comprehensive?: boolean
|
||||
comprehensive?: boolean,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListComponentCardDataResponse>>;
|
||||
listHistory: (
|
||||
deviceId: string | number,
|
||||
|
|
@ -57,30 +62,32 @@ export interface IComponentAPIContext {
|
|||
keys?: string[],
|
||||
types?: string[]
|
||||
) => Promise<AxiosResponse<pond.ListComponentHistoryResponse>>;
|
||||
listMeasurements: (
|
||||
device: number,
|
||||
component: string,
|
||||
startDate: any,
|
||||
endDate: any,
|
||||
limit: number,
|
||||
offset: number,
|
||||
order: string,
|
||||
orderBy: string,
|
||||
demo?: boolean,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
) => //exportMeasurements?: boolean
|
||||
Promise<AxiosResponse<pond.ListMeasurementsResponse>>;
|
||||
sampleMeasurements: (
|
||||
device: number | string,
|
||||
component: string,
|
||||
startDate: any,
|
||||
endDate: any,
|
||||
sampleSize: number,
|
||||
demo?: boolean,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
) => Promise<AxiosResponse<pond.SampleMeasurementsResponse>>;
|
||||
// Old measuremnt structure functions, no longer used in codebase
|
||||
// listMeasurements: (
|
||||
// device: number,
|
||||
// component: string,
|
||||
// startDate: any,
|
||||
// endDate: any,
|
||||
// limit: number,
|
||||
// offset: number,
|
||||
// order: string,
|
||||
// orderBy: string,
|
||||
// demo?: boolean,
|
||||
// keys?: string[],
|
||||
// types?: string[]
|
||||
// ) => //exportMeasurements?: boolean
|
||||
// Promise<AxiosResponse<pond.ListMeasurementsResponse>>;
|
||||
// sampleMeasurements: (
|
||||
// device: number | string,
|
||||
// component: string,
|
||||
// startDate: any,
|
||||
// endDate: any,
|
||||
// sampleSize: number,
|
||||
// demo?: boolean,
|
||||
// keys?: string[],
|
||||
// types?: string[],
|
||||
// as?: string
|
||||
// ) => Promise<AxiosResponse<pond.SampleMeasurementsResponse>>;
|
||||
sampleUnitMeasurements: (
|
||||
device: number | string,
|
||||
component: string,
|
||||
|
|
@ -90,7 +97,8 @@ export interface IComponentAPIContext {
|
|||
demo?: boolean,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
showErrors?: boolean
|
||||
showErrors?: boolean,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.SampleUnitMeasurementsResponse>>;
|
||||
// possibly a deprecated function as it is not used anywhere
|
||||
updateComponentPreferences: (
|
||||
|
|
@ -111,7 +119,8 @@ export interface IComponentAPIContext {
|
|||
measurementType?: number | quack.MeasurementType,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
showErrors?: boolean
|
||||
showErrors?: boolean,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListUnitMeasurementsResponse>>;
|
||||
}
|
||||
|
||||
|
|
@ -122,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,
|
||||
|
|
@ -147,7 +156,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
);
|
||||
};
|
||||
|
||||
const addComponent = (device: number, settings: pond.ComponentSettings) => {
|
||||
const addComponent = (device: number, settings: pond.ComponentSettings, as?: string) => {
|
||||
let url = "/devices/" + device + "/components"
|
||||
if (as) url = url + `?as=${as}`
|
||||
return new Promise<AxiosResponse<pond.AddComponentResponse>>((resolve, reject) => {
|
||||
|
|
@ -160,7 +169,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const addMultiComponents = (device: number, components: pond.MultiComponentSettings) => {
|
||||
const addMultiComponents = (device: number, components: pond.MultiComponentSettings, as?: string) => {
|
||||
let url = "/devices/" + device + "/multiComponents"
|
||||
if (as) url = url + `?as=${as}`
|
||||
return new Promise<AxiosResponse<pond.AddMultiComponentsResponse>>((resolve, reject)=>{
|
||||
|
|
@ -177,7 +186,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
device: number,
|
||||
settings: pond.ComponentSettings,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: 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
|
||||
|
|
@ -207,7 +217,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
device: number,
|
||||
component: string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: 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
|
||||
|
|
@ -232,7 +243,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getComponent = (device: number, component: string, keys?: string[], types?: string[]) => {
|
||||
const getComponent = (device: number, component: string, keys?: string[], types?: string[], as?: string) => {
|
||||
let k: string[] = keys ? keys : [];
|
||||
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 : [];
|
||||
|
|
@ -261,7 +272,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
demo: boolean = false,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
comprehensive?: boolean
|
||||
comprehensive?: boolean,
|
||||
as?: string
|
||||
) => {
|
||||
let k = keys ? keys : [];
|
||||
let t = types ? types : [];
|
||||
|
|
@ -291,7 +303,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const listComponentsForObject = (keys: string[], types: string[]) => {
|
||||
const listComponentsForObject = (keys: string[], types: string[], as?: string) => {
|
||||
let url = pondURL("/components/forObject?keys=" + keys + "&types=" + types + (as ? "&as=" + as : ""))
|
||||
return new Promise<AxiosResponse<pond.ListComponentsResponse>>((resolve, reject) => {
|
||||
get<pond.ListComponentsResponse>(url).then(resp => {
|
||||
|
|
@ -308,7 +320,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
demo: boolean = false,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
comprehensive = false
|
||||
comprehensive = false,
|
||||
as?: string
|
||||
) => {
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
|
|
@ -368,84 +381,86 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const listMeasurements = (
|
||||
device: number,
|
||||
component: string,
|
||||
startDate: any,
|
||||
endDate: any,
|
||||
limit: number,
|
||||
offset: number,
|
||||
order: string,
|
||||
orderBy: string,
|
||||
demo: boolean = false,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
// exportMeasurements: boolean = false
|
||||
) => {
|
||||
const url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
"/components/" +
|
||||
component +
|
||||
"/measurements" +
|
||||
//(exportMeasurements ? "/export" : "") +
|
||||
dateRange(startDate, endDate) +
|
||||
"&limit=" +
|
||||
limit +
|
||||
"&offset=" +
|
||||
offset +
|
||||
"&order=" +
|
||||
order +
|
||||
"&by=" +
|
||||
orderBy +
|
||||
(as ? "&as=" + as : "") +
|
||||
(keys ? "&keys=" + keys : "&keys=" + [device]) +
|
||||
(types ? "&types=" + types : "&types=" + ["device"]),
|
||||
demo
|
||||
);
|
||||
return new Promise<AxiosResponse<pond.ListMeasurementsResponse>>((resolve,reject) => {
|
||||
return get<pond.ListMeasurementsResponse>(url).then(resp => {
|
||||
resp.data = pond.ListMeasurementsResponse.fromObject(resp.data)
|
||||
return resolve(resp)
|
||||
}).catch(err => {
|
||||
return reject(err)
|
||||
})
|
||||
})
|
||||
};
|
||||
// const listMeasurements = (
|
||||
// device: number,
|
||||
// component: string,
|
||||
// startDate: any,
|
||||
// endDate: any,
|
||||
// limit: number,
|
||||
// offset: number,
|
||||
// order: string,
|
||||
// orderBy: string,
|
||||
// demo: boolean = false,
|
||||
// keys?: string[],
|
||||
// types?: string[],
|
||||
// as?: string
|
||||
// // exportMeasurements: boolean = false
|
||||
// ) => {
|
||||
// const url = pondURL(
|
||||
// "/devices/" +
|
||||
// device +
|
||||
// "/components/" +
|
||||
// component +
|
||||
// "/measurements" +
|
||||
// //(exportMeasurements ? "/export" : "") +
|
||||
// dateRange(startDate, endDate) +
|
||||
// "&limit=" +
|
||||
// limit +
|
||||
// "&offset=" +
|
||||
// offset +
|
||||
// "&order=" +
|
||||
// order +
|
||||
// "&by=" +
|
||||
// orderBy +
|
||||
// (as ? "&as=" + as : "") +
|
||||
// (keys ? "&keys=" + keys : "&keys=" + [device]) +
|
||||
// (types ? "&types=" + types : "&types=" + ["device"]),
|
||||
// demo
|
||||
// );
|
||||
// return new Promise<AxiosResponse<pond.ListMeasurementsResponse>>((resolve,reject) => {
|
||||
// return get<pond.ListMeasurementsResponse>(url).then(resp => {
|
||||
// resp.data = pond.ListMeasurementsResponse.fromObject(resp.data)
|
||||
// return resolve(resp)
|
||||
// }).catch(err => {
|
||||
// return reject(err)
|
||||
// })
|
||||
// })
|
||||
// };
|
||||
|
||||
const sampleMeasurements = (
|
||||
device: number | string,
|
||||
component: string,
|
||||
startDate: any,
|
||||
endDate: any,
|
||||
sampleSize: number,
|
||||
demo: boolean = false,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
) => {
|
||||
const url = pondURL(
|
||||
"/devices/" +
|
||||
device +
|
||||
"/components/" +
|
||||
component +
|
||||
"/measurements/sample" +
|
||||
dateRange(startDate, endDate) +
|
||||
"&size=" +
|
||||
sampleSize +
|
||||
(as ? "&as=" + as : "") +
|
||||
(keys ? "&keys=" + keys : "&keys=" + [device]) +
|
||||
(types ? "&types=" + types : "&types=" + ["device"]),
|
||||
demo
|
||||
);
|
||||
return new Promise<AxiosResponse<pond.SampleMeasurementsResponse>>((resolve, reject) => {
|
||||
get<pond.SampleMeasurementsResponse>(url).then(resp => {
|
||||
resp.data = pond.SampleMeasurementsResponse.fromObject(resp.data)
|
||||
return resolve(resp)
|
||||
}).catch(err => {
|
||||
return reject(err)
|
||||
})
|
||||
})
|
||||
};
|
||||
// const sampleMeasurements = (
|
||||
// device: number | string,
|
||||
// component: string,
|
||||
// startDate: any,
|
||||
// endDate: any,
|
||||
// sampleSize: number,
|
||||
// demo: boolean = false,
|
||||
// keys?: string[],
|
||||
// types?: string[],
|
||||
// as?: string
|
||||
// ) => {
|
||||
// const url = pondURL(
|
||||
// "/devices/" +
|
||||
// device +
|
||||
// "/components/" +
|
||||
// component +
|
||||
// "/measurements/sample" +
|
||||
// dateRange(startDate, endDate) +
|
||||
// "&size=" +
|
||||
// sampleSize +
|
||||
// (as ? "&as=" + as : "") +
|
||||
// (keys ? "&keys=" + keys : "&keys=" + [device]) +
|
||||
// (types ? "&types=" + types : "&types=" + ["device"]),
|
||||
// demo
|
||||
// );
|
||||
// return new Promise<AxiosResponse<pond.SampleMeasurementsResponse>>((resolve, reject) => {
|
||||
// get<pond.SampleMeasurementsResponse>(url).then(resp => {
|
||||
// resp.data = pond.SampleMeasurementsResponse.fromObject(resp.data)
|
||||
// return resolve(resp)
|
||||
// }).catch(err => {
|
||||
// return reject(err)
|
||||
// })
|
||||
// })
|
||||
// };
|
||||
|
||||
const sampleUnitMeasurements = (
|
||||
device: number | string,
|
||||
|
|
@ -456,7 +471,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
demo: boolean = false,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
showErrors: boolean = true
|
||||
showErrors: boolean = true,
|
||||
as?: string
|
||||
) => {
|
||||
const url = pondURL(
|
||||
"/devices/" +
|
||||
|
|
@ -519,7 +535,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
measurementType?: number | quack.MeasurementType,
|
||||
keys?: string[],
|
||||
types?: string[],
|
||||
showErrors?: boolean
|
||||
showErrors?: boolean,
|
||||
as?: string
|
||||
) => {
|
||||
const url = pondURL(
|
||||
"/devices/" +
|
||||
|
|
@ -563,8 +580,8 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
|
|||
listForObject: listComponentsForObject,
|
||||
listComponentCardData: listComponentCardData,
|
||||
listHistory,
|
||||
listMeasurements: listMeasurements,
|
||||
sampleMeasurements: sampleMeasurements,
|
||||
//listMeasurements: listMeasurements,
|
||||
//sampleMeasurements: sampleMeasurements,
|
||||
sampleUnitMeasurements,
|
||||
updateComponentPreferences: updateComponentPreferences,
|
||||
listUnitMeasurements
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { useHTTP, usePermissionAPI } from "hooks";
|
||||
// import { useWebsocket } from "websocket";
|
||||
import { /*Component,*/ Component, deviceScope, User } from "models";
|
||||
import { /*Component,*/ Component, deviceScope, Team, User } from "models";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { pondURL } from "./pond";
|
||||
|
|
@ -12,18 +12,19 @@ import { dateRange } from "providers/http";
|
|||
// import { reject, result } from "lodash";
|
||||
|
||||
export interface IDeviceAPIContext {
|
||||
add: (name: string, description: string, backpack: pond.BackpackSettings) => Promise<AxiosResponse<pond.AddDeviceResponse>>;
|
||||
update: (id: number, settings: pond.DeviceSettings) => Promise<AxiosResponse<pond.UpdateDeviceResponse>>;
|
||||
remove: (id: number) => Promise<AxiosResponse<pond.RemoveDeviceResponse>>;
|
||||
get: (id: number | string, demo?: boolean, keys?: string[], types?: string[]) => Promise<AxiosResponse<pond.Device>>
|
||||
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>>
|
||||
getPageData: (
|
||||
id: number | string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.GetDevicePageDataResponse>>;
|
||||
getMulti: (ids: number[] | string[]) => Promise<AxiosResponse<pond.GetMultiDeviceResponse>>;
|
||||
getGeoJson: (id: number | string, demo?: boolean) => Promise<any>;
|
||||
getMultiGeoJson: (ids: number[] | string[]) => Promise<any>;
|
||||
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>;
|
||||
list: (
|
||||
limit: number,
|
||||
offset: number,
|
||||
|
|
@ -40,6 +41,7 @@ export interface IDeviceAPIContext {
|
|||
types?: string[],
|
||||
fieldContains?: Map<string, string>,
|
||||
prefixSearch?: string,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListDevicesResponse>>;
|
||||
listForUser: (
|
||||
asRoot: boolean,
|
||||
|
|
@ -62,19 +64,22 @@ export interface IDeviceAPIContext {
|
|||
id: number | string,
|
||||
preferences: pond.DevicePreferences,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => Promise<any>;
|
||||
updateComponentPreferences: (
|
||||
id: number | string,
|
||||
component: string,
|
||||
preferences: pond.DeviceComponentPreferences,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.UpdateDeviceComponentPreferencesResponse>>;
|
||||
listDeviceComponentPreferences: (
|
||||
id: number | string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListDeviceComponentPreferencesResponse>>;
|
||||
updateStatus: (
|
||||
id: number | string,
|
||||
|
|
@ -94,7 +99,7 @@ export interface IDeviceAPIContext {
|
|||
newCap: number
|
||||
) => Promise<AxiosResponse<pond.BulkChangeDataCapsResponse>>;
|
||||
resume: (id: number) => Promise<any>;
|
||||
getUpgradeStatus: (id: number, keys?: string[], types?: string[]) => Promise<any>;
|
||||
getUpgradeStatus: (id: number, keys?: string[], types?: string[], as?: string) => Promise<any>;
|
||||
loadBackpack: (id: number, backpack: number) => Promise<any>;
|
||||
setTags: (id: number, tags: string[]) => Promise<any>;
|
||||
setWifi: (
|
||||
|
|
@ -102,7 +107,8 @@ export interface IDeviceAPIContext {
|
|||
gateway: string,
|
||||
password: string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => Promise<any>;
|
||||
statistics: (
|
||||
keys?: string[],
|
||||
|
|
@ -122,7 +128,8 @@ export interface IDeviceAPIContext {
|
|||
limit: number,
|
||||
offset: number,
|
||||
order: string,
|
||||
orderBy: string
|
||||
orderBy: string,
|
||||
as?: string
|
||||
) => Promise<AxiosResponse<pond.ListDeviceExportedMeasurementsResponse>>;
|
||||
listSimpleJSON: (device: number) => Promise<any>;
|
||||
resetQuackCount: (id: number) => Promise<any>;
|
||||
|
|
@ -150,9 +157,9 @@ 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) => {
|
||||
const add = (name: string, description: string, backpack: pond.BackpackSettings, as?: string) => {
|
||||
let url = pondURL("/devices")
|
||||
if (as) url = pondURL("/devices?as=" + as)
|
||||
return new Promise<AxiosResponse<pond.AddDeviceResponse>>((resolve, reject) => {
|
||||
|
|
@ -169,7 +176,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
id: number | string,
|
||||
demo: boolean = false,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => {
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
|
|
@ -222,7 +230,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
const getDevicePageData = (
|
||||
id: number | string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
): Promise<AxiosResponse<pond.GetDevicePageDataResponse>> => {
|
||||
let url = pondURL(
|
||||
"/devicePageData/" +
|
||||
|
|
@ -250,7 +259,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getDeviceGeoJSON = (id: number | string, demo: boolean = false) => {
|
||||
const getDeviceGeoJSON = (id: number | string, demo: boolean = false, as?: string) => {
|
||||
let url = pondURL("/devices/" + id + "/geojson", demo);
|
||||
if (as) url = pondURL("/devices/" + id + "/geojson?as=" + as, demo)
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
|
|
@ -262,7 +271,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getMulti = (ids: number[] | string[]) => {
|
||||
const getMulti = (ids: number[] | string[], as?: string) => {
|
||||
let idString = "";
|
||||
ids.forEach((id: number | string, i: number) => {
|
||||
if (i === 0) {
|
||||
|
|
@ -282,7 +291,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getMultiDevicesGeoJSON = (ids: number[] | string[]) => {
|
||||
const getMultiDevicesGeoJSON = (ids: number[] | string[], as?: string) => {
|
||||
let idString = "";
|
||||
ids.forEach((id: number | string, i: number) => {
|
||||
if (i === 0) {
|
||||
|
|
@ -317,6 +326,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
types?: string[],
|
||||
fieldContains?: Map<string, string>,
|
||||
prefixSearch?: string,
|
||||
as?: string
|
||||
) => {
|
||||
const url = pondURL(
|
||||
"/devices" +
|
||||
|
|
@ -375,7 +385,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const remove = (id: number) => {
|
||||
const remove = (id: number, as?: string) => {
|
||||
const url = pondURL("/devices/" + id + (as ? "?as=" + as : ""))
|
||||
return new Promise<AxiosResponse<pond.RemoveDeviceResponse>>((resolve, reject) => {
|
||||
del<pond.RemoveDeviceResponse>(url).then(resp => {
|
||||
|
|
@ -387,7 +397,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const update = (id: number, settings: pond.DeviceSettings) => {
|
||||
const update = (id: number, settings: pond.DeviceSettings, as?: string) => {
|
||||
const url = pondURL("/devices/" + id + "/update" + (as ? "?as=" + as : ""));
|
||||
return new Promise<AxiosResponse<pond.UpdateDeviceResponse>>((resolve, reject) => {
|
||||
put<pond.UpdateDeviceResponse>(url, settings).then(resp => {
|
||||
|
|
@ -452,7 +462,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
id: number | string,
|
||||
preferences: pond.DevicePreferences,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => {
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
|
|
@ -477,7 +488,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
component: string,
|
||||
preferences: pond.DeviceComponentPreferences,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => {
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
|
|
@ -503,7 +515,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
const listDeviceComponentPreferences = (
|
||||
id: number | string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => {
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
|
|
@ -535,7 +548,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
id: number | string,
|
||||
status: pond.DeviceStatus,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => {
|
||||
let url = pondURL(
|
||||
"/devices/" +
|
||||
|
|
@ -626,7 +640,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
const getUpgradeStatus = (id: number, keys?: string[], types?: string[]) => {
|
||||
const getUpgradeStatus = (id: number, keys?: string[], types?: string[], as?: string) => {
|
||||
let a = as ? "?as=" + as : "";
|
||||
if (keys && keys.length > 0 && types && types.length > 0) {
|
||||
a = as ? a + "&keys=" + keys + "&types=" + types : "?keys=" + keys + "&types=" + types;
|
||||
|
|
@ -666,7 +680,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
gateway: string,
|
||||
password: string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string
|
||||
) => {
|
||||
let a = as ? "?as=" + as : "";
|
||||
if (keys && keys.length > 0 && types && types.length > 0) {
|
||||
|
|
@ -764,7 +779,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
limit: number,
|
||||
offset: number,
|
||||
order: string,
|
||||
orderBy: string
|
||||
orderBy: string,
|
||||
as?: string
|
||||
) => {
|
||||
let keyString = "";
|
||||
components.forEach((comp, i) => {
|
||||
|
|
@ -875,10 +891,12 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
MB: number,
|
||||
source?: string,
|
||||
keys?: string[],
|
||||
types?: string[]
|
||||
types?: string[],
|
||||
as?: string,
|
||||
team?: Team
|
||||
) => {
|
||||
let url = "/devices/" + id + "/buyData?MB=" + MB;
|
||||
if (as === team.key()) url = url + "&team=" + team.key();
|
||||
if (as === team?.key()) url = url + "&team=" + team?.key();
|
||||
if (source) url = url + "&source=" + source;
|
||||
if (keys) url = url + "&keys=" + keys;
|
||||
if (types) url = url + "&types=" + types;
|
||||
|
|
@ -936,7 +954,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
getDataUsage,
|
||||
buyData,
|
||||
updateComponentPreferences,
|
||||
listDeviceComponentPreferences
|
||||
listDeviceComponentPreferences//as
|
||||
}}>
|
||||
{children}
|
||||
</DeviceAPIContext.Provider>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue