1 import { Component, OnInit, ViewChild, ViewEncapsulation } from '@angular/core';
2 import { Observable } from 'rxjs/Observable';
3 import { CollapseModule } from 'ngx-bootstrap/collapse';
5 import { ConfigService, IConfig } from '../services/config.service';
6 import { ProjectService, IProject } from '../services/project.service';
7 import { XDSAgentService, IAgentStatus, IXDSConfig } from '../services/xdsagent.service';
8 import { AlertService } from '../services/alert.service';
9 import { ProjectAddModalComponent } from '../projects/projectAddModal.component';
10 import { SdkService, ISdk } from '../services/sdk.service';
11 import { SdkAddModalComponent } from '../sdks/sdkAddModal.component';
14 selector: 'app-config',
15 templateUrl: './config.component.html',
16 styleUrls: ['./config.component.css'],
17 encapsulation: ViewEncapsulation.None
20 // Inspired from https://embed.plnkr.co/jgDTXknPzAaqcg9XA9zq/
21 // and from http://plnkr.co/edit/vCdjZM?p=preview
23 export class ConfigComponent implements OnInit {
24 @ViewChild('childProjectModal') childProjectModal: ProjectAddModalComponent;
25 @ViewChild('childSdkModal') childSdkModal: SdkAddModalComponent;
27 config$: Observable<IConfig>;
28 projects$: Observable<IProject[]>;
29 sdks$: Observable<ISdk[]>;
30 agentStatus$: Observable<IAgentStatus>;
35 userEditedLabel = false;
37 gConfigIsCollapsed = true;
38 sdksIsCollapsed = true;
39 projectsIsCollapsed = false;
41 // TODO replace by reactive FormControl + add validation
42 xdsServerConnected = false;
44 xdsServerRetry: string;
45 projectsRootDir: string; // FIXME: should be remove when projectAddModal will always return full path
46 showApplyBtn = { // Used to show/hide Apply buttons
52 private configSvr: ConfigService,
53 private projectSvr: ProjectService,
54 private xdsAgentSvr: XDSAgentService,
55 private sdkSvr: SdkService,
56 private alert: AlertService,
61 this.config$ = this.configSvr.Conf$;
62 this.projects$ = this.projectSvr.Projects$;
63 this.sdks$ = this.sdkSvr.Sdks$;
64 this.agentStatus$ = this.xdsAgentSvr.Status$;
66 // FIXME support multiple servers
69 // Bind xdsServerUrl to baseURL
70 this.xdsAgentSvr.XdsConfig$.subscribe(cfg => {
71 if (!cfg || cfg.servers.length < 1) {
74 const svr = cfg.servers[this.curServer];
75 this.curServerID = svr.id;
76 this.xdsServerConnected = svr.connected;
77 this.xdsServerUrl = svr.url;
78 this.xdsServerRetry = String(svr.connRetry);
79 this.projectsRootDir = ''; // SEB FIXME: add in go config? cfg.projectsRootDir;
83 submitGlobConf(field: string) {
86 const re = new RegExp('^[0-9]+$');
87 const rr = parseInt(this.xdsServerRetry, 10);
88 if (re.test(this.xdsServerRetry) && rr >= 0) {
89 this.xdsAgentSvr.setServerRetry(this.curServerID, rr);
91 this.alert.warning('Not a valid number', true);
95 this.configSvr.projectsRootDir = this.projectsRootDir;
100 this.showApplyBtn[field] = false;
103 xdsAgentRestartConn() {
104 const url = this.xdsServerUrl;
105 this.xdsAgentSvr.setServerUrl(this.curServerID, url);