3 * Copyright (C) 2017-2018 "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 export interface IBuildSettings {
35 export class BuildSettingsService {
36 public settings$: Observable<IBuildSettings>;
38 private settingsSubject: BehaviorSubject<IBuildSettings>;
39 private settingsStore: IBuildSettings;
42 private cookie: CookieService,
47 // Load build settings from cookie
49 // Try to retrieve previous config from cookie
50 const cookConf = this.cookie.getObject('xds-build-settings');
51 if (cookConf != null) {
52 this.settingsStore = <IBuildSettings>cookConf;
55 this.settingsStore = {
57 cmdClean: 'rm -rf build && echo Done',
58 cmdPrebuild: 'mkdir -p build && cd build && cmake ..',
59 cmdBuild: 'cd build && make',
60 cmdPopulate: 'cd build && make remote-target-populate',
67 // Save config into cookie
70 this.settingsSubject.next(Object.assign({}, this.settingsStore));
72 const cfg = Object.assign({}, this.settingsStore);
73 this.cookie.putObject('xds-build-settings', cfg);
76 // Get whole config values
77 get(): IBuildSettings {
78 return this.settingsStore;
81 // Get whole config values
82 set(bs: IBuildSettings) {
83 this.settingsStore = bs;
87 get subpath(): string {
88 return this.settingsStore.subpath;
91 set subpath(p: string) {
92 this.settingsStore.subpath = p;