Skip to content

Commit

Permalink
Occtax: remove diffusion level
Browse files Browse the repository at this point in the history
  • Loading branch information
TheoLechemia committed Aug 20, 2020
1 parent ae38905 commit b1e5ebd
Show file tree
Hide file tree
Showing 14 changed files with 860 additions and 901 deletions.
2 changes: 0 additions & 2 deletions backend/tests/sample_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ INSERT INTO pr_occtax.t_occurrences_occtax (
id_nomenclature_bio_status,
id_nomenclature_naturalness,
id_nomenclature_exist_proof,
id_nomenclature_diffusion_level,
id_nomenclature_observation_status,
id_nomenclature_blurring,
determiner,
Expand All @@ -250,7 +249,6 @@ VALUES
ref_nomenclatures.get_id_nomenclature('STATUT_BIO', '1'),
ref_nomenclatures.get_id_nomenclature('NATURALITE', '1'),
ref_nomenclatures.get_id_nomenclature('PREUVE_EXIST', '0'),
ref_nomenclatures.get_id_nomenclature('NIV_PRECIS', '0'),
ref_nomenclatures.get_id_nomenclature('STATUT_OBS', 'Pr'),
ref_nomenclatures.get_id_nomenclature('DEE_FLOU', 'NON'),
'Gil',
Expand Down
1 change: 0 additions & 1 deletion contrib/occtax/backend/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"id_nomenclature_bio_status",
"id_nomenclature_naturalness",
"id_nomenclature_exist_proof",
"id_nomenclature_diffusion_level",
"id_nomenclature_observation_status",
"id_nomenclature_blurring",
"id_nomenclature_determination_method",
Expand Down
2 changes: 0 additions & 2 deletions contrib/occtax/data/sample_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ INSERT INTO pr_occtax.t_occurrences_occtax (
id_nomenclature_bio_status,
id_nomenclature_naturalness,
id_nomenclature_exist_proof,
id_nomenclature_diffusion_level,
id_nomenclature_observation_status,
id_nomenclature_blurring,
determiner,
Expand All @@ -222,7 +221,6 @@ VALUES
ref_nomenclatures.get_id_nomenclature('STATUT_BIO', '1'),
ref_nomenclatures.get_id_nomenclature('NATURALITE', '1'),
ref_nomenclatures.get_id_nomenclature('PREUVE_EXIST', '0'),
ref_nomenclatures.get_id_nomenclature('NIV_PRECIS', '0'),
ref_nomenclatures.get_id_nomenclature('STATUT_OBS', 'Pr'),
ref_nomenclatures.get_id_nomenclature('DEE_FLOU', 'NON'),
'Gil',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,6 @@ <h4>
</pnx-nomenclature>
</div>

<div
*ngIf="occtaxConfig.form_fields.diffusion_level"
class="col-lg-4 col-sm-6">
<pnx-nomenclature
label="{{ 'Taxon.DiffusionLevel' | translate }}"
[parentFormControl]="occurrenceParamForm.get('id_nomenclature_diffusion_level')"
codeNomenclatureType="NIV_PRECIS">
</pnx-nomenclature>
</div>

<div
*ngIf="occtaxConfig.form_fields.blurring"
class="col-lg-4 col-sm-6">
Expand Down
163 changes: 107 additions & 56 deletions contrib/occtax/frontend/app/occtax-form/form-param/form-param.dialog.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,63 @@
import { Component, OnInit } from "@angular/core";
import { animate, state, style, transition, trigger } from '@angular/animations';
import { MatDialogRef } from '@angular/material';
import {
animate,
state,
style,
transition,
trigger,
} from "@angular/animations";
import { MatDialogRef } from "@angular/material";
import { FormBuilder, FormGroup, Validators } from "@angular/forms";
import { combineLatest } from "rxjs";
import { filter, map } from "rxjs/operators";
import { ModuleConfig } from "../../module.config";
import { OcctaxFormMapService } from '../map/map.service';
import { OcctaxFormReleveService } from '../releve/releve.service';
import { OcctaxFormOccurrenceService } from '../occurrence/occurrence.service';
import { OcctaxFormParamService } from './form-param.service';

import { ModuleConfig } from "../../module.config";
import { OcctaxFormMapService } from "../map/map.service";
import { OcctaxFormReleveService } from "../releve/releve.service";
import { OcctaxFormOccurrenceService } from "../occurrence/occurrence.service";
import { OcctaxFormParamService } from "./form-param.service";

@Component({
selector: "pnx-occtax-form-param",
templateUrl: "./form-param.dialog.html",
styleUrls: ["./form-param.dialog.scss"],
animations: [
trigger('detailExpand', [
state('collapsed', style({height: '0px', minHeight: '0', margin: '-1px', overflow: 'hidden', padding: '0'})),
state('expanded', style({height: '*'})),
transition('expanded <=> collapsed', animate('225ms cubic-bezier(0.4, 0.0, 0.2, 1)')),
trigger("detailExpand", [
state(
"collapsed",
style({
height: "0px",
minHeight: "0",
margin: "-1px",
overflow: "hidden",
padding: "0",
})
),
state("expanded", style({ height: "*" })),
transition(
"expanded <=> collapsed",
animate("225ms cubic-bezier(0.4, 0.0, 0.2, 1)")
),
]),
],
})
export class OcctaxFormParamDialog implements OnInit {

public occtaxConfig: any;
public paramsForm: FormGroup;
public selectedIndex: number = null;
public state: string = 'collapsed';
public state: string = "collapsed";

get geometryParamForm() { return this.paramsForm.get('geometry'); }
get releveParamForm() { return this.paramsForm.get('releve'); }
get occurrenceParamForm() { return this.paramsForm.get('occurrence'); }
get countingParamForm() { return this.paramsForm.get('counting'); }
get geometryParamForm() {
return this.paramsForm.get("geometry");
}
get releveParamForm() {
return this.paramsForm.get("releve");
}
get occurrenceParamForm() {
return this.paramsForm.get("occurrence");
}
get countingParamForm() {
return this.paramsForm.get("counting");
}

constructor(
public dialogRef: MatDialogRef<OcctaxFormParamDialog>,
Expand All @@ -45,22 +69,31 @@ export class OcctaxFormParamDialog implements OnInit {
) {
this.occtaxConfig = ModuleConfig;
}

ngOnInit() {

ngOnInit() {
this.paramsForm = this.fb.group({
geometry:null,
geometry: null,
releve: this.fb.group({
id_dataset: null,
date_min: null,
date_max: null,
hour_min: [null, Validators.pattern("^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$")],
hour_max: [null, Validators.pattern("^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$")],
hour_min: [
null,
Validators.pattern(
"^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$"
),
],
hour_max: [
null,
Validators.pattern(
"^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9](:[0-5][0-9])?$"
),
],
comment: null,
id_nomenclature_obs_technique: null,
observers: null,
observers_txt: null,
id_nomenclature_grp_typ: null
id_nomenclature_grp_typ: null,
}),
occurrence: this.fb.group({
id_nomenclature_obs_meth: null,
Expand All @@ -69,55 +102,69 @@ export class OcctaxFormParamDialog implements OnInit {
id_nomenclature_naturalness: null,
id_nomenclature_exist_proof: null,
id_nomenclature_observation_status: null,
id_nomenclature_diffusion_level: null,
id_nomenclature_blurring: null,
id_nomenclature_source_status: null,
determiner: null,
id_nomenclature_determination_method: null,
sample_number_proof: null,
comment: null
comment: null,
}),
counting: this.fb.group({
id_nomenclature_life_stage: null,
id_nomenclature_sex: null,
id_nomenclature_obj_count: null,
id_nomenclature_type_count: null,
count_min: null,
count_max: null
})
count_max: null,
}),
});

this.paramsForm.patchValue(this.occtaxFormParamService.parameters);

//a chaque changement du formulairen on patch le service des paramètres
this.paramsForm.valueChanges
.pipe(
filter(()=>this.paramsForm.valid)
)
.subscribe(values=>this.occtaxFormParamService.parameters = values);
.pipe(filter(() => this.paramsForm.valid))
.subscribe((values) => (this.occtaxFormParamService.parameters = values));

//Observe l'état des switchs pour activer ou non le formulaire
this.occtaxFormParamService.releveState
.subscribe((value: boolean)=>{value ? this.paramsForm.get('releve').enable() : this.paramsForm.get('releve').disable()});
this.occtaxFormParamService.occurrenceState
.subscribe((value: boolean)=>{value ? this.paramsForm.get('occurrence').enable() : this.paramsForm.get('occurrence').disable()});
this.occtaxFormParamService.countingState
.subscribe((value: boolean)=>{value ? this.paramsForm.get('counting').enable() : this.paramsForm.get('counting').disable()});
this.occtaxFormParamService.releveState.subscribe((value: boolean) => {
value
? this.paramsForm.get("releve").enable()
: this.paramsForm.get("releve").disable();
});
this.occtaxFormParamService.occurrenceState.subscribe((value: boolean) => {
value
? this.paramsForm.get("occurrence").enable()
: this.paramsForm.get("occurrence").disable();
});
this.occtaxFormParamService.countingState.subscribe((value: boolean) => {
value
? this.paramsForm.get("counting").enable()
: this.paramsForm.get("counting").disable();
});

//On observe les cases cochées pour savoir quel onglet affiché
//Uniquement si un seul switch est activé
combineLatest(
this.occtaxFormParamService.geometryState,
this.occtaxFormParamService.releveState,
this.occtaxFormParamService.occurrenceState,
this.occtaxFormParamService.geometryState,
this.occtaxFormParamService.releveState,
this.occtaxFormParamService.occurrenceState,
this.occtaxFormParamService.countingState
)
.pipe(
filter(([geometryState, releveState, occurrenceState, countingState])=>{
//si un unique switch est activé
return ((geometryState ? 1 : 0) + (releveState ? 1 : 0) + (occurrenceState ? 1 : 0) + (countingState ? 1 : 0)) === 1
}),
map(([geometryState, releveState, occurrenceState, countingState])=>{
filter(
([geometryState, releveState, occurrenceState, countingState]) => {
//si un unique switch est activé
return (
(geometryState ? 1 : 0) +
(releveState ? 1 : 0) +
(occurrenceState ? 1 : 0) +
(countingState ? 1 : 0) ===
1
);
}
),
map(([geometryState, releveState, occurrenceState, countingState]) => {
//convertit la case coché en index de tab à activer
if (geometryState) {
return 0;
Expand All @@ -133,24 +180,28 @@ export class OcctaxFormParamDialog implements OnInit {
}
})
)
.subscribe(index=>this.selectedIndex = index)
.subscribe((index) => (this.selectedIndex = index));
}

geometryFormMapper() {
this.paramsForm.get('geometry').patchValue(this.occtaxFormMapService.geometry.value);
this.paramsForm
.get("geometry")
.patchValue(this.occtaxFormMapService.geometry.value);
}

releveFormMapper() {
this.paramsForm.get('releve').patchValue(this.occtaxFormReleveService.propertiesForm.value);
this.paramsForm
.get("releve")
.patchValue(this.occtaxFormReleveService.propertiesForm.value);
}

occurrenceFormMapper() {
this.paramsForm.get('occurrence').patchValue(this.occtaxFormOccurrenceService.form.value);
this.paramsForm
.get("occurrence")
.patchValue(this.occtaxFormOccurrenceService.form.value);
}

collapse(){
this.state = (this.state === 'collapsed' ? 'expanded' : 'collapsed');
collapse() {
this.state = this.state === "collapsed" ? "expanded" : "collapsed";
}


}
}
Loading

0 comments on commit b1e5ebd

Please sign in to comment.