diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 8509d10d659747afc9c1163d6986006598ee6060..fd0349151d4610e6ea46009b6f6413ee34d6a268 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -82,7 +82,6 @@ import { FixedResultsComponent } from "./components/fixedvar-results/fixed-resul import { VarResultsComponent } from "./components/fixedvar-results/var-results.component"; import { LogEntryComponent } from "./components/log-entry/log-entry.component"; import { ParamLinkComponent } from "./components/param-link/param-link.component"; -import { SelectModelFieldLineComponent } from "./components/select-model-field-line/select-model-field-line.component"; import { PabProfileChartComponent } from "./components/pab-profile-chart/pab-profile-chart.component"; import { PabTableComponent } from "./components/pab-table/pab-table.component"; import { VariableResultsSelectorComponent } from "./components/variable-results-selector/variable-results-selector.component"; @@ -229,7 +228,6 @@ const appRoutes: Routes = [ SectionCanvasComponent, SectionResultsComponent, SelectFieldLineComponent, - SelectModelFieldLineComponent, SessionPropertiesComponent, VarResultsComponent ], diff --git a/src/app/components/select-model-field-line/select-model-field-line.component.html b/src/app/components/select-model-field-line/select-model-field-line.component.html deleted file mode 100644 index e85ced8afc0a379e6b71eb12bae14d907f8ea3c7..0000000000000000000000000000000000000000 --- a/src/app/components/select-model-field-line/select-model-field-line.component.html +++ /dev/null @@ -1,24 +0,0 @@ -<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" [title]="selectItemLabel(e)"> - {{ selectItemLabel(e) }} - </mat-option> - </mat-select> - </mat-form-field> - </div> - - <div class="button-container" fxFlex="0 0 auto"> - <button type="button" mat-icon-button *ngIf="selectedValue" [routerLink]="['/calculator/', modelUid]"> - <mat-icon>edit</mat-icon> - </button> - <button type="button" mat-icon-button *ngIf="entries.length === 0" (click)="createModel()" id="create-model"> - <mat-icon>add</mat-icon> - </button> - </div> - -</div> \ No newline at end of file diff --git a/src/app/components/select-model-field-line/select-model-field-line.component.scss b/src/app/components/select-model-field-line/select-model-field-line.component.scss deleted file mode 100644 index a7a72dfa5fe7aded324cfbd83dbb9e9e40f9a1e3..0000000000000000000000000000000000000000 --- a/src/app/components/select-model-field-line/select-model-field-line.component.scss +++ /dev/null @@ -1,12 +0,0 @@ -mat-form-field { - width: calc(100% - 8px); - margin-right: 8px; -} - -.button-container { - text-align: right; - - button { - margin-top: 4px; - } -} diff --git a/src/app/components/select-model-field-line/select-model-field-line.component.ts b/src/app/components/select-model-field-line/select-model-field-line.component.ts deleted file mode 100644 index 31082006ed3bea6f79b8d933b411789e9f80da81..0000000000000000000000000000000000000000 --- a/src/app/components/select-model-field-line/select-model-field-line.component.ts +++ /dev/null @@ -1,94 +0,0 @@ -import { Component, Input, OnInit } from "@angular/core"; -import { Router } from "@angular/router"; - -import { SelectEntry } from "../../formulaire/elements/select-entry"; -import { FormulaireService } from "../../services/formulaire.service"; -import { FieldsetContainer } from "../../formulaire/elements/fieldset-container"; -import { SelectFieldModel } from "../../formulaire/elements/select-field-model"; - -@Component({ - selector: "select-model-field-line", - templateUrl: "./select-model-field-line.component.html", - styleUrls: [ - "./select-model-field-line.component.scss" - ] -}) -export class SelectModelFieldLineComponent implements OnInit { - @Input() - private _select: SelectFieldModel; - - public constructor( - private _formService: FormulaireService, - private router: Router - ) {} - - public get selectId() { - return this._select.id; - } - - public get entries(): SelectEntry[] { - if (! this._select) { - return []; - } - return this._select.entries; - } - - public get modelUid() { - return this.selectedValue && ! Array.isArray(this.selectedValue) ? this.selectedValue.id : ""; - } - - public get isValid(): boolean { - return (this._select.getValue() !== undefined); - } - - // called every time we navigate to the module - ngOnInit(): void { - this._select.updateEntries(); - } - - /** - * Label d'une entrée du select des modèles de cloisons - */ - public selectItemLabel(entry: SelectEntry): string { - if (entry && entry.id) { - const cloisonsForm = this._formService.getFormulaireFromNubId(entry.id); - const name = cloisonsForm.calculatorName; - return name; - } - } - - public get selectedValue(): SelectEntry | SelectEntry[] { - return this._select.getValue(); - } - - public set selectedValue(v: SelectEntry | SelectEntry[]) { - this._select.setValue(v); - } - - public get label() { - if (this._select) { - return this._select.label; - } else { - return ""; - } - } - - /** - * Creates a new Nub of type _select.calcType, to be used as a model - * when no other is available - */ - public createModel() { - this._formService.createFormulaire(this._select.calcType).then(f => { - this.router.navigate(["/calculator", f.uid]); - return f; - }).then(f => { - // on ajoute un ouvrage aux modulex de type "parallèle" - for (const e of f.allFormElements) { - if (e instanceof FieldsetContainer) { - e.addFromTemplate(0); - break; - } - } - }); - } -} diff --git a/src/app/formulaire/elements/select-field-model.ts b/src/app/formulaire/elements/select-field-model.ts deleted file mode 100644 index 322ae965d3b2f02288ae5f78d39af22aff52a672..0000000000000000000000000000000000000000 --- a/src/app/formulaire/elements/select-field-model.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { SelectField } from "./select-field"; -import { SelectEntry } from "./select-entry"; -import { FormulaireNode } from "./formulaire-node"; -import { CalculatorType } from "jalhyd"; - -/** - * A select field that populates itself with references to - * available modules - */ -export abstract class SelectFieldModel extends SelectField { - - /** type of the targetted models; used by enclosing component to create new model */ - public calcType: CalculatorType; - - constructor(parent: FormulaireNode, calcType: CalculatorType) { - super(parent); - this.calcType = calcType; - this.initSelectedValue(); - } - - protected abstract initSelectedValue(); - - /** - * Populates entries with available models - */ - protected abstract populate(); - - /** - * Reloads available entries, trying to keep the current selected - * value; does not notify observers if value did not change - */ - public updateEntries() { - // store previous selected entry - const pse = this._selectedEntry; - // empty - this.clearEntries(); - // populate - this.populate(); - // keep previously selected entry if possible - if (pse && ! Array.isArray(pse) && pse.id) { // @TODO manage multiple values - this.setValueFromId(pse.id); - } - // if no entry is available anymore, unset value - if (this.entries.length === 0) { - super.setValue(undefined); - } - } - - /** - * Updates selectedValue; notifies observers only if - * value.id has changed - */ - public setValue(v: SelectEntry | SelectEntry[]) { - const previousSelectedEntry = this._selectedEntry; - this._selectedEntry = v; - if ( - ! previousSelectedEntry - || ( // @TODO manage multiple values - ! Array.isArray(previousSelectedEntry) - && previousSelectedEntry.id !== (v as SelectEntry).id - ) - ) { - this.notifyObservers({ - "action": "select", - "value": v - }, this); - } - } - - /** - * Sets value from given ID; if it was not found, sets the - * first available entry as selectedValue - */ - public setValueFromId(id: string) { - let found = false; - for (const e of this._entries) { - if (e.id === id) { - found = true; - this.setValue(e); - } - } - if (! found) { - // default to first available entry if any - if (this._entries.length > 0) { - this.setValue(this._entries[0]); - } else { - // notify observers that no value is selected anymore - this.notifyObservers({ - "action": "select", - "value": undefined - }, this); - } - } - } -}