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

Removed unused component

parent 8c68ce1c
No related branches found
No related tags found
1 merge request!82Resolve "Ajout de la fonctionnalité "Respect des critères""
......@@ -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";
......@@ -231,7 +230,6 @@ const appRoutes: Routes = [
SectionCanvasComponent,
SectionResultsComponent,
SelectFieldLineComponent,
SelectModelFieldLineComponent,
SessionPropertiesComponent,
VarResultsComponent
],
......
<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
mat-form-field {
width: calc(100% - 8px);
margin-right: 8px;
}
.button-container {
text-align: right;
button {
margin-top: 4px;
}
}
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;
}
}
});
}
}
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);
}
}
}
}
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