-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/individuals-widget' into feat/individuals
- Loading branch information
Showing
14 changed files
with
364 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
frontend/src/app/GN2CommonModule/form/individuals/create/individuals-create.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<div class="modal-header"> | ||
<h5 class="modal-title">Création d'un individu</h5> | ||
<button type="button" class="close" aria-label="Close" (click)="cancelCreate()"> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
</div> | ||
|
||
<form class="modal-content"> | ||
<div class="modal-body" id="bodyModal" style="padding-top: 30px"> | ||
<small>Nom de l'individu</small> | ||
<input | ||
class="form-control form-control-sm" | ||
type="text" | ||
data-qa="pnx-individuals-create-individual-name" | ||
[formControl]="form.get('individual_name')" | ||
/> | ||
<pnx-nomenclature | ||
label="Sexe" | ||
[parentFormControl]="form.get('id_nomenclature_sex')" | ||
codeNomenclatureType="SEXE" | ||
keyValue="id_nomenclature" | ||
> | ||
</pnx-nomenclature> | ||
<small>Commentaires</small> | ||
<textarea | ||
class="form-control form-control-sm" | ||
[formControl]="form.get('comment')" | ||
type="textarea" | ||
> | ||
</textarea> | ||
<pnx-taxonomy | ||
*ngIf="cdNom === null" | ||
label="Taxon" | ||
[parentFormControl]="form.get('cd_nom_temp')" | ||
[idList]="idList" | ||
displayedLabel="nom_valide" | ||
charNumber="3" | ||
listLength="20" | ||
(onChange)="taxonSelected($event)" | ||
> | ||
</pnx-taxonomy> | ||
</div> | ||
</form> | ||
<div class="modal-footer"> | ||
<div class="d-flex justify-content-between"> | ||
<button id="cancelButton" type="button" color="warn" mat-raised-button (click)="cancelCreate()"> | ||
Annuler | ||
</button> | ||
<button | ||
id="createButton" | ||
type="button" | ||
class="button-success" | ||
mat-raised-button | ||
(click)="createIndividual()" | ||
> | ||
Créer un individu | ||
</button> | ||
</div> | ||
</div> |
5 changes: 5 additions & 0 deletions
5
frontend/src/app/GN2CommonModule/form/individuals/create/individuals-create.component.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#createButton { | ||
float: right; | ||
//background-color: #1976D2; | ||
border: none; | ||
} |
65 changes: 65 additions & 0 deletions
65
frontend/src/app/GN2CommonModule/form/individuals/create/individuals-create.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { Component, Output, EventEmitter, Input, OnInit } from '@angular/core'; | ||
import { FormControl, FormGroup } from '@angular/forms'; | ||
import { Validators } from '@angular/forms'; | ||
import { Taxon } from '@geonature_common/form/taxonomy/taxonomy.component'; | ||
import { NgbTypeaheadSelectItemEvent } from '@ng-bootstrap/ng-bootstrap'; | ||
import { IndividualsService } from '../individuals.service'; | ||
import { Individual } from '../interfaces'; | ||
import { throwError } from 'rxjs'; | ||
@Component({ | ||
selector: 'pnx-individuals-create', | ||
templateUrl: './individuals-create.component.html', | ||
styleUrls: ['./individuals-create.component.scss'], | ||
}) | ||
export class IndividualsCreateComponent implements OnInit { | ||
@Input() idModule: null | number = null; | ||
@Input() idList: null | string = null; | ||
@Input() cdNom: null | number = null; | ||
@Output() individualEvent = new EventEmitter<Individual>(); | ||
@Output() cancelEvent = new EventEmitter(); | ||
|
||
form: FormGroup<{ | ||
individual_name: FormControl<string>; | ||
id_nomenclature_sex: FormControl<number | null>; | ||
cd_nom: FormControl<number | null>; | ||
cd_nom_temp: FormControl<number | null>; | ||
comment: FormControl<string>; | ||
}>; | ||
|
||
constructor(private _individualsService: IndividualsService) {} | ||
|
||
ngOnInit() { | ||
this.form = new FormGroup({ | ||
individual_name: new FormControl<string>('', { | ||
validators: [Validators.required], | ||
}), | ||
id_nomenclature_sex: new FormControl<number | null>(null), | ||
cd_nom: new FormControl<number | null>(this.cdNom, { | ||
validators: [Validators.required], | ||
}), | ||
// Normally we could avoid providing a form to taxonomy | ||
// widget, but it needs it and affecting the entire taxon | ||
// to the form control. Creating a temp one to fix this problem | ||
cd_nom_temp: new FormControl<number | null>(this.cdNom, { | ||
validators: [Validators.required], | ||
}), | ||
comment: new FormControl<string>(''), | ||
}); | ||
} | ||
|
||
taxonSelected(value: NgbTypeaheadSelectItemEvent<Taxon>) { | ||
this.form.patchValue({ cd_nom: value.item.cd_nom }); | ||
} | ||
|
||
createIndividual() { | ||
const value = this.form.getRawValue(); | ||
delete value.cd_nom_temp; | ||
this._individualsService | ||
.postIndividual(value as Individual, this.idModule) | ||
.subscribe((value) => this.individualEvent.emit(value)); | ||
} | ||
|
||
cancelCreate() { | ||
this.cancelEvent.emit(); | ||
} | ||
} |
Oops, something went wrong.