add filters for all routes
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
from sqlmodel import Session, select
|
||||
import src.models as models
|
||||
|
||||
def get_all(session: Session, names: list[str], types: list[str]) -> list[models.ProductorPublic]:
|
||||
def get_all(
|
||||
session: Session,
|
||||
names: list[str],
|
||||
types: list[str]
|
||||
) -> list[models.ProductorPublic]:
|
||||
statement = select(models.Productor)
|
||||
if len(names) > 0:
|
||||
statement = statement.where(models.Productor.name.in_(names))
|
||||
|
||||
@@ -14,7 +14,12 @@ def get_products(
|
||||
types: list[str] = Query([]),
|
||||
productors: list[str] = Query([]),
|
||||
):
|
||||
return service.get_all(session, names, productors, types)
|
||||
return service.get_all(
|
||||
session,
|
||||
names,
|
||||
productors,
|
||||
types,
|
||||
)
|
||||
|
||||
@router.get('/{id}', response_model=models.ProductPublic)
|
||||
def get_product(id: int, session: Session = Depends(get_session)):
|
||||
|
||||
@@ -6,7 +6,6 @@ def get_all(
|
||||
names: list[str],
|
||||
productors: list[str],
|
||||
types: list[str],
|
||||
|
||||
) -> list[models.ProductPublic]:
|
||||
statement = select(models.Product)
|
||||
if len(names) > 0:
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
from sqlmodel import Session, select
|
||||
import src.models as models
|
||||
|
||||
def get_all(session: Session) -> list[models.ShipmentPublic]:
|
||||
def get_all(
|
||||
session: Session,
|
||||
names: list[str],
|
||||
dates: list[str],
|
||||
forms: list[int]
|
||||
) -> list[models.ShipmentPublic]:
|
||||
statement = select(models.Shipment)
|
||||
if len(names) > 0:
|
||||
statement = statement.where(models.Shipment.name.in_(names))
|
||||
if len(dates) > 0:
|
||||
statement = statement.where(models.Shipment.date.in_(list(map(lambda x: datetime.strptime(x, '%Y-%m-%d'), dates))))
|
||||
if len(forms) > 0:
|
||||
statement = statement.join(models.Form).where(models.Form.name.in_(forms))
|
||||
return session.exec(statement.order_by(models.Shipment.name)).all()
|
||||
|
||||
def get_one(session: Session, shipment_id: int) -> models.ShipmentPublic:
|
||||
|
||||
@@ -1,15 +1,26 @@
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
from fastapi import APIRouter, HTTPException, Depends, Query
|
||||
import src.messages as messages
|
||||
import src.models as models
|
||||
from src.database import get_session
|
||||
from sqlmodel import Session
|
||||
import src.shipments.service as service
|
||||
from src.auth.auth import get_current_user
|
||||
|
||||
router = APIRouter(prefix='/shipments')
|
||||
|
||||
@router.get('/', response_model=list[models.ShipmentPublic], )
|
||||
def get_shipments(session: Session = Depends(get_session)):
|
||||
return service.get_all(session)
|
||||
def get_shipments(
|
||||
session: Session = Depends(get_session),
|
||||
names: list[str] = Query([]),
|
||||
dates: list[str] = Query([]),
|
||||
forms: list[str] = Query([]),
|
||||
):
|
||||
return service.get_all(
|
||||
session,
|
||||
names,
|
||||
dates,
|
||||
forms,
|
||||
)
|
||||
|
||||
@router.get('/{id}', response_model=models.ShipmentPublic)
|
||||
def get_shipment(id: int, session: Session = Depends(get_session)):
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
from sqlmodel import Session, select
|
||||
import src.models as models
|
||||
|
||||
def get_all(session: Session) -> list[models.UserPublic]:
|
||||
def get_all(
|
||||
session: Session,
|
||||
names: list[str],
|
||||
emails: list[str],
|
||||
) -> list[models.UserPublic]:
|
||||
statement = select(models.User)
|
||||
if len(names) > 0:
|
||||
statement = statement.where(models.User.name.in_(names))
|
||||
if len(emails) > 0:
|
||||
statement = statement.where(models.User.email.in_(emails))
|
||||
return session.exec(statement.order_by(models.User.name)).all()
|
||||
|
||||
def get_one(session: Session, user_id: int) -> models.UserPublic:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, HTTPException, Depends
|
||||
from fastapi import APIRouter, HTTPException, Depends, Query
|
||||
import src.messages as messages
|
||||
import src.models as models
|
||||
from src.database import get_session
|
||||
@@ -8,8 +8,16 @@ import src.users.service as service
|
||||
router = APIRouter(prefix='/users')
|
||||
|
||||
@router.get('/', response_model=list[models.UserPublic])
|
||||
def get_users(session: Session = Depends(get_session)):
|
||||
return service.get_all(session)
|
||||
def get_users(
|
||||
session: Session = Depends(get_session),
|
||||
names: list[str] = Query([]),
|
||||
emails: list[str] = Query([]),
|
||||
):
|
||||
return service.get_all(
|
||||
session,
|
||||
names,
|
||||
emails,
|
||||
)
|
||||
|
||||
@router.get('/{id}', response_model=models.UserPublic)
|
||||
def get_users(id: int, session: Session = Depends(get_session)):
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>frontend</title>
|
||||
<title>Amap Croix-luizet</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
|
||||
@@ -121,5 +121,5 @@
|
||||
"error deleting shipment": "error deleting shipment",
|
||||
"there is no contract for now": "there is no contract for now.",
|
||||
"the product unit will be assigned to the quantity requested in the form": "the product unit will be assigned to the quantity requested in the form",
|
||||
"all theses informations are for contract generation, no informations is stored outside of contracts": "all theses informations are for contract generation, no informations is stored outside of contracts."
|
||||
"all theses informations are for contract generation": "all theses informations are for contract generation."
|
||||
}
|
||||
@@ -134,5 +134,5 @@
|
||||
"there is no contract for now": "Il n'y a pas de contrats pour le moment.",
|
||||
|
||||
"the product unit will be assigned to the quantity requested in the form": "L'unité de vente du produit définit l'unité associée a la quantité demandée dans le formulaire des amapiens.",
|
||||
"all theses informations are for contract generation, no informations is stored outside of contracts": "ces informations sont nécéssaires pour la génération de contrat, aucune information personnelle n'est gardée ailleurs que dans les contrats générés."
|
||||
"all theses informations are for contract generation": "ces informations sont nécéssaires pour la génération de contrat."
|
||||
}
|
||||
@@ -3,11 +3,11 @@ nav {
|
||||
justify-self: left;
|
||||
padding: 1rem;
|
||||
background-color: var(--mantine-color-blue-4);
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.navLink {
|
||||
color: #fff;
|
||||
font-weight: bold;
|
||||
margin-right: 1rem;
|
||||
text-decoration: none;
|
||||
}
|
||||
@@ -1,21 +1,34 @@
|
||||
import { NavLink } from "react-router";
|
||||
import { t } from "@/config/i18n";
|
||||
import "./index.css";
|
||||
import { Group } from "@mantine/core";
|
||||
import { Config } from "@/config/config";
|
||||
|
||||
export function Navbar() {
|
||||
return (
|
||||
<nav>
|
||||
<Group>
|
||||
<NavLink
|
||||
className={"navLink"}
|
||||
aria-label={t('home')}
|
||||
to="/"
|
||||
>
|
||||
{t("home", {capfirst: true})}
|
||||
</NavLink>
|
||||
<NavLink
|
||||
className={"navLink"}
|
||||
aria-label={t('dashboard')}
|
||||
to="/dashboard/productors"
|
||||
>
|
||||
{t("dashboard", {capfirst: true})}
|
||||
</NavLink>
|
||||
</Group>
|
||||
<NavLink
|
||||
className={"navLink"}
|
||||
to="/"
|
||||
className={"navLink"}
|
||||
aria-label={t("login with keycloak")}
|
||||
to={`${Config.backend_uri}/auth/login`}
|
||||
>
|
||||
{t("home", {capfirst: true})}
|
||||
</NavLink>
|
||||
<NavLink
|
||||
className={"navLink"}
|
||||
to="/dashboard/productors"
|
||||
>
|
||||
{t("dashboard", {capfirst: true})}
|
||||
{t("login with keycloak", {capfirst: true})}
|
||||
</NavLink>
|
||||
</nav>
|
||||
);
|
||||
|
||||
@@ -24,7 +24,7 @@ export default function ProductorRow({
|
||||
<Table.Td>
|
||||
{
|
||||
productor.payment_methods.map((value) =>(
|
||||
<Badge ml="xs">
|
||||
<Badge key={value.name} ml="xs">
|
||||
{t(value.name, {capfirst: true})}
|
||||
</Badge>
|
||||
))
|
||||
|
||||
@@ -4,18 +4,23 @@ import { t } from "@/config/i18n";
|
||||
|
||||
export type ShipmentFiltersProps = {
|
||||
names: string[];
|
||||
forms: string[];
|
||||
filters: URLSearchParams;
|
||||
onFilterChange: (values: string[], filter: string) => void;
|
||||
}
|
||||
|
||||
export default function ShipmentsFilters({
|
||||
names,
|
||||
forms,
|
||||
filters,
|
||||
onFilterChange
|
||||
}: ShipmentFiltersProps) {
|
||||
const defaultNames = useMemo(() => {
|
||||
return filters.getAll("names")
|
||||
}, [filters]);
|
||||
const defaultForms = useMemo(() => {
|
||||
return filters.getAll("forms")
|
||||
}, [filters]);
|
||||
|
||||
return (
|
||||
<Group>
|
||||
@@ -28,6 +33,18 @@ export default function ShipmentsFilters({
|
||||
onFilterChange(values, 'names')
|
||||
}}
|
||||
clearable
|
||||
searchable
|
||||
/>
|
||||
<MultiSelect
|
||||
aria-label={t("filter by form", {capfirst: true})}
|
||||
placeholder={t("filter by form", {capfirst: true})}
|
||||
data={forms}
|
||||
defaultValue={defaultForms}
|
||||
onChange={(values: string[]) => {
|
||||
onFilterChange(values, 'forms')
|
||||
}}
|
||||
clearable
|
||||
searchable
|
||||
/>
|
||||
</Group>
|
||||
);
|
||||
|
||||
@@ -44,6 +44,7 @@ export default function ShipmentModal({
|
||||
const { data: allForms } = getForms();
|
||||
const { data: allProducts } = getProducts(new URLSearchParams("types=1"));
|
||||
const { data: allProductors } = getProductors()
|
||||
|
||||
const formsSelect = useMemo(() => {
|
||||
return allForms?.map(form => ({value: String(form.id), label: `${form.name} ${form.season}`}))
|
||||
}, [allForms]);
|
||||
|
||||
@@ -80,7 +80,7 @@ export function Contract() {
|
||||
shipment.products
|
||||
);
|
||||
if (total < (form?.minimum_shipment_value || 0)) {
|
||||
return shipment.id; // mark shipment as invalid
|
||||
return shipment.id;
|
||||
}
|
||||
return null;
|
||||
})
|
||||
@@ -125,8 +125,18 @@ export function Contract() {
|
||||
}
|
||||
}, [inputForm, inputRefs, isShipmentsMinimumValue, form]);
|
||||
|
||||
|
||||
if (!form)
|
||||
return <Loader/>;
|
||||
return (
|
||||
<Group
|
||||
align="center"
|
||||
justify="center"
|
||||
h="80vh"
|
||||
w="100%"
|
||||
>
|
||||
<Loader color="pink"/>
|
||||
</Group>
|
||||
);
|
||||
|
||||
|
||||
return (
|
||||
@@ -134,7 +144,7 @@ export function Contract() {
|
||||
<Title order={2}>{form.name}</Title>
|
||||
<Title order={3}>{t("informations", {capfirst: true})}</Title>
|
||||
<Text size="sm">
|
||||
{t("all theses informations are for contract generation, no informations is stored outside of contracts", {capfirst: true})}
|
||||
{t("all theses informations are for contract generation", {capfirst: true})}
|
||||
</Text>
|
||||
<Group grow>
|
||||
<TextInput
|
||||
|
||||
@@ -8,7 +8,6 @@ import FormModal from "@/components/Forms/Modal";
|
||||
import FormRow from "@/components/Forms/Row";
|
||||
import type { Form, FormInputs } from "@/services/resources/forms";
|
||||
import FilterForms from "@/components/Forms/Filter";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
|
||||
export function Forms() {
|
||||
const [ searchParams, setSearchParams ] = useSearchParams();
|
||||
@@ -59,11 +58,7 @@ export function Forms() {
|
||||
minimum_shipment_value: Number(form.minimum_shipment_value),
|
||||
});
|
||||
closeModal();
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully created form", {capfirst: true}),
|
||||
});
|
||||
}, [createFormMutation]);
|
||||
}, [createFormMutation, closeModal]);
|
||||
|
||||
const handleEditForm = useCallback(async (form: FormInputs, id?: number) => {
|
||||
if (!id)
|
||||
@@ -80,11 +75,7 @@ export function Forms() {
|
||||
}
|
||||
});
|
||||
closeModal();
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully edited form", {capfirst: true}),
|
||||
});
|
||||
}, [editFormMutation]);
|
||||
}, [editFormMutation, closeModal]);
|
||||
|
||||
const onFilterChange = useCallback((
|
||||
values: string[],
|
||||
@@ -102,9 +93,19 @@ export function Forms() {
|
||||
});
|
||||
}, [searchParams, setSearchParams])
|
||||
|
||||
if (!data || isPending)
|
||||
return (<Loader color="blue"/>);
|
||||
|
||||
if (!data || isPending)
|
||||
return (
|
||||
<Group
|
||||
align="center"
|
||||
justify="center"
|
||||
h="80vh"
|
||||
w="100%"
|
||||
>
|
||||
<Loader color="pink"/>
|
||||
</Group>
|
||||
);
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
<Group justify="space-between">
|
||||
|
||||
@@ -8,7 +8,6 @@ import { ProductorModal } from "@/components/Productors/Modal";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import type { Productor, ProductorInputs } from "@/services/resources/productors";
|
||||
import ProductorsFilters from "@/components/Productors/Filter";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
|
||||
export default function Productors() {
|
||||
const [ searchParams, setSearchParams ] = useSearchParams();
|
||||
@@ -51,11 +50,7 @@ export default function Productors() {
|
||||
...productor
|
||||
});
|
||||
closeModal();
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully created productor", {capfirst: true}),
|
||||
});
|
||||
}, [createProductorMutation]);
|
||||
}, [createProductorMutation, closeModal]);
|
||||
|
||||
const handleEditProductor = useCallback(async (productor: ProductorInputs, id?: number) => {
|
||||
if (!id)
|
||||
@@ -65,11 +60,7 @@ export default function Productors() {
|
||||
productor: productor
|
||||
});
|
||||
closeModal();
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully edited productor", {capfirst: true}),
|
||||
});
|
||||
}, []);
|
||||
}, [editProductorMutation, closeModal]);
|
||||
|
||||
const onFilterChange = useCallback((values: string[], filter: string) => {
|
||||
setSearchParams(prev => {
|
||||
@@ -84,7 +75,16 @@ export default function Productors() {
|
||||
}, [searchParams, setSearchParams])
|
||||
|
||||
if (!productors || isPending)
|
||||
return <Loader/>
|
||||
return (
|
||||
<Group
|
||||
align="center"
|
||||
justify="center"
|
||||
h="80vh"
|
||||
w="100%"
|
||||
>
|
||||
<Loader color="pink"/>
|
||||
</Group>
|
||||
);
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
|
||||
@@ -8,7 +8,6 @@ import { ProductModal } from "@/components/Products/Modal";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { productCreateFromProductInputs, type Product, type ProductInputs } from "@/services/resources/products";
|
||||
import ProductsFilters from "@/components/Products/Filter";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
|
||||
export default function Products() {
|
||||
const [ searchParams, setSearchParams ] = useSearchParams();
|
||||
@@ -49,11 +48,7 @@ export default function Products() {
|
||||
const handleCreateProduct = useCallback(async (product: ProductInputs) => {
|
||||
await createProductMutation.mutateAsync(productCreateFromProductInputs(product));
|
||||
closeModal();
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully created product", {capfirst: true}),
|
||||
});
|
||||
}, [createProductMutation]);
|
||||
}, [createProductMutation, closeModal]);
|
||||
|
||||
const handleEditProduct = useCallback(async (product: ProductInputs, id?: number) => {
|
||||
if (!id)
|
||||
@@ -63,11 +58,7 @@ export default function Products() {
|
||||
product: productCreateFromProductInputs(product)
|
||||
});
|
||||
closeModal();
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully edited product", {capfirst: true}),
|
||||
});
|
||||
}, []);
|
||||
}, [editProductMutation, closeModal]);
|
||||
|
||||
const onFilterChange = useCallback((values: string[], filter: string) => {
|
||||
setSearchParams(prev => {
|
||||
@@ -82,8 +73,17 @@ export default function Products() {
|
||||
}, [searchParams, setSearchParams])
|
||||
|
||||
if (!products || isPending)
|
||||
return <Loader/>
|
||||
|
||||
return (
|
||||
<Group
|
||||
align="center"
|
||||
justify="center"
|
||||
h="80vh"
|
||||
w="100%"
|
||||
>
|
||||
<Loader color="pink"/>
|
||||
</Group>
|
||||
);
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
<Group justify="space-between">
|
||||
|
||||
@@ -8,7 +8,6 @@ import { useCallback, useMemo } from "react";
|
||||
import { shipmentCreateFromShipmentInputs, type Shipment, type ShipmentInputs } from "@/services/resources/shipments";
|
||||
import ShipmentModal from "@/components/Shipments/Modal";
|
||||
import ShipmentsFilters from "@/components/Shipments/Filter";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
|
||||
export default function Shipments() {
|
||||
const [ searchParams, setSearchParams ] = useSearchParams();
|
||||
@@ -38,17 +37,18 @@ export default function Shipments() {
|
||||
.filter((season, index, array) => array.indexOf(season) === index)
|
||||
}, [allShipments])
|
||||
|
||||
const forms = useMemo(() => {
|
||||
return allShipments?.map((shipment: Shipment) => (shipment.form.name))
|
||||
.filter((season, index, array) => array.indexOf(season) === index)
|
||||
}, [allShipments])
|
||||
|
||||
const createShipmentMutation = createShipment();
|
||||
const editShipmentMutation = editShipment();
|
||||
|
||||
const handleCreateShipment = useCallback(async (shipment: ShipmentInputs) => {
|
||||
await createShipmentMutation.mutateAsync(shipmentCreateFromShipmentInputs(shipment));
|
||||
closeModal();
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully created shipment", {capfirst: true}),
|
||||
});
|
||||
}, [createShipmentMutation]);
|
||||
}, [createShipmentMutation, closeModal]);
|
||||
|
||||
const handleEditShipment = useCallback(async (shipment: ShipmentInputs, id?: number) => {
|
||||
if (!id)
|
||||
@@ -58,11 +58,7 @@ export default function Shipments() {
|
||||
shipment: shipmentCreateFromShipmentInputs(shipment)
|
||||
});
|
||||
closeModal();
|
||||
notifications.show({
|
||||
title: t("success", {capfirst: true}),
|
||||
message: t("successfully edited shipment", {capfirst: true}),
|
||||
});
|
||||
}, []);
|
||||
}, [editShipmentMutation, closeModal]);
|
||||
|
||||
const onFilterChange = useCallback((values: string[], filter: string) => {
|
||||
setSearchParams(prev => {
|
||||
@@ -77,7 +73,16 @@ export default function Shipments() {
|
||||
}, [searchParams, setSearchParams])
|
||||
|
||||
if (!shipments || isPending)
|
||||
return <Loader/>
|
||||
return (
|
||||
<Group
|
||||
align="center"
|
||||
justify="center"
|
||||
h="80vh"
|
||||
w="100%"
|
||||
>
|
||||
<Loader color="pink"/>
|
||||
</Group>
|
||||
);
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
@@ -106,6 +111,7 @@ export default function Shipments() {
|
||||
/>
|
||||
</Group>
|
||||
<ShipmentsFilters
|
||||
forms={forms || []}
|
||||
names={names || []}
|
||||
filters={searchParams}
|
||||
onFilterChange={onFilterChange}
|
||||
|
||||
@@ -44,7 +44,7 @@ export default function Users() {
|
||||
const handleCreateUser = useCallback(async (user: UserInputs) => {
|
||||
await createUserMutation.mutateAsync(user);
|
||||
closeModal();
|
||||
}, [createUserMutation]);
|
||||
}, [createUserMutation, closeModal]);
|
||||
|
||||
const handleEditUser = useCallback(async (user: UserInputs, id?: number) => {
|
||||
if (!id)
|
||||
@@ -54,7 +54,7 @@ export default function Users() {
|
||||
user: user
|
||||
});
|
||||
closeModal();
|
||||
}, []);
|
||||
}, [editUserMutation, closeModal]);
|
||||
|
||||
const onFilterChange = useCallback((values: string[], filter: string) => {
|
||||
setSearchParams(prev => {
|
||||
@@ -69,7 +69,16 @@ export default function Users() {
|
||||
}, [searchParams, setSearchParams])
|
||||
|
||||
if (!users || isPending)
|
||||
return <Loader/>
|
||||
return (
|
||||
<Group
|
||||
align="center"
|
||||
justify="center"
|
||||
h="80vh"
|
||||
w="100%"
|
||||
>
|
||||
<Loader color="pink"/>
|
||||
</Group>
|
||||
);
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
|
||||
@@ -12,7 +12,6 @@ import Users from "@/pages/Users";
|
||||
import Shipments from "./pages/Shipments";
|
||||
import { Contract } from "./pages/Contract";
|
||||
import { NotFound } from "./pages/NotFound";
|
||||
// import { CreateForms } from "@/pages/Forms/CreateForm";
|
||||
|
||||
export const router = createBrowserRouter([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user