1 import { Injectable } from '@angular/core';
2 import { CookieService } from 'ngx-cookie';
3 import { Observable } from 'rxjs/Observable';
4 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
6 import { AlertService, IAlert } from "../services/alert.service";
7 import { UtilsService } from "../services/utils.service";
9 export interface IConfig {
10 projectsRootDir: string;
14 export class ConfigService {
16 public Conf$: Observable<IConfig>;
18 private confSubject: BehaviorSubject<IConfig>;
19 private confStore: IConfig;
21 constructor(private _window: Window,
22 private cookie: CookieService,
23 private alert: AlertService,
24 private utils: UtilsService,
27 this.confSubject = <BehaviorSubject<IConfig>>new BehaviorSubject(this.confStore);
28 this.Conf$ = this.confSubject.asObservable();
33 // Try to retrieve previous config from cookie
34 let cookConf = this.cookie.getObject("xds-config");
35 if (cookConf != null) {
36 this.confStore = <IConfig>cookConf;
46 // Save config into cookie
49 this.confSubject.next(Object.assign({}, this.confStore));
51 // Don't save projects in cookies (too big!)
52 let cfg = Object.assign({}, this.confStore);
53 this.cookie.putObject("xds-config", cfg);
56 set projectsRootDir(p: string) {
57 this.confStore.projectsRootDir = p;