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
|
|
@ -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