update as in the grain bag api
This commit is contained in:
parent
9b9f4cdf63
commit
1acbfe36b0
9 changed files with 42 additions and 33 deletions
|
|
@ -104,7 +104,7 @@ export default function ContractTransactionTable(props: Props) {
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case pond.ObjectType.OBJECT_TYPE_GRAIN_BAG:
|
case pond.ObjectType.OBJECT_TYPE_GRAIN_BAG:
|
||||||
bagAPI.getGrainBag(transaction.transaction.fromKey).then(resp => {
|
bagAPI.getGrainBag(transaction.transaction.fromKey, as).then(resp => {
|
||||||
if (resp.data.grainBag) {
|
if (resp.data.grainBag) {
|
||||||
let bag = GrainBag.create(resp.data.grainBag);
|
let bag = GrainBag.create(resp.data.grainBag);
|
||||||
setTransactionSource(bag);
|
setTransactionSource(bag);
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ export default function GrainTransaction(props: Props) {
|
||||||
if (!bagsLoading) {
|
if (!bagsLoading) {
|
||||||
setBagsLoading(true);
|
setBagsLoading(true);
|
||||||
grainBagAPI
|
grainBagAPI
|
||||||
.listGrainBags(0, 0)
|
.listGrainBags(0, 0, undefined, 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[] = [];
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import GrainDescriber from "grain/GrainDescriber";
|
||||||
import { GrainBag } from "models/GrainBag";
|
import { GrainBag } from "models/GrainBag";
|
||||||
import moment, { Moment } from "moment";
|
import moment, { Moment } from "moment";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useGrainBagAPI, useSnackbar } from "providers";
|
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { getGrainUnit } from "utils";
|
import { getGrainUnit } from "utils";
|
||||||
|
|
||||||
|
|
@ -21,12 +21,13 @@ export default function GrainBagInventoryGraph(props: Props) {
|
||||||
const [data, setData] = useState<BarData[]>([]);
|
const [data, setData] = useState<BarData[]>([]);
|
||||||
const [loadingData, setLoadingData] = useState<boolean>(false);
|
const [loadingData, setLoadingData] = useState<boolean>(false);
|
||||||
const { openSnack } = useSnackbar();
|
const { openSnack } = useSnackbar();
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (grainBag.key() && !loadingData) {
|
if (grainBag.key() && !loadingData) {
|
||||||
setLoadingData(true);
|
setLoadingData(true);
|
||||||
grainBagAPI
|
grainBagAPI
|
||||||
.listHistory(grainBag.key(), 500, 0, startDate.toISOString(), endDate.toISOString())
|
.listHistory(grainBag.key(), 500, 0, startDate.toISOString(), endDate.toISOString(), as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
let barData: BarData[] = [];
|
let barData: BarData[] = [];
|
||||||
let lastBushels = 0;
|
let lastBushels = 0;
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ export default function GrainBagSettings(props: Props) {
|
||||||
const [bagLengthM, setBagLengthM] = useState(0);
|
const [bagLengthM, setBagLengthM] = useState(0);
|
||||||
const [bagDiameterDisplay, setBagDiameterDisplay] = useState(0);
|
const [bagDiameterDisplay, setBagDiameterDisplay] = useState(0);
|
||||||
const [bagLengthDispla, setBagLengthDisplay] = useState(0);
|
const [bagLengthDispla, setBagLengthDisplay] = useState(0);
|
||||||
const [{ user }] = useGlobalState();
|
const [{ user, as }] = useGlobalState();
|
||||||
const [isCustom, setIsCustom] = useState<boolean>(false);
|
const [isCustom, setIsCustom] = useState<boolean>(false);
|
||||||
const [customType, setCustomType] = useState("");
|
const [customType, setCustomType] = useState("");
|
||||||
const [supportedGrainType, setSupportedGrainType] = useState(pond.Grain.GRAIN_INVALID);
|
const [supportedGrainType, setSupportedGrainType] = useState(pond.Grain.GRAIN_INVALID);
|
||||||
|
|
@ -104,7 +104,7 @@ export default function GrainBagSettings(props: Props) {
|
||||||
const removeGrainBag = () => {
|
const removeGrainBag = () => {
|
||||||
if (!grainBag) return;
|
if (!grainBag) return;
|
||||||
grainBagAPI
|
grainBagAPI
|
||||||
.removeGrainBag(grainBag.key())
|
.removeGrainBag(grainBag.key(), as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Removed Grain Bag");
|
openSnack("Removed Grain Bag");
|
||||||
close();
|
close();
|
||||||
|
|
@ -138,7 +138,7 @@ export default function GrainBagSettings(props: Props) {
|
||||||
setGrainUpdate(true);
|
setGrainUpdate(true);
|
||||||
} else {
|
} else {
|
||||||
grainBagAPI
|
grainBagAPI
|
||||||
.updateGrainBag(grainBag.key(), bagName, grainBag.settings)
|
.updateGrainBag(grainBag.key(), bagName, grainBag.settings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Grain Bag Updated");
|
openSnack("Grain Bag Updated");
|
||||||
let updatedBag = clone(grainBag);
|
let updatedBag = clone(grainBag);
|
||||||
|
|
@ -170,7 +170,7 @@ export default function GrainBagSettings(props: Props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
grainBagAPI
|
grainBagAPI
|
||||||
.addGrainBag(bagName, settings)
|
.addGrainBag(bagName, settings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("New grain bag added");
|
openSnack("New grain bag added");
|
||||||
let newBag = GrainBag.create(
|
let newBag = GrainBag.create(
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ import MapMarkerSettings from "maps/MapMarkerSettings";
|
||||||
import { GrainBag as BagModel } from "models/GrainBag";
|
import { GrainBag as BagModel } from "models/GrainBag";
|
||||||
import GrainBag from "pages/grainBag";
|
import GrainBag from "pages/grainBag";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useGrainBagAPI, useSnackbar } from "providers";
|
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
|
|
@ -23,6 +23,7 @@ export default function GrainBagDrawer(props: Props) {
|
||||||
const [openMarkerSettings, setOpenMarkerSettings] = useState(false);
|
const [openMarkerSettings, setOpenMarkerSettings] = useState(false);
|
||||||
const bagAPI = useGrainBagAPI();
|
const bagAPI = useGrainBagAPI();
|
||||||
const { openSnack } = useSnackbar();
|
const { openSnack } = useSnackbar();
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let b = grainBags.get(selectedBag);
|
let b = grainBags.get(selectedBag);
|
||||||
|
|
@ -99,7 +100,7 @@ export default function GrainBagDrawer(props: Props) {
|
||||||
settings.startLocation = undefined;
|
settings.startLocation = undefined;
|
||||||
settings.endLocation = undefined;
|
settings.endLocation = undefined;
|
||||||
bagAPI
|
bagAPI
|
||||||
.updateGrainBag(bag.key(), bag.name(), settings)
|
.updateGrainBag(bag.key(), bag.name(), settings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Grain bag location removed");
|
openSnack("Grain bag location removed");
|
||||||
removeMarker(bag.key());
|
removeMarker(bag.key());
|
||||||
|
|
@ -133,7 +134,7 @@ export default function GrainBagDrawer(props: Props) {
|
||||||
let settings = bag.settings;
|
let settings = bag.settings;
|
||||||
settings.theme = newTheme;
|
settings.theme = newTheme;
|
||||||
bagAPI
|
bagAPI
|
||||||
.updateGrainBag(bag.key(), bag.name(), settings)
|
.updateGrainBag(bag.key(), bag.name(), settings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("marker settings updated");
|
openSnack("marker settings updated");
|
||||||
updateMarker(bag.key(), settings);
|
updateMarker(bag.key(), settings);
|
||||||
|
|
|
||||||
|
|
@ -304,7 +304,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
|
|
||||||
const loadGrainBags = useCallback(() => {
|
const loadGrainBags = useCallback(() => {
|
||||||
grainBagAPI
|
grainBagAPI
|
||||||
.listGrainBags(100, 0)
|
.listGrainBags(100, 0, undefined, 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[] = [];
|
||||||
|
|
@ -367,7 +367,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
openSnack("Failed to load Grain Bags");
|
openSnack("Failed to load Grain Bags");
|
||||||
});
|
});
|
||||||
}, [grainBagAPI, openSnack]); // eslint-disable-line react-hooks/exhaustive-deps
|
}, [grainBagAPI, openSnack, as]); // eslint-disable-line react-hooks/exhaustive-deps
|
||||||
|
|
||||||
const loadYards = useCallback(() => {
|
const loadYards = useCallback(() => {
|
||||||
let yardMap: Map<string, pond.BinYardSettings> = new Map();
|
let yardMap: Map<string, pond.BinYardSettings> = new Map();
|
||||||
|
|
@ -1286,7 +1286,7 @@ import { Result } from "@mapbox/mapbox-gl-geocoder";
|
||||||
const updateBag = (bag: BagModel) => {
|
const updateBag = (bag: BagModel) => {
|
||||||
//update the bag
|
//update the bag
|
||||||
grainBagAPI
|
grainBagAPI
|
||||||
.updateGrainBag(bag.key(), bag.name(), bag.settings)
|
.updateGrainBag(bag.key(), bag.name(), bag.settings, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
openSnack("Grain Bag location set");
|
openSnack("Grain Bag location set");
|
||||||
//if the update succeeded than update the geo state and ref
|
//if the update succeeded than update the geo state and ref
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import SearchSelect, { Option } from "common/SearchSelect";
|
||||||
import { GrainOptions } from "grain";
|
import { GrainOptions } from "grain";
|
||||||
import { GrainBag } from "models/GrainBag";
|
import { GrainBag } from "models/GrainBag";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useGrainBagAPI, useSnackbar } from "providers";
|
import { useGlobalState, useGrainBagAPI, useSnackbar } from "providers";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import { getDistanceUnit } from "utils";
|
import { getDistanceUnit } from "utils";
|
||||||
|
|
||||||
|
|
@ -28,6 +28,7 @@ export default function BulkGrainBagSettings(props: Props) {
|
||||||
const [bushels, setBushels] = useState<number | undefined>();
|
const [bushels, setBushels] = useState<number | undefined>();
|
||||||
const [fillDate, setFillDate] = useState<string | undefined>();
|
const [fillDate, setFillDate] = useState<string | undefined>();
|
||||||
const [initialMoisture, setInitialMoisture] = useState<number | undefined>();
|
const [initialMoisture, setInitialMoisture] = useState<number | undefined>();
|
||||||
|
const [{as}] = useGlobalState();
|
||||||
|
|
||||||
const convertedDistance = (enteredDistance: number) => {
|
const convertedDistance = (enteredDistance: number) => {
|
||||||
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
|
if (getDistanceUnit() === pond.DistanceUnit.DISTANCE_UNIT_FEET) {
|
||||||
|
|
@ -60,7 +61,7 @@ export default function BulkGrainBagSettings(props: Props) {
|
||||||
});
|
});
|
||||||
|
|
||||||
grainBagAPI
|
grainBagAPI
|
||||||
.bulkUpdateGrainBags(bagsToUpdate)
|
.bulkUpdateGrainBags(bagsToUpdate, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
if (resp.data.successfull > 0) {
|
if (resp.data.successfull > 0) {
|
||||||
refreshCallback(true);
|
refreshCallback(true);
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export default function GrainBag(props: Props) {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
grainBagAPI
|
grainBagAPI
|
||||||
.getGrainBag(bagID)
|
.getGrainBag(bagID, as)
|
||||||
.then(resp => {
|
.then(resp => {
|
||||||
if (resp.data.grainBag) {
|
if (resp.data.grainBag) {
|
||||||
setGrainBag(IGrainBag.create(resp.data.grainBag));
|
setGrainBag(IGrainBag.create(resp.data.grainBag));
|
||||||
|
|
@ -48,7 +48,7 @@ export default function GrainBag(props: Props) {
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
openSnack("There was a problem loading the Grain Bag");
|
openSnack("There was a problem loading the Grain Bag");
|
||||||
});
|
});
|
||||||
}, [bagID, grainBagAPI, openSnack]);
|
}, [bagID, grainBagAPI, openSnack, as]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let key = bagID;
|
let key = bagID;
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,8 @@ 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
|
||||||
) => Promise<AxiosResponse<pond.AddGrainBagResponse>>;
|
) => Promise<AxiosResponse<pond.AddGrainBagResponse>>;
|
||||||
listGrainBags: (
|
listGrainBags: (
|
||||||
limit: number,
|
limit: number,
|
||||||
|
|
@ -20,24 +21,28 @@ export interface IGrainBagInterface {
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
numerical?: boolean,
|
numerical?: boolean,
|
||||||
specificUser?: string
|
specificUser?: 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
|
||||||
) => Promise<AxiosResponse<pond.UpdateGrainBagResponse>>;
|
) => Promise<AxiosResponse<pond.UpdateGrainBagResponse>>;
|
||||||
bulkUpdateGrainBags: (
|
bulkUpdateGrainBags: (
|
||||||
bags: pond.GrainBag[]
|
bags: pond.GrainBag[],
|
||||||
|
as?: string
|
||||||
) => Promise<AxiosResponse<pond.BulkGrainBagUpdateResponse>>;
|
) => Promise<AxiosResponse<pond.BulkGrainBagUpdateResponse>>;
|
||||||
getGrainBag: (key: string) => Promise<AxiosResponse<pond.GetGrainBagResponse>>;
|
getGrainBag: (key: string, as?: string) => Promise<AxiosResponse<pond.GetGrainBagResponse>>;
|
||||||
removeGrainBag: (key: string) => Promise<AxiosResponse<pond.RemoveGrainBagResponse>>;
|
removeGrainBag: (key: string, as?: 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
|
||||||
) => Promise<AxiosResponse<pond.ListGrainBagHistoryResponse>>;
|
) => Promise<AxiosResponse<pond.ListGrainBagHistoryResponse>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,9 +53,9 @@ 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) => {
|
const addGrainBag = (name: string, settings: pond.GrainBagSettings, as?: string) => {
|
||||||
if (as) {
|
if (as) {
|
||||||
return post<pond.AddGrainBagResponse>(
|
return post<pond.AddGrainBagResponse>(
|
||||||
pondURL("/grainbags?name=" + name + "&as=" + as),
|
pondURL("/grainbags?name=" + name + "&as=" + as),
|
||||||
|
|
@ -69,7 +74,8 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
|
||||||
keys?: string[],
|
keys?: string[],
|
||||||
types?: string[],
|
types?: string[],
|
||||||
numerical?: boolean,
|
numerical?: boolean,
|
||||||
specificUser?: string
|
specificUser?: string,
|
||||||
|
as?: string
|
||||||
) => {
|
) => {
|
||||||
let asText = "";
|
let asText = "";
|
||||||
if (as) asText = "&as=" + as;
|
if (as) asText = "&as=" + as;
|
||||||
|
|
@ -91,7 +97,7 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateGrainBag = (key: string, name: string, settings: pond.GrainBagSettings) => {
|
const updateGrainBag = (key: string, name: string, settings: pond.GrainBagSettings, as?: string) => {
|
||||||
if (as) {
|
if (as) {
|
||||||
return put<pond.UpdateGrainBagResponse>(
|
return put<pond.UpdateGrainBagResponse>(
|
||||||
pondURL("/grainbags/" + key + "?as=" + as + "&name=" + name),
|
pondURL("/grainbags/" + key + "?as=" + as + "&name=" + name),
|
||||||
|
|
@ -104,7 +110,7 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const bulkUpdateGrainBags = (bags: pond.GrainBag[]) => {
|
const bulkUpdateGrainBags = (bags: pond.GrainBag[], as?: string) => {
|
||||||
if (as)
|
if (as)
|
||||||
return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update?as=" + as), {
|
return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update?as=" + as), {
|
||||||
bags: bags
|
bags: bags
|
||||||
|
|
@ -112,21 +118,21 @@ export default function GrainBagProvider(props: PropsWithChildren<Props>) {
|
||||||
return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update"), { bags: bags });
|
return put<pond.BulkGrainBagUpdateResponse>(pondURL("/bulkGrainBags/update"), { bags: bags });
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeGrainBag = (key: string) => {
|
const removeGrainBag = (key: string, as?: string) => {
|
||||||
if (as) {
|
if (as) {
|
||||||
return del<pond.RemoveGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + as));
|
return del<pond.RemoveGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + as));
|
||||||
}
|
}
|
||||||
return del<pond.RemoveGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + as));
|
return del<pond.RemoveGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + as));
|
||||||
};
|
};
|
||||||
|
|
||||||
const getGrainBag = (key: string) => {
|
const getGrainBag = (key: string, as?: string) => {
|
||||||
if (as) {
|
if (as) {
|
||||||
return get<pond.GetGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + as));
|
return get<pond.GetGrainBagResponse>(pondURL("/grainbags/" + key + "?as=" + as));
|
||||||
}
|
}
|
||||||
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) => {
|
const listHistory = (id: string, limit: number, offset: number, start?: string, end?: string, as?: string) => {
|
||||||
let url = pondURL(
|
let url = pondURL(
|
||||||
"/grainbags/" +
|
"/grainbags/" +
|
||||||
id +
|
id +
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue