Skip to content

Commit

Permalink
Add diffusion-level form in datasets elements
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrieuclp committed Mar 29, 2024
1 parent 27118fa commit 02aac1b
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 2 deletions.
9 changes: 9 additions & 0 deletions backend/geonature/core/gn_meta/models/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ class TDatasets(db.Model):
ForeignKey("ref_nomenclatures.t_nomenclatures.id_nomenclature"),
default=lambda: TNomenclatures.get_default_nomenclature("RESOURCE_TYP"),
)
id_nomenclature_diffusion_level = DB.Column(
DB.Integer,
ForeignKey("ref_nomenclatures.t_nomenclatures.id_nomenclature"),
default=lambda: TNomenclatures.get_default_nomenclature("NIV_PRECIS"),
)
meta_create_date = DB.Column(DB.DateTime, server_default=FetchedValue())
meta_update_date = DB.Column(DB.DateTime, server_default=FetchedValue())
active = DB.Column(DB.Boolean, default=True)
Expand Down Expand Up @@ -113,6 +118,10 @@ class TDatasets(db.Model):
TNomenclatures,
foreign_keys=[id_nomenclature_resource_type],
)
nomenclature_diffusion_level = DB.relationship(
TNomenclatures,
foreign_keys=[id_nomenclature_diffusion_level],
)

cor_territories = DB.relationship(
TNomenclatures,
Expand Down
1 change: 1 addition & 0 deletions backend/geonature/core/gn_meta/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def get_dataset(scope, id_dataset):
"nomenclature_data_origin",
"nomenclature_source_status",
"nomenclature_resource_type",
"nomenclature_diffusion_level",
"cor_territories",
"acquisition_framework",
"acquisition_framework.creator",
Expand Down
1 change: 1 addition & 0 deletions backend/geonature/core/gn_meta/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class Meta:
nomenclature_data_origin = MA.Nested(NomenclatureSchema, dump_only=True)
nomenclature_source_status = MA.Nested(NomenclatureSchema, dump_only=True)
nomenclature_resource_type = MA.Nested(NomenclatureSchema, dump_only=True)
nomenclature_diffusion_level = MA.Nested(NomenclatureSchema, dump_only=True)
cor_territories = MA.Nested(NomenclatureSchema, many=True, unknown=EXCLUDE)
acquisition_framework = MA.Nested("AcquisitionFrameworkSchema", dump_only=True)
sources = MA.Nested(SourceSchema, many=True, dump_only=True)
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/app/GN2CommonModule/GN2Common.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { MatIconRegistry } from '@angular/material/icon';
import { MatSelectModule } from '@angular/material/select';
import { MatSidenavModule } from '@angular/material/sidenav';
import { MatSlideToggleModule } from '@angular/material/slide-toggle';
import { MatSliderModule } from '@angular/material/slider';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { RouterModule } from '@angular/router';

Expand Down Expand Up @@ -124,6 +125,7 @@ import { TaxonTreeComponent } from './form/taxon-tree/taxon-tree.component';
MatSelectModule,
MatSidenavModule,
MatSlideToggleModule,
MatSliderModule,
MatStepperModule,
MatTabsModule,
MatToolbarModule,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ <h5>Fiche descriptive</h5>

<br />

<h4>Spécificités GRETIA</h4>
<div class="align">
<b> Niveau de diffusion :</b>
{{ dataset?.nomenclature_diffusion_level?.definition_default || 'Non renseigné'}}
</div>

<br />

<h4>Spécificités GeoNature</h4>
<div class="align" data-qa='pnx-metadata-dataset-status'> <b>Actif : </b> {{dataset.active ? 'Oui' : 'Non'}} </div>
<div class="align"> <b> Validable :</b> {{dataset.validable ? 'Oui' : 'Non'}} </div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,24 @@ <h3 class="main-color">Jeu de données</h3>
</div>
</div>

<h5 style="margin-top: 10px;"> Spécifique GRETIA </h5>

<div class="row">
<div class="col-md-6 col-lg-4">
<pnx-nomenclature
label="Niveau de diffusion souhaité"
[parentFormControl]="form.get('id_nomenclature_diffusion_level')"
codeNomenclatureType="NIV_PRECIS"
data-qa="pnx-dataset-form-datatype"
(labelsLoaded)="nivPrecisLoaded($event)"
>
</pnx-nomenclature>
</div>
<div class="col-md-6 col-lg-8">
<div class="niv-diff-info">{{ NIV_PRECIS_INFO.value }}</div>
</div>
</div>

<h5 style="margin-top: 10px">Spécifique GeoNature</h5>

<div>
Expand Down
29 changes: 27 additions & 2 deletions frontend/src/app/metadataModule/datasets/dataset-form.component.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { UntypedFormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import { of, Observable } from 'rxjs';
import { switchMap, tap } from 'rxjs/operators';
import { of, Observable, BehaviorSubject, combineLatest } from 'rxjs';
import { switchMap, tap, startWith, map, filter } from 'rxjs/operators';

import { CommonService } from '@geonature_common/service/common.service';
import { DataFormService } from '@geonature_common/form/data-form.service';
Expand All @@ -23,6 +23,8 @@ export class DatasetFormComponent implements OnInit {
//observable pour la liste déroulantes HTML des AF
public acquisitionFrameworks: Observable<any>;
public taxaBibList: number;
public NIV_PRECIS_DATA = new BehaviorSubject<any[]>([]);
public NIV_PRECIS_INFO = new BehaviorSubject<string>(null);

constructor(
private _route: ActivatedRoute,
Expand All @@ -36,6 +38,15 @@ export class DatasetFormComponent implements OnInit {
private metadataDataS: MetadataDataService
) {}

/**
* gestion du form de niveau de diffusion
*/
nivPrecisLoaded(data) {
this.NIV_PRECIS_DATA.next(data);
}

/** Fin **/

ngOnInit() {
// get the id from the route
this._route.params
Expand All @@ -51,6 +62,20 @@ export class DatasetFormComponent implements OnInit {
this._dfs.getTaxaBibList().subscribe((d) => (this.taxaBibList = d));

this.acquisitionFrameworks = this._dfs.getAcquisitionFrameworksList();

combineLatest(
this.form.get('id_nomenclature_diffusion_level').valueChanges
.pipe(
startWith(this.form.get('id_nomenclature_diffusion_level').value),
filter(val => val !== null)
),
this.NIV_PRECIS_DATA.asObservable()
)
.pipe(
map(([value, labels]: [any, any[]]) => labels.find((e) => e.id_nomenclature == value)),
map((res) => res != null ? res.definition_default : null)
)
.subscribe(val => this.NIV_PRECIS_INFO.next(val))
}

genericActorFormSubmit(result) {
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/app/metadataModule/form.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ h5.actor-title {
margin-left: -20px;
font-style: italic;
}

.niv-diff-info {
color: #444;
padding-top: 22px;
font-size: 90%;
font-style: italic;
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class DatasetFormService {
id_nomenclature_data_origin: [null, Validators.required],
id_nomenclature_source_status: [null, Validators.required],
id_nomenclature_resource_type: [null, Validators.required],
id_nomenclature_diffusion_level: [null, Validators.required],
validable: null,
active: [null, Validators.required],
id_taxa_list: null,
Expand Down

0 comments on commit 02aac1b

Please sign in to comment.