Skip to content

Commit

Permalink
Merge pull request #427 from hypsug0/dev
Browse files Browse the repository at this point in the history
Fix and merge #415
  • Loading branch information
hypsug0 authored Nov 20, 2024
2 parents 68469ff + 8fbf926 commit 448a8bb
Show file tree
Hide file tree
Showing 14 changed files with 254 additions and 106 deletions.
6 changes: 3 additions & 3 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# STAGE BASE
FROM python:3.8.10 as python-base
FROM python:3.8.10 AS python-base

ENV PIP_NO_CACHE_DIR=off \
PIP_DISABLE_PIP_VERSION_CHECK=on \
Expand All @@ -16,7 +16,7 @@ ENV PIP_NO_CACHE_DIR=off \
ENV PATH="$POETRY_PATH/bin:$VENV_PATH/bin:$PATH"

# STAGE POETRY
FROM python-base as poetry
FROM python-base AS poetry

WORKDIR $PYSETUP_PATH
RUN pip install --upgrade pip \
Expand All @@ -26,7 +26,7 @@ COPY poetry.lock pyproject.toml ./
RUN poetry install

# STAGE RUNTIME
FROM python-base as runtime
FROM python-base AS runtime
WORKDIR /app

COPY --from=poetry $PYSETUP_PATH $PYSETUP_PATH
Expand Down
24 changes: 17 additions & 7 deletions backend/gncitizen/utils/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""A module to manage taxonomy"""

from threading import Thread
from typing import Dict, List, Union
from typing import Dict, List, Optional, Union

import requests
from flask import current_app
Expand All @@ -15,13 +15,22 @@

session.mount("https://", HTTPAdapter(max_retries=retries))


logger = current_app.logger


TAXHUB_API = (
current_app.config["API_TAXHUB"] + "/"
if current_app.config["API_TAXHUB"][-1] != "/"
else current_app.config["API_TAXHUB"]
)

logger = current_app.logger
if "TAXHUB_LISTS_EXCLUDE" in current_app.config:
excluded_list_ids = set(current_app.config["TAXHUB_LISTS_EXCLUDE"])
else:
excluded_list_ids = set()

logger.info(f"TAXHUB_EXCLUDED_LISTS {excluded_list_ids}")

Taxon = Dict[str, Union[str, Dict[str, str], List[Dict]]]

Expand All @@ -45,7 +54,7 @@ def taxhub_rest_get_taxon_list(taxhub_list_id: int) -> Dict:
return res.json()


def taxhub_rest_get_all_lists() -> Dict:
def taxhub_rest_get_all_lists() -> Optional[Dict]:
url = f"{TAXHUB_API}biblistes"
res = session.get(
url,
Expand All @@ -55,11 +64,14 @@ def taxhub_rest_get_all_lists() -> Dict:
if res.status_code == 200:
try:
taxa_lists = res.json()["data"]
taxa_lists = [taxa for taxa in taxa_lists if not taxa["id_liste"] in excluded_list_ids]
for taxa_list in taxa_lists:
taxonomy_lists.append((taxa_list["id_liste"], taxa_list["nom_liste"]))
print(f"taxonomy_lists {taxonomy_lists}")
except Exception as e:
logger.critical(str(e))
return res.json().get("data", [])
return None


def taxhub_rest_get_taxon(taxhub_id: int) -> Taxon:
Expand All @@ -81,9 +93,7 @@ def taxhub_rest_get_taxon(taxhub_id: int) -> Taxon:
media_types = ("Photo_gncitizen", "Photo_principale", "Photo")
i = 0
while i < len(media_types):
filtered_medias = [
d for d in data["medias"] if d["nom_type_media"] == media_types[i]
]
filtered_medias = [d for d in data["medias"] if d["nom_type_media"] == media_types[i]]
if len(filtered_medias) >= 1:
break
i += 1
Expand Down Expand Up @@ -141,7 +151,7 @@ def refresh_taxonlist() -> Dict:
count = 0
for taxhub_list in taxhub_lists:
count += 1
logger.info(f"loading list {count}/{len(taxhub_list)}")
logger.info(f"loading list {count}/{len(taxhub_lists)}")
r = make_taxon_repository(taxhub_list["id_liste"])
taxhub_full_lists[taxhub_list["id_liste"]] = r
else:
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.4"

services:
frontend:
image: gnc-front-dev
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.4"

services:
frontend:
image: gnc-front
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "3.4"

services:
frontend:
container_name: citizen-front
Expand Down
6 changes: 3 additions & 3 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# STAGE INSTALL NODE_MODULES
FROM node:14 as builder
FROM node:14 AS builder

COPY ./package.json ./package-lock.json /

RUN npm install
# && npm install --save-dev webpack webpack-cli html-webpack-plugin webpack-dev-server webpack-dev-middleware
# && npm install --save-dev webpack webpack-cli html-webpack-plugin webpack-dev-server webpack-dev-middleware

# STAGE RUNTIME
FROM builder as runtime
FROM builder AS runtime

WORKDIR /app

Expand Down
28 changes: 24 additions & 4 deletions frontend/src/app/programs/observations/detail/detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ import {

declare let $: any;

const map_conf = {
BASE_LAYERS: MainConfig['BASEMAPS'].reduce((acc, baseLayer: Object) => {
const layerConf: any = {
name: baseLayer['name'],
attribution: baseLayer['attribution'],
detectRetina: baseLayer['detectRetina'],
maxZoom: baseLayer['maxZoom'],
bounds: baseLayer['bounds'],
apiKey: baseLayer['apiKey'],
layerName: baseLayer['layerName'],
};
if (baseLayer['subdomains']) {
layerConf.subdomains = baseLayer['subdomains'];
}
acc[baseLayer['name']] = L.tileLayer(baseLayer['layer'], layerConf);
return acc;
}, {}),
DEFAULT_BASE_MAP: () =>
map_conf.BASE_LAYERS[MainConfig['DEFAULT_PROVIDER']],
};

@Component({
selector: 'app-obs-detail',
templateUrl: '../../base/detail/detail.component.html',
Expand Down Expand Up @@ -48,10 +69,9 @@ export class ObsDetailComponent
});

// setup map
const map = L.map('map');
L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'OpenStreetMap',
}).addTo(map);
const map = L.map('map', {
layers: [map_conf.DEFAULT_BASE_MAP()],
} as any);

let coord = this.obs.geometry.coordinates;
let latLng = L.latLng(coord[1], coord[0]);
Expand Down
13 changes: 6 additions & 7 deletions frontend/src/app/programs/observations/form/form.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { FormGroup, FormBuilder, Validators } from '@angular/forms';
import { geometryValidator, ngbDateMaxIsToday } from './formValidators';
import { MainConfig } from './../../../../conf/main.config';
import { BaseLayer } from '../../programs.models';
import * as L from 'leaflet';

import {
Expand Down Expand Up @@ -47,8 +48,8 @@ import { ControlPosition } from 'leaflet';
const map_conf = {
GEOLOCATION_CONTROL_POSITION: 'topright',
GEOLOCATION_HIGH_ACCURACY: false,
BASE_LAYERS: MainConfig['BASEMAPS'].reduce((acc, baseLayer: Object) => {
const layerConf: any = {
BASE_LAYERS: MainConfig['BASEMAPS'].reduce((acc, baseLayer: BaseLayer) => {
const layerConf: BaseLayer = {
name: baseLayer['name'],
attribution: baseLayer['attribution'],
detectRetina: baseLayer['detectRetina'],
Expand Down Expand Up @@ -235,13 +236,11 @@ export class ObsFormComponent implements AfterViewInit {

// build map control
const formMap = L.map('formMap', {
layers: [map_conf.DEFAULT_BASE_MAP()],
gestureHandling: true,
} as any);
this.formMap = formMap;

L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'OpenStreetMap',
}).addTo(formMap);
L.control
.layers(map_conf.BASE_LAYERS, null, {
collapsed: map_conf.BASE_LAYER_CONTROL_INIT_COLLAPSED,
Expand All @@ -251,8 +250,8 @@ export class ObsFormComponent implements AfterViewInit {
L.control['fullscreen']({
position: 'topright',
title: {
false: 'View Fullscreen',
true: 'Exit Fullscreefullscreenn',
false: 'Voir en plein écran',
true: 'Sortir du plein écran',
},
pseudoFullscreen: true,
}).addTo(formMap);
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/app/programs/programs.models.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SafeHtml } from '@angular/platform-browser';
import { TileLayerOptions } from 'leaflet';

export class Program {
id_program: number;
Expand All @@ -15,3 +16,12 @@ export class Program {
registration_required: boolean;
on_sidebar: boolean;
}

export interface BaseLayer extends TileLayerOptions {
name: string;
layer?: string;
attribution: string;
detectRetina?: boolean;
apiKey?: string;
layerName?: string;
}
28 changes: 24 additions & 4 deletions frontend/src/app/programs/sites/detail/detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ import { UserService } from '../../../auth/user-dashboard/user.service.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
import { SiteService } from '../sites.service';

const map_conf = {
BASE_LAYERS: MainConfig['BASEMAPS'].reduce((acc, baseLayer: Object) => {
const layerConf: any = {
name: baseLayer['name'],
attribution: baseLayer['attribution'],
detectRetina: baseLayer['detectRetina'],
maxZoom: baseLayer['maxZoom'],
bounds: baseLayer['bounds'],
apiKey: baseLayer['apiKey'],
layerName: baseLayer['layerName'],
};
if (baseLayer['subdomains']) {
layerConf.subdomains = baseLayer['subdomains'];
}
acc[baseLayer['name']] = L.tileLayer(baseLayer['layer'], layerConf);
return acc;
}, {}),
DEFAULT_BASE_MAP: () =>
map_conf.BASE_LAYERS[MainConfig['DEFAULT_PROVIDER']],
};

@Component({
selector: 'app-site-detail',
templateUrl: '../../base/detail/detail.component.html',
Expand Down Expand Up @@ -88,10 +109,9 @@ export class SiteDetailComponent

prepareSiteData(): void {
// setup map
const map = L.map('map');
L.tileLayer('//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: 'OpenStreetMap',
}).addTo(map);
const map = L.map('map', {
layers: [map_conf.DEFAULT_BASE_MAP()],
} as any);
const coord = this.site.geometry.coordinates;
const latLng = L.latLng(coord[1], coord[0]);
map.setView(latLng, 13);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#formMap {
min-height: 225px; /*50vh*/
min-height: 375px; /*50vh*/
width: 100%;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<form id="siteForm" [formGroup]="siteForm" (ngSubmit)="onFormSubmit()">

<div class="form-row">
<div class="form-group col-lg-6 col-md-12 half">
<div class="form-group col-lg-12 col-md-12">
<h5>Informations</h5>
<label for="counting">*Type de site&nbsp;</label>
<select
Expand All @@ -21,7 +21,7 @@ <h5>Informations</h5>
<label for="counting">*Nom du site&nbsp;</label>
<input type="text" formControlName="name" class="form-control" />
</div>
<div class="form-group col-lg-6 col-md-12 half">
<div class="form-group col-lg-12 col-md-12">
<h5>Où est-il situé ?</h5>
<div class="position-relative">
<div class="zoom-alert" *ngIf="hasZoomAlert">
Expand Down
Loading

0 comments on commit 448a8bb

Please sign in to comment.