diff --git a/src/app/components/field-set/field-set.component.html b/src/app/components/field-set/field-set.component.html index 88654611e535f4cf3834616084282c15d310ea6b..381115b094250a8aaf4f585382ce568b33276a2b 100644 --- a/src/app/components/field-set/field-set.component.html +++ b/src/app/components/field-set/field-set.component.html @@ -45,7 +45,7 @@ (inputChange)=onInputChange($event) (tabPressed)="onTabPressed($event)"> </param-field-line> - <select-field-line *ngIf="isSelectField(p)" [_select]=p> + <select-field-line *ngIf="isSelectField(p)" [_select]=p (valueChanged)=onSelectLineChanged($event)> </select-field-line> </ng-template> </mat-card-content> diff --git a/src/app/components/field-set/field-set.component.ts b/src/app/components/field-set/field-set.component.ts index 889b28d60f4dc9f93d981e8536aeb1113eb9abc4..16298d652fe94b3d142e20cfe0a1670763fa5088 100644 --- a/src/app/components/field-set/field-set.component.ts +++ b/src/app/components/field-set/field-set.component.ts @@ -268,6 +268,14 @@ export class FieldSetComponent implements DoCheck { this.updateValidity(true); } + /** + * réception d'un événement de validité de SelectFieldLineComponent + */ + public onSelectLineChanged(value:any) { + this.updateValidity(true); + } + + /** * réception d'un événement de changement de valeur d'un input */ diff --git a/src/app/components/generic-select/generic-select.component.html b/src/app/components/generic-select/generic-select.component.html index 0a75a714e006ecb3a3a4b20d2e946762b82c5831..1597c621cad2b677c529a9ce9d6b71cb50c4cc08 100644 --- a/src/app/components/generic-select/generic-select.component.html +++ b/src/app/components/generic-select/generic-select.component.html @@ -1,5 +1,5 @@ <mat-form-field> - <mat-select [id]="selectId" [placeholder]="label" [(value)]="selectedValue" [multiple]="isMultiple"> + <mat-select [id]="selectId" [placeholder]="label" [(value)]="selectedValue" [multiple]="isMultiple" (selectionChange) ="onValueChange($event)"> <mat-select-trigger *ngIf="isMultiple"> {{ selectedValue && selectedValue[0] ? entryLabel(selectedValue[0]) : '' }} <span *ngIf="selectedValue?.length > 1" class="multiple-selection-label"> @@ -11,7 +11,7 @@ </mat-option> </mat-select> <button mat-button *ngIf="showClearButton" matSuffix mat-icon-button aria-label="Clear" - (click)="selectedValue=[]; $event.stopPropagation()"> + (click)="emptySelectedList($event)"> <mat-icon>close</mat-icon> </button> <div *ngIf="enableHelpButton" class="overlap-select"> diff --git a/src/app/components/results-chart/chart-type.component.ts b/src/app/components/results-chart/chart-type.component.ts index 123657c5173e1f09900f327f140c4cdd6eb3dc65..f8a7be771f6aaa774e37d516c46168e91908ffaf 100644 --- a/src/app/components/results-chart/chart-type.component.ts +++ b/src/app/components/results-chart/chart-type.component.ts @@ -1,4 +1,4 @@ -import { Component } from "@angular/core"; +import { Component, EventEmitter, Output } from "@angular/core"; import { IObservable, Observer } from "jalhyd"; import { I18nService } from "../../services/internationalisation.service"; import { ChartType } from "../../results/chart-type"; @@ -16,6 +16,9 @@ import { decodeHtml } from "../../util/util"; export class ChartTypeSelectComponent implements IObservable { private _select: SelectFieldChartType; + @Output() + private valueChanged = new EventEmitter(); + constructor(private intlService: I18nService) { this._select = new SelectFieldChartType(undefined, this.intlService); this._select.afterParseConfig(); // fill entries, set default value @@ -65,6 +68,10 @@ export class ChartTypeSelectComponent implements IObservable { return this._select.multiple; } + public onValueChange($event) { + this.selectedValue = $event.value + this.valueChanged.emit(this.selectedValue) + } // interface IObservable /** diff --git a/src/app/components/select-field-line/select-field-line.component.ts b/src/app/components/select-field-line/select-field-line.component.ts index 7c4b067efcece001ba65882f713c0e286d660f48..ddc5f24f8d411885deaa2aa51fd2e87b6bc6d383 100644 --- a/src/app/components/select-field-line/select-field-line.component.ts +++ b/src/app/components/select-field-line/select-field-line.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from "@angular/core"; +import { Component, DoCheck, EventEmitter, Input, OnInit, Output } from "@angular/core"; import { SelectField } from "../../formulaire/elements/select/select-field"; import { SelectEntry } from "../../formulaire/elements/select/select-entry"; @@ -21,17 +21,23 @@ export class SelectFieldLineComponent implements OnInit { @Input() private _select: SelectField; + /** + * événément de changement de valeur d'un select + */ + @Output() + private valueChanged = new EventEmitter(); + public constructor( private i18nService: I18nService, private appSetupService: ApplicationSetupService ) {} - + public get selectId() { return this._select.id; } public get isMultiple(): boolean { - return this._select.multiple; + return this._select.multiple; } public get entries(): SelectEntry[] { @@ -53,10 +59,32 @@ export class SelectFieldLineComponent implements OnInit { return this._select.getValue(); } + public onValueChange($event: any) { + this.selectedValue = $event.value + this.valueChanged.emit(this.selectedValue) + } + + public emptySelectedList($event:any) { + this.selectedValue = []; + this.valueChanged.emit(this.selectedValue) + $event.stopPropagation(); + } + public get isValid(): boolean { - return (this._select.getValue() !== undefined); + if(this._select.getValue() !== undefined) { + if(Object.keys(this._select.getValue()).length > 0) { + return true; + } + else { + return false + } + } + else { + return false + } } + public set selectedValue(v: SelectEntry | SelectEntry[]) { this._select.setValue(v); } diff --git a/src/app/formulaire/elements/select/select-field-species-list.ts b/src/app/formulaire/elements/select/select-field-species-list.ts index 7b94345aa073bbd77580775e01dfc5504d78fb64..7b02467586b34a6bae85efda95917b7600c47fc0 100644 --- a/src/app/formulaire/elements/select/select-field-species-list.ts +++ b/src/app/formulaire/elements/select/select-field-species-list.ts @@ -16,6 +16,7 @@ import { SelectField } from "./select-field"; export class SelectFieldSpeciesList extends SelectField { constructor(parent: FormulaireNode) { super(parent); + this._messageWhenEmpty = "INFO_VERIF_SELECT_SPECIES_FIRST"; this._multiple = true; } diff --git a/src/app/formulaire/elements/select/select-field.ts b/src/app/formulaire/elements/select/select-field.ts index b45f59c42d2581d536dc40659295cb86ed57cc62..b9145158089167b107a6d0b34fa612be39d7f297 100644 --- a/src/app/formulaire/elements/select/select-field.ts +++ b/src/app/formulaire/elements/select/select-field.ts @@ -82,7 +82,7 @@ export abstract class SelectField extends Field { || ( !Array.isArray(previousSelectedEntry) && !Array.isArray(v) - && previousSelectedEntry.id !== v.id + && previousSelectedEntry?.id !== v?.id ) || ( Array.isArray(previousSelectedEntry) @@ -292,9 +292,14 @@ export abstract class SelectField extends Field { return this._entriesBaseId; } + public isEmptySelectField() { + return this._selectedEntry !== undefined && Object.keys(this._selectedEntry).length === 0; + } + + public get messageWhenEmpty(): string { let msg: string; - if (this._selectedEntry === undefined && this._messageWhenEmpty) { + if ((this._selectedEntry === undefined && this._messageWhenEmpty) || this.isEmptySelectField()) { msg = ServiceFactory.i18nService.localizeText(this._messageWhenEmpty); } return msg; diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index 49d04bcaa7a4dbf5e72870eb669396dbf985576c..46a339559719ffa901ec289baac5ad631a0f81e8 100755 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -664,6 +664,7 @@ "INFO_TRIGO_DESCRIPTION": "cosinus sinus tangent arc maths mathematics", "INFO_TRIGO_TITRE_COURT": "Trigo. f.", "INFO_VERIF_CREATE_PASS_FRIST": "Create first a fish ladder, a baffle fishway or a rock-ramp fishpass", + "INFO_VERIF_SELECT_SPECIES_FIRST": "Select first one or several fish species", "INFO_VERIF_OK": "Crossing criteria are met for all species", "INFO_VERIF_VARYING_OK": "Crossing criteria are met for all species and all pass modalities", "WARNING_VERIF_OK_BUT": "Crossing criteria are met for all species, but there are warnings", diff --git a/src/locale/messages.fr.json b/src/locale/messages.fr.json index 764dfbbbf7eb42a5a05132f83ce0c5025c4123f2..d305b2ecc2cac74e19deac35def21553690daa1f 100755 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -665,6 +665,7 @@ "INFO_TRIGO_DESCRIPTION": "cosinus sinus tangente arc maths mathématiques", "INFO_TRIGO_TITRE_COURT": "F. trigo.", "INFO_VERIF_CREATE_PASS_FRIST": "Créer d'abord une passe à bassins, à ralentisseurs, ou à macrorugosités", + "INFO_VERIF_SELECT_SPECIES_FIRST": "Selectionner d'abord une ou plusieurs espèces", "INFO_VERIF_OK": "Les critères de franchissement sont remplis pour toutes les espèces", "INFO_VERIF_VARYING_OK": "Les critères de franchissement sont remplis pour toutes les espèces et toutes les modalités de la passe", "WARNING_VERIF_OK_BUT": "Les critères de franchissement sont remplis pour toutes les espèces, mais il y a des avertissements",