Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add SINP nomenclature in annotation form #81

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ TAXAPI_IMAGE=registry.gitlab.com/natural-solutions/geonature/taxapi:taxapi-lates
TAXAPI_TAXREF_FILE="TAXREF_v16_2022.zip"
TAXAPI_ROOT_PATH=/taxapi

NOMENCLAPI_ROOT_PATH=/nomenclapi

TRAEFIK_IMAGE=traefik:v2.6
TRAEFIK_PORT=${HTTP_HTTPS_PORT}
TRAEFIK_DASHBOARD_PORT=8890
TRAEFIK_ROUTER_RULE_API=HOST(`${DOMAIN}`) && PathPrefix(`${API_ROOT_PATH}`)
TRAEFIK_ROUTER_RULE_NOMENCLAPI=HOST(`${DOMAIN}`) && PathPrefix(`${NOMENCLAPI_ROOT_PATH}`)
TRAEFIK_ROUTER_RULE_KEYCLOAK=HOST(`${DOMAIN}`) && PathPrefix(`${KC_HTTP_RELATIVE_PATH}`)
TRAEFIK_ROUTER_RULE_FRONTEND=HOST(`${DOMAIN}`) && PathPrefix(`/`)
TRAEFIK_ROUTER_RULE_MINIO=Host(`${DOMAIN}`) && PathPrefix(`/${MINIO_BUCKET_NAME}`)
Expand Down
4 changes: 4 additions & 0 deletions docker/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ services:
ports:
- "5666:5666"

nomenclapi:
ports:
- "5777:5777"

frontend:
build:
context: ../frontend
Expand Down
6 changes: 6 additions & 0 deletions docker/docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ services:
- traefik.http.routers.taxapi.tls=true
- traefik.http.routers.taxapi.tls.certresolver=le

nomenclapi:
labels:
- traefik.http.routers.nomenclapi.entrypoints=websecure
- traefik.http.routers.nomenclapi.tls=true
- traefik.http.routers.nomenclapi.tls.certresolver=le

keycloak:
labels:
- traefik.http.routers.keycloak.entrypoints=websecure
Expand Down
16 changes: 16 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,22 @@ services:
retries: 5
start_period: 10s

nomenclapi:
<<: *project_defaults
image: nomenclapi:dev
container_name: nomenclapi
build:
context: ../nomenclapi
dockerfile: Dockerfile
volumes:
- ../nomenclapi:/app
labels:
- traefik.enable=true
- traefik.http.routers.nomenclapi.rule=${TRAEFIK_ROUTER_RULE_NOMENCLAPI:-PathPrefix(`/nomenclapi`)}
- traefik.http.routers.nomenclapi.entrypoints=web
- traefik.http.routers.nomenclapi.middlewares=api-stripprefix
- traefik.http.middlewares.nomenclapi-stripprefix.stripprefix.prefixes=${NOMENCLAPI_ROOT_PATH:-/nomenclapi}

frontend:
<<: *project_defaults
image: ${FRONTEND_IMAGE:-registry.gitlab.com/natural-solutions/geonature/annotation:frontend-dev}
Expand Down
34 changes: 19 additions & 15 deletions frontend/src/components/annotation/ObservationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { useAnnotationContext } from "../../contexts/annotationContext";
import { FC } from "react";
import { Annotation } from "../../client/models/Annotation";
import NestedList from "../common/collapsableButton";
// import TraitInput from "./TraitInput";
import TraitInput from "./TraitInput";

interface ObservationFormProps {
observation: Annotation;
Expand Down Expand Up @@ -83,31 +83,35 @@ const ObservationForm: FC<ObservationFormProps> = ({
</Grid>
</Grid>
<NestedList>
{/* <Grid container spacing={1}>
<Grid container spacing={1}>
<TraitInput
type="biological_state"
type="biological_state"
observation={ observation }
/>
<TraitInput
type="sex"
observation={ observation }
/>
<TraitInput
type="behaviour"
observation={ observation }
/>
<TraitInput
type="life_stage"
observation={ observation }
/>
</Grid> */}
<Grid item lg={12} xs={12}>
<TextField
id="comments"
name="comments"
label={ capitalize(t("main.comments")) }
size="small"
variant="filled"
value={ observation.comments}
onChange={ (e) => handleFormChange(observation.id, "comments", e.target.value) }
fullWidth
/>
<Grid item lg={12} xs={12}>
<TextField
id="comments"
name="comments"
label={ capitalize(t("main.comments")) }
size="small"
variant="filled"
value={ observation.comments}
onChange={ (e) => handleFormChange(observation.id, "comments", e.target.value) }
fullWidth
/>
</Grid>
</Grid>
</NestedList>
</form>
Expand Down
61 changes: 46 additions & 15 deletions frontend/src/components/annotation/TraitInput.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,65 @@
import { capitalize, Grid, MenuItem, TextField } from "@mui/material";
import { useState } from "react";
import { capitalize, Grid, MenuItem, TextField, IconButton } from "@mui/material";
import HighlightOffIcon from '@mui/icons-material/HighlightOff';
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";

const traitList = {
sex: ["", "Mâle", "Femelle", "Indéterminé"],
behaviour: ["", "Comportement A", "Comportement B", "Comportement C"],
life_stage: ["", "Oeuf", "Juvénile", "Adulte"],
biological_state: ["", "Vivant", "Mort"],
};

import { useAnnotationContext } from "../../contexts/annotationContext";

const TraitInput = (
props
) => {
const { t } = useTranslation();
const [trait, setTrait] = useState();
const [nomenclatureData, setNomenclatureData] = useState<any>(null);
const { handleFormChange } = useAnnotationContext();

const onChange = (e) => {
handleFormChange(props.observation.id, props.type, e.target.value);
};

const clear = () => {
handleFormChange(props.observation.id, props.type, undefined)
};

useEffect(() => {
const fetchData = async () => {
try {
const response = await fetch('/nomenclapi');
if (!response.ok) {
throw new Error('Error during data loading');
}
const data = await response.json();
setNomenclatureData(data);

} catch (error) {
console.error('Error during nomenclature fetch:', error);
}
}
fetchData();
}, []);

return(
<Grid item lg={6} xs={12}>
<TextField
type={ props.type }
select
label={ capitalize(t(`taxon.${props.type}`)) }
value={ props.observation[props.type] }
onChange={ onChange }
size="small"
variant="filled"
fullWidth
>
{traitList[props.type].map((item) => (
<MenuItem key={item} value={item}>
{item}
InputProps={{
endAdornment:
props.observation[props.type] &&
<IconButton
onClick={ () => { clear() }}
>
<HighlightOffIcon fontSize="small"/>
</IconButton>
}}
>
{nomenclatureData && nomenclatureData[props.type].map((item) => (
<MenuItem key={item.CODE} value={item.LABEL}>
{item.LABEL}
</MenuItem>
))}
</TextField>
Expand Down
17 changes: 17 additions & 0 deletions nomenclapi/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3.8-slim-buster

ENV MODE development

WORKDIR /app

RUN apt update\
&& apt-get install -y --no-install-recommends curl

RUN apt install -y wget
RUN python -m pip install --upgrade pip

RUN pip3 install pipenv

EXPOSE 5777

CMD python3 -m pipenv install --skip-lock; python3 -m pipenv run start
19 changes: 19 additions & 0 deletions nomenclapi/Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pandas = "*"
openpyxl = "*"
fastapi = "*"
uvicorn = "*"
requests = "*"

[dev-packages]

[requires]
python_version = "3.8"

[scripts]
start = "uvicorn main:app --reload --host 0.0.0.0 --port 5777"
Loading
Loading