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/species page/status #3191

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
74 changes: 0 additions & 74 deletions backend/geonature/core/gn_synthese/synthese_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,77 +100,3 @@
{"prop": "dataset_name", "name": "JDD", "max_width": 200},
{"prop": "observers", "name": "observateur", "max_width": 200},
]


class DefaultProfile:
ENABLED = True
## DEFAULT PROFILE INDICATORS
LIST_INDICATORS = [
{
"name": "observation(s) valide(s)",
"matIcon": "search",
"field": "count_valid_data",
"type": "number",
},
{
"name": "Première observation",
"matIcon": "schedule",
"field": "first_valid_data",
"type": "date",
},
{
"name": "Dernière observation",
"matIcon": "search",
"field": "last_valid_data",
"type": "date",
},
{
"name": "Plage d'altitude(s)",
"matIcon": "terrain",
"field": ["altitude_min", "altitude_max"],
"unit": "m",
"type": "number",
},
]


class DefaultGeographicOverview:
pass


class DefaultSpeciesSheet:
## DEFAULT SPECIES SHEET INDICATORS
LIST_INDICATORS = [
{
"name": "observation(s)",
"matIcon": "search",
"field": "observation_count",
"type": "number",
},
{
"name": "observateur(s)",
"matIcon": "people",
"field": "observer_count",
"type": "number",
},
{
"name": "commune(s)",
"matIcon": "location_on",
"field": "area_count",
"type": "number",
},
{
"name": "Plage d'altitude(s)",
"matIcon": "terrain",
"unit": "m",
"type": "number",
"field": ["altitude_min", "altitude_max"],
},
{
"name": "Plage d'observation(s)",
"matIcon": "date_range",
"type": "date",
"field": ["date_min", "date_max"],
"separator": "-",
},
]
25 changes: 3 additions & 22 deletions backend/geonature/utils/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,7 @@
)
from marshmallow.validate import OneOf, Regexp, Email, Length

from geonature.core.gn_synthese.synthese_config import (
DEFAULT_EXPORT_COLUMNS,
DEFAULT_LIST_COLUMN,
DefaultGeographicOverview,
DefaultProfile,
DefaultSpeciesSheet,
)
from geonature.core.gn_synthese.synthese_config import DEFAULT_EXPORT_COLUMNS, DEFAULT_LIST_COLUMN
from geonature.utils.env import GEONATURE_VERSION, BACKEND_DIR, ROOT_DIR
from geonature.utils.module import iter_modules_dist, get_module_config
from geonature.utils.utilsmails import clean_recipients
Expand Down Expand Up @@ -277,24 +271,11 @@ class ExportObservationSchema(Schema):
geojson_local_field = fields.String(load_default="geojson_local")


class SpeciesSheetProfile(Schema):
ENABLED = fields.Boolean(load_default=DefaultProfile.ENABLED)
LIST_INDICATORS = fields.List(fields.Dict, load_default=DefaultProfile.LIST_INDICATORS)


class SpeciesSheetGeographicOverview(Schema):
pass


class SpeciesSheet(Schema):
# --------------------------------------------------------------------
# SYNTHESE - SPECIES_SHEET
LIST_INDICATORS = fields.List(fields.Dict, load_default=DefaultSpeciesSheet.LIST_INDICATORS)

GEOGRAPHIC_OVERVIEW = fields.Dict(
load_default=SpeciesSheetGeographicOverview().load({})
) # rename
PROFILE = fields.Nested(SpeciesSheetProfile, load_default=SpeciesSheetProfile().load({}))
ENABLE_PROFILE = fields.Boolean(load_default=True)
ENABLE_TAXONOMY = fields.Boolean(load_default=True)


