1 import { Component, OnInit } from '@angular/core';
2 import { Observable } from 'rxjs/Observable';
4 import { XDSConfigService } from '../../../@core-xds/services/xds-config.service';
5 import { IXDServerCfg } from '../../../@core-xds/services/xdsagent.service';
6 import { AlertService, IAlert } from '../../../@core-xds/services/alert.service';
7 import { NotificationsComponent } from '../../notifications/notifications.component';
9 // Import RxJs required methods
10 import 'rxjs/add/operator/map';
11 import 'rxjs/add/operator/catch';
14 selector: 'xds-config-xds',
15 styleUrls: ['./config-xds.component.scss'],
16 templateUrl: './config-xds.component.html',
18 export class ConfigXdsComponent {
20 // TODO: cleanup agentStatus$: Observable<IAgentStatus>;
23 server: IXDServerCfg = { id: '', url: 'http://localhost:8000', connRetry: 10, connected: false };
25 configFormChanged = false;
28 private XdsConfigSvr: XDSConfigService,
29 private alert: AlertService,
31 // FIXME support multiple servers
32 this.XdsConfigSvr.onCurServer().subscribe(svr => {
33 this.xdsServerUrl = svr.url;
34 this.server = Object.assign({}, svr);
38 isApplyBtnEnable(): boolean {
39 return this.xdsServerUrl !== '' && (!this.server.connected || this.configFormChanged);
43 if (!this.configFormChanged && this.server.connected) {
46 this.configFormChanged = false;
48 this.server.url = this.xdsServerUrl;
49 this.XdsConfigSvr.setCurServer(this.server)
51 this.alert.info('XDS Server successfully connected (' + cfg.url + ')');
52 this.server = Object.assign({}, cfg);
53 this.applying = false;
56 this.applying = false;
57 this.alert.error(err);