diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.html b/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.html index 375c3a884b..cc370722a9 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.html +++ b/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.html @@ -42,30 +42,7 @@
- -
-
{{field.name}}
-
- - - - - - - - - - - -
- {{column.name}} -
- {{ getCellValue(row, column) }} -
-
-
+
diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.spec.ts index 49d5339b79..2cb5bee5b9 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.spec.ts @@ -15,6 +15,7 @@ * limitations under the License. */ +import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; import { ComponentFixture, TestBed, async } from '@angular/core/testing'; import { CoreModule, LogServiceMock } from 'ng2-alfresco-core'; import { Observable } from 'rxjs/Rx'; @@ -25,7 +26,6 @@ import { EcmModelService } from '../../../services/ecm-model.service'; import { FormFieldModel } from './../core/form-field.model'; import { FormFieldTypes } from '../core/form-field-types'; import { FormModel } from '../core/form.model'; -import { DynamicTableColumn, DynamicTableRow } from './../dynamic-table/dynamic-table.widget.model'; import { WidgetVisibilityService } from '../../../services/widget-visibility.service'; describe('DisplayValueWidget', () => { @@ -608,135 +608,6 @@ describe('DisplayValueWidget', () => { expect(widget.value).toBe(value); }); - it('should setup [DYNAMIC_TABLE] field', () => { - let columns = [{id: '1', visible: false}, {id: '2', visible: true}]; - let rows = [{}, {}]; - - widget.field = new FormFieldModel(null, { - type: FormFieldTypes.DISPLAY_VALUE, - params: { - field: { - type: FormFieldTypes.DYNAMIC_TABLE - } - }, - columnDefinitions: columns, - value: rows - }); - widget.ngOnInit(); - - expect(widget.columns.length).toBe(2); - expect(widget.columns[0].id).toBe(columns[0].id); - expect(widget.columns[1].id).toBe(columns[1].id); - - expect(widget.visibleColumns.length).toBe(1); - expect(widget.visibleColumns[0].id).toBe(columns[1].id); - - expect(widget.rows.length).toBe(2); - }); - - it('should setup [DYNAMIC_TABLE] field with empty schema', () => { - widget.field = new FormFieldModel(null, { - type: FormFieldTypes.DISPLAY_VALUE, - params: { - field: { - type: FormFieldTypes.DYNAMIC_TABLE - } - }, - columnDefinitions: null, - value: null - }); - widget.ngOnInit(); - - expect(widget.value).toBeNull(); - expect(widget.columns).toEqual([]); - expect(widget.rows).toEqual([]); - }); - - it('should retrieve default cell value', () => { - const value = ''; - let row = {value: {key: value}}; - let column = {id: 'key'}; - - expect(widget.getCellValue(row, column)).toBe(value); - }); - - it('should retrieve dropdown cell value', () => { - const value = {id: '1', name: 'one'}; - let row = {value: {key: value}}; - let column = {id: 'key', type: 'Dropdown'}; - - expect(widget.getCellValue(row, column)).toBe(value.name); - }); - - it('should fallback to empty cell value for dropdown', () => { - let row = {value: {}}; - let column = {id: 'key', type: 'Dropdown'}; - - expect(widget.getCellValue(row, column)).toBe(''); - }); - - it('should retrieve boolean cell value', () => { - let row1 = {value: {key: true}}; - let row2 = {value: {key: 'positive'}}; - let row3 = {value: {key: null}}; - let column = {id: 'key', type: 'Boolean'}; - - expect(widget.getCellValue(row1, column)).toBe(true); - expect(widget.getCellValue(row2, column)).toBe(true); - expect(widget.getCellValue(row3, column)).toBe(false); - }); - - it('should retrieve date cell value', () => { - const value = '2016-10-04T00:00:00.000Z'; - let row = {value: {key: value}}; - let column = {id: 'key', type: 'Date'}; - - expect(widget.getCellValue(row, column)).toBe('4-10-2016'); - }); - - it('should fallback to empty cell value for date', () => { - let row = {value: {}}; - let column = {id: 'key', type: 'Date'}; - - expect(widget.getCellValue(row, column)).toBe(''); - }); - - it('should retrieve empty text cell value', () => { - let row = {value: {}}; - let column = {id: 'key'}; - - expect(widget.getCellValue(row, column)).toBe(''); - }); - - it('should prepend default amount currency', () => { - const value = '10'; - let row = {value: {key: value}}; - let column = {id: 'key', type: 'Amount'}; - - const expected = `$ ${value}`; - expect(widget.getCellValue(row, column)).toBe(expected); - }); - - it('should prepend custom amount currency', () => { - const value = '10'; - const currency = 'GBP'; - let row = {value: {key: value}}; - let column = {id: 'key', type: 'Amount', amountCurrency: currency}; - - const expected = `${currency} ${value}`; - expect(widget.getCellValue(row, column)).toBe(expected); - }); - - it('should use zero for missing amount', () => { - const value = null; - const currency = 'GBP'; - let row = {value: {key: value}}; - let column = {id: 'key', type: 'Amount', amountCurrency: currency}; - - const expected = `${currency} 0`; - expect(widget.getCellValue(row, column)).toBe(expected); - }); - describe('UI check', () => { let widgetUI: DisplayValueWidget; let fixture: ComponentFixture; @@ -748,12 +619,16 @@ describe('DisplayValueWidget', () => { window['componentHandler'] = componentHandler; TestBed.configureTestingModule({ imports: [CoreModule], - declarations: [DisplayValueWidget, ActivitiContent], + declarations: [ + DisplayValueWidget, + ActivitiContent + ], providers: [ EcmModelService, FormService, WidgetVisibilityService - ] + ], + schemas: [ CUSTOM_ELEMENTS_SCHEMA ] }).compileComponents().then(() => { fixture = TestBed.createComponent(DisplayValueWidget); widgetUI = fixture.componentInstance; diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.ts index b50edcce45..c1f16decf6 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/display-value/display-value.widget.ts @@ -22,7 +22,6 @@ import { WidgetComponent } from './../widget.component'; import { FormFieldTypes } from '../core/form-field-types'; import { FormService } from '../../../services/form.service'; import { FormFieldOption } from './../core/form-field-option'; -import { DynamicTableColumn, DynamicTableRow } from './../dynamic-table/dynamic-table.widget.model'; import { WidgetVisibilityService } from '../../../services/widget-visibility.service'; import { NumberFieldValidator } from '../core/form-field-validator'; @@ -43,9 +42,7 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit { linkText: string; // dynamic table - rows: DynamicTableRow[] = []; - columns: DynamicTableColumn[] = []; - visibleColumns: DynamicTableColumn[] = []; + tableEditable = false; // upload/attach hasFile: boolean = false; @@ -65,6 +62,10 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit { if (this.field.params['showDocumentContent'] !== undefined) { this.showDocumentContent = !!this.field.params['showDocumentContent']; } + if (this.field.params['tableEditable'] !== undefined) { + this.tableEditable = !!this.field.params['tableEditable']; + } + let originalField = this.field.params['field']; if (originalField && originalField.type) { this.fieldType = originalField.type; @@ -138,16 +139,6 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit { this.linkUrl = this.getHyperlinkUrl(this.field); this.linkText = this.getHyperlinkText(this.field); break; - case FormFieldTypes.DYNAMIC_TABLE: - let json = this.field.json; - if (json.columnDefinitions) { - this.columns = json.columnDefinitions.map(obj => obj); - this.visibleColumns = this.columns.filter(col => col.visible); - } - if (json.value) { - this.rows = json.value.map(obj => {selected: false, value: obj}); - } - break; default: this.value = this.field.value; break; @@ -222,31 +213,4 @@ export class DisplayValueWidget extends WidgetComponent implements OnInit { } ); } - - getCellValue(row: DynamicTableRow, column: DynamicTableColumn): any { - - let result = row.value[column.id]; - - if (column.type === 'Dropdown') { - if (result) { - return result.name; - } - } - - if (column.type === 'Boolean') { - return result ? true : false; - } - - if (column.type === 'Date') { - if (result) { - return moment(result.split('T')[0], 'YYYY-MM-DD').format('D-M-YYYY'); - } - } - - if (column.type === 'Amount') { - return (column.amountCurrency || '$') + ' ' + (result || 0); - } - - return result || ''; - } } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.html b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.html index cb78fcb0e8..7c5270ba6a 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.html +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.html @@ -1,9 +1,9 @@
-
{{content.name}}
+
{{content.name}}
-
-
+
+
@@ -24,9 +24,9 @@
-
+
-
+