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:
csawatzky 2025-04-28 10:47:59 -06:00
parent b404c45a4f
commit 59f7f7f4e1
25 changed files with 673 additions and 535 deletions

View file

@ -344,7 +344,7 @@ export default function BinSettings(props: Props) {
setBinYardOptions(y); setBinYardOptions(y);
} else { } else {
binYardAPI binYardAPI
.listBinYards(350, 0, "desc", as ? as : userID, undefined, undefined, undefined, as) .listBinYards(350, 0, "desc", as ? as : userID, undefined, undefined, as)
.then(resp => { .then(resp => {
let data = resp.data.yard ? resp.data.yard : []; let data = resp.data.yard ? resp.data.yard : [];
let yards: Option[] = data.map((yard: pond.BinYard) => { let yards: Option[] = data.map((yard: pond.BinYard) => {

View file

@ -147,7 +147,7 @@ export default function GrainTransaction(props: Props) {
if (!bagsLoading) { if (!bagsLoading) {
setBagsLoading(true); setBagsLoading(true);
grainBagAPI grainBagAPI
.listGrainBags(0, 0, undefined, undefined, undefined, undefined, undefined, undefined, undefined, as) .listGrainBags(0, 0, undefined, undefined, undefined, undefined, undefined, undefined, as)
.then(resp => { .then(resp => {
//let sourceOps: Option[] = sourceOptions //let sourceOps: Option[] = sourceOptions
let bagOps: Option[] = []; let bagOps: Option[] = [];

View file

@ -304,7 +304,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
const loadGrainBags = useCallback(() => { const loadGrainBags = useCallback(() => {
grainBagAPI grainBagAPI
.listGrainBags(100, 0, undefined, undefined, undefined, undefined, undefined, undefined, undefined, as) .listGrainBags(100, 0, undefined, undefined, undefined, undefined, undefined, undefined, as)
.then(resp => { .then(resp => {
let bags: Map<string, BagModel> = new Map(); let bags: Map<string, BagModel> = new Map();
let bagOp: BagModel[] = []; let bagOp: BagModel[] = [];
@ -376,7 +376,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
let yardEntries: Result[] = []; let yardEntries: Result[] = [];
binYardAPI binYardAPI
.listBinYards(400, 0, "asc", undefined, undefined, undefined, undefined, as) .listBinYards(400, 0, "asc", undefined, undefined, undefined, as)
.then(resp => { .then(resp => {
resp.data.yard.forEach(yard => { resp.data.yard.forEach(yard => {
if (yard.settings) { if (yard.settings) {

View file

@ -34,7 +34,6 @@ export default function Contracts() {
undefined, undefined,
undefined, undefined,
undefined, undefined,
undefined,
year, year,
as as
) )

View file

@ -10,9 +10,9 @@ export interface IObjectHeaterAPIContext {
addObjectHeater: ( addObjectHeater: (
name: string, name: string,
heater: pond.ObjectHeaterSettings, heater: pond.ObjectHeaterSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddObjectHeaterResponse>>; ) => Promise<AxiosResponse<pond.AddObjectHeaterResponse>>;
getObjectHeater: (key: string, as?: string) => Promise<AxiosResponse<pond.GetObjectHeaterResponse>>; getObjectHeater: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetObjectHeaterResponse>>;
listObjectHeaters: ( listObjectHeaters: (
limit: number, limit: number,
offset: number, offset: number,
@ -20,17 +20,17 @@ export interface IObjectHeaterAPIContext {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string, otherTeam?: string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
numerical?: boolean numerical?: boolean
) => Promise<AxiosResponse<pond.ListObjectHeatersResponse>>; ) => Promise<AxiosResponse<pond.ListObjectHeatersResponse>>;
removeObjectHeater: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveObjectHeaterResponse>>; removeObjectHeater: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveObjectHeaterResponse>>;
updateObjectHeater: ( updateObjectHeater: (
key: string, key: string,
name: string, name: string,
settings: pond.ObjectHeaterSettings, settings: pond.ObjectHeaterSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateObjectHeaterResponse>>; ) => Promise<AxiosResponse<pond.UpdateObjectHeaterResponse>>;
updateLink: ( updateLink: (
parentKey: string, parentKey: string,
@ -38,7 +38,7 @@ export interface IObjectHeaterAPIContext {
objectID: string, objectID: string,
objectType: string, objectType: string,
permissions: string[], permissions: string[],
as?: string otherTeam?: string
) => Promise<any>; ) => Promise<any>;
listObjectHeatersPageData: ( listObjectHeatersPageData: (
limit: number, limit: number,
@ -46,7 +46,7 @@ export interface IObjectHeaterAPIContext {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => Promise<AxiosResponse<pond.ListObjectHeatersPageDataResponse>>; ) => Promise<AxiosResponse<pond.ListObjectHeatersPageDataResponse>>;
} }
@ -60,27 +60,30 @@ interface Props {}
export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) { export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addObjectHeater = (name: string, settings: pond.ObjectHeaterSettings, as?: string) => { const addObjectHeater = (name: string, settings: pond.ObjectHeaterSettings, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return post<pond.AddObjectHeaterResponse>( return post<pond.AddObjectHeaterResponse>(
pondURL("/objectHeaters?name=" + name + "&as=" + as), pondURL("/objectHeaters?name=" + name + "&as=" + view),
settings settings
); );
return post<pond.AddObjectHeaterResponse>(pondURL("/objectHeaters?name=" + name), settings); return post<pond.AddObjectHeaterResponse>(pondURL("/objectHeaters?name=" + name), settings);
}; };
const getObjectHeater = (key: string, as?: string) => { const getObjectHeater = (key: string, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + as)); if (view) {
return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + view));
} }
return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key)); return get<pond.GetObjectHeaterResponse>(pondURL("/objectHeaters/" + key));
}; };
const removeObjectHeater = (key: string, as?: string) => { const removeObjectHeater = (key: string, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + as)); if (view)
return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key + "?as=" + view));
return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key)); return del<pond.RemoveObjectHeaterResponse>(pondURL("/objectHeaters/" + key));
}; };
@ -91,11 +94,12 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string, otherTeam?: string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
numerical?: boolean numerical?: boolean
) => { ) => {
const view = otherTeam ? otherTeam : as
return get<pond.ListObjectHeatersResponse>( return get<pond.ListObjectHeatersResponse>(
pondURL( pondURL(
"/objectHeaters" + "/objectHeaters" +
@ -108,17 +112,18 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(numerical ? "&numerical=true" : "") + (numerical ? "&numerical=true" : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : "") (types ? "&types=" + types.toString() : "")
) )
); );
}; };
const updateObjectHeater = (key: string, name: string, settings: pond.ObjectHeaterSettings, as?: string) => { const updateObjectHeater = (key: string, name: string, settings: pond.ObjectHeaterSettings, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
return put<pond.UpdateObjectHeaterResponse>( return put<pond.UpdateObjectHeaterResponse>(
pondURL("/objectHeaters/" + key + "?as=" + as + "&name=" + name), pondURL("/objectHeaters/" + key + "?as=" + view + "&name=" + name),
settings settings
); );
} }
@ -134,10 +139,11 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
objectID: string, objectID: string,
objectType: string, objectType: string,
permissions: string[], permissions: string[],
as?: string otherTeam?: string
) => { ) => {
if (as) const view = otherTeam ? otherTeam : as
return post(pondURL(`/objectHeaters/` + parentID + `/link?as=${as}`), { if (view)
return post(pondURL(`/objectHeaters/` + parentID + `/link?as=${view}`), {
Key: objectID, Key: objectID,
Type: objectType, Type: objectType,
Parent: parentID, Parent: parentID,
@ -159,9 +165,10 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => { ) => {
const view = otherTeam ? otherTeam : as
return get<pond.ListObjectHeatersPageDataResponse>( return get<pond.ListObjectHeatersPageDataResponse>(
pondURL( pondURL(
"/objectHeatersWithData" + "/objectHeatersWithData" +
@ -171,7 +178,7 @@ export default function ObjectHeaterProvider(props: PropsWithChildren<Props>) {
offset + offset +
("&order=" + or(order, "asc")) + ("&order=" + or(order, "asc")) +
("&by=" + or(orderBy, "key")) + ("&by=" + or(orderBy, "key")) +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(search ? "&search=" + search : "") (search ? "&search=" + search : "")
) )

View file

@ -10,43 +10,43 @@ import { useGlobalState } from "providers";
import { quack } from "protobuf-ts/quack"; import { quack } from "protobuf-ts/quack";
export interface IBinAPIContext { export interface IBinAPIContext {
addBin: (bin: pond.BinSettings, as?: string) => Promise<AxiosResponse<pond.AddBinResponse>>; addBin: (bin: pond.BinSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddBinResponse>>;
updateBin: (key: string, bin: pond.BinSettings, as?: string) => Promise<AxiosResponse<pond.UpdateBinResponse>>; updateBin: (key: string, bin: pond.BinSettings, otherTeam?: string) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
bulkBinUpdate: (bins: pond.BinSettings[], as?: string) => Promise<AxiosResponse<pond.BulkBinUpdateResponse>>; bulkBinUpdate: (bins: pond.BinSettings[], otherTeam?: string) => Promise<AxiosResponse<pond.BulkBinUpdateResponse>>;
updateBinStatus: ( updateBinStatus: (
key: string, key: string,
binStatus: pond.BinStatus, binStatus: pond.BinStatus,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateBinResponse>>; ) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
removeBin: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveBinResponse>>; removeBin: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveBinResponse>>;
getBin: (key: string, as?: string) => Promise<AxiosResponse<pond.Bin>>; getBin: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.Bin>>;
addComponent: ( addComponent: (
bin: string, bin: string,
device: number, device: number,
component: string, component: string,
preferences?: pond.BinComponentPreferences, preferences?: pond.BinComponentPreferences,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddBinComponentResponse>>; ) => Promise<AxiosResponse<pond.AddBinComponentResponse>>;
removeComponent: ( removeComponent: (
bin: string, bin: string,
component: string, component: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.RemoveBinComponentResponse>>; ) => Promise<AxiosResponse<pond.RemoveBinComponentResponse>>;
removeAllComponents: (bin: string, as?: string) => Promise<AxiosResponse<pond.RemoveAllBinComponentsResponse>>; removeAllComponents: (bin: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveAllBinComponentsResponse>>;
updateComponentPreferences: ( updateComponentPreferences: (
bin: string, bin: string,
component: string, component: string,
preferences: pond.BinComponentPreferences, preferences: pond.BinComponentPreferences,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateBinComponentPreferencesResponse>>; ) => 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: ( listBins: (
limit: number, limit: number,
offset: number, offset: number,
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean, asRoot?: boolean,
numerical?: boolean, numerical?: boolean,
keys?: string[], keys?: string[],
@ -58,7 +58,7 @@ export interface IBinAPIContext {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean, asRoot?: boolean,
keys?: string[], keys?: string[],
types?: string[] types?: string[]
@ -89,13 +89,13 @@ export interface IBinAPIContext {
start: string, start: string,
end: string, end: string,
showErrors?: boolean, showErrors?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListBinComponentsMeasurementsResponse>>; ) => Promise<AxiosResponse<pond.ListBinComponentsMeasurementsResponse>>;
updateBinPermissions: ( updateBinPermissions: (
key: string, key: string,
users: User[] users: User[]
) => Promise<AxiosResponse<pond.UpdateBinResponse>>; ) => Promise<AxiosResponse<pond.UpdateBinResponse>>;
getBinMetrics: (search?: string, as?: string) => Promise<AxiosResponse<pond.GetBinMetricsResponse>>; getBinMetrics: (search?: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetBinMetricsResponse>>;
listBinLiters: ( listBinLiters: (
key: string, key: string,
start: string, start: string,
@ -105,13 +105,13 @@ export interface IBinAPIContext {
cable: string, cable: string,
pressure: string, pressure: string,
fan?: string, // the fan controller is optional so that if they don't have one the fan is assumed on 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>>; ) => Promise<AxiosResponse<pond.ListBinLiterResponse>>;
listBinPrefs: (key: string) => Promise<AxiosResponse<pond.ListBinComponentPreferencesResponse>>; listBinPrefs: (key: string) => Promise<AxiosResponse<pond.ListBinComponentPreferencesResponse>>;
updateTopNodes: ( updateTopNodes: (
key: string, key: string,
newTopNodes: pond.NewTopNode[], newTopNodes: pond.NewTopNode[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateTopNodesResponse>>; ) => Promise<AxiosResponse<pond.UpdateTopNodesResponse>>;
listBinMeasurements: ( listBinMeasurements: (
key: string, key: string,
@ -124,7 +124,7 @@ export interface IBinAPIContext {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
showErrors?: boolean, showErrors?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListObjectMeasurementsResponse>>; ) => Promise<AxiosResponse<pond.ListObjectMeasurementsResponse>>;
} }
@ -136,10 +136,11 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, post, put, del } = useHTTP(); const { get, post, put, del } = useHTTP();
const permissionAPI = usePermissionAPI(); const permissionAPI = usePermissionAPI();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addBin = (bin: pond.BinSettings, as?: string) => { const addBin = (bin: pond.BinSettings, otherTeam?: string) => {
const url = "/bins" + (as ? "?as=" + as : "") const view = otherTeam ? otherTeam : as
const url = "/bins" + (view ? "?as=" + view : "")
return new Promise<AxiosResponse<pond.AddBinResponse>>((resolve, reject)=>{ return new Promise<AxiosResponse<pond.AddBinResponse>>((resolve, reject)=>{
post<pond.AddBinResponse>(pondURL(url), bin).then(resp => { post<pond.AddBinResponse>(pondURL(url), bin).then(resp => {
resp.data = pond.AddBinResponse.fromObject(resp.data) 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 updateBin = (key: string, bin: pond.BinSettings, otherTeam?: string) => {
const url = "/bins/" + key + (as ? "?as=" + as : "") const view = otherTeam ? otherTeam : as
const url = "/bins/" + key + (view ? "?as=" + view : "")
return new Promise<AxiosResponse<pond.UpdateBinResponse>>((resolve, reject)=>{ return new Promise<AxiosResponse<pond.UpdateBinResponse>>((resolve, reject)=>{
put<pond.UpdateBinResponse>(pondURL(url), bin).then(resp => { put<pond.UpdateBinResponse>(pondURL(url), bin).then(resp => {
resp.data = pond.UpdateBinResponse.fromObject(resp.data) 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" 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)=>{ return new Promise<AxiosResponse<pond.BulkBinUpdateResponse>>((resolve, reject)=>{
put<pond.BulkBinUpdateResponse>(pondURL(url), { bins: bins }).then(resp => { put<pond.BulkBinUpdateResponse>(pondURL(url), { bins: bins }).then(resp => {
resp.data = pond.BulkBinUpdateResponse.fromObject(resp.data) 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" 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)=>{ return new Promise<AxiosResponse<pond.UpdateBinStatusResponse>>((resolve, reject)=>{
put<pond.UpdateBinStatusResponse>(pondURL(url), binStatus).then(resp=>{ put<pond.UpdateBinStatusResponse>(pondURL(url), binStatus).then(resp=>{
resp.data = pond.UpdateBinStatusResponse.fromObject(resp.data) 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 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) => { return new Promise<AxiosResponse<pond.RemoveBinResponse>>((resolve, reject) => {
del<pond.RemoveBinResponse>(pondURL(url)).then(resp => { del<pond.RemoveBinResponse>(pondURL(url)).then(resp => {
resp.data = pond.RemoveBinResponse.fromObject(resp.data) 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 getBin = (key: string, otherTeam?: string) => {
const url = "/bins/" + key + (as ? "?as=" + as : "") const view = otherTeam ? otherTeam : as
const url = "/bins/" + key + (view ? "?as=" + view : "")
return new Promise<AxiosResponse<pond.Bin>>((resolve, reject)=>{ return new Promise<AxiosResponse<pond.Bin>>((resolve, reject)=>{
get<pond.Bin>(pondURL(url)) get<pond.Bin>(pondURL(url))
.then(resp => { .then(resp => {
@ -220,14 +226,15 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
device: number, device: number,
component: string, component: string,
preferences?: pond.BinComponentPreferences, preferences?: pond.BinComponentPreferences,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = "/bins/" + bin + "/addComponent/" + device + "/" + component; let url = "/bins/" + bin + "/addComponent/" + device + "/" + component;
if (as) { if (view) {
url = url =
url + url +
"?as=" + "?as=" +
as + view +
(preferences ? "&binPref=" + preferences.type + "&fillNode=" + preferences.node : ""); (preferences ? "&binPref=" + preferences.type + "&fillNode=" + preferences.node : "");
} else if (preferences) { } else if (preferences) {
url = url + "?binPref=" + preferences.type + "&fillNode=" + preferences.node; 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; 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)=>{ return new Promise<AxiosResponse<pond.RemoveBinComponentResponse>>((resolve, reject)=>{
post<pond.RemoveBinComponentResponse>(pondURL(url)).then(resp => { post<pond.RemoveBinComponentResponse>(pondURL(url)).then(resp => {
resp.data = pond.RemoveBinComponentResponse.fromObject(resp.data) 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"; 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)=>{ return new Promise<AxiosResponse<pond.RemoveAllBinComponentsResponse>>((resolve, reject)=>{
post<pond.RemoveAllBinComponentsResponse>(pondURL(url)).then(resp => { post<pond.RemoveAllBinComponentsResponse>(pondURL(url)).then(resp => {
resp.data = pond.RemoveAllBinComponentsResponse.fromObject(resp.data) resp.data = pond.RemoveAllBinComponentsResponse.fromObject(resp.data)
@ -272,10 +281,11 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
bin: string, bin: string,
component: string, component: string,
preferences: pond.BinComponentPreferences, preferences: pond.BinComponentPreferences,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = "/bins/" + bin + "/updateComponent/" + component + "/preferences"; let url = "/bins/" + bin + "/updateComponent/" + component + "/preferences";
if (as) url = url + "/?as=" + as; if (view) url = url + "/?as=" + view;
interface request { interface request {
preferences: Object; 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/" + const url = "/bins/" +
binKey + binKey +
"/users/" + "/users/" +
userKey + userKey +
(showErrors ? "?showErrors=true" : "?showErrors=false") + (showErrors ? "?showErrors=true" : "?showErrors=false") +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
return new Promise<AxiosResponse<pond.GetBinPageDataResponse>>((resolve, reject)=>{ return new Promise<AxiosResponse<pond.GetBinPageDataResponse>>((resolve, reject)=>{
get<pond.GetBinPageDataResponse>(pondURL(url)) get<pond.GetBinPageDataResponse>(pondURL(url))
.then(resp => { .then(resp => {
@ -315,13 +326,14 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean, asRoot?: boolean,
numerical?: boolean, numerical?: boolean,
keys?: string[], keys?: string[],
types?: string[] types?: string[]
) => { ) => {
return new Promise<AxiosResponse<pond.ListBinsResponse>>((resolve, reject)=>{ return new Promise<AxiosResponse<pond.ListBinsResponse>>((resolve, reject)=>{
const view = otherTeam ? otherTeam : as
get<pond.ListBinsResponse>( get<pond.ListBinsResponse>(
pondURL( pondURL(
"/bins" + "/bins" +
@ -332,7 +344,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
("&order=" + or(order, "asc")) + ("&order=" + or(order, "asc")) +
("&by=" + or(orderBy, "key")) + ("&by=" + or(orderBy, "key")) +
(numerical ? "&numerical=true" : "") + (numerical ? "&numerical=true" : "") +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(keys ? "&keys=" + keys.join(",") : "") + (keys ? "&keys=" + keys.join(",") : "") +
@ -353,11 +365,12 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean, asRoot?: boolean,
keys?: string[], keys?: string[],
types?: string[] types?: string[]
) => { ) => {
const view = otherTeam ? otherTeam : as
const url = "/binsAndData" + const url = "/binsAndData" +
"?limit=" + "?limit=" +
limit + limit +
@ -365,7 +378,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
offset + offset +
("&order=" + or(order, "asc")) + ("&order=" + or(order, "asc")) +
("&by=" + or(orderBy, "key")) + ("&by=" + or(orderBy, "key")) +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(keys ? "&keys=" + keys.join(",") : "") + (keys ? "&keys=" + keys.join(",") : "") +
@ -430,15 +443,16 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
start: string, start: string,
end: string, end: string,
showErrors = false, showErrors = false,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = "/bins/" + let url = "/bins/" +
key + key +
"/components/measurements?start=" + "/components/measurements?start=" +
start + start +
"&end=" + "&end=" +
end + end +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(showErrors ? "&showErrors=true" : "&showErrors=false") (showErrors ? "&showErrors=true" : "&showErrors=false")
return new Promise<AxiosResponse<pond.ListBinComponentsMeasurementsResponse>>((resolve, reject) => { 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); 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 : "") let url = "/metrics/bins" + (search ? "?search=" + search : "")
if (as) { if (view) {
if (search){ 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)=>{ return new Promise<AxiosResponse<pond.GetBinMetricsResponse>>((resolve, reject)=>{
get<pond.GetBinMetricsResponse>(pondURL(url)).then(resp => { get<pond.GetBinMetricsResponse>(pondURL(url)).then(resp => {
@ -513,8 +528,9 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
cable: string, cable: string,
pressure: string, pressure: string,
fan?: string, fan?: string,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
const url = "/bins/" + const url = "/bins/" +
key + key +
"/liters?start=" + "/liters?start=" +
@ -530,7 +546,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
"&pressure=" + "&pressure=" +
pressure + pressure +
(fan ? "&fan=" + fan : "") + (fan ? "&fan=" + fan : "") +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
return new Promise<AxiosResponse<pond.ListBinLiterResponse>>((resolve, reject)=>{ return new Promise<AxiosResponse<pond.ListBinLiterResponse>>((resolve, reject)=>{
get<pond.ListBinLiterResponse>(pondURL(url)) get<pond.ListBinLiterResponse>(pondURL(url))
@ -543,8 +559,9 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const listBinPrefs = (key: string, as?: string) => { const listBinPrefs = (key: string, otherTeam?: string) => {
const url = "/bins/" + key + "/componentPreferences?as=" + as const view = otherTeam ? otherTeam : as
const url = "/bins/" + key + "/componentPreferences?as=" + view
return new Promise<AxiosResponse<pond.ListBinComponentPreferencesResponse>>((resolve, reject)=>{ return new Promise<AxiosResponse<pond.ListBinComponentPreferencesResponse>>((resolve, reject)=>{
get<pond.ListBinComponentPreferencesResponse>(pondURL(url)) get<pond.ListBinComponentPreferencesResponse>(pondURL(url))
.then(resp => { .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 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) => { return new Promise<AxiosResponse<pond.UpdateTopNodesResponse>>((resolve,response) => {
post<pond.UpdateTopNodesResponse>(pondURL(url),body).then(resp => { post<pond.UpdateTopNodesResponse>(pondURL(url),body).then(resp => {
resp.data = pond.UpdateTopNodesResponse.fromObject(resp.data) resp.data = pond.UpdateTopNodesResponse.fromObject(resp.data)
@ -580,8 +598,9 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
showErrors?: boolean, showErrors?: boolean,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
const url = pondURL( const url = pondURL(
"/objects/" + "/objects/" +
key + key +
@ -594,7 +613,7 @@ export default function BinProvider(props: PropsWithChildren<Props>) {
"&order=" + "&order=" +
order + order +
(measurementType ? "&type=" + measurementType : "") + (measurementType ? "&type=" + measurementType : "") +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(keys ? "&keys=" + keys : "") + (keys ? "&keys=" + keys : "") +
(types ? "&types=" + types : "") + (types ? "&types=" + types : "") +
(showErrors ? "&showErrors=true" : "&showErrors=false") (showErrors ? "&showErrors=true" : "&showErrors=false")

View file

@ -7,15 +7,15 @@ import { AxiosResponse } from "axios";
import { useGlobalState } from "providers"; import { useGlobalState } from "providers";
export interface IBinYardAPIContext { export interface IBinYardAPIContext {
addBinYard: (bin: pond.BinYardSettings, as?: string) => Promise<AxiosResponse<pond.AddBinYardResponse>>; addBinYard: (bin: pond.BinYardSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddBinYardResponse>>;
updateBinYard: ( updateBinYard: (
key: string, key: string,
binYard: pond.BinYardSettings, binYard: pond.BinYardSettings,
asRoot?: true, asRoot?: true,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateBinYardResponse>>; ) => Promise<AxiosResponse<pond.UpdateBinYardResponse>>;
removeBinYard: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveBinYardResponse>>; removeBinYard: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveBinYardResponse>>;
getBinYard: (key: string, as?: string) => Promise<AxiosResponse<pond.BinYard>>; getBinYard: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.BinYard>>;
listBinYards: ( listBinYards: (
limit: number, limit: number,
offset: number, offset: number,
@ -23,8 +23,7 @@ export interface IBinYardAPIContext {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
specificUser?: string, otherTeam?: string
as?: string
) => Promise<AxiosResponse<pond.ListBinYardsResponse>>; ) => Promise<AxiosResponse<pond.ListBinYardsResponse>>;
} }
@ -35,24 +34,26 @@ interface Props {}
export default function BinYardProvider(props: PropsWithChildren<Props>) { export default function BinYardProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, post, put, del } = useHTTP(); const { get, post, put, del } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addBinYard = (binYard: pond.BinYardSettings, as?: string) => { const addBinYard = (binYard: pond.BinYardSettings, otherTeam?: string) => {
if (as) return post<pond.AddBinYardResponse>(pondURL(`/binyard?as=${as}`), binYard); const view = otherTeam ? otherTeam : as
if (as) return post<pond.AddBinYardResponse>(pondURL(`/binyard?as=${view}`), binYard);
return post<pond.AddBinYardResponse>(pondURL("/binyard"), binYard); return post<pond.AddBinYardResponse>(pondURL("/binyard"), binYard);
}; };
const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean, as?: string) => { const updateBinYard = (key: string, binYard: pond.BinYardSettings, asRoot?: boolean, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
if (asRoot) { if (asRoot) {
return put<pond.UpdateBinYardResponse>( return put<pond.UpdateBinYardResponse>(
pondURL( pondURL(
"/binyards/" + key + (asRoot ? "?asRoot=" + asRoot.toString() : "") + "&as=" + as "/binyards/" + key + (asRoot ? "?asRoot=" + asRoot.toString() : "") + "&as=" + view
), ),
binYard 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>( return put<pond.UpdateBinYardResponse>(
pondURL("/binyards/" + key + (asRoot ? "?asRoot=" + asRoot.toString() : "")), pondURL("/binyards/" + key + (asRoot ? "?asRoot=" + asRoot.toString() : "")),
@ -60,13 +61,15 @@ export default function BinYardProvider(props: PropsWithChildren<Props>) {
); );
}; };
const removeBinYard = (key: string, as?: string) => { const removeBinYard = (key: string, otherTeam?: string) => {
if (as) return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key + "?as=" + as)); const view = otherTeam ? otherTeam : as
if (view) return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key + "?as=" + view));
return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key)); return del<pond.RemoveBinYardResponse>(pondURL("/binyard/" + key));
}; };
const getBinYard = (key: string, as?: string) => { const getBinYard = (key: string, otherTeam?: string) => {
if (as) return get<pond.BinYard>(pondURL("/binYard/" + key + "?as=" + as)); const view = otherTeam ? otherTeam : as
if (view) return get<pond.BinYard>(pondURL("/binYard/" + key + "?as=" + view));
return get<pond.BinYard>(pondURL("/binYard/" + key)); return get<pond.BinYard>(pondURL("/binYard/" + key));
}; };
@ -77,12 +80,11 @@ export default function BinYardProvider(props: PropsWithChildren<Props>) {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
specificUser?: string, otherTeam?: string
as?: string
) => { ) => {
let asText = ""; let asText = ""
if (as) asText = "&as=" + as; const view = otherTeam ? otherTeam : as
if (specificUser) asText = "&as=" + specificUser; if (view) asText = "&as=" + view;
return get<pond.ListBinYardsResponse>( return get<pond.ListBinYardsResponse>(
pondURL( pondURL(
"/binYards" + "/binYards" +

View file

@ -1,7 +1,7 @@
import { useHTTP } from "hooks"; import { useHTTP } from "hooks";
// import { useWebsocket } from "websocket"; // import { useWebsocket } from "websocket";
import { pond } from "protobuf-ts/pond"; 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 { dateRange } from "providers/http";
import { getComponentIDString } from "pbHelpers/Component"; import { getComponentIDString } from "pbHelpers/Component";
import { Component } from "models"; import { Component } from "models";
@ -18,33 +18,33 @@ export interface IComponentAPIContext {
url: string, url: string,
componentKey: string componentKey: string
) => Promise<any>; ) => 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: ( addMultiComponents: (
device: number, device: number,
components: pond.MultiComponentSettings, components: pond.MultiComponentSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddMultiComponentsResponse>>; ) => Promise<AxiosResponse<pond.AddMultiComponentsResponse>>;
update: ( update: (
device: number, device: number,
settings: pond.ComponentSettings, settings: pond.ComponentSettings,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateComponentResponse>>; ) => Promise<AxiosResponse<pond.UpdateComponentResponse>>;
remove: (device: number, component: string, keys?: string[], types?: string[], as?: string) => Promise<AxiosResponse<pond.RemoveComponentResponse>>; remove: (device: number, component: string, keys?: string[], types?: string[], otherTeam?: string) => Promise<AxiosResponse<pond.RemoveComponentResponse>>;
get: (device: number, component: string, keys?: string[], types?: string[], as?: string) => Promise<AxiosResponse<pond.Component>>; get: (device: number, component: string, keys?: string[], types?: string[], otherTeam?: string) => Promise<AxiosResponse<pond.Component>>;
list: ( list: (
device: number | string, device: number | string,
demo?: boolean, demo?: boolean,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
comprehensive?: boolean, comprehensive?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListComponentsResponse>>; ) => Promise<AxiosResponse<pond.ListComponentsResponse>>;
listForObject: ( listForObject: (
keys: string[], keys: string[],
types: string[], types: string[],
as?:string otherTeam?:string
) => Promise<AxiosResponse<pond.ListComponentsResponse>>; ) => Promise<AxiosResponse<pond.ListComponentsResponse>>;
listComponentCardData: ( listComponentCardData: (
device: number | string, device: number | string,
@ -52,7 +52,7 @@ export interface IComponentAPIContext {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
comprehensive?: boolean, comprehensive?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListComponentCardDataResponse>>; ) => Promise<AxiosResponse<pond.ListComponentCardDataResponse>>;
listHistory: ( listHistory: (
deviceId: string | number, deviceId: string | number,
@ -86,7 +86,7 @@ export interface IComponentAPIContext {
// demo?: boolean, // demo?: boolean,
// keys?: string[], // keys?: string[],
// types?: string[], // types?: string[],
// as?: string // otherTeam?: string
// ) => Promise<AxiosResponse<pond.SampleMeasurementsResponse>>; // ) => Promise<AxiosResponse<pond.SampleMeasurementsResponse>>;
sampleUnitMeasurements: ( sampleUnitMeasurements: (
device: number | string, device: number | string,
@ -98,7 +98,7 @@ export interface IComponentAPIContext {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
showErrors?: boolean, showErrors?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.SampleUnitMeasurementsResponse>>; ) => Promise<AxiosResponse<pond.SampleUnitMeasurementsResponse>>;
// possibly a deprecated function as it is not used anywhere // possibly a deprecated function as it is not used anywhere
updateComponentPreferences: ( updateComponentPreferences: (
@ -120,7 +120,7 @@ export interface IComponentAPIContext {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
showErrors?: boolean, showErrors?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListUnitMeasurementsResponse>>; ) => Promise<AxiosResponse<pond.ListUnitMeasurementsResponse>>;
} }
@ -131,7 +131,7 @@ interface Props {}
export default function ComponentProvider(props: PropsWithChildren<Props>) { export default function ComponentProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, post, put, del } = useHTTP(); const { get, post, put, del } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const newCron = ( const newCron = (
device: number, 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" 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) => { return new Promise<AxiosResponse<pond.AddComponentResponse>>((resolve, reject) => {
post<pond.AddComponentResponse>(pondURL(url), settings).then(resp => { post<pond.AddComponentResponse>(pondURL(url), settings).then(resp => {
resp.data = pond.AddComponentResponse.fromObject(resp.data) 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" 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)=>{ return new Promise<AxiosResponse<pond.AddMultiComponentsResponse>>((resolve, reject)=>{
post<pond.AddMultiComponentsResponse>(pondURL(url), components).then(resp => { post<pond.AddMultiComponentsResponse>(pondURL(url), components).then(resp => {
resp.data = pond.AddMultiComponentsResponse.fromObject(resp.data) resp.data = pond.AddMultiComponentsResponse.fromObject(resp.data)
@ -187,12 +189,13 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
settings: pond.ComponentSettings, settings: pond.ComponentSettings,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => { ) => {
let k: string[] = keys ? keys : []; 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 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 : []; let t: string[] = types ? types : [];
if (!t.includes("device")) t.push("device"); // if "device" is already in the types do not add it again 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( const url = pondURL(
"/devices/" + "/devices/" +
device + device +
@ -201,7 +204,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
"/update" + "/update" +
("?keys=" + k) + ("?keys=" + k) +
("&types=" + t) + ("&types=" + t) +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
); );
return new Promise<AxiosResponse<pond.UpdateComponentResponse>>((resolve, reject)=>{ return new Promise<AxiosResponse<pond.UpdateComponentResponse>>((resolve, reject)=>{
put<pond.UpdateComponentResponse>(url, settings).then(resp => { put<pond.UpdateComponentResponse>(url, settings).then(resp => {
@ -218,12 +221,13 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
component: string, component: string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => { ) => {
let k: string[] = keys ? keys : []; 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 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 : []; let t: string[] = types ? types : [];
if (!t.includes("device")) t.push("device"); // if "device" is already in the types do not add it again 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( const url = pondURL(
"/devices/" + "/devices/" +
device + device +
@ -231,7 +235,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
component + component +
("?keys=" + k) + ("?keys=" + k) +
("&types=" + t) + ("&types=" + t) +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
); );
return new Promise<AxiosResponse<pond.RemoveComponentResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.RemoveComponentResponse>>((resolve, reject) => {
del<pond.RemoveComponentResponse>(url).then(resp => { 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 : []; 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 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 : []; let t: string[] = types ? types : [];
if (!t.includes("device")) t.push("device"); // if "device" is already in the types do not add it again 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( const url = pondURL(
"/devices/" + "/devices/" +
device + device +
@ -255,7 +260,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
component + component +
("?keys=" + k) + ("?keys=" + k) +
("&types=" + t) + ("&types=" + t) +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
); );
return new Promise<AxiosResponse<pond.Component>>((resolve, reject) => { return new Promise<AxiosResponse<pond.Component>>((resolve, reject) => {
get<pond.Component>(url).then(resp => { get<pond.Component>(url).then(resp => {
@ -273,10 +278,11 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
comprehensive?: boolean, comprehensive?: boolean,
as?: string otherTeam?: string
) => { ) => {
let k = keys ? keys : []; let k = keys ? keys : [];
let t = types ? types : []; let t = types ? types : [];
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/devices/" + "/devices/" +
device + device +
@ -287,9 +293,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
(comprehensive ? "&comprehensive=" + comprehensive.toString() : ""), (comprehensive ? "&comprehensive=" + comprehensive.toString() : ""),
demo demo
); );
if (as) if (view)
url = pondURL( url = pondURL(
`/devices/${device}/components?as=${as}&keys=${k}&types=${t}` + `/devices/${device}/components?as=${view}&keys=${k}&types=${t}` +
(comprehensive ? "&comprehensive=" + comprehensive.toString() : ""), (comprehensive ? "&comprehensive=" + comprehensive.toString() : ""),
demo demo
); );
@ -303,8 +309,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const listComponentsForObject = (keys: string[], types: string[], as?: string) => { const listComponentsForObject = (keys: string[], types: string[], otherTeam?: string) => {
let url = pondURL("/components/forObject?keys=" + keys + "&types=" + types + (as ? "&as=" + as : "")) 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) => { return new Promise<AxiosResponse<pond.ListComponentsResponse>>((resolve, reject) => {
get<pond.ListComponentsResponse>(url).then(resp => { get<pond.ListComponentsResponse>(url).then(resp => {
resp.data = pond.ListComponentsResponse.fromObject(resp.data) resp.data = pond.ListComponentsResponse.fromObject(resp.data)
@ -321,8 +328,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
comprehensive = false, comprehensive = false,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/devices/" + "/devices/" +
device + device +
@ -334,9 +342,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
demo demo
); );
if (as) if (view)
url = pondURL( url = pondURL(
`/devices/${device}/componentCards?as=${as}` + `/devices/${device}/componentCards?as=${view}` +
(keys ? "&keys=" + keys : "&keys=" + [device.toString()]) + (keys ? "&keys=" + keys : "&keys=" + [device.toString()]) +
(types ? "&types=" + types : "&types=" + ["device"]), (types ? "&types=" + types : "&types=" + ["device"]),
demo demo
@ -393,7 +401,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
// demo: boolean = false, // demo: boolean = false,
// keys?: string[], // keys?: string[],
// types?: string[], // types?: string[],
// as?: string // otherTeam?: string
// // exportMeasurements: boolean = false // // exportMeasurements: boolean = false
// ) => { // ) => {
// const url = pondURL( // const url = pondURL(
@ -436,7 +444,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
// demo: boolean = false, // demo: boolean = false,
// keys?: string[], // keys?: string[],
// types?: string[], // types?: string[],
// as?: string // otherTeam?: string
// ) => { // ) => {
// const url = pondURL( // const url = pondURL(
// "/devices/" + // "/devices/" +
@ -472,8 +480,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
showErrors: boolean = true, showErrors: boolean = true,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
const url = pondURL( const url = pondURL(
"/devices/" + "/devices/" +
device + device +
@ -483,7 +492,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
dateRange(startDate, endDate) + dateRange(startDate, endDate) +
"&size=" + "&size=" +
sampleSize + sampleSize +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(keys ? "&keys=" + keys : "&keys=" + [device]) + (keys ? "&keys=" + keys : "&keys=" + [device]) +
(types ? "&types=" + types : "&types=" + ["device"]) + (types ? "&types=" + types : "&types=" + ["device"]) +
(showErrors ? "&showErrors=true" : "&showErrors=false"), (showErrors ? "&showErrors=true" : "&showErrors=false"),
@ -536,8 +545,9 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
showErrors?: boolean, showErrors?: boolean,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
const url = pondURL( const url = pondURL(
"/devices/" + "/devices/" +
device + device +
@ -552,7 +562,7 @@ export default function ComponentProvider(props: PropsWithChildren<Props>) {
"&order=" + "&order=" +
order + order +
(measurementType ? "&type=" + measurementType : "") + (measurementType ? "&type=" + measurementType : "") +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(keys ? "&keys=" + keys : "&keys=" + [device]) + (keys ? "&keys=" + keys : "&keys=" + [device]) +
(types ? "&types=" + types : "&types=" + ["device"]) + (types ? "&types=" + types : "&types=" + ["device"]) +
(showErrors ? "&showErrors=true" : "&showErrors=false") (showErrors ? "&showErrors=true" : "&showErrors=false")

View file

@ -1,5 +1,5 @@
import { useHTTP } from "hooks"; import { useHTTP } from "hooks";
import React, { createContext, PropsWithChildren, useContext } from "react"; import { createContext, PropsWithChildren, useContext } from "react";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
@ -9,7 +9,7 @@ export interface IContractInterface {
addContract: ( addContract: (
name: string, name: string,
settings: pond.ContractSettings, settings: pond.ContractSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddContractResponse>>; ) => Promise<AxiosResponse<pond.AddContractResponse>>;
listContracts: ( listContracts: (
limit: number, limit: number,
@ -21,15 +21,15 @@ export interface IContractInterface {
types?: string[], types?: string[],
numerical?: boolean, numerical?: boolean,
specificUser?: string, specificUser?: string,
as?: string, otherTeam?: string,
) => Promise<AxiosResponse<pond.ListContractsResponse>>; ) => Promise<AxiosResponse<pond.ListContractsResponse>>;
updateContract: ( updateContract: (
key: string, key: string,
name: string, name: string,
settings: pond.ContractSettings, settings: pond.ContractSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateContractResponse>>; ) => Promise<AxiosResponse<pond.UpdateContractResponse>>;
removeContract: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveContractResponse>>; removeContract: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveContractResponse>>;
listContractsByYear: ( listContractsByYear: (
limit: number, limit: number,
offset: number, offset: number,
@ -41,10 +41,10 @@ export interface IContractInterface {
numerical?: boolean, numerical?: boolean,
specificUser?: string, specificUser?: string,
contractYear?: string, contractYear?: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListContractsByYearResponse>>; ) => Promise<AxiosResponse<pond.ListContractsByYearResponse>>;
//list contract page data //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 //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>) { export default function ContractProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
//add //add
const addContract = (name: string, settings: pond.ContractSettings, as?: string) => { const addContract = (name: string, settings: pond.ContractSettings, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
return post<pond.AddContractResponse>( return post<pond.AddContractResponse>(
pondURL("/contracts?name=" + name + "&as=" + as), pondURL("/contracts?name=" + name + "&as=" + view),
settings settings
); );
} }
@ -77,12 +78,11 @@ export default function ContractProvider(props: PropsWithChildren<Props>) {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
numerical?: boolean, numerical?: boolean,
specificUser?: string, otherTeam?: string
as?: string
) => { ) => {
let asText = ""; let asText = "";
if (as) asText = "&as=" + as; const view = otherTeam ? otherTeam : as
if (specificUser) asText = "&as=" + specificUser; if (view) asText = "&as=" + view;
return get<pond.ListContractsResponse>( return get<pond.ListContractsResponse>(
pondURL( pondURL(
"/contracts?limit=" + "/contracts?limit=" +
@ -108,13 +108,12 @@ export default function ContractProvider(props: PropsWithChildren<Props>) {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
numerical?: boolean, numerical?: boolean,
specificUser?: string,
contractYear?: string, contractYear?: string,
as?: string, otherTeam?: string,
) => { ) => {
let asText = ""; let asText = "";
if (as) asText = "&as=" + as; const view = otherTeam ? otherTeam : as
if (specificUser) asText = "&as=" + specificUser; if (view) asText = "&as=" + view;
return get<pond.ListContractsByYearResponse>( return get<pond.ListContractsByYearResponse>(
pondURL( pondURL(
"/contractsByYear?limit=" + "/contractsByYear?limit=" +
@ -133,10 +132,11 @@ export default function ContractProvider(props: PropsWithChildren<Props>) {
); );
}; };
//update //update
const updateContract = (key: string, name: string, settings: pond.ContractSettings, as?: string) => { const updateContract = (key: string, name: string, settings: pond.ContractSettings, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
return put<pond.UpdateContractResponse>( return put<pond.UpdateContractResponse>(
pondURL("/contracts/" + key + "?as=" + as + "&name=" + name), pondURL("/contracts/" + key + "?as=" + view + "&name=" + name),
settings settings
); );
} }
@ -146,16 +146,18 @@ export default function ContractProvider(props: PropsWithChildren<Props>) {
); );
}; };
//remove //remove
const removeContract = (key: string, as?: string) => { const removeContract = (key: string, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
return del<pond.RemoveContractResponse>(pondURL("/contracts/" + key + "?as=" + 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) => { const getContractPageData = (key: string, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
return get<pond.GetContractPageDataResponse>(pondURL("/contractsPage/" + key + "?as=" + as)); if (view) {
return get<pond.GetContractPageDataResponse>(pondURL("/contractsPage/" + key + "?as=" + view));
} }
return get<pond.GetContractPageDataResponse>(pondURL("/contractsPage/" + key)); return get<pond.GetContractPageDataResponse>(pondURL("/contractsPage/" + key));

View file

@ -12,19 +12,19 @@ import { dateRange } from "providers/http";
// import { reject, result } from "lodash"; // import { reject, result } from "lodash";
export interface IDeviceAPIContext { export interface IDeviceAPIContext {
add: (name: string, description: string, backpack: pond.BackpackSettings, as?: string) => Promise<AxiosResponse<pond.AddDeviceResponse>>; add: (name: string, description: string, backpack: pond.BackpackSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddDeviceResponse>>;
update: (id: number, settings: pond.DeviceSettings, as?: string) => Promise<AxiosResponse<pond.UpdateDeviceResponse>>; update: (id: number, settings: pond.DeviceSettings, otherTeam?: string) => Promise<AxiosResponse<pond.UpdateDeviceResponse>>;
remove: (id: number, as?: string) => Promise<AxiosResponse<pond.RemoveDeviceResponse>>; remove: (id: number, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveDeviceResponse>>;
get: (id: number | string, demo?: boolean, keys?: string[], types?: string[], as?: string) => Promise<AxiosResponse<pond.Device>> get: (id: number | string, demo?: boolean, keys?: string[], types?: string[], otherTeam?: string) => Promise<AxiosResponse<pond.Device>>
getPageData: ( getPageData: (
id: number | string, id: number | string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.GetDevicePageDataResponse>>; ) => Promise<AxiosResponse<pond.GetDevicePageDataResponse>>;
getMulti: (ids: number[] | string[], as?: string) => Promise<AxiosResponse<pond.GetMultiDeviceResponse>>; getMulti: (ids: number[] | string[], otherTeam?: string) => Promise<AxiosResponse<pond.GetMultiDeviceResponse>>;
getGeoJson: (id: number | string, demo?: boolean, as?: string) => Promise<any>; getGeoJson: (id: number | string, demo?: boolean, otherTeam?: string) => Promise<any>;
getMultiGeoJson: (ids: number[] | string[], as?: string) => Promise<any>; getMultiGeoJson: (ids: number[] | string[], otherTeam?: string) => Promise<any>;
list: ( list: (
limit: number, limit: number,
offset: number, offset: number,
@ -41,7 +41,7 @@ export interface IDeviceAPIContext {
types?: string[], types?: string[],
fieldContains?: Map<string, string>, fieldContains?: Map<string, string>,
prefixSearch?: string, prefixSearch?: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListDevicesResponse>>; ) => Promise<AxiosResponse<pond.ListDevicesResponse>>;
listForUser: ( listForUser: (
asRoot: boolean, asRoot: boolean,
@ -65,7 +65,7 @@ export interface IDeviceAPIContext {
preferences: pond.DevicePreferences, preferences: pond.DevicePreferences,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => Promise<any>; ) => Promise<any>;
updateComponentPreferences: ( updateComponentPreferences: (
id: number | string, id: number | string,
@ -73,13 +73,13 @@ export interface IDeviceAPIContext {
preferences: pond.DeviceComponentPreferences, preferences: pond.DeviceComponentPreferences,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateDeviceComponentPreferencesResponse>>; ) => Promise<AxiosResponse<pond.UpdateDeviceComponentPreferencesResponse>>;
listDeviceComponentPreferences: ( listDeviceComponentPreferences: (
id: number | string, id: number | string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListDeviceComponentPreferencesResponse>>; ) => Promise<AxiosResponse<pond.ListDeviceComponentPreferencesResponse>>;
updateStatus: ( updateStatus: (
id: number | string, id: number | string,
@ -99,7 +99,7 @@ export interface IDeviceAPIContext {
newCap: number newCap: number
) => Promise<AxiosResponse<pond.BulkChangeDataCapsResponse>>; ) => Promise<AxiosResponse<pond.BulkChangeDataCapsResponse>>;
resume: (id: number) => Promise<any>; 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>; loadBackpack: (id: number, backpack: number) => Promise<any>;
setTags: (id: number, tags: string[]) => Promise<any>; setTags: (id: number, tags: string[]) => Promise<any>;
setWifi: ( setWifi: (
@ -108,7 +108,7 @@ export interface IDeviceAPIContext {
password: string, password: string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => Promise<any>; ) => Promise<any>;
statistics: ( statistics: (
keys?: string[], keys?: string[],
@ -129,9 +129,9 @@ export interface IDeviceAPIContext {
offset: number, offset: number,
order: string, order: string,
orderBy: string, orderBy: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListDeviceExportedMeasurementsResponse>>; ) => Promise<AxiosResponse<pond.ListDeviceExportedMeasurementsResponse>>;
listSimpleJSON: (device: number, as?: string) => Promise<any>; listSimpleJSON: (device: number, otherTeam?: string) => Promise<any>;
resetQuackCount: (id: number) => Promise<any>; resetQuackCount: (id: number) => Promise<any>;
resetQuackCountTx: (id: number) => Promise<any>; resetQuackCountTx: (id: number) => Promise<any>;
resetQuackCountTx1000: (id: number) => Promise<any>; resetQuackCountTx1000: (id: number) => Promise<any>;
@ -157,11 +157,12 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, post, put, del } = useHTTP(); const { get, post, put, del } = useHTTP();
const permissionAPI = usePermissionAPI(); 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") 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) => { return new Promise<AxiosResponse<pond.AddDeviceResponse>>((resolve, reject) => {
post<pond.AddDeviceResponse>(url, { name, description, backpack }).then(resp => { post<pond.AddDeviceResponse>(url, { name, description, backpack }).then(resp => {
resp.data = pond.AddDeviceResponse.fromObject(resp.data) resp.data = pond.AddDeviceResponse.fromObject(resp.data)
@ -177,8 +178,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
demo: boolean = false, demo: boolean = false,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/devices/" + "/devices/" +
id + id +
@ -186,11 +188,11 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
(types ? "&types=" + types.toString() : ""), (types ? "&types=" + types.toString() : ""),
demo demo
); );
if (as) { if (view) {
url = pondURL( url = pondURL(
"/devices/" + "/devices/" +
id + id +
"?as=" + as + "?as=" + view +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : ""), (types ? "&types=" + types.toString() : ""),
demo demo
@ -231,20 +233,21 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
id: number | string, id: number | string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
): Promise<AxiosResponse<pond.GetDevicePageDataResponse>> => { ): Promise<AxiosResponse<pond.GetDevicePageDataResponse>> => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/devicePageData/" + "/devicePageData/" +
id + id +
(keys ? "?keys=" + keys.toString() : "") + (keys ? "?keys=" + keys.toString() : "") +
(types ? "&types=" + types.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( url = pondURL(
"/devicePageData/" + "/devicePageData/" +
id + id +
"?as=" + "?as=" +
as + view +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.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); 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) => { return new Promise<AxiosResponse>((resolve, reject) => {
get(url).catch(resp => { get(url).catch(resp => {
return resolve(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 = ""; let idString = "";
ids.forEach((id: number | string, i: number) => { ids.forEach((id: number | string, i: number) => {
if (i === 0) { if (i === 0) {
@ -280,7 +284,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
idString = idString + "," + id; 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) => { return new Promise<AxiosResponse<pond.GetMultiDeviceResponse>>((resolve, reject) => {
get<pond.GetMultiDeviceResponse>(url).then(resp => { get<pond.GetMultiDeviceResponse>(url).then(resp => {
resp.data = pond.GetMultiDeviceResponse.fromObject(resp.data) 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 = ""; let idString = "";
ids.forEach((id: number | string, i: number) => { ids.forEach((id: number | string, i: number) => {
if (i === 0) { if (i === 0) {
@ -300,7 +305,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
idString = idString + "," + id; 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) => { return new Promise<AxiosResponse>((resolve, reject) => {
get(url).then(resp => { get(url).then(resp => {
return resolve(resp) return resolve(resp)
@ -326,8 +332,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
types?: string[], types?: string[],
fieldContains?: Map<string, string>, fieldContains?: Map<string, string>,
prefixSearch?: string, prefixSearch?: string,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
const url = pondURL( const url = pondURL(
"/devices" + "/devices" +
"?limit=" + "?limit=" +
@ -341,7 +348,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
(status ? "&status=" + status : "") + (status ? "&status=" + status : "") +
(ids ? "&ids=" + ids.join(",") : "") + (ids ? "&ids=" + ids.join(",") : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (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() : "") + (comprehensive ? "&comprehensive=" + comprehensive.toString() : "") +
(withMeasurements ? "&measurements=" + withMeasurements.toString() : "") + (withMeasurements ? "&measurements=" + withMeasurements.toString() : "") +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
@ -385,8 +392,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const remove = (id: number, as?: string) => { const remove = (id: number, otherTeam?: string) => {
const url = pondURL("/devices/" + id + (as ? "?as=" + as : "")) const view = otherTeam ? otherTeam : as
const url = pondURL("/devices/" + id + (view ? "?as=" + view : ""))
return new Promise<AxiosResponse<pond.RemoveDeviceResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.RemoveDeviceResponse>>((resolve, reject) => {
del<pond.RemoveDeviceResponse>(url).then(resp => { del<pond.RemoveDeviceResponse>(url).then(resp => {
resp.data = pond.RemoveDeviceResponse.fromObject(resp.data) 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 update = (id: number, settings: pond.DeviceSettings, otherTeam?: string) => {
const url = pondURL("/devices/" + id + "/update" + (as ? "?as=" + as : "")); const view = otherTeam ? otherTeam : as
const url = pondURL("/devices/" + id + "/update" + (view ? "?as=" + view : ""));
return new Promise<AxiosResponse<pond.UpdateDeviceResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.UpdateDeviceResponse>>((resolve, reject) => {
put<pond.UpdateDeviceResponse>(url, settings).then(resp => { put<pond.UpdateDeviceResponse>(url, settings).then(resp => {
resp.data = pond.UpdateDeviceResponse.fromObject(resp) resp.data = pond.UpdateDeviceResponse.fromObject(resp)
@ -463,14 +472,15 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
preferences: pond.DevicePreferences, preferences: pond.DevicePreferences,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/devices/" + "/devices/" +
id + id +
"/preferences" + "/preferences" +
"?as=" + "?as=" +
or(as, "") + or(view, "") +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : "") (types ? "&types=" + types.toString() : "")
) )
@ -489,8 +499,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
preferences: pond.DeviceComponentPreferences, preferences: pond.DeviceComponentPreferences,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/devices/" + "/devices/" +
id + id +
@ -498,7 +509,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
component + component +
"/componentPreferences" + "/componentPreferences" +
"?as=" + "?as=" +
as + view +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : "") (types ? "&types=" + types.toString() : "")
) )
@ -516,8 +527,9 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
id: number | string, id: number | string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/devices/" + "/devices/" +
id + id +
@ -525,11 +537,11 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
(keys ? "?keys=" + keys.toString() : "") + (keys ? "?keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : "") (types ? "&types=" + types.toString() : "")
) )
if (as) { if (view) {
url = pondURL( url = pondURL(
"/devices/" + "/devices/" +
id + id +
"/componentPreferences?as=" + as + "/componentPreferences?as=" + view +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : "") (types ? "&types=" + types.toString() : "")
) )
@ -549,14 +561,15 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
status: pond.DeviceStatus, status: pond.DeviceStatus,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/devices/" + "/devices/" +
id + id +
"/updateStatus" + "/updateStatus" +
"?as=" + "?as=" +
as + view +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.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) => { const getUpgradeStatus = (id: number, keys?: string[], types?: 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) { 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); let url = pondURL("/devices/" + id + "/firmware" + a);
return new Promise<AxiosResponse>((resolve, reject) => { return new Promise<AxiosResponse>((resolve, reject) => {
@ -681,11 +695,12 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
password: string, password: string,
keys?: string[], keys?: string[],
types?: 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) { 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) => { return new Promise<AxiosResponse>((resolve, reject) => {
put(pondURL("/devices/" + id + "/wifi" + a), { gateway, password }).then(resp => { put(pondURL("/devices/" + id + "/wifi" + a), { gateway, password }).then(resp => {
@ -780,7 +795,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
offset: number, offset: number,
order: string, order: string,
orderBy: string, orderBy: string,
as?: string otherTeam?: string
) => { ) => {
let keyString = ""; let keyString = "";
components.forEach((comp, i) => { components.forEach((comp, i) => {
@ -790,7 +805,8 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
keyString = keyString + "," + comp.key(); keyString = keyString + "," + comp.key();
} }
}); });
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
return get<pond.ListDeviceExportedMeasurementsResponse>( return get<pond.ListDeviceExportedMeasurementsResponse>(
pondURL( pondURL(
"/devices/" + "/devices/" +
@ -808,7 +824,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
"&orderBy=" + "&orderBy=" +
orderBy + orderBy +
"&as=" + "&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" 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) => { return new Promise<AxiosResponse>((resolve, reject) => {
get(pondURL(url)).then(resp => { get(pondURL(url)).then(resp => {
return resolve(resp) return resolve(resp)
@ -894,11 +911,11 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
source?: string, source?: string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string, otherTeam?: string
team?: Team
) => { ) => {
let url = "/devices/" + id + "/buyData?MB=" + MB; 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 (source) url = url + "&source=" + source;
if (keys) url = url + "&keys=" + keys; if (keys) url = url + "&keys=" + keys;
if (types) url = url + "&types=" + types; if (types) url = url + "&types=" + types;
@ -956,7 +973,7 @@ export default function DeviceProvider(props: PropsWithChildren<Props>) {
getDataUsage, getDataUsage,
buyData, buyData,
updateComponentPreferences, updateComponentPreferences,
listDeviceComponentPreferences//as listDeviceComponentPreferences
}}> }}>
{children} {children}
</DeviceAPIContext.Provider> </DeviceAPIContext.Provider>

View file

@ -7,23 +7,23 @@ import { or } from "utils";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
export interface IFieldAPIContext { export interface IFieldAPIContext {
addField: (field: pond.FieldSettings, as?: string) => Promise<any>; addField: (field: pond.FieldSettings, otherTeam?: string) => Promise<any>;
getField: (fieldId: string, as?: string) => Promise<any>; getField: (fieldId: string, otherTeam?: string) => Promise<any>;
listFields: ( listFields: (
limit: number, limit: number,
offset: number, offset: number,
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => Promise<AxiosResponse<pond.ListFieldsResponse>>; ) => Promise<AxiosResponse<pond.ListFieldsResponse>>;
removeField: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveFieldResponse>>; removeField: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveFieldResponse>>;
updateField: ( updateField: (
key: string, key: string,
field: pond.FieldSettings, field: pond.FieldSettings,
asRoot?: true, asRoot?: true,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateSiteResponse>>; ) => Promise<AxiosResponse<pond.UpdateSiteResponse>>;
} }
@ -34,20 +34,23 @@ interface Props {}
export default function FieldProvider(props: PropsWithChildren<Props>) { export default function FieldProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addField = (field: pond.FieldSettings, as?: string) => { const addField = (field: pond.FieldSettings, otherTeam?: string) => {
if (as) return post<pond.AddFieldResponse>(pondURL("/fields?as=" + as), field); const view = otherTeam ? otherTeam : as
if (view) return post<pond.AddFieldResponse>(pondURL("/fields?as=" + view), field);
return post(pondURL("/fields"), field); return post(pondURL("/fields"), field);
}; };
const getField = (fieldId: string, as?: string) => { const getField = (fieldId: string, otherTeam?: string) => {
if (as) return get(pondURL("/field/" + fieldId + "?as=" + as)); const view = otherTeam ? otherTeam : as
if (view) return get(pondURL("/field/" + fieldId + "?as=" + view));
return get(pondURL("/field/" + fieldId)); return get(pondURL("/field/" + fieldId));
}; };
const removeField = (key: string, as?: string) => { const removeField = (key: string, otherTeam?: string) => {
if (as) return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key + "?as=" + as)); const view = otherTeam ? otherTeam : as
if (view) return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key + "?as=" + view));
return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key)); return del<pond.RemoveFieldResponse>(pondURL("/fields/" + key));
}; };
@ -57,9 +60,10 @@ export default function FieldProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => { ) => {
const view = otherTeam ? otherTeam : as
return get<pond.ListFieldsResponse>( return get<pond.ListFieldsResponse>(
pondURL( pondURL(
"/fields" + "/fields" +
@ -69,17 +73,18 @@ export default function FieldProvider(props: PropsWithChildren<Props>) {
offset + offset +
("&order=" + or(order, "asc")) + ("&order=" + or(order, "asc")) +
("&by=" + or(orderBy, "key")) + ("&by=" + or(orderBy, "key")) +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(search ? "&search=" + search : "") (search ? "&search=" + search : "")
) )
); );
}; };
const updateField = (key: string, field: pond.FieldSettings, asRoot?: boolean, as?: string) => { const updateField = (key: string, field: pond.FieldSettings, asRoot?: boolean, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return put<pond.UpdateFieldResponse>( return put<pond.UpdateFieldResponse>(
pondURL("/fields/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "")), pondURL("/fields/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")),
field field
); );
return put<pond.UpdateFieldResponse>( return put<pond.UpdateFieldResponse>(

View file

@ -8,9 +8,9 @@ import { pondURL } from "./pond";
export interface IFieldMarkerAPIContext { export interface IFieldMarkerAPIContext {
addFieldMarker: ( addFieldMarker: (
fieldMarker: pond.FieldMarkerSettings, fieldMarker: pond.FieldMarkerSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddFieldMarkerResponse>>; ) => Promise<AxiosResponse<pond.AddFieldMarkerResponse>>;
getFieldMarker: (fieldMarkerID: string) => Promise<AxiosResponse<pond.FieldMarker>>; getFieldMarker: (fieldMarkerID: string, otherTeam?: string) => Promise<AxiosResponse<pond.FieldMarker>>;
listFieldMarkers: ( listFieldMarkers: (
limit: number, limit: number,
offset: number, offset: number,
@ -18,17 +18,17 @@ export interface IFieldMarkerAPIContext {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListFieldMarkersResponse>>; ) => Promise<AxiosResponse<pond.ListFieldMarkersResponse>>;
removeFieldMarker: ( removeFieldMarker: (
fieldMarkerID: string, fieldMarkerID: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.RemoveFieldMarkerResponse>>; ) => Promise<AxiosResponse<pond.RemoveFieldMarkerResponse>>;
updateFieldMarker: ( updateFieldMarker: (
key: string, key: string,
fieldMarker: pond.FieldMarkerSettings, fieldMarker: pond.FieldMarkerSettings,
asRoot?: true, asRoot?: true,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateFieldMarkerResponse>>; ) => Promise<AxiosResponse<pond.UpdateFieldMarkerResponse>>;
} }
@ -41,22 +41,25 @@ interface Props {}
export default function FieldMarkerProvider(props: PropsWithChildren<Props>) { export default function FieldMarkerProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addFieldMarker = (fieldMarker: pond.FieldMarkerSettings, as?: string) => { const addFieldMarker = (fieldMarker: pond.FieldMarkerSettings, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
return post<pond.AddFieldMarkerResponse>(pondURL("/fieldMarkers?as=" + as), fieldMarker); if (view)
return post<pond.AddFieldMarkerResponse>(pondURL("/fieldMarkers?as=" + view), fieldMarker);
return post<pond.AddFieldMarkerResponse>(pondURL("/fieldMarkers"), fieldMarker); return post<pond.AddFieldMarkerResponse>(pondURL("/fieldMarkers"), fieldMarker);
}; };
const getFieldMarker = (fieldMarkerId: string, as?: string) => { const getFieldMarker = (fieldMarkerId: string, otherTeam?: string) => {
if (as) return get<pond.FieldMarker>(pondURL("/fieldMarkers/" + fieldMarkerId + "?as=" + as)); const view = otherTeam ? otherTeam : as
if (view) return get<pond.FieldMarker>(pondURL("/fieldMarkers/" + fieldMarkerId + "?as=" + view));
return get<pond.FieldMarker>(pondURL("/fieldMarkers/" + fieldMarkerId)); return get<pond.FieldMarker>(pondURL("/fieldMarkers/" + fieldMarkerId));
}; };
const removeFieldMarker = (key: string, as?: string) => { const removeFieldMarker = (key: string, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
return del<pond.RemoveFieldMarkerResponse>(pondURL("/fieldMarkers/" + key + "?as=" + as)); if (view)
return del<pond.RemoveFieldMarkerResponse>(pondURL("/fieldMarkers/" + key + "?as=" + view));
return del<pond.RemoveFieldMarkerResponse>(pondURL("/fieldMarkers/" + key)); return del<pond.RemoveFieldMarkerResponse>(pondURL("/fieldMarkers/" + key));
}; };
@ -67,8 +70,9 @@ export default function FieldMarkerProvider(props: PropsWithChildren<Props>) {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
return get<pond.ListFieldMarkersResponse>( return get<pond.ListFieldMarkersResponse>(
pondURL( pondURL(
"/fieldMarkers" + "/fieldMarkers" +
@ -80,16 +84,17 @@ export default function FieldMarkerProvider(props: PropsWithChildren<Props>) {
("&by=" + (orderBy ? orderBy : "key")) + ("&by=" + (orderBy ? orderBy : "key")) +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
) )
); );
}; };
const updateFieldMarker = (key: string, hm: pond.FieldMarkerSettings, asRoot?: boolean, as?: string) => { const updateFieldMarker = (key: string, hm: pond.FieldMarkerSettings, asRoot?: boolean, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return put<pond.UpdateFieldMarkerResponse>( return put<pond.UpdateFieldMarkerResponse>(
pondURL( pondURL(
"/fieldMarkers/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "") "/fieldMarkers/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")
), ),
hm hm
); );

View file

@ -9,7 +9,7 @@ export interface IGateInterface {
addGate: ( addGate: (
name: string, name: string,
settings: pond.GateSettings, settings: pond.GateSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddGateResponse>>; ) => Promise<AxiosResponse<pond.AddGateResponse>>;
listGates: ( listGates: (
limit: number, limit: number,
@ -22,23 +22,23 @@ export interface IGateInterface {
types?: string[], types?: string[],
numerical?: boolean, numerical?: boolean,
specificUser?: string, specificUser?: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListGatesResponse>>; ) => Promise<AxiosResponse<pond.ListGatesResponse>>;
updateGate: ( updateGate: (
key: string, key: string,
name: string, name: string,
settings: pond.GateSettings, settings: pond.GateSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateGateResponse>>; ) => Promise<AxiosResponse<pond.UpdateGateResponse>>;
getGate: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGateResponse>>; getGate: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetGateResponse>>;
removeGate: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveGateResponse>>; removeGate: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveGateResponse>>;
updateLink: ( updateLink: (
parentKey: string, parentKey: string,
parentType: string, parentType: string,
objectID: string, objectID: string,
objectType: string, objectType: string,
permissions: string[], permissions: string[],
as?: string otherTeam?: string
) => Promise<any>; ) => Promise<any>;
updatePrefs: ( updatePrefs: (
gateKey: string, gateKey: string,
@ -47,9 +47,9 @@ export interface IGateInterface {
gatePref: pond.GateComponentType | pond.GateDeviceType, gatePref: pond.GateComponentType | pond.GateDeviceType,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateGatePreferencesResponse>>; ) => Promise<AxiosResponse<pond.UpdateGatePreferencesResponse>>;
getGatePageData: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGatePageDataResponse>>; getGatePageData: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetGatePageDataResponse>>;
listGateAirflow: ( listGateAirflow: (
gate: string, gate: string,
device: number | string, device: number | string,
@ -59,7 +59,7 @@ export interface IGateInterface {
end: string, end: string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListGateAirflowResponse>>; ) => Promise<AxiosResponse<pond.ListGateAirflowResponse>>;
listGateFlowEvents: ( listGateFlowEvents: (
gate: string, gate: string,
@ -72,13 +72,13 @@ export interface IGateInterface {
flowVariance: number, flowVariance: number,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListGateFlowEventsResponse>>; ) => Promise<AxiosResponse<pond.ListGateFlowEventsResponse>>;
listGateMeasurements: ( listGateMeasurements: (
key: string, key: string,
start: string, start: string,
end: string, end: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>; ) => Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>;
} }
@ -89,10 +89,11 @@ interface Props {}
export default function GateProvider(props: PropsWithChildren<Props>) { export default function GateProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addGate = (name: string, settings: pond.GateSettings, as?: string) => { const addGate = (name: string, settings: pond.GateSettings, otherTeam?: string) => {
let url = pondURL("/gates?name=" + name + (as ? "&as=" + as : "")) const view = otherTeam ? otherTeam : as
let url = pondURL("/gates?name=" + name + (view ? "&as=" + view : ""))
return new Promise<AxiosResponse<pond.AddGateResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.AddGateResponse>>((resolve, reject) => {
post<pond.AddGateResponse>(url, settings).then(resp => { post<pond.AddGateResponse>(url, settings).then(resp => {
resp.data = pond.AddGateResponse.fromObject(resp.data) resp.data = pond.AddGateResponse.fromObject(resp.data)
@ -114,10 +115,11 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
types?: string[], types?: string[],
numerical?: boolean, numerical?: boolean,
specificUser?: string, specificUser?: string,
as?: string otherTeam?: string
) => { ) => {
let asText = ""; let asText = "";
if (as) asText = "&as=" + as; const view = otherTeam ? otherTeam : as
if (view) asText = "&as=" + view;
if (specificUser) asText = "&as=" + specificUser; if (specificUser) asText = "&as=" + specificUser;
let url = pondURL( let url = pondURL(
"/gates?limit=" + "/gates?limit=" +
@ -143,8 +145,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const updateGate = (key: string, name: string, settings: pond.GateSettings, as?: string) => { const updateGate = (key: string, name: string, settings: pond.GateSettings, otherTeam?: string) => {
let url = pondURL("/gates/" + key + "?name=" + name + (as ? "&as=" + as : "")) const view = otherTeam ? otherTeam : as
let url = pondURL("/gates/" + key + "?name=" + name + (view ? "&as=" + view : ""))
return new Promise<AxiosResponse<pond.UpdateGateResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.UpdateGateResponse>>((resolve, reject) => {
put<pond.UpdateGateResponse>(url, settings).then(resp => { put<pond.UpdateGateResponse>(url, settings).then(resp => {
resp.data = pond.UpdateGateResponse.fromObject(resp.data) resp.data = pond.UpdateGateResponse.fromObject(resp.data)
@ -155,8 +158,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const removeGate = (key: string, as?: string) => { const removeGate = (key: string, otherTeam?: string) => {
let url = pondURL("/gates/" + key + (as ? "?as=" + as : "")) const view = otherTeam ? otherTeam : as
let url = pondURL("/gates/" + key + (view ? "?as=" + view : ""))
return new Promise<AxiosResponse<pond.RemoveGateResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.RemoveGateResponse>>((resolve, reject) => {
del<pond.RemoveGateResponse>(url).then(resp => { del<pond.RemoveGateResponse>(url).then(resp => {
resp.data = pond.RemoveGateResponse.fromObject(resp.data) resp.data = pond.RemoveGateResponse.fromObject(resp.data)
@ -167,8 +171,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const getGate = (key: string, as?: string) => { const getGate = (key: string, otherTeam?: string) => {
let url = pondURL("/gates/" + key + (as ? "?as=" + as : "")) const view = otherTeam ? otherTeam : as
let url = pondURL("/gates/" + key + (view ? "?as=" + view : ""))
return new Promise<AxiosResponse<pond.GetGateResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.GetGateResponse>>((resolve, reject) => {
get<pond.GetGateResponse>(url).then(resp => { get<pond.GetGateResponse>(url).then(resp => {
resp.data = pond.GetGateResponse.fromObject(resp.data) resp.data = pond.GetGateResponse.fromObject(resp.data)
@ -179,8 +184,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
}) })
}; };
const getGatePageData = (key: string, as?: string) => { const getGatePageData = (key: string, otherTeam?: string) => {
let url = pondURL("/gatePage/" + key + (as ? "?as=" + as : "")) const view = otherTeam ? otherTeam : as
let url = pondURL("/gatePage/" + key + (view ? "?as=" + view : ""))
return new Promise<AxiosResponse<pond.GetGatePageDataResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.GetGatePageDataResponse>>((resolve, reject) => {
get<pond.GetGatePageDataResponse>(url).then(resp => { get<pond.GetGatePageDataResponse>(url).then(resp => {
resp.data = pond.GetGatePageDataResponse.fromObject(resp.data) resp.data = pond.GetGatePageDataResponse.fromObject(resp.data)
@ -197,9 +203,10 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
objectID: string, objectID: string,
objectType: string, objectType: string,
permissions: 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) => { return new Promise<AxiosResponse>((resolve, reject) => {
post(url, { post(url, {
Key: objectID, Key: objectID,
@ -223,8 +230,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
gatePref: pond.GateComponentType | pond.GateDeviceType, gatePref: pond.GateComponentType | pond.GateDeviceType,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
`/gatePrefs/` + `/gatePrefs/` +
gateKey + gateKey +
@ -234,7 +242,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
childKey + childKey +
"&gatePreference=" + "&gatePreference=" +
gatePref + gatePref +
(as ? `&as=` + as : "") + (view ? `&as=` + view : "") +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : "") (types ? "&types=" + types.toString() : "")
) )
@ -257,8 +265,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
end: string, end: string,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/gates/" + "/gates/" +
gate + gate +
@ -272,7 +281,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
start + start +
"&end=" + "&end=" +
end + end +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.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) => { const listGateMeasurements = (key: string, start: string, end: string, otherTeam?: string) => {
let url = pondURL("/gates/" + key + "/measurements?start=" + start + "&end=" + end + "&as=" + as) 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) => { return new Promise<AxiosResponse<pond.ListGateMeasurementsResponse>>((resolve, reject) => {
get<pond.ListGateMeasurementsResponse>(url).then(resp => { get<pond.ListGateMeasurementsResponse>(url).then(resp => {
resp.data = pond.ListGateMeasurementsResponse.fromObject(resp.data) resp.data = pond.ListGateMeasurementsResponse.fromObject(resp.data)
@ -309,8 +319,9 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
flowVariance: number, flowVariance: number,
keys?: string[], keys?: string[],
types?: string[], types?: string[],
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
return get<pond.ListGateFlowEventsResponse>( return get<pond.ListGateFlowEventsResponse>(
pondURL( pondURL(
"/gates/" + "/gates/" +
@ -329,7 +340,7 @@ export default function GateProvider(props: PropsWithChildren<Props>) {
idleFlow + idleFlow +
"&variance=" + "&variance=" +
flowVariance + flowVariance +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(keys ? "&keys=" + keys.toString() : "") + (keys ? "&keys=" + keys.toString() : "") +
(types ? "&types=" + types.toString() : "") (types ? "&types=" + types.toString() : "")
) )

View file

@ -4,13 +4,12 @@ import { pond } from "protobuf-ts/pond";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
import { useGlobalState } from "providers"; import { useGlobalState } from "providers";
import { GrainBag } from "models/GrainBag";
export interface IGrainBagInterface { export interface IGrainBagInterface {
addGrainBag: ( addGrainBag: (
name: string, name: string,
settings: pond.GrainBagSettings, settings: pond.GrainBagSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddGrainBagResponse>>; ) => Promise<AxiosResponse<pond.AddGrainBagResponse>>;
listGrainBags: ( listGrainBags: (
limit: number, limit: number,
@ -21,28 +20,27 @@ export interface IGrainBagInterface {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
numerical?: boolean, numerical?: boolean,
specificUser?: string, otherTeam?: string
as?: string
) => Promise<AxiosResponse<pond.ListGrainBagsResponse>>; ) => Promise<AxiosResponse<pond.ListGrainBagsResponse>>;
updateGrainBag: ( updateGrainBag: (
key: string, key: string,
name: string, name: string,
settings: pond.GrainBagSettings, settings: pond.GrainBagSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateGrainBagResponse>>; ) => Promise<AxiosResponse<pond.UpdateGrainBagResponse>>;
bulkUpdateGrainBags: ( bulkUpdateGrainBags: (
bags: pond.GrainBag[], bags: pond.GrainBag[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.BulkGrainBagUpdateResponse>>; ) => Promise<AxiosResponse<pond.BulkGrainBagUpdateResponse>>;
getGrainBag: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGrainBagResponse>>; getGrainBag: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetGrainBagResponse>>;
removeGrainBag: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveGrainBagResponse>>; removeGrainBag: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveGrainBagResponse>>;
listHistory: ( listHistory: (
id: string, id: string,
limit: number, limit: number,
offset: number, offset: number,
start?: string, start?: string,
end?: string, end?: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListGrainBagHistoryResponse>>; ) => Promise<AxiosResponse<pond.ListGrainBagHistoryResponse>>;
} }
@ -53,12 +51,13 @@ interface Props {}
export default function GrainBagProvider(props: PropsWithChildren<Props>) { export default function GrainBagProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addGrainBag = (name: string, settings: pond.GrainBagSettings, as?: string) => { const addGrainBag = (name: string, settings: pond.GrainBagSettings, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
return post<pond.AddGrainBagResponse>( return post<pond.AddGrainBagResponse>(
pondURL("/grainbags?name=" + name + "&as=" + as), pondURL("/grainbags?name=" + name + "&as=" + view),
settings settings
); );
} }
@ -74,12 +73,11 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
keys?: string[], keys?: string[],
types?: string[], types?: string[],
numerical?: boolean, numerical?: boolean,
specificUser?: string, otherTeam?: string
as?: string
) => { ) => {
let asText = ""; let asText = "";
if (as) asText = "&as=" + as; const view = otherTeam ? otherTeam : as
if (specificUser) asText = "&as=" + specificUser; if (view) asText = "&as=" + view;
return get<pond.ListGrainBagsResponse>( return get<pond.ListGrainBagsResponse>(
pondURL( pondURL(
"/grainbags?limit=" + "/grainbags?limit=" +
@ -97,10 +95,11 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
); );
}; };
const updateGrainBag = (key: string, name: string, settings: pond.GrainBagSettings, as?: string) => { const updateGrainBag = (key: string, name: string, settings: pond.GrainBagSettings, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
return put<pond.UpdateGrainBagResponse>( return put<pond.UpdateGrainBagResponse>(
pondURL("/grainbags/" + key + "?as=" + as + "&name=" + name), pondURL("/grainbags/" + key + "?as=" + view + "&name=" + name),
settings settings
); );
} }
@ -110,29 +109,33 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
); );
}; };
const bulkUpdateGrainBags = (bags: pond.GrainBag[], as?: string) => { const bulkUpdateGrainBags = (bags: pond.GrainBag[], otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update?as=" + as), { if (view)
return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update?as=" + view), {
bags: bags bags: bags
}); });
return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update"), { bags: bags }); return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update"), { bags: bags });
}; };
const removeGrainBag = (key: string, as?: string) => { const removeGrainBag = (key: string, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
return del<pond.RemoveGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + 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) => { const getGrainBag = (key: string, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
return get<pond.GetGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + as)); if (view) {
return get<pond.GetGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + view));
} }
return get<pond.GetGrainBagResponse>(pondURL("/grainbags/" + key)); 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( let url = pondURL(
"/grainbags/" + "/grainbags/" +
id + id +
@ -143,8 +146,8 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
(start && "&start=" + start) + (start && "&start=" + start) +
(end && "&end=" + end) (end && "&end=" + end)
) )
if (as) { if (view) {
url = url + "?as=" + as url = url + "?as=" + view
} }
return get<pond.ListGrainBagHistoryResponse>(url); return get<pond.ListGrainBagHistoryResponse>(url);
}; };

View file

@ -7,15 +7,15 @@ import { or } from "utils";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
export interface IHarvestPlanAPIContext { export interface IHarvestPlanAPIContext {
addHarvestPlan: (harvestPlan: pond.HarvestPlanSettings, as?: string) => Promise<any>; addHarvestPlan: (harvestPlan: pond.HarvestPlanSettings, otherTeam?: string) => Promise<any>;
getHarvestPlan: (harvestPlanId: string, as?: string) => Promise<any>; getHarvestPlan: (harvestPlanId: string, otherTeam?: string) => Promise<any>;
listHarvestPlans: ( listHarvestPlans: (
limit: number, limit: number,
offset: number, offset: number,
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => Promise<AxiosResponse<pond.ListHarvestPlansResponse>>; ) => Promise<AxiosResponse<pond.ListHarvestPlansResponse>>;
listHistory: ( listHistory: (
@ -25,13 +25,13 @@ export interface IHarvestPlanAPIContext {
) => Promise<AxiosResponse<pond.ListHarvestPlanHistoryResponse>>; ) => Promise<AxiosResponse<pond.ListHarvestPlanHistoryResponse>>;
removeHarvestPlan: ( removeHarvestPlan: (
harvestPlanId: string, harvestPlanId: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.RemoveHarvestPlanResponse>>; ) => Promise<AxiosResponse<pond.RemoveHarvestPlanResponse>>;
updateHarvestPlan: ( updateHarvestPlan: (
key: string, key: string,
harvestPlan: pond.HarvestPlanSettings, harvestPlan: pond.HarvestPlanSettings,
asRoot?: true, asRoot?: true,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateHarvestPlanResponse>>; ) => Promise<AxiosResponse<pond.UpdateHarvestPlanResponse>>;
} }
@ -44,21 +44,24 @@ interface Props {}
export default function HarvestPlanProvider(props: PropsWithChildren<Props>) { export default function HarvestPlanProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addHarvestPlan = (harvestPlan: pond.HarvestPlanSettings, as?: string) => { const addHarvestPlan = (harvestPlan: pond.HarvestPlanSettings, otherTeam?: string) => {
if (as) return post(pondURL("/harvestPlans?as=" + as), harvestPlan); const view = otherTeam ? otherTeam : as
if (view) return post(pondURL("/harvestPlans?as=" + view), harvestPlan);
return post(pondURL("/harvestPlans"), harvestPlan); return post(pondURL("/harvestPlans"), harvestPlan);
}; };
const getHarvestPlan = (harvestPlanId: string, as?: string) => { const getHarvestPlan = (harvestPlanId: string, otherTeam?: string) => {
if (as) return get(pondURL("/harvestPlans/" + harvestPlanId + "?as=" + as)); const view = otherTeam ? otherTeam : as
if (view) return get(pondURL("/harvestPlans/" + harvestPlanId + "?as=" + view));
return get(pondURL("/harvestPlans/" + harvestPlanId)); return get(pondURL("/harvestPlans/" + harvestPlanId));
}; };
const removeHarvestPlan = (key: string, as?: string) => { const removeHarvestPlan = (key: string, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
return del<pond.RemoveHarvestPlanResponse>(pondURL("/harvestPlans/" + key + "?as=" + as)); if (view)
return del<pond.RemoveHarvestPlanResponse>(pondURL("/harvestPlans/" + key + "?as=" + view));
return del<pond.RemoveHarvestPlanResponse>(pondURL("/harvestPlans/" + key)); return del<pond.RemoveHarvestPlanResponse>(pondURL("/harvestPlans/" + key));
}; };
@ -68,9 +71,10 @@ export default function HarvestPlanProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => { ) => {
const view = otherTeam ? otherTeam : as
return get<pond.ListHarvestPlansResponse>( return get<pond.ListHarvestPlansResponse>(
pondURL( pondURL(
"/harvestPlans" + "/harvestPlans" +
@ -82,7 +86,7 @@ export default function HarvestPlanProvider(props: PropsWithChildren<Props>) {
("&by=" + or(orderBy, "key")) + ("&by=" + or(orderBy, "key")) +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
) )
); );
}; };
@ -97,14 +101,15 @@ export default function HarvestPlanProvider(props: PropsWithChildren<Props>) {
key: string, key: string,
harvestPlan: pond.HarvestPlanSettings, harvestPlan: pond.HarvestPlanSettings,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => { ) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return put<pond.UpdateHarvestPlanResponse>( return put<pond.UpdateHarvestPlanResponse>(
pondURL( pondURL(
"/harvestPlans/" + "/harvestPlans/" +
key + key +
(as ? "?as=" + as : "") + (view ? "?as=" + view : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") (asRoot ? "&asRoot=" + asRoot.toString() : "")
), ),
harvestPlan harvestPlan

View file

@ -8,7 +8,7 @@ import { pondURL } from "./pond";
export interface IHomeMarkerAPIContext { export interface IHomeMarkerAPIContext {
addHomeMarker: ( addHomeMarker: (
homeMarker: pond.HomeMarkerSettings, homeMarker: pond.HomeMarkerSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddHomeMarkerResponse>>; ) => Promise<AxiosResponse<pond.AddHomeMarkerResponse>>;
getHomeMarker: (homeMarkerID: string) => Promise<AxiosResponse<pond.HomeMarker>>; getHomeMarker: (homeMarkerID: string) => Promise<AxiosResponse<pond.HomeMarker>>;
listHomeMarkers: ( listHomeMarkers: (
@ -18,14 +18,14 @@ export interface IHomeMarkerAPIContext {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListHomeMarkersResponse>>; ) => Promise<AxiosResponse<pond.ListHomeMarkersResponse>>;
removeHomeMarker: (homeMarkerID: string) => Promise<AxiosResponse<pond.RemoveHomeMarkerResponse>>; removeHomeMarker: (homeMarkerID: string) => Promise<AxiosResponse<pond.RemoveHomeMarkerResponse>>;
updateHomeMarker: ( updateHomeMarker: (
key: string, key: string,
homeMarker: pond.HomeMarkerSettings, homeMarker: pond.HomeMarkerSettings,
asRoot?: true, asRoot?: true,
as?:string otherTeam?:string
) => Promise<AxiosResponse<pond.UpdateHomeMarkerResponse>>; ) => Promise<AxiosResponse<pond.UpdateHomeMarkerResponse>>;
} }
@ -38,10 +38,11 @@ interface Props {}
export default function HomeMarkerProvider(props: PropsWithChildren<Props>) { export default function HomeMarkerProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addHomeMarker = (homeMarker: pond.HomeMarkerSettings, as?: string) => { const addHomeMarker = (homeMarker: pond.HomeMarkerSettings, otherTeam?: string) => {
if (as) return post<pond.AddHomeMarkerResponse>(pondURL("/homeMarkers?as=" + as), homeMarker); const view = otherTeam ? otherTeam : as
if (view) return post<pond.AddHomeMarkerResponse>(pondURL("/homeMarkers?as=" + view), homeMarker);
return post<pond.AddHomeMarkerResponse>(pondURL("/homeMarkers"), homeMarker); return post<pond.AddHomeMarkerResponse>(pondURL("/homeMarkers"), homeMarker);
}; };
@ -60,8 +61,9 @@ export default function HomeMarkerProvider(props: PropsWithChildren<Props>) {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
return get<pond.ListHomeMarkersResponse>( return get<pond.ListHomeMarkersResponse>(
pondURL( pondURL(
"/homeMarkers" + "/homeMarkers" +
@ -73,16 +75,17 @@ export default function HomeMarkerProvider(props: PropsWithChildren<Props>) {
("&by=" + (orderBy ? orderBy : "key")) + ("&by=" + (orderBy ? orderBy : "key")) +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
) )
); );
}; };
const updateHomeMarker = (key: string, hm: pond.HomeMarkerSettings, asRoot?: boolean, as?: string) => { const updateHomeMarker = (key: string, hm: pond.HomeMarkerSettings, asRoot?: boolean, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return put<pond.UpdateHomeMarkerResponse>( return put<pond.UpdateHomeMarkerResponse>(
pondURL( pondURL(
"/homeMarkers/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "") "/homeMarkers/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")
), ),
hm hm
); );

View file

@ -10,31 +10,31 @@ import { has } from "utils/types";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
export interface IInteractionsAPIContext { export interface IInteractionsAPIContext {
addInteraction: (device: number, settings: pond.IInteractionSettings, as?: string) => Promise<AxiosResponse<pond.AddInteractionResponse>>; addInteraction: (device: number, settings: pond.IInteractionSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddInteractionResponse>>;
addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings, as?: string) => Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>; addMultiInteractions: (device: number, settings: pond.MultiInteractionSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>;
addInteractionToComponents: ( addInteractionToComponents: (
fullComponentLocations: string[], fullComponentLocations: string[],
settings: pond.IInteractionSettings, settings: pond.IInteractionSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddInteractionToComponentsResponse>>; ) => 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: ( updateInteractionPondSettings: (
device: number, device: number,
interaction: string, interaction: string,
settings: pond.IInteractionPondSettings, settings: pond.IInteractionPondSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>; ) => Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>;
removeInteraction: (device: number, interaction: string, as?: string) => Promise<AxiosResponse<pond.RemoveInteractionResponse>>; removeInteraction: (device: number, interaction: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveInteractionResponse>>;
listInteractionsByDevice: (device: number | string, demo?: boolean, as?: string) => Promise<Interaction[]>; listInteractionsByDevice: (device: number | string, demo?: boolean, otherTeam?: string) => Promise<Interaction[]>;
listInteractionsByComponent: ( listInteractionsByComponent: (
device: number, device: number,
component: quack.ComponentID, component: quack.ComponentID,
demo?: boolean, demo?: boolean,
as?: string otherTeam?: string
) => Promise<Interaction[]>; ) => Promise<Interaction[]>;
setAlertInteractions: ( setAlertInteractions: (
alerts: pond.AlertData[], alerts: pond.AlertData[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.SetAlertInteractionsResponse>>; ) => Promise<AxiosResponse<pond.SetAlertInteractionsResponse>>;
} }
@ -60,12 +60,13 @@ function sanitizeInteraction(interaction: pond.IInteractionSettings): pond.IInte
export default function InteractionProvider(props: PropsWithChildren<Props>) { export default function InteractionProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, post, put, del } = useHTTP(); 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) => { return new Promise<AxiosResponse<pond.AddInteractionResponse>>((resolve, reject) => {
post<pond.AddInteractionResponse>( post<pond.AddInteractionResponse>(
pondURL("/devices/" + device + "/interactions" + (as ? "?as=" + as : "")), pondURL("/devices/" + device + "/interactions" + (view ? "?as=" + view : "")),
sanitizeInteraction(settings) sanitizeInteraction(settings)
).then(resp => { ).then(resp => {
resp.data = pond.AddInteractionResponse.fromObject(resp) resp.data = pond.AddInteractionResponse.fromObject(resp)
@ -85,13 +86,14 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
const addInteractionToComponents = ( const addInteractionToComponents = (
fullComponentLocations: string[], fullComponentLocations: string[],
settings: pond.IInteractionSettings, settings: pond.IInteractionSettings,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/interactions/forComponents/" + "/interactions/forComponents/" +
"?componentIds=" + "?componentIds=" +
fullComponentLocations.toString() + fullComponentLocations.toString() +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
) )
return new Promise<AxiosResponse<pond.AddInteractionToComponentsResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.AddInteractionToComponentsResponse>>((resolve, reject) => {
post<pond.AddInteractionToComponentsResponse>(url,sanitizeInteraction(settings)).then(resp => { 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) => { const addMultiInteractions = (device: number, settings: pond.MultiInteractionSettings, otherTeam?: string) => {
let url = pondURL("/devices/" + device + "/interactions/multi" + (as ? "?as=" + as : "")) const view = otherTeam ? otherTeam : as
let url = pondURL("/devices/" + device + "/interactions/multi" + (view ? "?as=" + view : ""))
return new Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.AddMultiInteractionsResponse>>((resolve, reject) => {
post<pond.AddMultiInteractionsResponse>(url,settings).then(resp => { post<pond.AddMultiInteractionsResponse>(url,settings).then(resp => {
resp.data = pond.AddMultiInteractionsResponse.fromObject(resp.data) 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( let url = pondURL(
"/devices/" + "/devices/" +
device + device +
@ -123,7 +127,7 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
[device] + [device] +
"&types=" + "&types=" +
["device"] + ["device"] +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
) )
return new Promise<AxiosResponse<pond.UpdateInteractionResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.UpdateInteractionResponse>>((resolve, reject) => {
put<pond.UpdateInteractionResponse>(url,sanitizeInteraction(settings)).then(resp => { put<pond.UpdateInteractionResponse>(url,sanitizeInteraction(settings)).then(resp => {
@ -139,8 +143,9 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
device: number, device: number,
interaction: string, interaction: string,
settings: pond.IInteractionPondSettings, settings: pond.IInteractionPondSettings,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/devices/" + "/devices/" +
device + device +
@ -150,7 +155,7 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
[device] + [device] +
"&types=" + "&types=" +
["device"] + ["device"] +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
) )
return new Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.UpdateInteractionPondSettingsResponse>>((resolve, reject) => {
put<pond.UpdateInteractionPondSettingsResponse>(url, sanitizeInteraction(settings)).then(resp => { 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) => { const removeInteraction = (device: number, interaction: string, otherTeam?: string) => {
let url = pondURL("/devices/" + device + "/interactions/" + interaction + (as ? "?as=" + as : "")) const view = otherTeam ? otherTeam : as
let url = pondURL("/devices/" + device + "/interactions/" + interaction + (view ? "?as=" + view : ""))
return new Promise<AxiosResponse<pond.RemoveInteractionResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.RemoveInteractionResponse>>((resolve, reject) => {
del<pond.RemoveInteractionResponse>(url).then(resp => { del<pond.RemoveInteractionResponse>(url).then(resp => {
resp.data = pond.RemoveInteractionResponse.fromObject(resp.data) resp.data = pond.RemoveInteractionResponse.fromObject(resp.data)
@ -178,10 +184,11 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
const listInteractionsByDevice = ( const listInteractionsByDevice = (
device: number | string, device: number | string,
demo: boolean = false, demo: boolean = false,
as?: string otherTeam?: string
): Promise<Interaction[]> => { ): Promise<Interaction[]> => {
const view = otherTeam ? otherTeam : as
return new Promise((resolve, reject) => { 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) => { .then((response: any) => {
if (!has(response, "data.interactions")) { if (!has(response, "data.interactions")) {
return resolve([]); return resolve([]);
@ -217,8 +224,9 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
device: number, device: number,
component: quack.ComponentID, component: quack.ComponentID,
demo: boolean = false, demo: boolean = false,
as?: string otherTeam?: string
): Promise<Interaction[]> => { ): Promise<Interaction[]> => {
const view = otherTeam ? otherTeam : as
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
get( get(
pondURL( pondURL(
@ -227,7 +235,7 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
"/components/" + "/components/" +
componentIDToString(component) + componentIDToString(component) +
"/interactions" + "/interactions" +
(as ? "?as=" + as : ""), (view ? "?as=" + view : ""),
demo demo
) )
) )
@ -264,9 +272,10 @@ export default function InteractionProvider(props: PropsWithChildren<Props>) {
const setAlertInteractions = ( const setAlertInteractions = (
alerts: pond.AlertData[], alerts: pond.AlertData[],
as?: string otherTeam?: string
): Promise<AxiosResponse<pond.SetAlertInteractionsResponse>> => { ): 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) => { return new Promise<AxiosResponse<pond.SetAlertInteractionsResponse>>((resolve, reject) => {
post<pond.SetAlertInteractionsResponse>(url, { data: alerts }).then(resp => { post<pond.SetAlertInteractionsResponse>(url, { data: alerts }).then(resp => {
resp.data = pond.SetAlertInteractionsResponse.fromObject(resp.data) resp.data = pond.SetAlertInteractionsResponse.fromObject(resp.data)

View file

@ -7,15 +7,15 @@ import { createContext, PropsWithChildren, useContext } from "react";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
export interface IMineAPIContext { export interface IMineAPIContext {
addMine: (mine: pond.MineSettings, as?: string) => Promise<AxiosResponse<pond.AddMineResponse>>; addMine: (mine: pond.MineSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddMineResponse>>;
getMine: (key: string, as?: string) => Promise<AxiosResponse<pond.GetMineResponse>>; getMine: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.GetMineResponse>>;
addDevice: (key: string, deviceID: string, permissions: pond.Permission[], as?: string) => Promise<any>; addDevice: (key: string, deviceID: string, permissions: pond.Permission[], otherTeam?: string) => Promise<any>;
addComponent: ( addComponent: (
key: string, key: string,
deviceID: string, deviceID: string,
componentKey: string, componentKey: string,
permissions: pond.Permission[], permissions: pond.Permission[],
as?: string otherTeam?: string
) => Promise<any>; ) => Promise<any>;
listMines: ( listMines: (
limit: number, limit: number,
@ -24,7 +24,7 @@ export interface IMineAPIContext {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListMinesResponse>>; ) => Promise<AxiosResponse<pond.ListMinesResponse>>;
listMinesSimple: ( listMinesSimple: (
limit: number, limit: number,
@ -33,9 +33,9 @@ export interface IMineAPIContext {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListMinesSimpleResponse>>; ) => Promise<AxiosResponse<pond.ListMinesSimpleResponse>>;
removeMine: (key: string, as?: string) => Promise<AxiosResponse<pond.RemoveMineResponse>>; removeMine: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveMineResponse>>;
updateMine: ( updateMine: (
mine: pond.MineSettings, mine: pond.MineSettings,
componentPreferences: Map<string, pond.MineComponentPreferences> componentPreferences: Map<string, pond.MineComponentPreferences>
@ -49,14 +49,16 @@ interface Props {}
export default function MineProvider(props: PropsWithChildren<Props>) { export default function MineProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addMine = (mine: pond.MineSettings, as?: string) => { const addMine = (mine: pond.MineSettings, otherTeam?: string) => {
return post<pond.AddMineResponse>(pondURL("/mines" + (as ? "?as=" + as : "")), mine); const view = otherTeam ? otherTeam : as
return post<pond.AddMineResponse>(pondURL("/mines" + (view ? "?as=" + view : "")), mine);
}; };
const getMine = (key: string, as?: string) => { const getMine = (key: string, otherTeam?: string) => {
return get<pond.GetMineResponse>(pondURL("/mines/" + key + (as ? "?as=" + as : ""))); const view = otherTeam ? otherTeam : as
return get<pond.GetMineResponse>(pondURL("/mines/" + key + (view ? "?as=" + view : "")));
}; };
const listMines = ( const listMines = (
@ -68,8 +70,9 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
asRoot?: boolean, asRoot?: boolean,
keys?: string, keys?: string,
types?: string, types?: string,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
const url = pondURL( const url = pondURL(
"/mines" + "/mines" +
"?limit=" + "?limit=" +
@ -80,7 +83,7 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
("&by=" + (orderBy ? orderBy : "deviceId")) + ("&by=" + (orderBy ? orderBy : "deviceId")) +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(keys ? "&keys=" + keys : "") + (keys ? "&keys=" + keys : "") +
(types ? "&types=" + types : "") (types ? "&types=" + types : "")
); );
@ -94,8 +97,9 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
const url = pondURL( const url = pondURL(
"/minesSimple" + "/minesSimple" +
"?limit=" + "?limit=" +
@ -106,13 +110,14 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
("&by=" + (orderBy ? orderBy : "deviceId")) + ("&by=" + (orderBy ? orderBy : "deviceId")) +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
); );
return get<pond.ListMinesSimpleResponse>(url); return get<pond.ListMinesSimpleResponse>(url);
}; };
const removeMine = (key: string, as?: string) => { const removeMine = (key: string, otherTeam?: string) => {
return del<pond.RemoveMineResponse>(pondURL("/mines/" + key + (as ? "?as=" + as : ""))); const view = otherTeam ? otherTeam : as
return del<pond.RemoveMineResponse>(pondURL("/mines/" + key + (view ? "?as=" + view : "")));
}; };
const updateMine = ( const updateMine = (
@ -132,9 +137,10 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
return put<pond.AddMineResponse>(pondURL("/mines"), request); return put<pond.AddMineResponse>(pondURL("/mines"), request);
}; };
const addDevice = (key: string, deviceID: string, permissions: pond.Permission[], as?: string) => { const addDevice = (key: string, deviceID: string, permissions: pond.Permission[], otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID + `?as=${as}`), { if (view)
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID + `?as=${view}`), {
permissions: permissions.map(permission => permissionToString(permission)) permissions: permissions.map(permission => permissionToString(permission))
}); });
return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID), { return post(pondURL(`/mines/` + key + `/addDevice/` + deviceID), {
@ -147,11 +153,12 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
deviceID: string, deviceID: string,
componentKey: string, componentKey: string,
permissions: pond.Permission[], permissions: pond.Permission[],
as?: string otherTeam?: string
) => { ) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return post( return post(
pondURL(`/mines/` + key + `/addComponent/` + deviceID + "/" + componentKey + `?as=${as}`), pondURL(`/mines/` + key + `/addComponent/` + deviceID + "/" + componentKey + `?as=${view}`),
{ {
permissions: permissions.map(permission => permissionToString(permission)) permissions: permissions.map(permission => permissionToString(permission))
} }
@ -169,8 +176,8 @@ export default function MineProvider(props: PropsWithChildren<Props>) {
addDevice, addDevice,
addComponent, addComponent,
listMines, listMines,
listMinesSimple,// listMinesSimple,
removeMine,// removeMine,
updateMine updateMine
}}> }}>
{children} {children}

View file

@ -1,6 +1,7 @@
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
import { useHTTP } from "hooks"; import { useHTTP } from "hooks";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { useGlobalState } from "providers";
import { createContext, PropsWithChildren, useContext } from "react"; import { createContext, PropsWithChildren, useContext } from "react";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
@ -15,7 +16,7 @@ export interface INoteAPIContext {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListNotesResponse>>; ) => Promise<AxiosResponse<pond.ListNotesResponse>>;
listChats: ( listChats: (
limit: number, limit: number,
@ -24,7 +25,7 @@ export interface INoteAPIContext {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListChatsResponse>>; ) => Promise<AxiosResponse<pond.ListChatsResponse>>;
removeNote: (noteID: string) => Promise<AxiosResponse<pond.RemoveBinResponse>>; removeNote: (noteID: string) => Promise<AxiosResponse<pond.RemoveBinResponse>>;
} }
@ -36,6 +37,7 @@ interface Props {}
export default function NoteProvider(props: PropsWithChildren<Props>) { export default function NoteProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
const [{as}] = useGlobalState()
const addNote = (note: pond.NoteSettings, attachments?: string[]) => { const addNote = (note: pond.NoteSettings, attachments?: string[]) => {
let url = pondURL("/notes" + (attachments ? "?attachments=" + attachments.toString() : "")) let url = pondURL("/notes" + (attachments ? "?attachments=" + attachments.toString() : ""))
@ -86,8 +88,9 @@ export default function NoteProvider(props: PropsWithChildren<Props>) {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/notes" + "/notes" +
"?limit=" + "?limit=" +
@ -98,7 +101,7 @@ export default function NoteProvider(props: PropsWithChildren<Props>) {
("&by=" + (orderBy ? orderBy : "key")) + ("&by=" + (orderBy ? orderBy : "key")) +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
) )
return new Promise<AxiosResponse<pond.ListNotesResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.ListNotesResponse>>((resolve, reject) => {
get<pond.ListNotesResponse>(url).then(resp => { get<pond.ListNotesResponse>(url).then(resp => {
@ -117,8 +120,9 @@ export default function NoteProvider(props: PropsWithChildren<Props>) {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/chats" + "/chats" +
"?limit=" + "?limit=" +
@ -129,7 +133,7 @@ export default function NoteProvider(props: PropsWithChildren<Props>) {
("&by=" + (orderBy ? orderBy : "key")) + ("&by=" + (orderBy ? orderBy : "key")) +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
) )
return new Promise<AxiosResponse<pond.ListChatsResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.ListChatsResponse>>((resolve, reject) => {
get<pond.ListChatsResponse>(url).then(resp => { get<pond.ListChatsResponse>(url).then(resp => {

View file

@ -4,6 +4,7 @@ import { pond } from "protobuf-ts/pond";
import { or } from "utils/types"; import { or } from "utils/types";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
import { useGlobalState } from "providers";
export interface INotificationAPIContext { export interface INotificationAPIContext {
listNotifications: ( listNotifications: (
@ -12,7 +13,7 @@ export interface INotificationAPIContext {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => Promise<AxiosResponse<pond.ListNotificationsResponse>>; ) => Promise<AxiosResponse<pond.ListNotificationsResponse>>;
hideNotification: (keys: string[]) => Promise<AxiosResponse<pond.HideNotificationResponse>>; hideNotification: (keys: string[]) => Promise<AxiosResponse<pond.HideNotificationResponse>>;
@ -24,7 +25,7 @@ export interface INotificationAPIContext {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListObjectNotificationsResponse>>; ) => Promise<AxiosResponse<pond.ListObjectNotificationsResponse>>;
} }
@ -37,6 +38,7 @@ interface Props {}
export default function NotificationProvider(props: PropsWithChildren<Props>) { export default function NotificationProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, put } = useHTTP(); const { get, put } = useHTTP();
const [{as}] = useGlobalState();
const listNotifications = ( const listNotifications = (
limit: number, limit: number,
@ -44,9 +46,10 @@ export default function NotificationProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/notifications" + "/notifications" +
"?limit=" + "?limit=" +
@ -55,7 +58,7 @@ export default function NotificationProvider(props: PropsWithChildren<Props>) {
offset + offset +
("&order=" + or(order, "asc")) + ("&order=" + or(order, "asc")) +
("&by=" + or(orderBy, "key")) + ("&by=" + or(orderBy, "key")) +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(search ? "&search=" + search : "") (search ? "&search=" + search : "")
) )
@ -77,8 +80,9 @@ export default function NotificationProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string otherTeam?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/object/notifications" + "/object/notifications" +
"?objectKey=" + "?objectKey=" +
@ -92,7 +96,7 @@ export default function NotificationProvider(props: PropsWithChildren<Props>) {
("&order=" + or(order, "asc")) + ("&order=" + or(order, "asc")) +
("&by=" + or(orderBy, "key")) + ("&by=" + or(orderBy, "key")) +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
) )
return new Promise<AxiosResponse<pond.ListObjectNotificationsResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.ListObjectNotificationsResponse>>((resolve, reject) => {
get<pond.ListObjectNotificationsResponse>(url).then(resp => { get<pond.ListObjectNotificationsResponse>(url).then(resp => {

View file

@ -2,21 +2,21 @@ import { AxiosResponse } from "axios";
import { useHTTP } from "hooks"; import { useHTTP } from "hooks";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { useGlobalState } from "providers/StateContainer"; import { useGlobalState } from "providers/StateContainer";
import React, { createContext, PropsWithChildren, useContext } from "react"; import { createContext, PropsWithChildren, useContext } from "react";
import { or } from "utils"; import { or } from "utils";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
export interface ISiteAPIContext { export interface ISiteAPIContext {
addSite: (site: pond.SiteSettings, as?: string) => Promise<any>; addSite: (site: pond.SiteSettings, otherTeam?: string) => Promise<any>;
getSite: (siteID: string, as?: string) => Promise<any>; getSite: (siteID: string, otherTeam?: string) => Promise<any>;
getSitePage: (siteID: string, as?: string) => Promise<any>; getSitePage: (siteID: string, otherTeam?: string) => Promise<any>;
listSites: ( listSites: (
limit: number, limit: number,
offset: number, offset: number,
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => Promise<AxiosResponse<pond.ListSitesResponse>>; ) => Promise<AxiosResponse<pond.ListSitesResponse>>;
listSitesPageData: ( listSitesPageData: (
@ -25,7 +25,7 @@ export interface ISiteAPIContext {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => Promise<AxiosResponse<pond.ListSitesPageDataResponse>>; ) => Promise<AxiosResponse<pond.ListSitesPageDataResponse>>;
removeSite: (siteID: string) => Promise<AxiosResponse<pond.RemoveSiteResponse>>; removeSite: (siteID: string) => Promise<AxiosResponse<pond.RemoveSiteResponse>>;
@ -33,7 +33,7 @@ export interface ISiteAPIContext {
key: string, key: string,
site: pond.SiteSettings, site: pond.SiteSettings,
asRoot?: true, asRoot?: true,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateSiteResponse>>; ) => Promise<AxiosResponse<pond.UpdateSiteResponse>>;
updateLink: ( updateLink: (
parentKey: string, parentKey: string,
@ -41,7 +41,7 @@ export interface ISiteAPIContext {
objectID: string, objectID: string,
objectType: string, objectType: string,
permissions: string[], permissions: string[],
as?: string otherTeam?: string
) => Promise<any>; ) => Promise<any>;
} }
@ -52,20 +52,23 @@ interface Props {}
export default function SiteProvider(props: PropsWithChildren<Props>) { export default function SiteProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const getSitePage = (siteID: string, as?: string) => { const getSitePage = (siteID: string, otherTeam?: string) => {
if (as) return get(pondURL("/sitePage/" + siteID + "?as=" + as)); const view = otherTeam ? otherTeam : as
if (view) return get(pondURL("/sitePage/" + siteID + "?as=" + view));
return get(pondURL("/sitePage/" + siteID)); return get(pondURL("/sitePage/" + siteID));
}; };
const addSite = (site: pond.SiteSettings, as?: string) => { const addSite = (site: pond.SiteSettings, otherTeam?: string) => {
if (as) return post(pondURL("/sites?as=" + as), site); const view = otherTeam ? otherTeam : as
if (view) return post(pondURL("/sites?as=" + view), site);
return post(pondURL("/sites"), site); return post(pondURL("/sites"), site);
}; };
const getSite = (siteID: string, as?: string) => { const getSite = (siteID: string, otherTeam?: string) => {
if (as) return get(pondURL("/site/" + siteID + "?as=" + as)); const view = otherTeam ? otherTeam : as
if (view) return get(pondURL("/site/" + siteID + "?as=" + view));
return get(pondURL("/site/" + siteID)); return get(pondURL("/site/" + siteID));
}; };
@ -79,9 +82,10 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => { ) => {
const view = otherTeam ? otherTeam : as
return get<pond.ListSitesResponse>( return get<pond.ListSitesResponse>(
pondURL( pondURL(
"/sites" + "/sites" +
@ -91,7 +95,7 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
offset + offset +
("&order=" + or(order, "asc")) + ("&order=" + or(order, "asc")) +
("&by=" + or(orderBy, "key")) + ("&by=" + or(orderBy, "key")) +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(search ? "&search=" + search : "") (search ? "&search=" + search : "")
) )
@ -104,9 +108,10 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string, otherTeam?: string,
asRoot?: boolean asRoot?: boolean
) => { ) => {
const view = otherTeam ? otherTeam : as
return get<pond.ListSitesPageDataResponse>( return get<pond.ListSitesPageDataResponse>(
pondURL( pondURL(
"/sitesWithData" + "/sitesWithData" +
@ -116,18 +121,19 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
offset + offset +
("&order=" + or(order, "asc")) + ("&order=" + or(order, "asc")) +
("&by=" + or(orderBy, "key")) + ("&by=" + or(orderBy, "key")) +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(search ? "&search=" + search : "") (search ? "&search=" + search : "")
) )
); );
}; };
const updateSite = (key: string, site: pond.SiteSettings, asRoot?: boolean, as?: string) => { const updateSite = (key: string, site: pond.SiteSettings, asRoot?: boolean, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return put<pond.UpdateSiteResponse>( return put<pond.UpdateSiteResponse>(
pondURL( pondURL(
"/sites/" + key + (as ? "?as=" + as : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") "/sites/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")
), ),
site site
); );
@ -143,10 +149,11 @@ export default function SiteProvider(props: PropsWithChildren<Props>) {
objectID: string, objectID: string,
objectType: string, objectType: string,
permissions: string[], permissions: string[],
as?: string otherTeam?: string
) => { ) => {
if (as) const view = otherTeam ? otherTeam : as
return post(pondURL(`/sites/` + parentID + `/link?as=${as}`), { if (view)
return post(pondURL(`/sites/` + parentID + `/link?as=${view}`), {
Key: objectID, Key: objectID,
Type: objectType, Type: objectType,
Parent: parentID, Parent: parentID,

View file

@ -6,8 +6,8 @@ import { createContext, PropsWithChildren, useContext } from "react";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
export interface ITaskAPIContext { export interface ITaskAPIContext {
addTask: (task: pond.TaskSettings, as?: string) => Promise<AxiosResponse<pond.AddTaskResponse>>; addTask: (task: pond.TaskSettings, otherTeam?: string) => Promise<AxiosResponse<pond.AddTaskResponse>>;
getTask: (taskID: string, as?: string) => Promise<AxiosResponse<pond.Task>>; getTask: (taskID: string, otherTeam?: string) => Promise<AxiosResponse<pond.Task>>;
listTasks: ( listTasks: (
limit: number, limit: number,
offset: number, offset: number,
@ -15,18 +15,18 @@ export interface ITaskAPIContext {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string, otherTeam?: string,
from?: string, from?: string,
to?: string to?: string
) => Promise<AxiosResponse<pond.ListTasksResponse>>; ) => Promise<AxiosResponse<pond.ListTasksResponse>>;
removeTask: (taskID: string, as?: string) => Promise<AxiosResponse<pond.RemoveTaskResponse>>; removeTask: (taskID: string, otherTeam?: string) => Promise<AxiosResponse<pond.RemoveTaskResponse>>;
updateTask: ( updateTask: (
key: string, key: string,
task: pond.TaskSettings, task: pond.TaskSettings,
asRoot?: true, asRoot?: true,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateTaskResponse>>; ) => 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); export const TaskAPIContext = createContext<ITaskAPIContext>({} as ITaskAPIContext);
@ -36,20 +36,23 @@ interface Props {}
export default function TaskProvider(props: PropsWithChildren<Props>) { export default function TaskProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addTask = (task: pond.TaskSettings, as?: string) => { const addTask = (task: pond.TaskSettings, otherTeam?: string) => {
if (as) return post<pond.AddTaskResponse>(pondURL("/tasks?as=" + as), task); const view = otherTeam ? otherTeam : as
if (view) return post<pond.AddTaskResponse>(pondURL("/tasks?as=" + view), task);
return post<pond.AddTaskResponse>(pondURL("/tasks"), task); return post<pond.AddTaskResponse>(pondURL("/tasks"), task);
}; };
const getTask = (taskID: string, as?: string) => { const getTask = (taskID: string, otherTeam?: string) => {
if (as) return get<pond.Task>(pondURL("/task/" + taskID + "?as=" + as)); const view = otherTeam ? otherTeam : as
if (view) return get<pond.Task>(pondURL("/task/" + taskID + "?as=" + view));
return get<pond.Task>(pondURL("/task/" + taskID)); return get<pond.Task>(pondURL("/task/" + taskID));
}; };
const removeTask = (key: string, as?: string) => { const removeTask = (key: string, otherTeam?: string) => {
if (as) return del<pond.RemoveTaskResponse>(pondURL("/tasks/" + key + "?as=" + as)); const view = otherTeam ? otherTeam : as
if (view) return del<pond.RemoveTaskResponse>(pondURL("/tasks/" + key + "?as=" + view));
return del<pond.RemoveTaskResponse>(pondURL("/tasks/" + key)); return del<pond.RemoveTaskResponse>(pondURL("/tasks/" + key));
}; };
@ -60,10 +63,11 @@ export default function TaskProvider(props: PropsWithChildren<Props>) {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string, otherTeam?: string,
from?: string, from?: string,
to?: string to?: string
) => { ) => {
const view = otherTeam ? otherTeam : as
return get<pond.ListTasksResponse>( return get<pond.ListTasksResponse>(
pondURL( pondURL(
"/tasks" + "/tasks" +
@ -75,17 +79,18 @@ export default function TaskProvider(props: PropsWithChildren<Props>) {
("&by=" + (orderBy ? orderBy : "key")) + ("&by=" + (orderBy ? orderBy : "key")) +
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(as ? "&as=" + as : "") + (view ? "&as=" + view : "") +
(from ? "&from=" + from : "") + (from ? "&from=" + from : "") +
(to ? "&to=" + to : "") (to ? "&to=" + to : "")
) )
); );
}; };
const updateTask = (key: string, task: pond.TaskSettings, asRoot?: boolean, as?: string) => { const updateTask = (key: string, task: pond.TaskSettings, asRoot?: boolean, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return put<pond.UpdateTaskResponse>( return put<pond.UpdateTaskResponse>(
pondURL("/tasks/" + key + "?as=" + as + (asRoot ? "&asRoot=" + asRoot.toString() : "")), pondURL("/tasks/" + key + "?as=" + view + (asRoot ? "&asRoot=" + asRoot.toString() : "")),
task task
); );
return put<pond.UpdateTaskResponse>( return put<pond.UpdateTaskResponse>(
@ -94,10 +99,11 @@ export default function TaskProvider(props: PropsWithChildren<Props>) {
); );
}; };
const getMultiTasks = (objectKeys: string[], as?: string) => { const getMultiTasks = (objectKeys: string[], otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return get<pond.GetMultiTasksResponse>( return get<pond.GetMultiTasksResponse>(
pondURL("/multitasks?objectKeys=" + objectKeys.join(",") + "&as=" + as) pondURL("/multitasks?objectKeys=" + objectKeys.join(",") + "&as=" + view)
); );
return get<pond.GetMultiTasksResponse>( return get<pond.GetMultiTasksResponse>(
pondURL("/multitasks?objectKeys=" + objectKeys.join(",")) pondURL("/multitasks?objectKeys=" + objectKeys.join(","))

View file

@ -5,6 +5,7 @@ import { pond } from "protobuf-ts/pond";
import { createContext, PropsWithChildren, useContext } from "react"; import { createContext, PropsWithChildren, useContext } from "react";
import { or } from "utils/types"; import { or } from "utils/types";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
import { useGlobalState } from "providers";
export interface ITeamAPIContext { export interface ITeamAPIContext {
addTeam: (team: pond.TeamSettings) => Promise<AxiosResponse<pond.AddTeamResponse>>; addTeam: (team: pond.TeamSettings) => Promise<AxiosResponse<pond.AddTeamResponse>>;
@ -27,11 +28,11 @@ export interface ITeamAPIContext {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string, otherTeam?: string,
prefixSearch?: string, prefixSearch?: string,
) => Promise<AxiosResponse<pond.ListTeamsResponse>>; ) => Promise<AxiosResponse<pond.ListTeamsResponse>>;
listAllTeams: () => 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>>; removeTeam: (key: string) => Promise<AxiosResponse<pond.RemoveTeamResponse>>;
} }
@ -42,7 +43,7 @@ interface Props {}
export default function TeamProvider(props: PropsWithChildren<Props>) { export default function TeamProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ team }] = useGlobalState(); const [{ as }] = useGlobalState();
const addTeam = (team: pond.TeamSettings) => { const addTeam = (team: pond.TeamSettings) => {
return new Promise<AxiosResponse<pond.AddTeamResponse>>((resolve, reject) => { return new Promise<AxiosResponse<pond.AddTeamResponse>>((resolve, reject) => {
@ -114,10 +115,11 @@ export default function TeamProvider(props: PropsWithChildren<Props>) {
orderBy?: string, orderBy?: string,
search?: string, search?: string,
asRoot?: boolean, asRoot?: boolean,
as?: string, otherTeam?: string,
prefixSearch?: string, prefixSearch?: string,
) => { ) => {
//let asText = team ? "&as=" + team.key() : ""; //let asText = team ? "&as=" + team.key() : "";
const view = otherTeam ? otherTeam : as
let url = pondURL( let url = pondURL(
"/teams" + "/teams" +
"?limit=" + "?limit=" +
@ -129,7 +131,7 @@ export default function TeamProvider(props: PropsWithChildren<Props>) {
(search ? "&search=" + search : "") + (search ? "&search=" + search : "") +
(prefixSearch ? "&prefixSearch=" + prefixSearch : "") + (prefixSearch ? "&prefixSearch=" + prefixSearch : "") +
(asRoot ? "&asRoot=" + asRoot.toString() : "") + (asRoot ? "&asRoot=" + asRoot.toString() : "") +
(as ? "&as=" + as : "") (view ? "&as=" + view : "")
) )
return new Promise<AxiosResponse<pond.ListTeamsResponse>>((resolve, reject)=>{ return new Promise<AxiosResponse<pond.ListTeamsResponse>>((resolve, reject)=>{
get<pond.ListTeamsResponse>(url).then(resp => { 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" 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) => { return new Promise<AxiosResponse>((resolve, reject) => {
get(pondURL(url)).then(resp => { get(pondURL(url)).then(resp => {
return resolve(resp) return resolve(resp)

View file

@ -9,7 +9,7 @@ export interface ITerminalAPIContext {
addTerminal: ( addTerminal: (
name: string, name: string,
terminal: pond.TerminalSettings, terminal: pond.TerminalSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddTerminalResponse>>; ) => Promise<AxiosResponse<pond.AddTerminalResponse>>;
listTerminals: ( listTerminals: (
limit: number, limit: number,
@ -17,7 +17,7 @@ export interface ITerminalAPIContext {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListTerminalsResponse>>; ) => Promise<AxiosResponse<pond.ListTerminalsResponse>>;
listTerminalsAndGates: ( listTerminalsAndGates: (
limit: number, limit: number,
@ -25,15 +25,15 @@ export interface ITerminalAPIContext {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListTerminalsAndGatesResponse>>; ) => Promise<AxiosResponse<pond.ListTerminalsAndGatesResponse>>;
updateTerminal: ( updateTerminal: (
key: string, key: string,
name: string, name: string,
settings: pond.TerminalSettings, settings: pond.TerminalSettings,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateTerminalResponse>>; ) => 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); export const TerminalAPIContext = createContext<ITerminalAPIContext>({} as ITerminalAPIContext);
@ -43,12 +43,13 @@ interface Props {}
export default function TerminalProvider(props: PropsWithChildren<Props>) { export default function TerminalProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, del, post, put } = useHTTP(); const { get, del, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addTerminal = (name: string, terminal: pond.TerminalSettings, as?: string) => { const addTerminal = (name: string, terminal: pond.TerminalSettings, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return post<pond.AddTerminalResponse>( return post<pond.AddTerminalResponse>(
pondURL("/terminals?name=" + name + "&as=" + as), pondURL("/terminals?name=" + name + "&as=" + view),
terminal terminal
); );
return post<pond.AddTerminalResponse>(pondURL("/terminals?name=" + name), terminal); return post<pond.AddTerminalResponse>(pondURL("/terminals?name=" + name), terminal);
@ -60,13 +61,14 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string otherTeam?: string
) => { ) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return get<pond.ListTerminalsResponse>( return get<pond.ListTerminalsResponse>(
pondURL( pondURL(
"/terminals?as=" + "/terminals?as=" +
as + view +
"&limit=" + "&limit=" +
limit + limit +
"&offset=" + "&offset=" +
@ -95,13 +97,14 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
order?: "asc" | "desc", order?: "asc" | "desc",
orderBy?: string, orderBy?: string,
search?: string, search?: string,
as?: string otherTeam?: string
) => { ) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return get<pond.ListTerminalsAndGatesResponse>( return get<pond.ListTerminalsAndGatesResponse>(
pondURL( pondURL(
"/terminalsAndGates?as=" + "/terminalsAndGates?as=" +
as + view +
"&limit=" + "&limit=" +
limit + limit +
"&offset=" + "&offset=" +
@ -124,10 +127,11 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
); );
}; };
const updateTerminal = (key: string, name: string, settings: pond.TerminalSettings, as?: string) => { const updateTerminal = (key: string, name: string, settings: pond.TerminalSettings, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
return put<pond.UpdateTerminalResponse>( return put<pond.UpdateTerminalResponse>(
pondURL("/terminals/" + key + "?as=" + as + "&name=" + name), pondURL("/terminals/" + key + "?as=" + view + "&name=" + name),
settings settings
); );
} }
@ -137,9 +141,10 @@ export default function TerminalProvider(props: PropsWithChildren<Props>) {
); );
}; };
const removeTerminal = (key: string, as?: string) => { const removeTerminal = (key: string, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
return del<pond.RemoveTerminalResponse>(pondURL("/terminals/" + key + "?as=" + as)); if (view) {
return del<pond.RemoveTerminalResponse>(pondURL("/terminals/" + key + "?as=" + view));
} }
return del<pond.RemoveTerminalResponse>(pondURL("/terminals/" + key)); return del<pond.RemoveTerminalResponse>(pondURL("/terminals/" + key));
}; };

View file

@ -1,5 +1,5 @@
import { useHTTP } from "hooks"; import { useHTTP } from "hooks";
import React, { createContext, PropsWithChildren, useContext } from "react"; import { createContext, PropsWithChildren, useContext } from "react";
import { pond } from "protobuf-ts/pond"; import { pond } from "protobuf-ts/pond";
import { pondURL } from "./pond"; import { pondURL } from "./pond";
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
@ -9,12 +9,12 @@ export interface ITransactionAPIContext {
addTransaction: ( addTransaction: (
transaction: pond.Transaction, transaction: pond.Transaction,
fileIDs?: string[], fileIDs?: string[],
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.AddTransactionResponse>>; ) => Promise<AxiosResponse<pond.AddTransactionResponse>>;
transactionPageData: ( transactionPageData: (
start: string, start: string,
end: string, end: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.TransactionPageDataResponse>>; ) => Promise<AxiosResponse<pond.TransactionPageDataResponse>>;
listTransactions: ( listTransactions: (
start: string, start: string,
@ -23,13 +23,13 @@ export interface ITransactionAPIContext {
toObject?: pond.ObjectType, toObject?: pond.ObjectType,
fromKey?: string, fromKey?: string,
toKey?: string, toKey?: string,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.ListTransactionsResponse>>; ) => Promise<AxiosResponse<pond.ListTransactionsResponse>>;
revokeTransaction: (key: string, as?: string) => Promise<AxiosResponse<pond.RevokeTransactionResponse>>; revokeTransaction: (key: string, otherTeam?: string) => Promise<AxiosResponse<pond.RevokeTransactionResponse>>;
updateTransaction: ( updateTransaction: (
key: string, key: string,
data: pond.TransactionData, data: pond.TransactionData,
as?: string otherTeam?: string
) => Promise<AxiosResponse<pond.UpdateTransactionResponse>>; ) => Promise<AxiosResponse<pond.UpdateTransactionResponse>>;
} }
@ -42,13 +42,14 @@ interface Props {}
export default function TransactionProvider(props: PropsWithChildren<Props>) { export default function TransactionProvider(props: PropsWithChildren<Props>) {
const { children } = props; const { children } = props;
const { get, post, put } = useHTTP(); const { get, post, put } = useHTTP();
//const [{ as }] = useGlobalState(); const [{ as }] = useGlobalState();
const addTransaction = (transaction: pond.Transaction, fileIDs?: string[], as?: string) => { const addTransaction = (transaction: pond.Transaction, fileIDs?: string[], otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return post<pond.AddTransactionResponse>( return post<pond.AddTransactionResponse>(
pondURL( pondURL(
"/transactions?as=" + as + (fileIDs ? "&fileAttachments=" + fileIDs.toString() : "") "/transactions?as=" + view + (fileIDs ? "&fileAttachments=" + fileIDs.toString() : "")
), ),
transaction transaction
); );
@ -65,11 +66,12 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
toObject?: pond.ObjectType, toObject?: pond.ObjectType,
fromKey?: string, fromKey?: string,
toKey?: string, toKey?: string,
as?: string otherTeam?: string
) => { ) => {
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
return get<pond.ListTransactionsResponse>( return get<pond.ListTransactionsResponse>(
pondURL("/transactions?as=" + as + "&start=" + start + "&end=" + end) pondURL("/transactions?as=" + view + "&start=" + start + "&end=" + end)
); );
} }
return get<pond.ListTransactionsResponse>( return get<pond.ListTransactionsResponse>(
@ -86,19 +88,21 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
); );
}; };
const updateTransaction = (key: string, data: pond.TransactionData, as?: string) => { const updateTransaction = (key: string, data: pond.TransactionData, otherTeam?: string) => {
if (as) const view = otherTeam ? otherTeam : as
if (view)
return post<pond.UpdateTransactionResponse>( return post<pond.UpdateTransactionResponse>(
pondURL("/transactions/" + key + "/update?as=" + as), pondURL("/transactions/" + key + "/update?as=" + view),
data data
); );
return post<pond.UpdateTransactionResponse>(pondURL("/transactions/" + key + "/update"), data); return post<pond.UpdateTransactionResponse>(pondURL("/transactions/" + key + "/update"), data);
}; };
const transactionPageData = (start: string, end: string, as?: string) => { const transactionPageData = (start: string, end: string, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
return get<pond.TransactionPageDataResponse>( return get<pond.TransactionPageDataResponse>(
pondURL("/transactionsPage?as=" + as + "&start=" + start + "&end=" + end) pondURL("/transactionsPage?as=" + view + "&start=" + start + "&end=" + end)
); );
} }
return get<pond.TransactionPageDataResponse>( return get<pond.TransactionPageDataResponse>(
@ -106,10 +110,11 @@ export default function TransactionProvider(props: PropsWithChildren<Props>) {
); );
}; };
const revokeTransaction = (key: string, as?: string) => { const revokeTransaction = (key: string, otherTeam?: string) => {
if (as) { const view = otherTeam ? otherTeam : as
if (view) {
return put<pond.RevokeTransactionResponse>( return put<pond.RevokeTransactionResponse>(
pondURL("/transactions/" + key + "/revoke?as=" + as) pondURL("/transactions/" + key + "/revoke?as=" + view)
); );
} }
return put<pond.TransactionPageDataResponse>(pondURL("/transactions/" + key + "/revoke")); return put<pond.TransactionPageDataResponse>(pondURL("/transactions/" + key + "/revoke"));