Skip to content
Snippets Groups Projects
Commit 0dbd6ec8 authored by Mathias Chouet's avatar Mathias Chouet Committed by mathias.chouet
Browse files

Verificateur

PAB jet type is disabled when target pass is not a PAB
Species list selection is ordered
parent b117b79e
No related branches found
No related tags found
No related merge requests found
<mat-form-field>
<mat-select [id]="selectId" [placeholder]="label" [(value)]="selectedValue" [multiple]="isMultiple">
<mat-select [id]="selectId" [placeholder]="label" [(value)]="selectedValue" [multiple]="isMultiple" [disabled]="isDisabled">
<mat-select-trigger *ngIf="isMultiple">
{{ selectedValue && selectedValue[0] ? selectedValue[0].label : '' }}
{{ sortedSelectedValues && sortedSelectedValues[0] ? sortedSelectedValues[0].label : '' }}
<span *ngIf="selectedValue?.length > 1" class="multiple-selection-label">
(+ {{ selectedValue.length - 1 }} {{ selectedValue?.length === 2 ? uitextAndOther : uitextAndOthers }})
</span>
......
......@@ -57,6 +57,10 @@ export class ChartTypeSelectComponent implements IObservable {
return false;
}
public get isDisabled(): boolean {
return false;
}
public get showClearButton(): boolean {
return false;
}
......
......@@ -34,6 +34,10 @@ export class SelectFieldLineComponent implements OnInit {
return this._select.multiple;
}
public get isDisabled(): boolean {
return this._select.disabled;
}
public get entries(): SelectEntry[] {
if (! this._select) {
return [];
......@@ -49,6 +53,33 @@ export class SelectFieldLineComponent implements OnInit {
return this._select.getValue();
}
/**
* Present selected values in a meaningful order, for multiple select box label (… + n others)
*/
public get sortedSelectedValues(): SelectEntry[] {
let ssv: any[] = undefined;
if (Array.isArray(this.selectedValue)) {
ssv = JSON.parse(JSON.stringify(this.selectedValue)); // array copy
ssv.sort((a, b) => {
// numbers ?
if (! isNaN(Number(a._value)) && ! isNaN(Number(b._value))) {
return (Number(a._value) > Number(b._value)) ? 1 : ((Number(b._value) > Number(a._value)) ? -1 : 0)
} else {
// numbers after strings @TODO convenient for Verificateur/SpeciesList, but elsewhere ?
if (! isNaN(Number(a._value))) {
return 1;
} else if (! isNaN(Number(b._value))) {
return -1;
} else {
// keep original order
return 0;
}
}
});
}
return ssv;
}
public get isValid(): boolean {
return (this._select.getValue() !== undefined);
}
......
......@@ -38,7 +38,7 @@ export class FormulaireSolveur extends FormulaireFixedVar {
// interface Observer
public update(sender: IObservable, data: any) {
// copied from FormDefinition, to avoid calling super.update()
// copied from FormDefinition, to avoid calling super.update() that would trigger an unwanted this.refreshFieldsets();
if (sender instanceof Nub) {
switch (data.action) {
case "resultUpdated":
......
import { IObservable, Nub, Verificateur } from "jalhyd";
import { IObservable, Nub, Verificateur, CalculatorType } from "jalhyd";
import { SelectFieldCustom } from "../elements/select-field-custom";
import { SelectField } from '../elements/select-field';
import { FormulaireFixedVar } from "./form-fixedvar";
/**
......@@ -11,7 +12,7 @@ export class FormulaireVerificateur extends FormulaireFixedVar {
// interface Observer
public update(sender: IObservable, data: any) {
// copied from FormDefinition, to avoid calling super.update()
// copied from FormDefinition, to avoid calling super.update() that would trigger an unwanted this.refreshFieldsets();
if (sender instanceof Nub) {
switch (data.action) {
case "resultUpdated":
......@@ -25,13 +26,14 @@ export class FormulaireVerificateur extends FormulaireFixedVar {
this.reset();
}
console.log("> update", data, sender.constructor.name);
if (sender instanceof SelectFieldCustom) {
if (sender.id === "select_target_pass" && data.action === "select") {
// update Verificateur property: Pass to check
this._currentNub.properties.setPropValue("nubToVerify", data.value);
// @TODO refresh jet type selector
this._currentNub.properties.setPropValue("nubToVerify", data.value ? data.value.value : undefined);
// refresh jet type selector
const ntv = (this._currentNub as Verificateur).nubToVerify;
(this.getFormulaireNodeById("select_pab_jet_type") as SelectField).disabled = ! (ntv !== undefined && ntv.calcType === CalculatorType.Pab);
} else if (sender.id === "select_species_list" && data.action === "select") {
// update Verificateur property: Species list (string[])
this._currentNub.properties.setPropValue("speciesList", data.value.map((v: any) => v.value));
......
......@@ -122,7 +122,6 @@ export class SelectFieldCustom extends SelectField {
break;
case "verificateur_species":
console.log("[i] loading verif species");
// add UIDs of all Espece type Nubs in the session
const especeNubs = Session.getInstance().getAllNubs().filter((element) => element.calcType === CalculatorType.Espece);
for (const en of especeNubs) {
......@@ -208,10 +207,6 @@ export class SelectFieldCustom extends SelectField {
*/
public setValue(v: SelectEntry | SelectEntry[]) {
const previousSelectedEntry = this._selectedEntry;
/* if (Array.isArray(v)) {
// keep selection ordered
v.sort((a,b) => (a.value > b.value) ? -1 : ((b.value > a.value) ? 1 : 0));
} */
this._selectedEntry = v;
// if value changed
let valueChanged = (
......
......@@ -33,6 +33,9 @@ export class SelectField extends Field {
/** if true, user can select multiple values */
protected _multiple = false;
/** if true, select box is grayed out */
public disabled = false;
/** soruce identifier for populating with available values */
protected source: string;
......@@ -101,7 +104,6 @@ export class SelectField extends Field {
}
public notifyValueChanged() {
console.log("NOT VAL CHA", this.id, this._selectedEntry)
this.notifyObservers({
"action": "select",
"value": this._selectedEntry
......
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