An error occurred while loading the file. Please try again.
-
Mathias Chouet authored6950d74d
import { Component, OnInit } from "@angular/core";
import { Router } from "@angular/router";
import { CalculatorType, EnumEx, Session } from "jalhyd";
import { FormulaireDefinition } from "../../formulaire/definition/form-definition";
import { ServiceFactory } from "../../services/service-factory";
import { I18nService } from "../../services/internationalisation/internationalisation.service";
import { FormulaireParallelStructure } from "../../formulaire/definition/concrete/form-parallel-structures";
import { FieldsetContainer } from "../../formulaire/fieldset-container";
@Component({
selector: "list",
templateUrl: "./calculator-list.component.html",
styleUrls: ["./calculator-list.component.scss"]
})
export class CalculatorListComponent implements OnInit {
private _items: any[];
constructor(private router: Router) {
ServiceFactory.instance.i18nService.addObserver(this);
ServiceFactory.instance.applicationSetupService.addObserver(this);
}
/** triggered on init */
private loadCalculatorsThemes() {
this._items = [];
const unusedCalculators = EnumEx.getValues(CalculatorType);
const themes = ServiceFactory.instance.applicationSetupService.themes;
if (themes) {
// group by themes
for (const theme of themes) {
if (theme.name) {
// get theme details from config
const themeTitleKey = "INFO_THEME_" + theme.name + "_TITRE";
const themeDescriptionKey = "INFO_THEME_" + theme.name + "_DESCRIPTION";
const credits = ServiceFactory.instance.i18nService.localizeText("INFO_THEME_CREDITS");
const item = {
title: ServiceFactory.instance.i18nService.localizeText(themeTitleKey),
description: ServiceFactory.instance.i18nService.localizeText(themeDescriptionKey),
image: {
path: "assets/images/themes/" + theme.image.path,
title: theme.image.title,
credits: credits + " : " + theme.image.credits
},
calculators: []
};
// get calculators for this theme
for (const calcType of theme.calculators) {
item.calculators.push({
type: calcType,
label: ServiceFactory.instance.formulaireService.getLocalisedTitleFromCalculatorType(calcType),
buttonId: "create-calc-" + calcType
});
// mark as used
const index = unusedCalculators.indexOf(calcType);
if (index > -1) {
unusedCalculators.splice(index, 1);
}
}
this._items.push(item);
}
// else special theme for unused calculators
}
// extra card for unused calculators
if (unusedCalculators.length > 0) {
const unusedThemeConfig = themes.find(i => i.name === undefined);
const unusedTheme: any = {};
unusedTheme.calculators = [];
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
unusedTheme.title = ServiceFactory.instance.i18nService.localizeText("INFO_THEME_MODULES_INUTILISES_TITRE");
unusedTheme.description = ServiceFactory.instance.i18nService.localizeText("INFO_THEME_MODULES_INUTILISES_DESCRIPTION");
unusedTheme.image = {
path: "assets/images/themes/" + unusedThemeConfig.image.path
};
for (const t of unusedCalculators) {
if (t !== CalculatorType.Structure) {
unusedTheme.calculators.push({
type: t,
label: ServiceFactory.instance.formulaireService.getLocalisedTitleFromCalculatorType(t),
buttonId: "create-calc-" + t
});
}
}
if (unusedTheme.calculators.length > 0) {
this._items.push(unusedTheme);
} // else the only remaining calculator was "Structure", the one we don't want
}
}
}
private create(t: CalculatorType) {
const p: Promise<FormulaireDefinition> = ServiceFactory.instance.formulaireService.createFormulaire(t);
p.then(f => {
this.router.navigate(["/calculator", f.uid]);
return f;
}).then(f => {
// on ajoute un ouvrage après l'ouverture du module de calcul "ouvrages parallèles"
if (f instanceof FormulaireParallelStructure) {
for (const e of f.allFormElements) {
if (e instanceof FieldsetContainer) {
e.addFromTemplate(0);
break;
}
}
}
});
}
public get nbOpenCalculators() {
return Session.getInstance().getNumberOfNubs();
}
public get items() {
return this._items;
}
public get uitextWelcomeTitle() {
return "Cassiopée";
}
public get uitextWelcomeSubtitle() {
return ServiceFactory.instance.i18nService.localizeText("INFO_WELCOME_SUBTITLE");
}
public get uitextWelcomeContent() {
return ServiceFactory.instance.i18nService.localizeText("INFO_WELCOME_CONTENT");
}
// interface Observer
update(sender: any, data: any): void {
if (sender instanceof I18nService) {
// reload themes if language changed
this.loadCalculatorsThemes();
}
}
ngOnInit() {
141142143144
this.loadCalculatorsThemes();
}
}