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 {
11 projectsRootDir: string;
15 export class ConfigService {
17 public Conf$: Observable<IConfig>;
19 private confSubject: BehaviorSubject<IConfig>;
20 private confStore: IConfig;
23 private cookie: CookieService,
24 private alert: AlertService,
25 private utils: UtilsService,
28 this.confSubject = <BehaviorSubject<IConfig>>new BehaviorSubject(this.confStore);
29 this.Conf$ = this.confSubject.asObservable();
34 // Try to retrieve previous config from cookie
35 const cookConf = this.cookie.getObject('xds-config');
36 if (cookConf != null) {
37 this.confStore = <IConfig>cookConf;
48 // Save config into cookie
51 this.confSubject.next(Object.assign({}, this.confStore));
53 // Don't save projects in cookies (too big!)
54 const cfg = Object.assign({}, this.confStore);
55 this.cookie.putObject('xds-config', cfg);
58 set projectsRootDir(p: string) {
59 this.confStore.projectsRootDir = p;