Add Cross SDKs support (part 2)
[src/xds/xds-server.git] / webapp / src / app / build / build.component.ts
index e1076c5..a99a1fe 100644 (file)
@@ -8,6 +8,7 @@ import 'rxjs/add/operator/startWith';
 import { XDSServerService, ICmdOutput } from "../common/xdsserver.service";
 import { ConfigService, IConfig, IProject } from "../common/config.service";
 import { AlertService, IAlert } from "../common/alert.service";
+import { SdkService } from "../common/sdk.service";
 
 @Component({
     selector: 'build',
@@ -32,8 +33,11 @@ export class BuildComponent implements OnInit, AfterViewChecked {
     private startTime: Map<string, number> = new Map<string, number>();
 
     // I initialize the app component.
-    constructor(private configSvr: ConfigService, private sdkSvr: XDSServerService,
-        private fb: FormBuilder, private alertSvr: AlertService
+    constructor(private configSvr: ConfigService,
+        private xdsSvr: XDSServerService,
+        private fb: FormBuilder,
+        private alertSvr: AlertService,
+        private sdkSvr: SdkService
     ) {
         this.cmdOutput = "";
         this.confValid = false;
@@ -44,18 +48,22 @@ export class BuildComponent implements OnInit, AfterViewChecked {
     ngOnInit() {
         this.config$ = this.configSvr.conf;
         this.config$.subscribe((cfg) => {
-            this.curProject = cfg.projects[0];
-
-            this.confValid = (cfg.projects.length && this.curProject.id != null);
+            if ("projects" in cfg) {
+                this.curProject = cfg.projects[0];
+                this.confValid = (cfg.projects.length && this.curProject.id != null);
+            } else {
+                this.curProject = null;
+                this.confValid = false;
+            }
         });
 
         // Command output data tunneling
-        this.sdkSvr.CmdOutput$.subscribe(data => {
+        this.xdsSvr.CmdOutput$.subscribe(data => {
             this.cmdOutput += data.stdout + "\n";
         });
 
         // Command exit
-        this.sdkSvr.CmdExit$.subscribe(exit => {
+        this.xdsSvr.CmdExit$.subscribe(exit => {
             if (this.startTime.has(exit.cmdID)) {
                 this.cmdInfo = 'Last command duration: ' + this._computeTime(this.startTime.get(exit.cmdID));
                 this.startTime.delete(exit.cmdID);
@@ -78,6 +86,10 @@ export class BuildComponent implements OnInit, AfterViewChecked {
     }
 
     make(args: string) {
+        if (!this.curProject) {
+            this.alertSvr.warning('No active project', true);
+        }
+
         let prjID = this.curProject.id;
 
         this.cmdOutput += this._outputHeader();
@@ -85,13 +97,15 @@ export class BuildComponent implements OnInit, AfterViewChecked {
         let t0 = performance.now();
         this.cmdInfo = 'Start build of ' + prjID + ' at ' + t0;
 
-        this.sdkSvr.make(prjID, this.buildForm.value.subpath, args)
+        let sdkid = this.sdkSvr.getCurrentId();
+
+        this.xdsSvr.make(prjID, this.buildForm.value.subpath, args, sdkid)
             .subscribe(res => {
                 this.startTime.set(String(res.cmdID), t0);
             },
             err => {
                 this.cmdInfo = 'Last command duration: ' + this._computeTime(t0);
-                this.alertSvr.add({ type: "danger", msg: 'ERROR: ' + err });
+                this.alertSvr.error('ERROR: ' + err);
             });
     }