Skip to content
Snippets Groups Projects
Commit 0cc1b539 authored by Mathias Chouet's avatar Mathias Chouet
Browse files

Work on GUI for Verificateur

parent 0baeaf47
No related branches found
No related tags found
No related merge requests found
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
{ {
"type": "select", "type": "select",
"id": "select_species_list", "id": "select_species_list",
"default": "SPECIES_1",
"source": "verificateur_species", "source": "verificateur_species",
"multiple": true "multiple": true
} }
......
...@@ -3,13 +3,17 @@ ...@@ -3,13 +3,17 @@
<mat-select-trigger *ngIf="isMultiple"> <mat-select-trigger *ngIf="isMultiple">
{{ selectedValue && selectedValue[0] ? selectedValue[0].label : '' }} {{ selectedValue && selectedValue[0] ? selectedValue[0].label : '' }}
<span *ngIf="selectedValue?.length > 1" class="multiple-selection-label"> <span *ngIf="selectedValue?.length > 1" class="multiple-selection-label">
(+ {{selectedValue.length - 1}} {{selectedValue?.length === 2 ? 'other' : 'others'}}) (+ {{ selectedValue.length - 1 }} {{ selectedValue?.length === 2 ? uitextAndOther : uitextAndOthers }})
</span> </span>
</mat-select-trigger> </mat-select-trigger>
<mat-option *ngFor="let e of entries" [value]="e" [title]="entryLabel(e)"> <mat-option *ngFor="let e of entries" [value]="e" [title]="entryLabel(e)">
{{ entryLabel(e) }} {{ entryLabel(e) }}
</mat-option> </mat-option>
</mat-select> </mat-select>
<button mat-button *ngIf="showClearButton" matSuffix mat-icon-button
aria-label="Clear" (click)="selectedValue=[]; $event.stopPropagation()">
<mat-icon>close</mat-icon>
</button>
<div *ngIf="enableHelpButton" class="overlap-select"> <div *ngIf="enableHelpButton" class="overlap-select">
<mat-icon id="help-select" (click)="openHelp($event)" [title]="uitextOpenHelp" color="accent"> <mat-icon id="help-select" (click)="openHelp($event)" [title]="uitextOpenHelp" color="accent">
help help
......
...@@ -57,6 +57,10 @@ export class ChartTypeSelectComponent implements IObservable { ...@@ -57,6 +57,10 @@ export class ChartTypeSelectComponent implements IObservable {
return false; return false;
} }
public get showClearButton(): boolean {
return false;
}
public get label() { public get label() {
return this.intlService.localizeText("INFO_PARAMFIELD_CHART_TYPE"); return this.intlService.localizeText("INFO_PARAMFIELD_CHART_TYPE");
} }
......
...@@ -97,13 +97,27 @@ export class SelectFieldLineComponent implements OnInit { ...@@ -97,13 +97,27 @@ export class SelectFieldLineComponent implements OnInit {
return false; return false;
} }
public get showClearButton(): boolean {
return this.isMultiple && this.selectedValue && ! (Array.isArray(this.selectedValue) && this.selectedValue.length === 0);
}
public get uitextOpenHelp() { public get uitextOpenHelp() {
return this.i18nService.localizeText("INFO_CALCULATOR_OPEN_HELP"); return this.i18nService.localizeText("INFO_CALCULATOR_OPEN_HELP");
} }
public get uitextAndOther() {
return this.i18nService.localizeText("INFO_SELECT_MULTIPLE_AND_OTHER");
}
public get uitextAndOthers() {
return this.i18nService.localizeText("INFO_SELECT_MULTIPLE_AND_OTHERS");
}
// called every time we navigate to the module // called every time we navigate to the module
ngOnInit(): void { ngOnInit(): void {
console.log("> ngOnInit()", this.selectId);
if (this._select instanceof SelectFieldReference) { if (this._select instanceof SelectFieldReference) {
console.log(">> updateEntries() !", this.selectId);
this._select.updateEntries(); this._select.updateEntries();
} }
} }
......
...@@ -2,6 +2,8 @@ import { SelectField } from "./select-field"; ...@@ -2,6 +2,8 @@ import { SelectField } from "./select-field";
import { SelectEntry } from "./select-entry"; import { SelectEntry } from "./select-entry";
import { FormulaireNode } from "./formulaire-node"; import { FormulaireNode } from "./formulaire-node";
import { arraysAreEqual } from "../../util";
/** /**
* A select field that populates itself with references to * A select field that populates itself with references to
* available objects (for ex. Nub or ParamDefinition) * available objects (for ex. Nub or ParamDefinition)
...@@ -46,7 +48,7 @@ export abstract class SelectFieldReference extends SelectField { ...@@ -46,7 +48,7 @@ export abstract class SelectFieldReference extends SelectField {
// if no entry is available anymore, unset value // if no entry is available anymore, unset value
if (this.entries.length === 0) { if (this.entries.length === 0) {
if (this.multiple) { if (this.multiple) {
super.setValue([ undefined ]); super.setValue([]);
} else { } else {
super.setValue(undefined); super.setValue(undefined);
} }
...@@ -64,16 +66,24 @@ export abstract class SelectFieldReference extends SelectField { ...@@ -64,16 +66,24 @@ export abstract class SelectFieldReference extends SelectField {
* Updates selectedValue; notifies observers only if * Updates selectedValue; notifies observers only if
* value.id has changed * value.id has changed
*/ */
public setValue(v: SelectEntry) { public setValue(v: SelectEntry | SelectEntry[]) {
const previousSelectedEntry = this._selectedEntry; const previousSelectedEntry = this._selectedEntry;
this._selectedEntry = v; this._selectedEntry = v;
if ( // if value changed
let valueChanged = (
! previousSelectedEntry ! previousSelectedEntry
|| ( // @TODO manage multiple values || (
! Array.isArray(previousSelectedEntry) ! Array.isArray(previousSelectedEntry)
&& ! Array.isArray(v)
&& previousSelectedEntry.id !== v.id && previousSelectedEntry.id !== v.id
) )
) { || (
Array.isArray(previousSelectedEntry)
&& Array.isArray(v)
&& arraysAreEqual(previousSelectedEntry, v, "id", true)
)
);
if (valueChanged) {
this.notifySelectValueChanged(); this.notifySelectValueChanged();
} }
} }
...@@ -94,7 +104,11 @@ export abstract class SelectFieldReference extends SelectField { ...@@ -94,7 +104,11 @@ export abstract class SelectFieldReference extends SelectField {
for (const e of this._entries) { for (const e of this._entries) {
if (e.id === id) { if (e.id === id) {
found = true; found = true;
this.setValue(e); if (this._multiple) {
this.setValue([ e ]);
} else {
this.setValue(e);
}
} }
} }
if (! found) { if (! found) {
...@@ -105,7 +119,11 @@ export abstract class SelectFieldReference extends SelectField { ...@@ -105,7 +119,11 @@ export abstract class SelectFieldReference extends SelectField {
protected setDefaultValue() { protected setDefaultValue() {
// default to first available entry if any // default to first available entry if any
if (this._entries.length > 0) { if (this._entries.length > 0) {
this.setValue(this._entries[0]); if (this._multiple) {
this.setValue([ this._entries[0] ]);
} else {
this.setValue(this._entries[0]);
}
} else { } else {
// notify observers that no value is selected anymore // notify observers that no value is selected anymore
this.notifySelectValueChanged(); this.notifySelectValueChanged();
......
...@@ -67,7 +67,11 @@ export class SelectField extends Field { ...@@ -67,7 +67,11 @@ export class SelectField extends Field {
public addEntry(e: SelectEntry) { public addEntry(e: SelectEntry) {
this._entries.push(e); this._entries.push(e);
if (! this._selectedEntry) { if (! this._selectedEntry) {
this.setValue(e); if (this._multiple) {
this.setValue([ e ]);
} else {
this.setValue(e);
}
} }
} }
...@@ -205,9 +209,11 @@ export class SelectField extends Field { ...@@ -205,9 +209,11 @@ export class SelectField extends Field {
} }
break; break;
// possible values depend on Session
case "verificateur_species": case "verificateur_species":
// add UIDs of all Espece type Nubs in the session // add UIDs of all Espece type Nubs in the session
const especeNubs = Session.getInstance().getAllNubs().filter((element) => element.calcType === CalculatorType.Espece); const especeNubs = Session.getInstance().getAllNubs().filter((element) => element.calcType === CalculatorType.Espece);
console.log("especeNubs", especeNubs);
for (const en of especeNubs) { for (const en of especeNubs) {
this.addEntry(new SelectEntry(en.uid, en.uid, "Espèce personnalisée : " + en.uid)); this.addEntry(new SelectEntry(en.uid, en.uid, "Espèce personnalisée : " + en.uid));
} }
......
...@@ -161,3 +161,25 @@ export function generateValuesCombination( ...@@ -161,3 +161,25 @@ export function generateValuesCombination(
return formula(nub, vals); return formula(nub, vals);
} }
} }
export function arraysAreEqual(arrayA: any[], arrayB: any[], property?: string, sort = false): boolean {
if (sort) {
arrayA.sort((a, b) => a-b);
arrayB.sort((a, b) => a-b);
}
let equal = true;
if (arrayA.length === arrayB.length) {
for (let i=0; i < arrayA.length; i++) {
const eA = arrayA[i];
const eB = arrayB[i];
if (property === undefined) {
equal = equal && (eA === eB);
} else {
equal = equal && (eA[property] === eB[property]);
}
}
} else {
equal = false;
}
return equal;
}
...@@ -450,6 +450,8 @@ ...@@ -450,6 +450,8 @@
"INFO_RESULTS_EXPORT_AS_SPREADSHEET": "Export as XLSX", "INFO_RESULTS_EXPORT_AS_SPREADSHEET": "Export as XLSX",
"INFO_SECTIONPARAMETREE_TITRE_COURT": "Param. section", "INFO_SECTIONPARAMETREE_TITRE_COURT": "Param. section",
"INFO_SECTIONPARAMETREE_TITRE": "Parametric section", "INFO_SECTIONPARAMETREE_TITRE": "Parametric section",
"INFO_SELECT_MULTIPLE_AND_OTHER": "other",
"INFO_SELECT_MULTIPLE_AND_OTHERS": "others",
"INFO_SETUP_ENABLE_HOTKEYS": "Enable keyboard shortcuts", "INFO_SETUP_ENABLE_HOTKEYS": "Enable keyboard shortcuts",
"INFO_SETUP_ENABLE_EMPTY_FIELDS": "Create new calculators with empty fields (no default values)", "INFO_SETUP_ENABLE_EMPTY_FIELDS": "Create new calculators with empty fields (no default values)",
"INFO_SETUP_ENABLE_NOTIFICATIONS": "Enable on-screen notifications", "INFO_SETUP_ENABLE_NOTIFICATIONS": "Enable on-screen notifications",
......
...@@ -450,6 +450,8 @@ ...@@ -450,6 +450,8 @@
"INFO_RESULTS_EXPORT_AS_SPREADSHEET": "Exporter en XLSX", "INFO_RESULTS_EXPORT_AS_SPREADSHEET": "Exporter en XLSX",
"INFO_SECTIONPARAMETREE_TITRE_COURT": "Sec. param.", "INFO_SECTIONPARAMETREE_TITRE_COURT": "Sec. param.",
"INFO_SECTIONPARAMETREE_TITRE": "Section paramétrée", "INFO_SECTIONPARAMETREE_TITRE": "Section paramétrée",
"INFO_SELECT_MULTIPLE_AND_OTHER": "autre",
"INFO_SELECT_MULTIPLE_AND_OTHERS": "autres",
"INFO_SETUP_ENABLE_HOTKEYS": "Activer les raccourcis clavier", "INFO_SETUP_ENABLE_HOTKEYS": "Activer les raccourcis clavier",
"INFO_SETUP_ENABLE_EMPTY_FIELDS": "Créer les nouveaux modules avec des champs vides (aucune valeur par défaut)", "INFO_SETUP_ENABLE_EMPTY_FIELDS": "Créer les nouveaux modules avec des champs vides (aucune valeur par défaut)",
"INFO_SETUP_ENABLE_NOTIFICATIONS": "Activer les notifications à l'écran", "INFO_SETUP_ENABLE_NOTIFICATIONS": "Activer les notifications à l'écran",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment