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