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 { Component, OnInit } from '@angular/core';
20 import { Observable } from 'rxjs/Observable';
22 import { XDSConfigService } from '../../../@core-xds/services/xds-config.service';
23 import { IXDServerCfg } from '../../../@core-xds/services/xdsagent.service';
24 import { AlertService, IAlert } from '../../../@core-xds/services/alert.service';
25 import { NotificationsComponent } from '../../notifications/notifications.component';
27 // Import RxJs required methods
28 import 'rxjs/add/operator/map';
29 import 'rxjs/add/operator/catch';
32 selector: 'xds-config-xds',
33 styleUrls: ['./config-xds.component.scss'],
34 templateUrl: './config-xds.component.html',
36 export class ConfigXdsComponent {
38 // TODO: cleanup agentStatus$: Observable<IAgentStatus>;
41 server: IXDServerCfg = { id: '', url: 'http://localhost:8000', connRetry: 10, connected: false };
43 configFormChanged = false;
46 private XdsConfigSvr: XDSConfigService,
47 private alert: AlertService,
49 // FIXME support multiple servers
50 this._updateServerCfg(this.XdsConfigSvr.getCurServer());
51 this.XdsConfigSvr.onCurServer().subscribe(svr => this._updateServerCfg(svr));
54 private _updateServerCfg(svr: IXDServerCfg) {
55 if (!svr || svr.url === '') {
58 this.xdsServerUrl = svr.url;
59 this.server = Object.assign({}, svr);
62 isApplyBtnEnable(): boolean {
63 return this.xdsServerUrl !== '' && (!this.server.connected || this.configFormChanged);
67 if (!this.configFormChanged && this.server.connected) {
70 this.configFormChanged = false;
72 this.server.url = this.xdsServerUrl;
73 this.XdsConfigSvr.setCurServer(this.server)
75 this.alert.info('XDS Server successfully connected (' + cfg.url + ')');
76 this.server = Object.assign({}, cfg);
77 this.applying = false;
80 this.applying = false;
81 this.alert.error(err);