[CORD-1538] Hiding id, backend-status and policy-status from forms, while displaying them in tables
Change-Id: If0412f76eb74a2c1274461781be4d3ce838e3258
diff --git a/src/app/core/services/helpers/config.helpers.spec.ts b/src/app/core/services/helpers/config.helpers.spec.ts
index d060001..5b2ae07 100644
--- a/src/app/core/services/helpers/config.helpers.spec.ts
+++ b/src/app/core/services/helpers/config.helpers.spec.ts
@@ -198,25 +198,22 @@
describe('the modelFieldToInputConfig', () => {
it('should return an array of inputs', () => {
const inputs: IXosFormInput[] = service.modelFieldToInputCfg(model.fields);
- expect(inputs[0].name).toBe('id');
- expect(inputs[0].type).toBe('number');
- expect(inputs[0].label).toBe('Id');
- expect(inputs[1].name).toBe('name');
+ expect(inputs[0].name).toBe('name');
+ expect(inputs[0].type).toBe('string');
+ expect(inputs[0].label).toBe('Name');
+ expect(inputs[0].validators.required).toBe(true);
+
+ expect(inputs[1].name).toBe('something');
expect(inputs[1].type).toBe('string');
- expect(inputs[1].label).toBe('Name');
- expect(inputs[1].validators.required).toBe(true);
+ expect(inputs[1].label).toBe('Something');
+ expect(inputs[1].validators.maxlength).toBe(30);
- expect(inputs[2].name).toBe('something');
- expect(inputs[2].type).toBe('string');
- expect(inputs[2].label).toBe('Something');
- expect(inputs[2].validators.maxlength).toBe(30);
-
- expect(inputs[3].name).toBe('else');
- expect(inputs[3].type).toBe('number');
- expect(inputs[3].label).toBe('Else');
- expect(inputs[3].validators.min).toBe(20);
- expect(inputs[3].validators.max).toBe(40);
+ expect(inputs[2].name).toBe('else');
+ expect(inputs[2].type).toBe('number');
+ expect(inputs[2].label).toBe('Else');
+ expect(inputs[2].validators.min).toBe(20);
+ expect(inputs[2].validators.max).toBe(40);
});
});
@@ -229,7 +226,8 @@
expect(config.actions[0].class).toBe('success');
expect(config.actions[0].icon).toBe('ok');
expect(config.actions[0].cb).toBeDefined();
- expect(config.inputs.length).toBe(4);
+ // NOTE 'id' and 'updated' are hidden fields
+ expect(config.inputs.length).toBe(3);
});
});
diff --git a/src/app/core/services/helpers/config.helpers.ts b/src/app/core/services/helpers/config.helpers.ts
index 32e0b16..ed3f0c0 100644
--- a/src/app/core/services/helpers/config.helpers.ts
+++ b/src/app/core/services/helpers/config.helpers.ts
@@ -61,9 +61,16 @@
'validators',
'password',
'backend_need_delete',
- 'backend_need_reap'
+ 'backend_need_reap',
+ 'leaf_model_name'
];
+ public form_excluded_fields = this.excluded_fields.concat([
+ 'id',
+ 'policy_status',
+ 'backend_status',
+ ]);
+
constructor(
private $state: ng.ui.IStateService,
private toastr: ng.toastr.IToastrService,
@@ -165,19 +172,19 @@
};
}
- if (f.name === 'backend_status') {
+ if (f.name === 'backend_status' || f.name === 'policy_status') {
col.type = 'icon';
col.hover = (item) => {
return item[f.name];
};
col.formatter = (item) => {
- if (item.backend_status.indexOf('1') > -1) {
+ if (item[f.name].indexOf('1') > -1) {
return 'check';
}
- if (item.backend_status.indexOf('2') > -1) {
+ if (item[f.name].indexOf('2') > -1) {
return 'exclamation-circle';
}
- if (item.backend_status.indexOf('0') > -1) {
+ if (item[f.name].indexOf('0') > -1) {
return 'clock-o';
}
};
@@ -236,13 +243,13 @@
}
return input;
})
- .filter(f => this.excluded_fields.indexOf(f.name) === -1);
+ .filter(f => this.form_excluded_fields.indexOf(f.name) === -1);
}
public modelToFormCfg(model: IXosModeldef): IXosFormCfg {
const formCfg: IXosFormCfg = {
formName: `${model.name}Form`,
- exclude: ['backend_status', 'creator', 'id'],
+ exclude: this.form_excluded_fields,
actions: [{
label: 'Save',
class: 'success',