Fixed build page when no project exists
authorSebastien Douheret <sebastien.douheret@iot.bzh>
Wed, 29 Nov 2017 23:11:34 +0000 (00:11 +0100)
committerSebastien Douheret <sebastien.douheret@iot.bzh>
Wed, 29 Nov 2017 23:11:34 +0000 (00:11 +0100)
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
webapp/src/app/pages/build/build.component.html
webapp/src/app/pages/build/build.component.ts
webapp/src/app/pages/build/settings/project-select-dropdown.component.ts
webapp/src/app/pages/config/config-xds/config-xds.component.ts
webapp/src/app/pages/dashboard/dashboard.component.html

index 1ce9484..6c8df72 100644 (file)
@@ -27,7 +27,7 @@
 
           <nb-card-body>
             <nb-actions size="medium" fullWidth>
-              <nb-action (click)="settingsShow()">
+              <nb-action (click)="settingsShow()" [disabled]="!isSetupValid()">
                 <i class="fa fa-cog"></i>
                 <span>Settings</span>
               </nb-action>
               <nb-action>
               </nb-action>
 
-              <nb-action (click)="clean()">
+              <nb-action (click)="clean()" [disabled]="!isSetupValid()">
                 <i class="fa fa-eraser"></i>
                 <span>Clean</span>
               </nb-action>
-              <nb-action (click)="preBuild()">
+              <nb-action (click)="preBuild()" [disabled]="!isSetupValid()">
                 <i class="nb-list"></i>
                 <span>Pre-Build</span>
               </nb-action>
-              <nb-action (click)="build()">
+              <nb-action (click)="build()" [disabled]="!isSetupValid()">
                 <i class="fa fa-wrench"></i>
                 <span>Build</span>
               </nb-action>
-              <nb-action (click)="populate()">
+              <nb-action (click)="populate()" [disabled]="!isSetupValid()">
                 <i class="fa fa-send"></i>
                 <span>Populate</span>
               </nb-action>
         </nb-tab>
 
         <nb-tab tabTitle="Deploy">
-          <span> Content deploy...</span>
+          <br><span>&nbsp;&nbsp; Under construction...</span>
         </nb-tab>
         <nb-tab tabTitle="Debug">
-          <span> Content debug...</span>
+          <br><span>&nbsp;&nbsp; Under construction...</span>
         </nb-tab>
       </nb-tabset>
     </nb-card>
