Reset default excluded_fields for different models

Change-Id: Iecaab7077ffcb0331aec410bf413d3bae27cf6a4
diff --git a/src/app/core/services/helpers/config.helpers.spec.ts b/src/app/core/services/helpers/config.helpers.spec.ts
index decc059..35e6268 100644
--- a/src/app/core/services/helpers/config.helpers.spec.ts
+++ b/src/app/core/services/helpers/config.helpers.spec.ts
@@ -84,7 +84,9 @@
     },
   ],
   description: '',
-  verbose_name: ''
+  verbose_name: '',
+  policy_implemented: 'True',
+  sync_implemented: 'True'
 };
 
 describe('The ConfigHelpers service', () => {
@@ -200,6 +202,7 @@
 
   describe('the modelFieldsToColumnsCfg method', () => {
     it('should return an array of columns', () => {
+
       const cols = service.modelFieldsToColumnsCfg({fields: model.fields, name: 'testUrl', app: 'test', description: '', verbose_name: ''});
       expect(cols[0].label).toBe('Id');
       expect(cols[0].prop).toBe('id');
@@ -220,10 +223,57 @@
       expect(cols[4]).not.toBeDefined();
     });
 
+    describe('it should handle sync_implemented and policy_implemented options', () => {
+
+      const modelFields: IXosModelDefsField[] = [
+        {
+          type: 'string',
+          name: 'policy_status',
+          validators: [],
+          read_only: false
+        },
+        {
+          type: 'string',
+          name: 'name',
+          validators: [],
+          read_only: false
+        },
+        {
+          type: 'string',
+          name: 'backend_status',
+          validators: [],
+          read_only: false
+        }
+      ];
+
+      const model: IXosModeldef = {
+        fields: modelFields,
+        name: 'testUrl',
+        app: 'test',
+        description: '',
+        verbose_name: ''
+      };
+
+      it('should not create columns for policy and sync status unless defined', () => {
+        model.policy_implemented = '';
+        model.sync_implemented = '';
+        const cols = service.modelFieldsToColumnsCfg(model);
+        expect(cols.length).toBe(1); // we strip backend_status and policy_status
+      });
+
+      it('should create columns for policy and sync status unless defined', () => {
+        model.policy_implemented = 'True';
+        model.sync_implemented = 'True';
+        const cols = service.modelFieldsToColumnsCfg(model);
+        expect(cols.length).toBe(3); // we DO NOT strip backend_status and policy_status
+      });
+
+    });
   });
 
   describe('the modelToTableCfg method', () => {
     it('should return a table config', () => {
+      service.excluded_fields = ['foo', 'bar'];
       const cfg: IXosTableCfg = service.modelToTableCfg(model, 'testUrl/:id?');
       expect(cfg.columns).toBeDefined();
       expect(cfg.filter).toBe('fulltext');
@@ -231,6 +281,7 @@
       expect(cfg.actions.length).toBe(2);
       expect(cfg.actions[0].label).toEqual('details');
       expect(cfg.actions[1].label).toEqual('delete');
+      expect(service.excluded_fields).toEqual(service.base_excluded_fields);
     });
   });
 
diff --git a/src/app/core/services/helpers/config.helpers.ts b/src/app/core/services/helpers/config.helpers.ts
index fff00ee..fcb9e00 100644
--- a/src/app/core/services/helpers/config.helpers.ts
+++ b/src/app/core/services/helpers/config.helpers.ts
@@ -46,6 +46,7 @@
 }
 
 export interface IXosConfigHelpersService {
+  base_excluded_fields: string[];
   excluded_fields: string[];
   form_excluded_fields: string[];
   modelFieldsToColumnsCfg(model: IXosModeldef): IXosTableColumn[];
@@ -70,7 +71,7 @@
     'XosFormHelpers'
   ];
 
-  public excluded_fields = [
+  public base_excluded_fields = [
     'created',
     'updated',
     'enacted',
@@ -94,6 +95,8 @@
     'backend_code'
   ];
 
+  public excluded_fields = angular.copy(this.base_excluded_fields);
+
   public form_excluded_fields = this.excluded_fields.concat([
     'id',
     'policy_status',
@@ -142,6 +145,7 @@
   }
 
   public modelToTableCfg(model: IXosModeldef, baseUrl: string): IXosTableCfg {
+    this.reset_excluded_fields();
     const cfg = {
       columns: this.modelFieldsToColumnsCfg(model),
       filter: 'fulltext',
@@ -188,14 +192,6 @@
     const fields: IXosModelDefsField[] = model.fields;
     const modelName: string = model.name;
     const columns =  _.map(fields, (f) => {
-      if (!angular.isDefined(f) || this.excluded_fields.indexOf(f.name) > -1) {
-        return;
-      }
-      const col: IXosTableColumn =  {
-        label: this.toLabel(f.name),
-        prop: f.name
-      };
-
       if (model.sync_implemented !== 'True') {
         this.excluded_fields.push('backend_status');
       }
@@ -204,6 +200,14 @@
         this.excluded_fields.push('policy_status');
       }
 
+      if (!angular.isDefined(f) || this.excluded_fields.indexOf(f.name) > -1) {
+        return;
+      }
+      const col: IXosTableColumn =  {
+        label: this.toLabel(f.name),
+        prop: f.name
+      };
+
       if (f.name === 'id' || f.name === 'name') {
         col.link = item => this.stateWithParamsForJs(modelName, item.id);
       }
@@ -449,4 +453,8 @@
         });
       });
   }
+
+  private reset_excluded_fields() {
+    this.excluded_fields = angular.copy(this.base_excluded_fields);
+  }
 }
diff --git a/src/app/datasources/stores/model.store.spec.ts b/src/app/datasources/stores/model.store.spec.ts
index ce3e2cd..80e7dc1 100644
--- a/src/app/datasources/stores/model.store.spec.ts
+++ b/src/app/datasources/stores/model.store.spec.ts
@@ -143,7 +143,7 @@
   describe('when a web-socket event is received for that model', () => {
     it('should update the collection', (done) => {
       let event = 0;
-      service.query('sample')
+      service.query('sample', '/core/samples')
         .subscribe(
           collection => {
             event++;