diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 938ba9907363bad1d3a2c1e3bbe92e009bb51d74..c668d895f1a239289576b6cfcfb9862bbb9086f0 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -45,6 +45,7 @@ export class AppComponent implements OnInit, OnDestroy, Observer { ServiceFactory.instance.applicationSetupService = appSetupService; ServiceFactory.instance.paramService = paramService; ServiceFactory.instance.internationalisationService = intlService; + ServiceFactory.instance.formulaireService = formulaireService; ServiceFactory.instance.httpService = httpService; } diff --git a/src/app/components/calculator-list/calculator-list.component.ts b/src/app/components/calculator-list/calculator-list.component.ts index 0d674c2e11e8c5a0e6957e2f59294557d011d617..91b239baac3176ea758b8a6f94dcbc995e64013f 100644 --- a/src/app/components/calculator-list/calculator-list.component.ts +++ b/src/app/components/calculator-list/calculator-list.component.ts @@ -4,14 +4,14 @@ import { Router } from '@angular/router'; import { CalculatorType, EnumEx } from "jalhyd"; import { FormulaireDefinition } from "../../formulaire/definition/form-definition"; -import { FormulaireService } from "../../services/formulaire/formulaire.service"; +import { ServiceFactory } from "../../services/service-factory"; import { InternationalisationService } from '../../services/internationalisation/internationalisation.service'; class ListElement { private _label: string; - constructor(private _type: CalculatorType, formulaireService: FormulaireService) { - this._label = formulaireService.getLocalisedTitleFromCalculatorType(_type); + constructor(private _type: CalculatorType) { + this._label = ServiceFactory.instance.formulaireService.getLocalisedTitleFromCalculatorType(_type); } public get label() { return this._label } @@ -26,23 +26,19 @@ class ListElement { export class CalculatorListComponent implements OnInit { private _items: ListElement[]; - constructor( - private formulaireService: FormulaireService, - private router: Router, - private intlService: InternationalisationService, - ) { - this.intlService.addObserver(this); + constructor(private router: Router) { + ServiceFactory.instance.internationalisationService.addObserver(this); } private updateLocale() { this._items = []; for (let t of EnumEx.getValues(CalculatorType)) if (t !== CalculatorType.Structure) - this._items.push(new ListElement(t, this.formulaireService)); + this._items.push(new ListElement(t)); } private create(t: CalculatorType) { - const p: Promise<FormulaireDefinition> = this.formulaireService.createFormulaire(t); + const p: Promise<FormulaireDefinition> = ServiceFactory.instance.formulaireService.createFormulaire(t); p.then(f => { this.router.navigate(['/calculator', f.uid]); }); diff --git a/src/app/components/check-field-line/check-field-line.component.ts b/src/app/components/check-field-line/check-field-line.component.ts index 6897543d23e5415f951fa89838301e0638953b29..94138891d987aa32c6b217edfb2a6e9434774d22 100644 --- a/src/app/components/check-field-line/check-field-line.component.ts +++ b/src/app/components/check-field-line/check-field-line.component.ts @@ -1,7 +1,6 @@ import { Component, Input, Output, EventEmitter } from "@angular/core"; import { CheckField } from "../../formulaire/check-field"; -import { FormulaireService } from "../../services/formulaire/formulaire.service"; @Component({ selector: "check-field-line", @@ -13,8 +12,7 @@ export class CheckFieldLineComponent { private _currentValue: boolean; - constructor(private formulaireService: FormulaireService) { - } + constructor() { } private onChange(event: any) { this._check.setValue(event); diff --git a/src/app/components/generic-calculator/calculator.component.ts b/src/app/components/generic-calculator/calculator.component.ts index d250d2523ce5e1d64417a5b1193372aec49ddcda..8a837c46dd2be72b66a1065ab93cfa2ab5be063b 100644 --- a/src/app/components/generic-calculator/calculator.component.ts +++ b/src/app/components/generic-calculator/calculator.component.ts @@ -15,6 +15,7 @@ import { CalculatorNameComponent } from "./calc-name.component"; import { FormulaireElement } from "../../formulaire/formulaire-element"; import { FieldsetContainer } from "../../formulaire/fieldset-container"; import { FieldsetContainerComponent } from "../fieldset-container/fieldset-container.component"; +import { ServiceFactory } from "../../services/service-factory"; @Component({ selector: 'hydrocalc', @@ -87,10 +88,15 @@ export class GenericCalculatorComponent extends BaseComponent implements OnInit, */ private isCalculateDisabled: boolean = true; - constructor(private intlService: InternationalisationService, - private formulaireService: FormulaireService, - private route: ActivatedRoute) { + // services + + private intlService: InternationalisationService; + private formulaireService: FormulaireService; + + constructor(private route: ActivatedRoute) { super(); + this.intlService = ServiceFactory.instance.internationalisationService; + this.formulaireService = ServiceFactory.instance.formulaireService; } private get formElements(): FormulaireElement[] { diff --git a/src/app/components/param-field-line/param-field-line.component.ts b/src/app/components/param-field-line/param-field-line.component.ts index d66120394fa469bd092f43df94c1a5ffe0d6ad82..d43df61f3c4f4a7bd72b86cee476ccf4f992d039 100644 --- a/src/app/components/param-field-line/param-field-line.component.ts +++ b/src/app/components/param-field-line/param-field-line.component.ts @@ -3,7 +3,7 @@ import { Component, ViewChild, Input, Output, EventEmitter, OnChanges } from "@a import { InternationalisationService } from "../../services/internationalisation/internationalisation.service"; import { NgParameter, ParamRadioConfig } from "../../formulaire/ngparam"; import { NgParamInputComponent } from "../ngparam-input/ngparam-input.component"; -import { FormulaireService } from "../../services/formulaire/formulaire.service"; +import { ServiceFactory } from "../../services/service-factory"; import { ParamValueMode } from "jalhyd"; @Component({ @@ -49,9 +49,10 @@ export class ParamFieldLineComponent implements OnChanges { */ private _isRangeValid: boolean = true; - constructor(private intlService: InternationalisationService, - private formulaireService: FormulaireService - ) { + private intlService: InternationalisationService; + + constructor() { + this.intlService = ServiceFactory.instance.internationalisationService; this.onValid = new EventEmitter(); this.inputChange = new EventEmitter(); } @@ -292,7 +293,7 @@ export class ParamFieldLineComponent implements OnChanges { } private get formHasResults(): boolean { - return this.formulaireService.currentFormHasResults; + return ServiceFactory.instance.formulaireService.currentFormHasResults; } /** diff --git a/src/app/components/select-field-line/select-field-line.component.ts b/src/app/components/select-field-line/select-field-line.component.ts index 5578fe79b75e677c49d5552f72ec90c6de8eec24..a544eed7d839c1ecd5f2f075d8ca599f0745cebf 100644 --- a/src/app/components/select-field-line/select-field-line.component.ts +++ b/src/app/components/select-field-line/select-field-line.component.ts @@ -2,7 +2,6 @@ import { Component, Input, Output, EventEmitter } from "@angular/core"; import { SelectField, } from "../../formulaire/select-field"; import { SelectEntry } from "../../formulaire/select-entry"; -import { FormulaireService } from "../../services/formulaire/formulaire.service"; import { GenericSelectComponent } from "../generic-select/generic-select.component"; @Component({ @@ -13,10 +12,6 @@ export class SelectFieldLineComponent extends GenericSelectComponent<SelectEntry @Input("param") private _select: SelectField; - constructor(private formulaireService: FormulaireService) { - super(); - } - protected get entries(): SelectEntry[] { if (this._select == undefined) return []; diff --git a/src/app/services/internationalisation/internationalisation.service.ts b/src/app/services/internationalisation/internationalisation.service.ts index eac0383b50c593067b59644388c270f838ff9de5..f418a88998bd01789e1106247a3002eeebe225da 100644 --- a/src/app/services/internationalisation/internationalisation.service.ts +++ b/src/app/services/internationalisation/internationalisation.service.ts @@ -3,7 +3,6 @@ import { Response } from '@angular/http'; import { Message, MessageCode, Observable } from "jalhyd"; -import { HttpService } from "../http/http.service"; import { StringMap } from "../../stringmap"; import { ServiceFactory } from '../service-factory'; @@ -51,7 +50,7 @@ export class InternationalisationService extends Observable { private _languages: Language[]; - public constructor(private httpService: HttpService) { + public constructor() { super(); this._languages = []; this._languages.push(new Language(LanguageCode.FRENCH, "fr", "Français")); @@ -124,7 +123,7 @@ export class InternationalisationService extends Observable { } let f: string = "error_messages." + l + ".json" - return this.httpService.httpGetRequest(undefined, undefined, undefined, "locale/" + f, processData); + return ServiceFactory.instance.httpService.httpGetRequest(undefined, undefined, undefined, "locale/" + f, processData); } private getMessageFromCode(c: MessageCode): string { diff --git a/src/app/services/service-factory.ts b/src/app/services/service-factory.ts index 65b08fa1ef58c4b696e2cde8098c4a2acc757320..fb5788767fb2331412721d36dc74ac0baca2d103 100644 --- a/src/app/services/service-factory.ts +++ b/src/app/services/service-factory.ts @@ -1,5 +1,6 @@ import { ApplicationSetupService } from "./app-setup/app-setup.service"; import { ParamService } from "./param/param.service"; +import { FormulaireService } from "./formulaire/formulaire.service"; import { InternationalisationService } from "./internationalisation/internationalisation.service"; import { HttpService } from "./http/http.service"; @@ -12,6 +13,8 @@ export class ServiceFactory { public paramService: ParamService; + public formulaireService: FormulaireService; + public internationalisationService: InternationalisationService; public httpService: HttpService;