An error occurred while loading the file. Please try again.
-
Grand Francois authored2d5ad174
import { Component, OnInit } from "@angular/core";
import { Router } from '@angular/router';
import { EnumEx } from "jalhyd";
import { CalculatorType, FormulaireDefinition } from "../../formulaire/formulaire-definition";
import { FormulaireService } from "../../services/formulaire/formulaire.service";
import { InternationalisationService } from '../../services/internationalisation/internationalisation.service';
class ListElement {
private _label: string;
constructor(private _type: CalculatorType, formulaireService: FormulaireService) {
this._label = formulaireService.getLocalisedTitleFromCalculatorType(_type);
}
public get label() { return this._label }
public get type() { return this._type }
}
@Component({
selector: "list",
templateUrl: "./calculator-list.component.html",
styleUrls: ["./calculator-list.component.css"]
})
export class CalculatorListComponent implements OnInit {
private _items: ListElement[];
constructor(
private formulaireService: FormulaireService,
private router: Router,
private intlService: InternationalisationService,
) {
this.intlService.addObserver(this);
}
private updateLocale() {
this._items = [];
for (let t of EnumEx.getValues(CalculatorType))
this._items.push(new ListElement(t, this.formulaireService));
}
private create(t: CalculatorType) {
const p: Promise<FormulaireDefinition> = this.formulaireService.createFormulaire(t);
p.then(f => {
this.router.navigate(['/calculator', f.uid]);
});
}
// interface Observer
update(sender: any, data: any): void {
if (sender instanceof InternationalisationService) {
this.updateLocale();
}
}
// OnInit
ngOnInit() {
this.updateLocale();
}
}