diff --git a/src/app/app.component.html b/src/app/app.component.html index 7c85695482c9d855809836ebe2a097d4a5bc61ee..c2d6ee7b1a805382dba100e74572d347588a960a 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -15,7 +15,7 @@ <!-- Links --> <ul class="navbar-nav mr-auto"> <li class="nav-item" *ngFor="let c of _calculators"> - <a class="nav-link waves-light" mdbRippleRadius [routerLink]="['/calculator/',c.uid]">{{c.title}}</a> + <a class="nav-link waves-light {{getHighlightClass(c.uid)}}" mdbRippleRadius [routerLink]="['/calculator/',c.uid]">{{c.title}}</a> </li> </ul> <!-- Links --> diff --git a/src/app/app.component.ts b/src/app/app.component.ts index c658ad70c49e504837494113adcbe715e7510344..0104bd1cff5cf29443f2e2dbd334d2073d0410ca 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -100,7 +100,7 @@ export class AppComponent implements OnInit, OnDestroy, Observer { } else if (sender instanceof FormulaireService) { switch (data["action"]) { - case "create": + case "createForm": const f: FormulaireDefinition = data["form"]; this._calculators.push( { @@ -110,13 +110,12 @@ export class AppComponent implements OnInit, OnDestroy, Observer { ); break; - case "invalidid": + case "invalidFormId": this.toList(); break; - - case "close": - const uid: number = data["formid"]; + case "closeForm": + const uid: number = data["formId"]; this.closeCalculator(uid); break; } @@ -169,6 +168,10 @@ export class AppComponent implements OnInit, OnDestroy, Observer { this.router.navigate(['/calculator', id]); } + private getHighlightClass(uid: number) { + return uid == this.formulaireService.currentFormId ? "blue darken-2" : ""; + } + // sidenav private openNav() { diff --git a/src/app/calculators/generic/calculator.component.ts b/src/app/calculators/generic/calculator.component.ts index d0ac5c5712fa5840cf56705ef22eeae490399921..c308fc8e1ee21451e565cc2b82c335a256ca13a1 100644 --- a/src/app/calculators/generic/calculator.component.ts +++ b/src/app/calculators/generic/calculator.component.ts @@ -102,12 +102,8 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, OnDestroy, O private subscribeRouter() { // récupération des paramètres passés avec la route (URL) this._subscription = this.route.params.subscribe(params => { - const uid: number = +params['uid']; - - this._formulaire = this.formulaireService.getFormulaireFromId(uid); - this.resultsComponent.formulaire = this._formulaire; - if (this._formulaire != undefined) - this._formulaire.updateNodeType(); + const uid: number = params['uid']; + this.formulaireService.setCurrentForm(+uid); }); } @@ -156,14 +152,17 @@ export class GenericCalculatorComponent implements OnInit, DoCheck, OnDestroy, O if (sender instanceof InternationalisationService) { this.formulaireService.updateLocalisation(); } - // else if (sender instanceof FormulaireService) { - // switch (data["action"]) { - // case "create": - // const f: FormulaireDefinition = data["form"]; - // this._resultsStatus.addFormulaire(f.uid); - // break; - // } - // } + else if (sender instanceof FormulaireService) { + switch (data["action"]) { + case "currentFormChanged": + const uid: number = +data["formId"]; + this._formulaire = this.formulaireService.getFormulaireFromId(uid); + this.resultsComponent.formulaire = this._formulaire; + if (this._formulaire != undefined) + this._formulaire.updateNodeType(); + break; + } + } } /** diff --git a/src/app/services/formulaire/formulaire.service.ts b/src/app/services/formulaire/formulaire.service.ts index e6c93a407fac7e06af2c2a3368a903023442f5fd..1b833bc14e79d4960f03fa567103a79d792b4e15 100644 --- a/src/app/services/formulaire/formulaire.service.ts +++ b/src/app/services/formulaire/formulaire.service.ts @@ -19,6 +19,8 @@ import { Observable } from "../observer"; export class FormulaireService extends Observable { private _formulaires: FormulaireDefinition[]; + private _currentFormId = -1; + constructor(private paramService: ParamService, private httpService: HttpService, private intlService: InternationalisationService @@ -104,7 +106,7 @@ export class FormulaireService extends Observable { }).then(f => { this.notifyObservers( { - "action": "create", + "action": "createForm", "form": f }); return f; @@ -116,11 +118,6 @@ export class FormulaireService extends Observable { if (f.uid == uid) return f; - this.notifyObservers({ - "action": "invalidid", - "formid": uid - }); - return undefined; } @@ -186,8 +183,30 @@ export class FormulaireService extends Observable { this._formulaires = this._formulaires.filter(f => f.uid !== uid); this.notifyObservers({ - "action": "close", - "formid": uid + "action": "closeForm", + "formId": uid + }); + } + } + + public get currentFormId() { + return this._currentFormId; + } + + public setCurrentForm(formId: number) { + const form = this.getFormulaireFromId(formId); + if (form == undefined) { + this._currentFormId = -1; + this.notifyObservers({ + "action": "invalidFormId", + "formId": formId + }); + } + else { + this._currentFormId = formId; + this.notifyObservers({ + "action": "currentFormChanged", + "formId": formId }); } }