class Synthese(Schema):
Expand Down
15 changes: 11 additions & 4 deletions config/default_config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ MEDIA_CLEAN_CRONTAB = "0 1 * * *"
# Vues d'export personnalisées
EXPORT_OBSERVATIONS_CUSTOM_VIEWS = [
{
label = "format personnalisé",
label = "format personnalisé",
view_name = "schema_name.view_name"
}
}
]
# Noms des colonnes obligatoires de la vue ``gn_synthese.v_metadata_for_export``
EXPORT_METADATA_ID_DATASET_COL = "jdd_id"
Expand Down Expand Up @@ -441,6 +441,13 @@ MEDIA_CLEAN_CRONTAB = "0 1 * * *"
# Seulement les données de présence
cd_nomenclature_observation_status = ['Pr']

[SYNTHESE.SPECIES_SHEET]
# Options dédiées à la fiche espèce
#Permet d'activer ou non la section "Profile" de la fiche espèce
ENABLE_PROFILE = True
# Permet d'activer ou non la section "Taxonomy" de la fiche espèce
ENABLE_TAXONOMY = True

# Gestion des demandes d'inscription
[ACCOUNT_MANAGEMENT]
# Activer l'affichage du lien vers le formulaire d'inscription
Expand Down Expand Up @@ -601,12 +608,12 @@ MEDIA_CLEAN_CRONTAB = "0 1 * * *"
[[AUTHENTICATION.PROVIDERS]]
module="pypnusershub.auth.providers.default.DefaultConfiguration"
id_provider="local_provider"

[[AUTHENTICATION.PROVIDERS]]
module="pypnusershub.auth.providers.openid_provider.OpenIDConnectProvider"
id_provider = "google"
logo = "<i class='fa fa-google' aria-hidden='true'></i>"
label = "Google"
ISSUER = "https://accounts.google.com/"
CLIENT_ID = "ID" # API key
CLIENT_SECRET = "SECRET" # API Secret
CLIENT_SECRET = "SECRET" # API Secret
6 changes: 6 additions & 0 deletions frontend/src/app/GN2CommonModule/GN2Common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { AreasIntersectedComponent } from './form/areas-intersected/areas-inters
import { AutoCompleteComponent } from '@geonature_common/form/autocomplete/autocomplete.component';
import { ConfirmationDialog } from '@geonature_common/others/modal-confirmation/confirmation.dialog';
import { DatalistComponent } from '@geonature_common/form/datalist/datalist.component';
import { BadgeComponent } from '@geonature_common/others/badge/badge.component';
import { BreadcrumbsComponent } from '@geonature_common/others/breadcrumbs/breadcrumbs.component';
import { DatasetsComponent } from './form/datasets/datasets.component';
import { DateComponent } from './form/date/date.component';
Expand Down Expand Up @@ -74,6 +75,7 @@ import { ObserversTextComponent } from '@geonature_common/form/observers-text/ob
import { PeriodComponent } from '@geonature_common/form/date/period.component';
import { PlacesComponent } from './map/places/places.component';
import { PlacesListComponent } from './map/placesList/placesList.component';
import { StatusBadgesComponent } from '@geonature_common/others/status-badges/status-badges.component';
import { SyntheseSearchComponent } from '@geonature_common/form/synthese-form/synthese-form.component';
import { TaxaComponent } from '@geonature_common/form/taxa/taxa.component';
import { TaxonAdvancedModalComponent } from '@geonature_common/form/synthese-form/advanced-form/synthese-advanced-form-component';
Expand Down Expand Up @@ -141,6 +143,7 @@ import { TaxonTreeComponent } from './form/taxon-tree/taxon-tree.component';
AreasComponent,
NomenclatureComponent,
ObserversComponent,
BadgeComponent,
BreadcrumbsComponent,
DateComponent,
TaxonomyComponent,
Expand Down Expand Up @@ -185,6 +188,7 @@ import { TaxonTreeComponent } from './form/taxon-tree/taxon-tree.component';
SafeHtmlPipe,
SyntheseSearchComponent,
SafeStripHtmlPipe,
StatusBadgesComponent,
StripHtmlPipe,
TaxaComponent,
TaxonAdvancedModalComponent,
Expand All @@ -208,6 +212,7 @@ import { TaxonTreeComponent } from './form/taxon-tree/taxon-tree.component';
AcquisitionFrameworksComponent,
AreasComponent,
MunicipalitiesComponent,
BadgeComponent,
BreadcrumbsComponent,
DynamicFormComponent,
NomenclatureComponent,
Expand Down Expand Up @@ -288,6 +293,7 @@ import { TaxonTreeComponent } from './form/taxon-tree/taxon-tree.component';
ReactiveFormsModule,
ReadablePropertiePipe,
SafeHtmlPipe,
StatusBadgesComponent,
TaxaComponent,
TaxonAdvancedModalComponent,
TaxonomyComponent,
Expand Down
4 changes: 4 additions & 0 deletions frontend/src/app/GN2CommonModule/form/data-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export class DataFormService {
});
}

fetchStatusSymbology() {
return this._http.get<any>(`${this.config.API_TAXHUB}/bdc_statuts/status_symbologies`);
}

getTaxonAttributsAndMedia(cd_nom: number, id_attributs?: Array<number>) {
let query_string = new HttpParams();
if (id_attributs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface Taxon {
nom_vern?: string;
ordre?: string;
phylum?: string;
statuts_protection?: any[];
status?: any[];
synonymes?: any[];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<span
class="badge badge-secondary"
[style]="symbologyAsCSS"
matTooltip="{{ tooltip }}"
>
{{ text }}
</span>
15 changes: 15 additions & 0 deletions frontend/src/app/GN2CommonModule/others/badge/badge.component.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.badge {
--bgColor: #ffffff; // Default value
--textColor: #444; // Default value

display: flex;
flex-flow: row nowrap;
white-space: nowrap;
gap: 0.25rem;
text-transform: uppercase;
font-weight: bold;

background-color: var(--bgColor);
border: 2px solid color-mix(in srgb, var(--bgColor) 80%, black);
color: var(--textColor);
}
66 changes: 66 additions & 0 deletions frontend/src/app/GN2CommonModule/others/badge/badge.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { Component, Input } from '@angular/core';

// ////////////////////////////////////////////////////////////////////////////
// helper method
// ////////////////////////////////////////////////////////////////////////////

function isHexadecimalColor(color: string) {
return /^#[0-9A-F]{6}$/i.test(color);
}

function computeContrastColor(backgroundColor: string) {
// Convertir la couleur en un format RGB
const r = parseInt(backgroundColor.slice(1, 3), 16);
const g = parseInt(backgroundColor.slice(3, 5), 16);
const b = parseInt(backgroundColor.slice(5, 7), 16);

// Calculer la luminosité
const luminance = 0.299 * r + 0.587 * g + 0.114 * b;

// Retourner une couleur claire ou foncée selon la luminosité
return luminance < 128 ? '#ffffff' : '#444';
}

function colorToCSS(color: string) {
return `--bgColor: ${color}; --textColor: ${computeContrastColor(color)};`;
}

// ////////////////////////////////////////////////////////////////////////////
// Badge parameters
// ////////////////////////////////////////////////////////////////////////////

export interface BadgeSymbology {
color?: string;
}

// ////////////////////////////////////////////////////////////////////////////
// helper method
// ////////////////////////////////////////////////////////////////////////////

@Component({
selector: 'gn-badge',
templateUrl: 'badge.component.html',
styleUrls: ['badge.component.scss'],
})
export class BadgeComponent {
@Input()
text: string;

@Input()
tooltip: string;

symbologyAsCSS: string;

@Input()
set symbology(symbology: BadgeSymbology | null) {
this.symbologyAsCSS = '';
if (!symbology) {
return;
}
if (!isHexadecimalColor(symbology.color)) {
console.warn(`[badge] ${symbology.color} is not a valid hexadecimal color`);
return;
}
this.symbologyAsCSS = colorToCSS(symbology.color);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<div class="StatusBadges">
<gn-badge
*ngFor="let status of status"
[tooltip]="status.tooltip"
[text]="status.badge"
[symbology]="status.symbology"
/>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.StatusBadges {
display: flex;
flex-flow: row wrap;
width: 100%;
gap: 0.5rem;
line-height: inherit;
}
Loading
Loading