Add folder interface and support native pathmap folder type.
[src/xds/xds-server.git] / webapp / src / app / config / config.component.ts
index 745e9f6..0df707b 100644 (file)
@@ -7,11 +7,13 @@ import 'rxjs/add/operator/map';
 import 'rxjs/add/operator/filter';
 import 'rxjs/add/operator/debounceTime';
 
-import { ConfigService, IConfig, IProject, ProjectType } from "../common/config.service";
-import { XDSServerService, IServerStatus } from "../common/xdsserver.service";
-import { SyncthingService, ISyncThingStatus } from "../common/syncthing.service";
-import { AlertService } from "../common/alert.service";
-import { ISdk, SdkService } from "../common/sdk.service";
+import { ConfigService, IConfig, IProject, ProjectType, ProjectTypes,
+    IxdsAgentPackage } from "../services/config.service";
+import { XDSServerService, IServerStatus, IXDSAgentInfo } from "../services/xdsserver.service";
+import { XDSAgentService, IAgentStatus } from "../services/xdsagent.service";
+import { SyncthingService, ISyncThingStatus } from "../services/syncthing.service";
+import { AlertService } from "../services/alert.service";
+import { ISdk, SdkService } from "../services/sdk.service";
 
 @Component({
     templateUrl: './app/config/config.component.html',
@@ -25,15 +27,19 @@ export class ConfigComponent implements OnInit {
 
     config$: Observable<IConfig>;
     sdks$: Observable<ISdk[]>;
-    severStatus$: Observable<IServerStatus>;
+    serverStatus$: Observable<IServerStatus>;
+    agentStatus$: Observable<IAgentStatus>;
     localSTStatus$: Observable<ISyncThingStatus>;
 
     curProj: number;
     userEditedLabel: boolean = false;
+    xdsAgentPackages: IxdsAgentPackage[] = [];
+    projectTypes = ProjectTypes;
 
     // TODO replace by reactive FormControl + add validation
     syncToolUrl: string;
-    syncToolRetry: string;
+    xdsAgentUrl: string;
+    xdsAgentRetry: string;
     projectsRootDir: string;
     showApplyBtn = {    // Used to show/hide Apply buttons
         "retry": false,
@@ -41,40 +47,49 @@ export class ConfigComponent implements OnInit {
     };
 
     addProjectForm: FormGroup;
-    pathCtrl = new FormControl("", Validators.required);
-
+    pathCliCtrl = new FormControl("", Validators.required);
+    pathSvrCtrl = new FormControl("", Validators.required);
 
     constructor(
         private configSvr: ConfigService,
-        private xdsSvr: XDSServerService,
+        private xdsServerSvr: XDSServerService,
+        private xdsAgentSvr: XDSAgentService,
         private stSvr: SyncthingService,
         private sdkSvr: SdkService,
         private alert: AlertService,
         private fb: FormBuilder
     ) {
-        // FIXME implement multi project support
+        // Define types (first one is special/placeholder)
+        this.projectTypes.unshift({value: -1, display: "--Select a type--"});
+        let selectedType = this.projectTypes[0].value;
+
         this.curProj = 0;
         this.addProjectForm = fb.group({
-            path: this.pathCtrl,
+            pathCli: this.pathCliCtrl,
+            pathSvr: this.pathSvrCtrl,
             label: ["", Validators.nullValidator],
+            type: [selectedType, Validators.pattern("[0-9]+")],
         });
     }
 
     ngOnInit() {
         this.config$ = this.configSvr.conf;
         this.sdks$ = this.sdkSvr.Sdks$;
-        this.severStatus$ = this.xdsSvr.Status$;
+        this.serverStatus$ = this.xdsServerSvr.Status$;
+        this.agentStatus$ = this.xdsAgentSvr.Status$;
         this.localSTStatus$ = this.stSvr.Status$;
 
-        // Bind syncToolUrl to baseURL
+        // Bind xdsAgentUrl to baseURL
         this.config$.subscribe(cfg => {
             this.syncToolUrl = cfg.localSThg.URL;
-            this.syncToolRetry = String(cfg.localSThg.retry);
+            this.xdsAgentUrl = cfg.xdsAgent.URL;
+            this.xdsAgentRetry = String(cfg.xdsAgent.retry);
             this.projectsRootDir = cfg.projectsRootDir;
+            this.xdsAgentPackages = cfg.xdsAgentPackages;
         });
 
         // Auto create label name
-        this.pathCtrl.valueChanges
+        this.pathCliCtrl.valueChanges
             .debounceTime(100)
             .filter(n => n)
             .map(n => "Project_" + n.split('/')[0])
@@ -83,6 +98,9 @@ export class ConfigComponent implements OnInit {
                     this.addProjectForm.patchValue({ label: value });
                 }
             });
+
+        // Select 1 first type by default
+        // SEB this.typeCtrl.setValue({type: ProjectTypes[0].value});
     }
 
     onKeyLabel(event: any) {
@@ -93,9 +111,9 @@ export class ConfigComponent implements OnInit {
         switch (field) {
             case "retry":
                 let re = new RegExp('^[0-9]+$');
-                let rr = parseInt(this.syncToolRetry, 10);
-                if (re.test(this.syncToolRetry) && rr >= 0) {
-                    this.configSvr.syncToolRetry = rr;
+                let rr = parseInt(this.xdsAgentRetry, 10);
+                if (re.test(this.xdsAgentRetry) && rr >= 0) {
+                    this.configSvr.xdsAgentRetry = rr;
                 } else {
                     this.alert.warning("Not a valid number", true);
                 }
@@ -109,20 +127,25 @@ export class ConfigComponent implements OnInit {
         this.showApplyBtn[field] = false;
     }
 
-    syncToolRestartConn() {
+    xdsAgentRestartConn() {
+        let aUrl = this.xdsAgentUrl;
         this.configSvr.syncToolURL = this.syncToolUrl;
+        this.configSvr.xdsAgentUrl = aUrl;
         this.configSvr.loadProjects();
     }
 
     onSubmit() {
         let formVal = this.addProjectForm.value;
 
+        let type = formVal['type'].value;
+        let numType = Number(formVal['type']);
         this.configSvr.addProject({
             label: formVal['label'],
-            path: formVal['path'],
-            type: ProjectType.SYNCTHING,
+            pathClient: formVal['pathCli'],
+            pathServer: formVal['pathSvr'],
+            type: numType,
             // FIXME: allow to set defaultSdkID from New Project config panel
         });
     }
 
-}
\ No newline at end of file
+}