device actions fully imported
This commit is contained in:
parent
59d9bf2e6b
commit
9cdf7514b2
7 changed files with 522 additions and 76 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { useHTTP, usePermissionAPI } from "hooks";
|
||||
// import { useWebsocket } from "websocket";
|
||||
import { /*Component,*/ deviceScope, User } from "models";
|
||||
import { /*Component,*/ Component, deviceScope, User } from "models";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { createContext, PropsWithChildren, useContext } from "react";
|
||||
import { pondURL } from "./pond";
|
||||
|
|
@ -8,6 +8,7 @@ import { AxiosResponse } from "axios";
|
|||
import { useGlobalState } from "providers";
|
||||
import moment from "moment";
|
||||
import { or } from "utils/types";
|
||||
import { dateRange } from "providers/http";
|
||||
// import { reject, result } from "lodash";
|
||||
|
||||
export interface IDeviceAPIContext {
|
||||
|
|
@ -113,16 +114,16 @@ export interface IDeviceAPIContext {
|
|||
isOverLimit: (id: number) => Promise<any>;
|
||||
isPaused: (id: number) => Promise<any>;
|
||||
setDatacap: (id: number, newCap: number) => Promise<any>;
|
||||
// listJSONMeasurements: (
|
||||
// id: number,
|
||||
// components: Component[],
|
||||
// startDate: any,
|
||||
// endDate: any,
|
||||
// limit: number,
|
||||
// offset: number,
|
||||
// order: string,
|
||||
// orderBy: string
|
||||
// ) => Promise<AxiosResponse<pond.ListDeviceExportedMeasurementsResponse>>;
|
||||
listJSONMeasurements: (
|
||||
id: number,
|
||||
components: Component[],
|
||||
startDate: any,
|
||||
endDate: any,
|
||||
limit: number,
|
||||
offset: number,
|
||||
order: string,
|
||||
orderBy: string
|
||||
) => Promise<AxiosResponse<pond.ListDeviceExportedMeasurementsResponse>>;
|
||||
listSimpleJSON: (device: number) => Promise<any>;
|
||||
resetQuackCount: (id: number) => Promise<any>;
|
||||
resetQuackCountTx: (id: number) => Promise<any>;
|
||||
|
|
@ -755,65 +756,65 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
})
|
||||
};
|
||||
|
||||
// const listJSONMeasurements = (
|
||||
// id: number,
|
||||
// components: Component[],
|
||||
// startDate: any,
|
||||
// endDate: any,
|
||||
// limit: number,
|
||||
// offset: number,
|
||||
// order: string,
|
||||
// orderBy: string
|
||||
// ) => {
|
||||
// let keyString = "";
|
||||
// components.forEach((comp, i) => {
|
||||
// if (i === 0) {
|
||||
// keyString = keyString + comp.key();
|
||||
// } else {
|
||||
// keyString = keyString + "," + comp.key();
|
||||
// }
|
||||
// });
|
||||
// if (as) {
|
||||
// return get<pond.ListDeviceExportedMeasurementsResponse>(
|
||||
// pondURL(
|
||||
// "/devices/" +
|
||||
// id +
|
||||
// "/measurements/exportComplex" +
|
||||
// dateRange(startDate, endDate) +
|
||||
// "&components=" +
|
||||
// keyString +
|
||||
// "&limit=" +
|
||||
// limit +
|
||||
// "&offset=" +
|
||||
// offset +
|
||||
// "&order=" +
|
||||
// order +
|
||||
// "&orderBy=" +
|
||||
// orderBy +
|
||||
// "&as=" +
|
||||
// as
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
// return get<pond.ListDeviceExportedMeasurementsResponse>(
|
||||
// pondURL(
|
||||
// "/devices/" +
|
||||
// id +
|
||||
// "/measurements/exportComplex" +
|
||||
// dateRange(startDate, endDate) +
|
||||
// "&components=" +
|
||||
// keyString +
|
||||
// "&limit=" +
|
||||
// limit +
|
||||
// "&offset=" +
|
||||
// offset +
|
||||
// "&order=" +
|
||||
// order +
|
||||
// "&orderBy=" +
|
||||
// orderBy
|
||||
// )
|
||||
// );
|
||||
// };
|
||||
const listJSONMeasurements = (
|
||||
id: number,
|
||||
components: Component[],
|
||||
startDate: any,
|
||||
endDate: any,
|
||||
limit: number,
|
||||
offset: number,
|
||||
order: string,
|
||||
orderBy: string
|
||||
) => {
|
||||
let keyString = "";
|
||||
components.forEach((comp, i) => {
|
||||
if (i === 0) {
|
||||
keyString = keyString + comp.key();
|
||||
} else {
|
||||
keyString = keyString + "," + comp.key();
|
||||
}
|
||||
});
|
||||
if (as) {
|
||||
return get<pond.ListDeviceExportedMeasurementsResponse>(
|
||||
pondURL(
|
||||
"/devices/" +
|
||||
id +
|
||||
"/measurements/exportComplex" +
|
||||
dateRange(startDate, endDate) +
|
||||
"&components=" +
|
||||
keyString +
|
||||
"&limit=" +
|
||||
limit +
|
||||
"&offset=" +
|
||||
offset +
|
||||
"&order=" +
|
||||
order +
|
||||
"&orderBy=" +
|
||||
orderBy +
|
||||
"&as=" +
|
||||
as
|
||||
)
|
||||
);
|
||||
}
|
||||
return get<pond.ListDeviceExportedMeasurementsResponse>(
|
||||
pondURL(
|
||||
"/devices/" +
|
||||
id +
|
||||
"/measurements/exportComplex" +
|
||||
dateRange(startDate, endDate) +
|
||||
"&components=" +
|
||||
keyString +
|
||||
"&limit=" +
|
||||
limit +
|
||||
"&offset=" +
|
||||
offset +
|
||||
"&order=" +
|
||||
order +
|
||||
"&orderBy=" +
|
||||
orderBy
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
const listSimpleJSON = (device: number) => {
|
||||
return new Promise<AxiosResponse>((resolve, reject) => {
|
||||
|
|
@ -925,7 +926,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
|
|||
isOverLimit,
|
||||
isPaused,
|
||||
setDatacap,
|
||||
// listJSONMeasurements,
|
||||
listJSONMeasurements,
|
||||
listSimpleJSON,
|
||||
resetQuackCount,
|
||||
resetQuackCountTx,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue