mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
fix dynamic table validation (#1741)
- dynamic table widget no longer creates a copy of field model, but uses original one, fixes the problem with validation and state management - update unit tests
This commit is contained in:
parent
d32ed969a7
commit
44808a31a3
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { FormWidgetModel } from './../core/form-widget.model';
|
import { FormWidgetModel } from './../core/form-widget.model';
|
||||||
import { FormModel } from './../core/form.model';
|
|
||||||
import { FormFieldModel } from './../core/form-field.model';
|
import { FormFieldModel } from './../core/form-field.model';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
|
||||||
@ -50,19 +49,19 @@ export class DynamicTableModel extends FormWidgetModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(form: FormModel, json?: any) {
|
constructor(field: FormFieldModel) {
|
||||||
super(form, json);
|
super(field.form, field.json);
|
||||||
|
this.field = field;
|
||||||
|
|
||||||
if (json) {
|
if (field.json) {
|
||||||
this.field = new FormFieldModel(form, json);
|
|
||||||
|
|
||||||
if (json.columnDefinitions) {
|
if (field.json.columnDefinitions) {
|
||||||
this.columns = json.columnDefinitions.map(obj => <DynamicTableColumn> obj);
|
this.columns = field.json.columnDefinitions.map(obj => <DynamicTableColumn> obj);
|
||||||
this.visibleColumns = this.columns.filter(col => col.visible);
|
this.visibleColumns = this.columns.filter(col => col.visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.value) {
|
if (field.json.value) {
|
||||||
this.rows = json.value.map(obj => <DynamicTableRow> {selected: false, value: obj});
|
this.rows = field.json.value.map(obj => <DynamicTableRow> {selected: false, value: obj});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
import { LogServiceMock } from 'ng2-alfresco-core';
|
import { LogServiceMock } from 'ng2-alfresco-core';
|
||||||
import { DynamicTableWidget } from './dynamic-table.widget';
|
import { DynamicTableWidget } from './dynamic-table.widget';
|
||||||
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './dynamic-table.widget.model';
|
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './dynamic-table.widget.model';
|
||||||
import { FormModel, FormFieldTypes } from './../core/index';
|
import { FormModel, FormFieldTypes, FormFieldModel } from './../core/index';
|
||||||
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
import { WidgetVisibilityService } from '../../../services/widget-visibility.service';
|
||||||
|
|
||||||
describe('DynamicTableWidget', () => {
|
describe('DynamicTableWidget', () => {
|
||||||
@ -30,7 +30,8 @@ describe('DynamicTableWidget', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
logService = new LogServiceMock();
|
logService = new LogServiceMock();
|
||||||
table = new DynamicTableModel(null);
|
const field = new FormFieldModel(new FormModel());
|
||||||
|
table = new DynamicTableModel(field);
|
||||||
visibilityService = new WidgetVisibilityService(null, logService);
|
visibilityService = new WidgetVisibilityService(null, logService);
|
||||||
widget = new DynamicTableWidget(null, visibilityService, logService);
|
widget = new DynamicTableWidget(null, visibilityService, logService);
|
||||||
widget.content = table;
|
widget.content = table;
|
||||||
@ -223,11 +224,12 @@ describe('DynamicTableWidget', () => {
|
|||||||
|
|
||||||
it('should take validation state from underlying field', () => {
|
it('should take validation state from underlying field', () => {
|
||||||
let form = new FormModel();
|
let form = new FormModel();
|
||||||
widget.content = new DynamicTableModel(form, {
|
let field = new FormFieldModel(form, {
|
||||||
type: FormFieldTypes.DYNAMIC_TABLE,
|
type: FormFieldTypes.DYNAMIC_TABLE,
|
||||||
required: true,
|
required: true,
|
||||||
value: null
|
value: null
|
||||||
});
|
});
|
||||||
|
widget.content = new DynamicTableModel(field);
|
||||||
|
|
||||||
expect(widget.content.field.validate()).toBeFalsy();
|
expect(widget.content.field.validate()).toBeFalsy();
|
||||||
expect(widget.isValid()).toBe(widget.content.field.isValid);
|
expect(widget.isValid()).toBe(widget.content.field.isValid);
|
||||||
|
@ -44,7 +44,7 @@ export class DynamicTableWidget extends WidgetComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
if (this.field) {
|
if (this.field) {
|
||||||
this.content = new DynamicTableModel(this.field.form, this.field.json);
|
this.content = new DynamicTableModel(this.field);
|
||||||
this.visibilityService.refreshVisibility(this.field.form);
|
this.visibilityService.refreshVisibility(this.field.form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import { ElementRef } from '@angular/core';
|
|||||||
import { DateEditorComponent } from './date.editor';
|
import { DateEditorComponent } from './date.editor';
|
||||||
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './../../dynamic-table.widget.model';
|
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './../../dynamic-table.widget.model';
|
||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
|
import { FormFieldModel, FormModel } from '../../../index';
|
||||||
|
|
||||||
describe('DateEditorComponent', () => {
|
describe('DateEditorComponent', () => {
|
||||||
|
|
||||||
@ -36,7 +37,8 @@ describe('DateEditorComponent', () => {
|
|||||||
|
|
||||||
row = <DynamicTableRow> { value: { date: '1879-03-14T00:00:00.000Z' } };
|
row = <DynamicTableRow> { value: { date: '1879-03-14T00:00:00.000Z' } };
|
||||||
column = <DynamicTableColumn> { id: 'date', type: 'Date' };
|
column = <DynamicTableColumn> { id: 'date', type: 'Date' };
|
||||||
table = new DynamicTableModel(null);
|
const field = new FormFieldModel(new FormModel());
|
||||||
|
table = new DynamicTableModel(field);
|
||||||
table.rows.push(row);
|
table.rows.push(row);
|
||||||
table.columns.push(column);
|
table.columns.push(column);
|
||||||
|
|
||||||
|
@ -51,8 +51,7 @@ describe('DropdownEditorComponent', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
form = new FormModel({ taskId: '<task-id>' });
|
form = new FormModel({ taskId: '<task-id>' });
|
||||||
table = new DynamicTableModel(form, null);
|
table = new DynamicTableModel(new FormFieldModel(form, { id: '<field-id>' }));
|
||||||
table.field = new FormFieldModel(form, { id: '<field-id>' });
|
|
||||||
table.rows.push(row);
|
table.rows.push(row);
|
||||||
table.columns.push(column);
|
table.columns.push(column);
|
||||||
|
|
||||||
@ -150,8 +149,7 @@ describe('DropdownEditorComponent', () => {
|
|||||||
it('should handle REST error getting option with processDefinitionId', () => {
|
it('should handle REST error getting option with processDefinitionId', () => {
|
||||||
column.optionType = 'rest';
|
column.optionType = 'rest';
|
||||||
let procForm = new FormModel ({processDefinitionId: '<process-definition-id>'});
|
let procForm = new FormModel ({processDefinitionId: '<process-definition-id>'});
|
||||||
let procTable = new DynamicTableModel(procForm, null);
|
let procTable = new DynamicTableModel(new FormFieldModel(procForm, { id: '<field-id>' }));
|
||||||
procTable.field = new FormFieldModel(form, { id: '<field-id>' });
|
|
||||||
component.table = procTable;
|
component.table = procTable;
|
||||||
const error = 'error';
|
const error = 'error';
|
||||||
|
|
||||||
@ -219,8 +217,7 @@ describe('DropdownEditorComponent', () => {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
form = new FormModel({ taskId: '<task-id>' });
|
form = new FormModel({ taskId: '<task-id>' });
|
||||||
dynamicTable = new DynamicTableModel(form, null);
|
dynamicTable = new DynamicTableModel(new FormFieldModel(form, { id: '<field-id>' }));
|
||||||
dynamicTable.field = new FormFieldModel(form, { id: '<field-id>' });
|
|
||||||
dynamicTable.rows.push(row);
|
dynamicTable.rows.push(row);
|
||||||
dynamicTable.columns.push(column);
|
dynamicTable.columns.push(column);
|
||||||
dropDownEditorComponent.table = dynamicTable;
|
dropDownEditorComponent.table = dynamicTable;
|
||||||
@ -261,8 +258,7 @@ describe('DropdownEditorComponent', () => {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
form = new FormModel({ processDefinitionId: '<proc-id>' });
|
form = new FormModel({ processDefinitionId: '<proc-id>' });
|
||||||
dynamicTable = new DynamicTableModel(form, null);
|
dynamicTable = new DynamicTableModel(new FormFieldModel(form, { id: '<field-id>' }));
|
||||||
dynamicTable.field = new FormFieldModel(form, { id: '<field-id>' });
|
|
||||||
dynamicTable.rows.push(row);
|
dynamicTable.rows.push(row);
|
||||||
dynamicTable.columns.push(column);
|
dynamicTable.columns.push(column);
|
||||||
dropDownEditorComponent.table = dynamicTable;
|
dropDownEditorComponent.table = dynamicTable;
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import { RowEditorComponent } from './row.editor';
|
import { RowEditorComponent } from './row.editor';
|
||||||
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn, DynamicRowValidationSummary } from './../dynamic-table.widget.model';
|
import { DynamicTableModel, DynamicTableRow, DynamicTableColumn, DynamicRowValidationSummary } from './../dynamic-table.widget.model';
|
||||||
|
import { FormFieldModel, FormModel } from '../../index';
|
||||||
|
|
||||||
describe('RowEditorComponent', () => {
|
describe('RowEditorComponent', () => {
|
||||||
|
|
||||||
@ -24,7 +25,8 @@ describe('RowEditorComponent', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
component = new RowEditorComponent();
|
component = new RowEditorComponent();
|
||||||
component.table = new DynamicTableModel(null);
|
const field = new FormFieldModel(new FormModel());
|
||||||
|
component.table = new DynamicTableModel(field);
|
||||||
component.row = <DynamicTableRow> {};
|
component.row = <DynamicTableRow> {};
|
||||||
component.column = <DynamicTableColumn> {};
|
component.column = <DynamicTableColumn> {};
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user