Add Image Path
[src/xds/xds-agent.git] / webapp / src / app / pages / sdks / sdk-management / sdk-management.component.ts
index 68620a1..20932d3 100644 (file)
@@ -1,6 +1,6 @@
 /**
 * @license
-* Copyright (C) 2017 "IoT.bzh"
+* Copyright (C) 2017-2018 "IoT.bzh"
 * Author Sebastien Douheret <sebastien@iot.bzh>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -48,7 +48,6 @@ interface ISdkMgt extends ISdk {
 
 export class SdkManagementComponent implements OnInit {
 
-  sdks$: Observable<ISdk[]>;
   sdks: ISdkMgt[];
   source: LocalDataSource = new LocalDataSource();
 
@@ -58,8 +57,9 @@ export class SdkManagementComponent implements OnInit {
       add: false,
       edit: false,
       delete: false,  // TODO, add delete == uninstall
+      position: 'right',
       custom: [
-        { name: 'install', title: '<i class="nb-plus"></i>' },
+        { name: 'install', title: '<button type="button">Install</button>' },
       ],
     },
     delete: {
@@ -68,8 +68,8 @@ export class SdkManagementComponent implements OnInit {
     },
     columns: {
       name: { title: 'Name', editable: false },
-      profile: { title: 'Profile', editable: false, filter: {} },
-      arch: { title: 'Architecture', editable: false, filter: {} },
+      profile: { title: 'Profile', editable: false, filter: { type: 'list', config: {} } },
+      arch: { title: 'Architecture', editable: false, filter: { type: 'list', config: {} } },
       version: { title: 'Version', editable: false },
       // TODO: add status when delete supported:
       // status: { title: 'Status', editable: false },
@@ -84,10 +84,16 @@ export class SdkManagementComponent implements OnInit {
   ) { }
 
   ngOnInit() {
+
     this.sdkSvr.Sdks$.subscribe(sdks => {
       const profMap = {};
       const archMap = {};
       this.sdks = [];
+
+      if (sdks.length === 0) {
+        return;
+      }
+
       sdks.forEach(s => {
         // only display not installed SDK
         if (s.status !== StatusType.NOT_INSTALLED) {
@@ -105,14 +111,22 @@ export class SdkManagementComponent implements OnInit {
 
       });
 
+      // Create new reference of settings object to trig ngOnChanges event in ng2-smart-table
+      // and consequently rebuild settings grid
+      this.settings = Object.assign({}, this.settings);
+
       // Add text box filter for Profile and Arch columns
-      const profList = []; Object.keys(profMap).forEach(a => profList.push({ value: a, title: a }));
+      const profList = [];
+      Object.keys(profMap).forEach(a => profList.push({ value: a, title: a }));
+
       this.settings.columns.profile.filter = {
         type: 'list',
         config: { selectText: 'Select...', list: profList },
       };
 
-      const archList = []; Object.keys(archMap).forEach(a => archList.push({ value: a, title: a }));
+      const archList = [];
+      Object.keys(archMap).forEach(a => archList.push({ value: a, title: a }));
+
       this.settings.columns.arch.filter = {
         type: 'list',
         config: { selectText: 'Select...', list: archList },
@@ -141,15 +155,20 @@ export class SdkManagementComponent implements OnInit {
 
       modal.result.then(res => {
         if (res === 'yes') {
-          // Request installation
-          this.sdkSvr.install(sdk).subscribe(r => { }, err => this.alert.error(err));
-
           const modalInstall = this.modalService.open(SdkInstallComponent, {
             size: 'lg',
             backdrop: 'static',
             container: 'nb-layout',
           });
           modalInstall.componentInstance.sdk = sdk;
+
+          // Request installation
+          this.sdkSvr.install(sdk).subscribe(
+            r => { },
+            err => {
+              modalInstall.dismiss('SDK install failure');
+              this.alert.error(err);
+            });
         }
       });