1 import { Component, ViewChild, OnInit } from "@angular/core";
2 import { Observable } from 'rxjs/Observable';
3 import { FormControl, FormGroup, Validators, FormBuilder } from '@angular/forms';
4 import { CollapseModule } from 'ngx-bootstrap/collapse';
6 import { ConfigService, IConfig, IxdsAgentPackage } from "../services/config.service";
7 import { XDSServerService, IServerStatus, IXDSAgentInfo } from "../services/xdsserver.service";
8 import { XDSAgentService, IAgentStatus } from "../services/xdsagent.service";
9 import { SyncthingService, ISyncThingStatus } from "../services/syncthing.service";
10 import { AlertService } from "../services/alert.service";
11 import { ISdk, SdkService } from "../services/sdk.service";
12 import { ProjectAddModalComponent } from "../projects/projectAddModal.component";
13 import { SdkAddModalComponent } from "../sdks/sdkAddModal.component";
16 templateUrl: './app/config/config.component.html',
17 styleUrls: ['./app/config/config.component.css']
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 sdks$: Observable<ISdk[]>;
29 serverStatus$: Observable<IServerStatus>;
30 agentStatus$: Observable<IAgentStatus>;
31 localSTStatus$: Observable<ISyncThingStatus>;
34 userEditedLabel: boolean = false;
35 xdsAgentPackages: IxdsAgentPackage[] = [];
37 gConfigIsCollapsed: boolean = true;
38 sdksIsCollapsed: boolean = true;
39 projectsIsCollapsed: boolean = false;
41 // TODO replace by reactive FormControl + add validation
44 xdsAgentRetry: 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 xdsServerSvr: XDSServerService,
54 private xdsAgentSvr: XDSAgentService,
55 private stSvr: SyncthingService,
56 private sdkSvr: SdkService,
57 private alert: AlertService,
62 this.config$ = this.configSvr.conf;
63 this.sdks$ = this.sdkSvr.Sdks$;
64 this.serverStatus$ = this.xdsServerSvr.Status$;
65 this.agentStatus$ = this.xdsAgentSvr.Status$;
66 this.localSTStatus$ = this.stSvr.Status$;
68 // Bind xdsAgentUrl to baseURL
69 this.config$.subscribe(cfg => {
70 this.syncToolUrl = cfg.localSThg.URL;
71 this.xdsAgentUrl = cfg.xdsAgent.URL;
72 this.xdsAgentRetry = String(cfg.xdsAgent.retry);
73 this.projectsRootDir = cfg.projectsRootDir;
74 this.xdsAgentPackages = cfg.xdsAgentPackages;
79 submitGlobConf(field: string) {
82 let re = new RegExp('^[0-9]+$');
83 let rr = parseInt(this.xdsAgentRetry, 10);
84 if (re.test(this.xdsAgentRetry) && rr >= 0) {
85 this.configSvr.xdsAgentRetry = rr;
87 this.alert.warning("Not a valid number", true);
91 this.configSvr.projectsRootDir = this.projectsRootDir;
96 this.showApplyBtn[field] = false;
99 xdsAgentRestartConn() {
100 let aUrl = this.xdsAgentUrl;
101 this.configSvr.syncToolURL = this.syncToolUrl;
102 this.configSvr.xdsAgentUrl = aUrl;
103 this.configSvr.loadProjects();