3 * Copyright (C) 2017 "IoT.bzh"
4 * Author Sebastien Douheret <sebastien@iot.bzh>
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import { Injectable } from '@angular/core';
20 import { CookieService } from 'ngx-cookie';
21 import { Observable } from 'rxjs/Observable';
22 import { BehaviorSubject } from 'rxjs/BehaviorSubject';
24 import { AlertService, IAlert } from '../services/alert.service';
26 export interface IConfig {
28 projectsRootDir: string;
32 export class ConfigService {
34 public Conf$: Observable<IConfig>;
36 private confSubject: BehaviorSubject<IConfig>;
37 private confStore: IConfig;
40 private cookie: CookieService,
41 private alert: AlertService,
44 this.confSubject = <BehaviorSubject<IConfig>>new BehaviorSubject(this.confStore);
45 this.Conf$ = this.confSubject.asObservable();
50 // Try to retrieve previous config from cookie
51 const cookConf = this.cookie.getObject('xds-config');
52 if (cookConf != null) {
53 this.confStore = <IConfig>cookConf;
64 // Save config into cookie
67 this.confSubject.next(Object.assign({}, this.confStore));
69 // Don't save projects in cookies (too big!)
70 const cfg = Object.assign({}, this.confStore);
71 this.cookie.putObject('xds-config', cfg);
74 set projectsRootDir(p: string) {
75 this.confStore.projectsRootDir = p;