Skip to content
Snippets Groups Projects
Commit 3257756f authored by mathias.chouet's avatar mathias.chouet
Browse files

Le service de configuration avertit ses observateurs lorsque le fichier de config JSON est chargé

parent 009f2ca5
No related branches found
No related tags found
1 merge request!29Resolve "Remplacer mdbootstrap par angular-material"
......@@ -41,6 +41,7 @@ export class ApplicationSetupComponent extends BaseComponent implements Observer
private intlService: InternationalisationService
) {
super();
this.appSetupService.addObserver(this);
}
public get currentLanguageLabel(): string {
......@@ -90,19 +91,26 @@ export class ApplicationSetupComponent extends BaseComponent implements Observer
// interface Observer
public update(sender: any, data: any): void {
const p: NgBaseParam = sender;
switch (p.symbol) {
case "dp":
this.appSetupService.displayPrecision = +data;
break;
case "cp":
this.appSetupService.computePrecision = +data;
break;
case "nmi":
this.appSetupService.newtonMaxIterations = +data;
break;
if (sender instanceof NgBaseParam) {
// someone typed a new value in the app-setup form
const p: NgBaseParam = sender;
switch (p.symbol) {
case "dp":
this.appSetupService.displayPrecision = +data;
break;
case "cp":
this.appSetupService.computePrecision = +data;
break;
case "nmi":
this.appSetupService.newtonMaxIterations = +data;
break;
}
}
if (sender instanceof ApplicationSetupService) {
// if app starts on /setup page, wait for config file to be (re)loaded by app-setup service
this.init();
}
}
}
import { HttpService } from "../http/http.service";
import { Injectable } from "@angular/core";
import { Observable } from "jalhyd";
/**
* Stores app preferences
*/
@Injectable()
export class ApplicationSetupService {
export class ApplicationSetupService extends Observable {
private CONFIG_FILE_PATH = "app/config.json";
......@@ -19,6 +20,8 @@ export class ApplicationSetupService {
public constructor(
private httpService: HttpService) {
super();
this.readValuesFromConfig();
}
......@@ -28,9 +31,7 @@ export class ApplicationSetupService {
// @TODO save preferences in cookie / localStorage ?
// read default values from config
// @TODO notify (?) so that if a user starts the app on the /setup page the values are correct
// (atm the default builtin values will be visible until the user changes page and goes back to /setup)
// read default values from config and notify observers
private readValuesFromConfig() {
this.httpService.httpGetRequestPromise(this.CONFIG_FILE_PATH).then((data: any) => {
this.displayPrecision = data.params.displayPrecision;
......@@ -38,6 +39,8 @@ export class ApplicationSetupService {
this.newtonMaxIterations = data.params.newtonMaxIterations;
this.language = data.params.language;
this.themes = data.themes;
this.notifyObservers(null);
});
}
}
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