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';
8 export interface IConfig {
10 projectsRootDir: string;
14 export class ConfigService {
16 public Conf$: Observable<IConfig>;
18 private confSubject: BehaviorSubject<IConfig>;
19 private confStore: IConfig;
22 private cookie: CookieService,
23 private alert: AlertService,
26 this.confSubject = <BehaviorSubject<IConfig>>new BehaviorSubject(this.confStore);
27 this.Conf$ = this.confSubject.asObservable();
32 // Try to retrieve previous config from cookie
33 const cookConf = this.cookie.getObject('xds-config');
34 if (cookConf != null) {
35 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 const cfg = Object.assign({}, this.confStore);
53 this.cookie.putObject('xds-config', cfg);
56 set projectsRootDir(p: string) {
57 this.confStore.projectsRootDir = p;