Newer
Older
import { Component, ApplicationRef } from '@angular/core';
//import { Component, ChangeDetectorRef, ApplicationRef, AfterViewChecked } from '@angular/core';
//import { MdDialog } from '@angular/material';
import { ComputeNodeType, ComputeNode } from 'jalhyd';
import { ParamService } from './services/param/param.service';
import { HttpService } from './services/http/http.service';
francois.grand
committed
import { InternationalisationService, Language, LanguageCode } from './services/internationalisation/internationalisation.service';
francois.grand
committed
import { Observer } from './services/observer';
import { ErrorService } from './services/error/error.service';
// import { AlertDialog } from './components/alert-dialog/alert-dialog.component';
import { FormulaireService } from './services/formulaire/formulaire.service';
import { FormulaireElement } from './formulaire/formulaire-element';
import { FormulaireDefinition, CalculatorType } from './formulaire/formulaire-definition';
francois.grand
committed
selector: 'nghyd-app',
francois.grand
committed
export class AppComponent implements Observer {
francois.grand
committed
private _currentLanguage: LanguageCode;
private _displayErrorDialog: boolean = false;
// constructor(private intlService: InternationalisationService, private appRef: ApplicationRef, private dialog: MdDialog, private errorService: ErrorService) { }
constructor(private intlService: InternationalisationService,
private appRef: ApplicationRef,
private errorService: ErrorService,
private router: Router,
private formulaireService: FormulaireService
) {
this.formulaireService.addObserver(this);
}
francois.grand
committed
private initLocale() {
let docLocale: string = document['locale'] as string;
this.intlService.setLocale(docLocale);
francois.grand
committed
this._currentLanguage = this.intlService.currentLanguage.code;
// process.on('unhandledRejection', (reason, p) => {
// console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
// // Stack Trace
// console.log(reason.stack);
// });
francois.grand
committed
}
ngOnInit() {
this.initLocale();
francois.grand
committed
this.subscribeErrorService();
}
francois.grand
committed
/**
* abonnement au service d'erreurs
*/
private subscribeErrorService() {
this.errorService.addObserver(this);
francois.grand
committed
}
francois.grand
committed
francois.grand
committed
this.intlService.setLocale(lc);
this._currentLanguage = this.intlService.currentLanguage.code;
let tag = this.intlService.currentLanguage.tag;
document['locale'] = tag;
// location.reload(true);
// this.cdRef.markForCheck();
// this.cdRef.detectChanges();
this.appRef.tick();
}
francois.grand
committed
// interface Observer
update(sender: any, data: any): void {
if (sender instanceof ErrorService) {
// on ouvre un dialogue avec le message d'erreur reçu
// if (this._displayErrorDialog) {
// let dialogRef = this.dialog.open(AlertDialog);
// let ad: AlertDialog = dialogRef.componentInstance;
// ad.text = String(data);
// }
// else
console.log(data);
}
else if (sender instanceof FormulaireService) {
const f: FormulaireDefinition = data;
this._calculators.push(
{
"title": CalculatorType[f.calculatorType] + String(f.uid),
"uid": String(f.uid)
}
);
}
francois.grand
committed
}
// sidenav
private openNav() {
document.getElementById("mySidenav").style.width = "300px";
}
private closeNav() {
document.getElementById("mySidenav").style.width = "0";
}
private newCalc() {
this.closeNav();
this.router.navigate(['/list']);
}
// sidenav