New dashboard look & feel
[src/xds/xds-agent.git] / webapp / src / app / pages / config / config-xds / config-xds.component.ts
1 import { Component, OnInit } from '@angular/core';
2 import { Observable } from 'rxjs/Observable';
3
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';
8
9 // Import RxJs required methods
10 import 'rxjs/add/operator/map';
11 import 'rxjs/add/operator/catch';
12
13 @Component({
14   selector: 'xds-config-xds',
15   styleUrls: ['./config-xds.component.scss'],
16   templateUrl: './config-xds.component.html',
17 })
18 export class ConfigXdsComponent implements OnInit {
19
20   // TODO: cleanup agentStatus$: Observable<IAgentStatus>;
21   connecting = false;
22   xdsServerUrl = '';
23   server: IXDServerCfg;
24
25   configFormChanged = false;
26
27   constructor(
28     private XdsConfigSvr: XDSConfigService,
29     private alert: AlertService,
30   ) {
31   }
32
33   ngOnInit() {
34     // FIXME support multiple servers
35
36     this.server = this.XdsConfigSvr.getCurServer();
37     this.xdsServerUrl = this.server.url;
38
39     this.XdsConfigSvr.onCurServer().subscribe(svr => {
40       this.xdsServerUrl = svr.url;
41       this.server = svr;
42     });
43   }
44
45   onSubmit() {
46     if (!this.configFormChanged && this.server.connected) {
47       return;
48     }
49     this.configFormChanged = false;
50     this.connecting = true;
51     this.server.url = this.xdsServerUrl;
52     this.XdsConfigSvr.setCurServer(this.server)
53       .subscribe(cfg => {
54         this.connecting = false;
55        },
56       err => {
57         this.connecting = false;
58         this.alert.error(err);
59       });
60   }
61
62 }
63