diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 3367199a616e52e5bead36943bb476fd693e52c1..40aa77006062c34a062626f1b0b6791c5f971a7f 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -89,6 +89,7 @@ import { JalhydModelValidationStepDirective } from "./directives/jalhyd-model-validation.directive"; import { ImmediateErrorStateMatcher } from "./formulaire/immediate-error-state-matcher"; +import { SelectCloisonsFieldLineComponent } from "./components/select-cloisons-field-line/select-cloisons-field-line.component"; const appRoutes: Routes = [ { path: "list", component: CalculatorListComponent }, @@ -176,6 +177,7 @@ const appRoutes: Routes = [ SectionCanvasComponent, SectionResultsComponent, SelectFieldLineComponent, + SelectCloisonsFieldLineComponent, VarResultsComponent ], entryComponents: [ diff --git a/src/app/components/field-set/field-set.component.html b/src/app/components/field-set/field-set.component.html index 0dea7034b85852407812e4aea01b96e592239fc6..81765bfc50bd8aec908e3eef13e69ecb278fb675 100644 --- a/src/app/components/field-set/field-set.component.html +++ b/src/app/components/field-set/field-set.component.html @@ -26,5 +26,8 @@ <select-field-line *ngIf="isSelectField(p)" [_select]=p> </select-field-line> + + <select-cloisons-field-line *ngIf="isSelectCloisonsField(p)" [_select]=p> + </select-cloisons-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 bb3c51de86b46f5a931fee54cf659e553c1b8fa4..30ae96fea44b4d6d68d78d0a9013b7c586ea12ac 100644 --- a/src/app/components/field-set/field-set.component.ts +++ b/src/app/components/field-set/field-set.component.ts @@ -6,6 +6,7 @@ import { ParamFieldLineComponent } from "../param-field-line/param-field-line.co import { Field } from "../../formulaire/field"; import { InputField } from "../../formulaire/input-field"; import { SelectField } from "../../formulaire/select-field"; +import { FormulairePab } from "../../formulaire/definition/concrete/form-pab"; @Component({ selector: "field-set", @@ -172,7 +173,22 @@ export class FieldSetComponent implements DoCheck { * détermine si un Field est du type SelectField */ private isSelectField(f: Field): boolean { - return f instanceof SelectField && f.isDisplayed; + return ( + f instanceof SelectField + && ! (f.parentForm instanceof FormulairePab) + && f.isDisplayed + ); + } + + /** + * détermine si un Field est du type SelectField + */ + private isSelectCloisonsField(f: Field): boolean { + return ( + f instanceof SelectField + && f.parentForm instanceof FormulairePab + && f.id === (f.parentForm as FormulairePab).modeleCloisonsSelectId + ); } /* diff --git a/src/app/components/select-cloisons-field-line/select-cloisons-field-line.component.html b/src/app/components/select-cloisons-field-line/select-cloisons-field-line.component.html new file mode 100644 index 0000000000000000000000000000000000000000..928f0d55a6ed3c69ff7c067a707760f0ad8fd23e --- /dev/null +++ b/src/app/components/select-cloisons-field-line/select-cloisons-field-line.component.html @@ -0,0 +1,21 @@ +<div class="container" fxLayout="row wrap" fxLayoutAlign="space-between start"> + + <!-- input de saisie de la valeur --> + <div fxFlex="1 0 120px"> + + <mat-form-field> + <mat-select [id]="selectId" [name]="selectId" [placeholder]="label" [(value)]="selectedValue" required> + <mat-option *ngFor="let e of entries" [value]="e"> + {{ selectItemLabel(e) }} + </mat-option> + </mat-select> + </mat-form-field> + </div> + + <div class="button-container" fxFlex="0 0 auto"> + <button mat-icon-button [disabled]="! selectedValue" [routerLink]="['/calculator/', cloisonsUid]"> + <mat-icon>settings</mat-icon> + </button> + </div> + +</div> \ No newline at end of file diff --git a/src/app/components/select-cloisons-field-line/select-cloisons-field-line.component.scss b/src/app/components/select-cloisons-field-line/select-cloisons-field-line.component.scss new file mode 100644 index 0000000000000000000000000000000000000000..3e2afd4a860a04c7c28b5210134abff63d141014 --- /dev/null +++ b/src/app/components/select-cloisons-field-line/select-cloisons-field-line.component.scss @@ -0,0 +1,33 @@ +mat-form-field { + width: calc(100% - 8px); + margin-right: 8px; + + mat-select { + + ::ng-deep .mat-select-value { + > span { + > span { + line-height: 1.3em; + } + } + } + } + + ::ng-deep .mat-form-field-label { + font-size: 1.1em; + line-height: 1.4em; + margin-top: -2px; + + &.mat-form-field-empty { + font-size: 1em; + } + } +} + +.button-container { + text-align: right; + + button { + margin-top: 4px; + } +} diff --git a/src/app/components/select-cloisons-field-line/select-cloisons-field-line.component.ts b/src/app/components/select-cloisons-field-line/select-cloisons-field-line.component.ts new file mode 100644 index 0000000000000000000000000000000000000000..57b10fd86e1b61e10232ec16e6e71b6f2a9d140b --- /dev/null +++ b/src/app/components/select-cloisons-field-line/select-cloisons-field-line.component.ts @@ -0,0 +1,63 @@ +import { Component, Input } from "@angular/core"; + +import { SelectField } from "../../formulaire/select-field"; +import { SelectEntry } from "../../formulaire/select-entry"; +import { FormulaireService } from "../../services/formulaire/formulaire.service"; + +@Component({ + selector: "select-cloisons-field-line", + templateUrl: "./select-cloisons-field-line.component.html", + styleUrls: [ + "./select-cloisons-field-line.component.scss" + ] +}) +export class SelectCloisonsFieldLineComponent { + @Input() + private _select: SelectField; + + public constructor( + private formulaireService: FormulaireService + ) { } + + public get selectId() { + return this._select.id; + } + + public get entries(): SelectEntry[] { + if (! this._select) { + return []; + } + return this._select.entries; + } + + public get cloisonsUid() { + return this.selectedValue ? this.selectedValue.id : ""; + } + + /** + * Label d'une entrée du select des modèles de cloisons + */ + public selectItemLabel(entry: SelectEntry): string { + if (entry && entry.id) { + const cloisonsForm = this.formulaireService.getFormulaireFromNubId(entry.id); + const name = cloisonsForm.calculatorName; + return name; + } + } + + public get selectedValue(): SelectEntry { + return this._select.getValue(); + } + + public set selectedValue(v: SelectEntry) { + this._select.setValue(v); + } + + public get label() { + if (this._select) { + return this._select.label; + } else { + return ""; + } + } +} diff --git a/src/app/formulaire/definition/concrete/form-pab.ts b/src/app/formulaire/definition/concrete/form-pab.ts index cb329818d2c5e29c3593f177381008191c8aa7ec..dae59761149efad1a952e359e60311a90b30d752 100644 --- a/src/app/formulaire/definition/concrete/form-pab.ts +++ b/src/app/formulaire/definition/concrete/form-pab.ts @@ -1,6 +1,5 @@ -import { Structure, Nub, ParallelStructure, StructureProperties, Props, Session, PabCloisons, Pab } from "jalhyd"; +import { Nub, Props, Session, PabCloisons, Pab } from "jalhyd"; -import { FormComputeParallelStructures } from "../form-compute-parallel-structures"; import { FormResultFixedVar } from "../form-result-fixedvar"; import { FieldsetContainer } from "../../fieldset-container"; import { FieldSet } from "../../fieldset"; @@ -9,6 +8,8 @@ import { NgParameter } from "../../ngparam"; import { FieldsetTemplate } from "../../fieldset-template"; import { FormulaireNode } from "../../formulaire-node"; import { FormulaireBase } from "./form-base"; +import { FormComputePab } from "../form-compute-pab"; +import { SelectEntry } from "../../select-entry"; /** * Formulaire pour les passes à bassins, inspiré du formulaire @@ -17,7 +18,7 @@ import { FormulaireBase } from "./form-base"; export class FormulairePab extends FormulaireBase { /** id du select configurant le modèle de cloisons */ - private __modeleCloisonsSelectId: string; + private _modeleCloisonsSelectId: string; constructor() { super(); @@ -25,7 +26,11 @@ export class FormulairePab extends FormulaireBase { // remove obsolete observer set by super() this.removeObserver(this._formCompute); - this._formCompute = new FormComputeParallelStructures(this, (this._formResult as FormResultFixedVar)); + this._formCompute = new FormComputePab(this, (this._formResult as FormResultFixedVar)); + } + + public get modeleCloisonsSelectId(): string { + return this._modeleCloisonsSelectId; } private createPabCloisons(templ: FieldsetTemplate): Nub { @@ -42,16 +47,15 @@ export class FormulairePab extends FormulaireBase { } /** - * ajoute un Nub Structure - * @param st structure à ajouter + * ajoute un Nub PabCloisons * @param after position après laquelle insérer la structure, à la fin sinon */ - private addPabCloisons(st: Structure, after?: number) { - this.parallelStructureNub.addChild(st, after); + private addPabCloisons(st: PabCloisons, after?: number) { + this.pabNub.addChild(st, after); } - private get parallelStructureNub(): ParallelStructure { - return this.currentNub as ParallelStructure; + private get pabNub(): Pab { + return this.currentNub as Pab; } /** @@ -67,7 +71,7 @@ export class FormulairePab extends FormulaireBase { * Replaces the current Nub in the current calculator module, with a new one built with properties "params" * @param params properties to build the new Nub (calcType, loiDebit...) */ - protected replaceNub(sn: Structure, params: Props): Nub { + protected replaceNub(sn: PabCloisons, params: Props): Nub { const parent = (this.currentNub as PabCloisons); const newBassin = this.createBassin(params); parent.replaceChildInplace(sn, newBassin); @@ -78,15 +82,13 @@ export class FormulairePab extends FormulaireBase { * Deleted the given child Nub in the current calculator module * @param params properties to build the new Nub (calcType, loiDebit...) */ - protected deleteNub(sn: Structure) { + protected deleteNub(sn: PabCloisons) { const parent = (this.currentNub as PabCloisons); parent.deleteChild(parent.getIndexForChild(sn)); } public createFieldset(parent: FormulaireNode, json: {}, data?: {}, nub?: Nub): FieldSet { - console.log("++++++++++ CREATE FIELDSET +++++++++++", parent.constructor.name, json, data, nub ? nub.constructor.name : "zizi"); if (json["calcType"] === "PabCloisons") { - console.log("youpidou"); // indice après lequel insérer le nouveau FieldSet const after = data["after"]; @@ -96,7 +98,7 @@ export class FormulairePab extends FormulaireBase { n = nub; } else { n = this.createPabCloisons(data["template"]); - this.addPabCloisons(n as Structure, after); + this.addPabCloisons(n as PabCloisons, after); } res.setNub(n, false); @@ -116,16 +118,17 @@ export class FormulairePab extends FormulaireBase { protected parseOptions(json: {}) { super.parseOptions(json); - // id du select configurant le type d'ouvrage - this.__modeleCloisonsSelectId = this.getOption(json, "ouvrageSelectId"); + this._modeleCloisonsSelectId = this.getOption(json, "modeleCloisonsSelectId"); } public afterParseFieldset(fs: FieldSet) { + console.log("_________ afterParseFieldset()"); // si le FieldSet contient le select de type d'ouvrage - if (this.__modeleCloisonsSelectId) { - const sel = fs.getFormulaireNodeById(this.__modeleCloisonsSelectId); + if (this._modeleCloisonsSelectId) { + const sel = (fs.getFormulaireNodeById(this._modeleCloisonsSelectId) as SelectField); if (sel) { + this.populateSelect(); // on abonne le formulaire aux propriétés du FieldSet fs.properties.addObserver(this); } @@ -133,7 +136,7 @@ export class FormulairePab extends FormulaireBase { } public moveFieldsetUp(fs: FieldSet) { - if (fs.nub instanceof Structure) { + if (fs.nub instanceof PabCloisons) { // déplacement du nub fs.nub.parent.moveChildUp(fs.nub); // déplacement du fieldset @@ -146,18 +149,20 @@ export class FormulairePab extends FormulaireBase { } public moveFieldsetDown(fs: FieldSet) { - if (fs.nub instanceof Structure) { + if (fs.nub instanceof PabCloisons) { // déplacement du nub fs.nub.parent.moveChildDown(fs.nub); // déplacement du fieldset this.fieldsetContainer.moveFieldsetDown(fs); this.resetResults(); - } else { super.moveFieldsetDown(fs); } + } else { + super.moveFieldsetDown(fs); + } } public removeFieldset(fs: FieldSet) { - if (fs.nub instanceof Structure) { + if (fs.nub instanceof PabCloisons) { // suppression du sous-nub dans le Nub parent this.deleteNub(fs.nub); @@ -165,13 +170,28 @@ export class FormulairePab extends FormulaireBase { this.fieldsetContainer.removeFieldset(fs); this.resetResults(); - } else { super.removeFieldset(fs); } + } else { + super.removeFieldset(fs); + } } protected completeParse(json: {}) { this.subscribeFieldsetContainer(); } + private populateSelect() { + console.log("______ POPULATE SELECT _____"); + const sel = (this.getFormulaireNodeById(this._modeleCloisonsSelectId) as SelectField); + // peuplement du select par les Cloisons disponibles + const cloisonsNubs = Session.getInstance().getCloisonsNubs(); + console.log(">> cloisons dispo", cloisonsNubs.length, cloisonsNubs); + for (const cl of cloisonsNubs) { + const e = new SelectEntry(cl.uid, cl); // label is displayed later by select-cloisons-field-line-component + console.log("SEL ENTR", e); + sel.addEntry(e); + } + } + private get fieldsetContainer(): FieldsetContainer { const n = this.getFormulaireNodeById("bassin_container"); if (n === undefined || !(n instanceof FieldsetContainer)) {