index 99b7e54..681efe2 100644 (file)
@@ -31,6 +31,7 @@ export class BuildComponent implements OnInit, AfterViewChecked {
   public buildIsCollapsed = false;
   public cmdOutput: string;
   public cmdInfo: string;
+  public curPrj: IProject;
 
   private startTime: Map<string, number> = new Map<string, number>();
 
@@ -42,11 +43,13 @@ export class BuildComponent implements OnInit, AfterViewChecked {
     private modalService: NgbModal,
   ) {
     this.cmdOutput = '';
-    this.cmdInfo = '';      // TODO: to be remove (only for debug)
-
+    this.cmdInfo = '';       // TODO: to be remove (only for debug)
   }
 
   ngOnInit() {
+    // Retreive current project
+    this.prjSvr.curProject$.subscribe(p => this.curPrj = p);
+
     // Command output data tunneling
     this.xdsSvr.CmdOutput$.subscribe(data => {
       this.cmdOutput += data.stdout;
@@ -76,66 +79,82 @@ export class BuildComponent implements OnInit, AfterViewChecked {
     this.cmdOutput = '';
   }
 
+  isSetupValid(): boolean {
+    return (typeof this.curPrj !== 'undefined');
+  }
+
   settingsShow() {
+    if (!this.isSetupValid()) {
+      return this.alertSvr.warning('Please select first a valid project.', true);
+    }
+
     const activeModal = this.modalService.open(BuildSettingsModalComponent, { size: 'lg', container: 'nb-layout' });
     activeModal.componentInstance.modalHeader = 'Large Modal';
   }
 
   clean() {
-    const curPrj = this.prjSvr.getCurrent();
+    if (!this.isSetupValid()) {
+      return this.alertSvr.warning('Please select first a valid project.', true);
+    }
     this._exec(
-      curPrj.uiSettings.cmdClean,
-      curPrj.uiSettings.subpath,
+      this.curPrj.uiSettings.cmdClean,
+      this.curPrj.uiSettings.subpath,
       [],
-      curPrj.uiSettings.envVars.join(' '));
+      this.curPrj.uiSettings.envVars.join(' '));
   }
 
   preBuild() {
-    const curPrj = this.prjSvr.getCurrent();
+    if (!this.isSetupValid()) {
+      return this.alertSvr.warning('Please select first a valid project.', true);
+    }
     this._exec(
-      curPrj.uiSettings.cmdPrebuild,
-      curPrj.uiSettings.subpath,
+      this.curPrj.uiSettings.cmdPrebuild,
+      this.curPrj.uiSettings.subpath,
       [],
-      curPrj.uiSettings.envVars.join(' '));
+      this.curPrj.uiSettings.envVars.join(' '));
   }
 
   build() {
-    const curPrj = this.prjSvr.getCurrent();
+    if (!this.isSetupValid()) {
+      return this.alertSvr.warning('Please select first a valid project.', true);
+    }
     this._exec(
-      curPrj.uiSettings.cmdBuild,
-      curPrj.uiSettings.subpath,
+      this.curPrj.uiSettings.cmdBuild,
+      this.curPrj.uiSettings.subpath,
       [],
-      curPrj.uiSettings.envVars.join(' '),
+      this.curPrj.uiSettings.envVars.join(' '),
     );
   }
 
   populate() {
-    const curPrj = this.prjSvr.getCurrent();
+    if (!this.isSetupValid()) {
+      return this.alertSvr.warning('Please select first a valid project.', true);
+    }
     this._exec(
-      curPrj.uiSettings.cmdPopulate,
-      curPrj.uiSettings.subpath,
+      this.curPrj.uiSettings.cmdPopulate,
+      this.curPrj.uiSettings.subpath,
       [], // args
-      curPrj.uiSettings.envVars.join(' '),
+      this.curPrj.uiSettings.envVars.join(' '),
     );
   }
 
   execCmd() {
-    const curPrj = this.prjSvr.getCurrent();
+    if (!this.isSetupValid()) {
+      return this.alertSvr.warning('Please select first a valid project.', true);
+    }
     this._exec(
-      curPrj.uiSettings.cmdArgs.join(' '),
-      curPrj.uiSettings.subpath,
+      this.curPrj.uiSettings.cmdArgs.join(' '),
+      this.curPrj.uiSettings.subpath,
       [],
-      curPrj.uiSettings.envVars.join(' '),
+      this.curPrj.uiSettings.envVars.join(' '),
     );
   }
 
   private _exec(cmd: string, dir: string, args: string[], env: string) {
-    this.curProject = this.prjSvr.getCurrent();
-    const prjID = this.curProject.id;
-
-    if (!this.curProject) {
+    if (!this.isSetupValid()) {
       return this.alertSvr.warning('No active project', true);
     }
+    const prjID = this.curPrj.id;
 
     this.cmdOutput += this._outputHeader();
 
index a83ec0a..a99dc6b 100644 (file)
@@ -28,7 +28,9 @@ export class ProjectSelectDropdownComponent implements OnInit {
   }
 
   select() {
-    this.projectSvr.setCurrentById(this.curPrj.id);
+    if (this.curPrj) {
+      this.projectSvr.setCurrentById(this.curPrj.id);
+    }
   }
 }
 
index e62cd37..bd46145 100644 (file)
@@ -20,7 +20,7 @@ export class ConfigXdsComponent {
   // TODO: cleanup agentStatus$: Observable<IAgentStatus>;
   applying = false;
   xdsServerUrl = '';
-  server: IXDServerCfg = { id: '', url: '', connRetry: 10, connected: false };
+  server: IXDServerCfg = { id: '', url: 'http://localhost:8000', connRetry: 10, connected: false };
 
   configFormChanged = false;
 
index 9160019..ed6cfdb 100644 (file)
@@ -1,10 +1,9 @@
 <div class="row">
-  Dashboard page...
-  <!--
   <div class="col-xxxl-3 col-md-6">
+    <!--
     <ngx-status-card title="Light" type="primary">
       <i class="nb-lightbulb"></i>
     </ngx-status-card>
+    -->
   </div>
--->
 </div>