From f4d608e648c2348d97f748a146f7cf1fd8f66d56 Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Thu, 3 Sep 2020 14:57:30 +0200 Subject: [PATCH] Fix #448 - Verificateur: show explicit error when pass to check is empty add option "messageWhenEmpty" in SelectField --- src/app/calculators/verificateur/config.json | 3 ++- .../generic-select.component.html | 5 ++++- .../select-field-line.component.scss | 5 +++++ .../select-field-line.component.ts | 4 ++++ src/app/formulaire/elements/select-field.ts | 17 ++++++++++++++++- src/locale/messages.en.json | 1 + src/locale/messages.fr.json | 1 + 7 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/app/calculators/verificateur/config.json b/src/app/calculators/verificateur/config.json index ad7798eaa..438d2bf32 100644 --- a/src/app/calculators/verificateur/config.json +++ b/src/app/calculators/verificateur/config.json @@ -6,7 +6,8 @@ { "id": "select_target_pass", "type": "select_custom", - "source": "verificateur_target" + "source": "verificateur_target", + "messageWhenEmpty": "INFO_VERIF_CREATE_PASS_FRIST" } ] }, diff --git a/src/app/components/generic-select/generic-select.component.html b/src/app/components/generic-select/generic-select.component.html index 5dcaf95e7..9c6880e13 100644 --- a/src/app/components/generic-select/generic-select.component.html +++ b/src/app/components/generic-select/generic-select.component.html @@ -20,4 +20,7 @@ help </mat-icon> </div> -</mat-form-field> \ No newline at end of file +</mat-form-field> +<div *ngIf="messageWhenEmpty" class="message-when-empty"> + {{ messageWhenEmpty }} +</div> \ No newline at end of file diff --git a/src/app/components/select-field-line/select-field-line.component.scss b/src/app/components/select-field-line/select-field-line.component.scss index 2bd3e2765..923276964 100644 --- a/src/app/components/select-field-line/select-field-line.component.scss +++ b/src/app/components/select-field-line/select-field-line.component.scss @@ -13,3 +13,8 @@ mat-form-field { } } } + +.message-when-empty { + color: #af1280; // like mat-error + font-weight: 500; +} 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 b438c0256..eccc37a99 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 @@ -46,6 +46,10 @@ export class SelectFieldLineComponent implements OnInit { return this._select.entries; } + public get messageWhenEmpty(): string { + return this._select.messageWhenEmpty; + } + protected entryLabel(entry: SelectEntry): string { return decodeHtml(entry.label); } diff --git a/src/app/formulaire/elements/select-field.ts b/src/app/formulaire/elements/select-field.ts index 0884f2564..d003d2a6d 100644 --- a/src/app/formulaire/elements/select-field.ts +++ b/src/app/formulaire/elements/select-field.ts @@ -35,9 +35,15 @@ export class SelectField extends Field { /** if true, select box is grayed out */ public disabled = false; - /** soruce identifier for populating with available values */ + /** source identifier for populating with available values */ protected source: string; + /** + * message to display below the select field when no option is selected, + * if this message is defined and not empty + */ + protected _messageWhenEmpty: string; + constructor(parent: FormulaireNode) { super(parent); this.clearEntries(); @@ -63,6 +69,14 @@ export class SelectField extends Field { return this._multiple; } + public get messageWhenEmpty(): string { + let msg: string; + if (this._selectedEntry === undefined && this._messageWhenEmpty) { + msg = ServiceFactory.i18nService.localizeText(this._messageWhenEmpty); + } + return msg; + } + public clearEntries() { this._entries = []; } @@ -145,6 +159,7 @@ export class SelectField extends Field { this._helpLink = field["help"]; this._associatedProperty = field["property"]; this._defaultValue = field["default"]; + this._messageWhenEmpty = field["messageWhenEmpty"]; if (field["multiple"] !== undefined) { this._multiple = field["multiple"]; } diff --git a/src/locale/messages.en.json b/src/locale/messages.en.json index acbc4c150..d65e11830 100644 --- a/src/locale/messages.en.json +++ b/src/locale/messages.en.json @@ -606,6 +606,7 @@ "INFO_TRIGO_TITRE": "Trigonometric function", "INFO_TRIGO_DESCRIPTION": "cosinus sinus tangent arc", "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_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 2fe2697aa..6804b1975 100644 --- a/src/locale/messages.fr.json +++ b/src/locale/messages.fr.json @@ -607,6 +607,7 @@ "INFO_TRIGO_TITRE": "Fonction trigonométrique", "INFO_TRIGO_DESCRIPTION": "cosinus sinus tangente arc", "INFO_TRIGO_TITRE_COURT": "F. trigo.", + "INFO_VERIF_CREATE_PASS_FRIST": "Créer d'abord une passe à bassins, à ralentisseurs, ou à macrorugosités", "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", -- GitLab