Fix sdk filters on page refresh 07/17307/2
authorelisa castro <elisa.castro@iot.bzh>
Thu, 18 Oct 2018 15:23:15 +0000 (17:23 +0200)
committerStéphane Desneux <stephane.desneux@iot.bzh>
Fri, 19 Oct 2018 23:43:34 +0000 (23:43 +0000)
Change-Id: I55e7c6f16eec3fdf6cca73f3c6f5cae08abc4a2b
Signed-off-by: elisa castro <elisa.castro@iot.bzh>
webapp/src/app/pages/sdks/sdk-management/sdk-management.component.ts

index 6e9b81b..051b6ef 100644 (file)
@@ -48,7 +48,6 @@ interface ISdkMgt extends ISdk {
 
 export class SdkManagementComponent implements OnInit {
 
-  sdks$: Observable<ISdk[]>;
   sdks: ISdkMgt[];
   source: LocalDataSource = new LocalDataSource();
 
@@ -68,8 +67,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 +83,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 +110,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 },