From 084d9622305d2a66574bb5698af1b44804c1ea7d Mon Sep 17 00:00:00 2001 From: Denys Vuika Date: Tue, 15 Nov 2016 10:46:49 +0000 Subject: [PATCH] #967 dynamic container resolution --- .../components/activiti-form.component.html | 15 +------------ .../activiti-start-form.component.html | 18 +-------------- .../container/container.widget.spec.ts | 12 +++++----- .../widgets/container/container.widget.ts | 22 +++++++++---------- .../src/components/widgets/core/form.model.ts | 1 + .../dynamic-table/dynamic-table.widget.ts | 11 +++++++--- .../components/widgets/tabs/tabs.widget.html | 15 +------------ .../components/widgets/widget.component.ts | 5 +++++ .../src/services/form-rendering.service.ts | 7 ++++-- 9 files changed, 38 insertions(+), 68 deletions(-) diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.html b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.html index acbafc7105..48411ae393 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.html +++ b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.html @@ -15,20 +15,7 @@
-
-
- -
-
- -
-
- -
-
- -
-
+
diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html b/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html index 2dd449b9b6..5914fefde0 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html +++ b/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html @@ -12,23 +12,7 @@
-
-
- -
-
- -
-
- -
-
- -
-
- UNKNOWN WIDGET TYPE: {{field.type}} -
-
+
diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.spec.ts b/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.spec.ts index 3d7b483660..e6b91febfd 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.spec.ts @@ -103,14 +103,14 @@ describe('ContainerWidget', () => { let widget = new ContainerWidget(); let fakeForm = new FormModel(); let fakeField = new FormFieldModel(fakeForm, {id: 'fakeField', value: 'fakeValue'}); - widget.formValueChanged.subscribe(field => { + widget.fieldChanged.subscribe(field => { expect(field).not.toBe(null); expect(field.id).toBe('fakeField'); expect(field.value).toBe('fakeValue'); done(); }); - widget.fieldChanged(fakeField); + widget.onFieldChanged(fakeField); }); describe('when template is ready', () => { @@ -180,7 +180,7 @@ describe('ContainerWidget', () => { it('should hide header when it becomes not visible', async(() => { containerWidgetComponent.content = fakeContainerVisible; fixture.detectChanges(); - containerWidgetComponent.formValueChanged.subscribe((res) => { + containerWidgetComponent.fieldChanged.subscribe((res) => { containerWidgetComponent.content.field.isVisible = false; fixture.detectChanges(); fixture.whenStable() @@ -189,12 +189,12 @@ describe('ContainerWidget', () => { expect(element.querySelector('#container-header-label')).toBeNull(); }); }); - containerWidgetComponent.fieldChanged(null); + containerWidgetComponent.onFieldChanged(null); })); it('should show header when it becomes visible', async(() => { containerWidgetComponent.content = fakeContainerInvisible; - containerWidgetComponent.formValueChanged.subscribe((res) => { + containerWidgetComponent.fieldChanged.subscribe((res) => { containerWidgetComponent.content.field.isVisible = true; fixture.detectChanges(); fixture.whenStable() @@ -205,7 +205,7 @@ describe('ContainerWidget', () => { expect(element.querySelector('#container-header-label').innerHTML).toContain('fake-cont-2-name'); }); }); - containerWidgetComponent.fieldChanged(null); + containerWidgetComponent.onFieldChanged(null); })); }); diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.ts index 713de93949..f4ed5d4b19 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/container/container.widget.ts @@ -15,8 +15,9 @@ * limitations under the License. */ -import { Component, Input, AfterViewInit, Output, EventEmitter } from '@angular/core'; -import { ContainerModel, FormFieldModel } from './../core/index'; +import { Component, AfterViewInit, OnInit } from '@angular/core'; +import { ContainerModel } from './../core/index'; +import { WidgetComponent } from './../widget.component'; @Component({ moduleId: module.id, @@ -24,20 +25,22 @@ import { ContainerModel, FormFieldModel } from './../core/index'; templateUrl: './container.widget.html', styleUrls: ['./container.widget.css'] }) -export class ContainerWidget implements AfterViewInit { +export class ContainerWidget extends WidgetComponent implements OnInit, AfterViewInit { - @Input() content: ContainerModel; - @Output() - formValueChanged: EventEmitter = new EventEmitter(); - onExpanderClicked() { if (this.content && this.content.isCollapsible()) { this.content.isExpanded = !this.content.isExpanded; } } + ngOnInit() { + if (this.field) { + this.content = new ContainerModel(this.field.form, this.field.json); + } + } + ngAfterViewInit() { this.setupMaterialComponents(); } @@ -50,9 +53,4 @@ export class ContainerWidget implements AfterViewInit { } return false; } - - fieldChanged(field: FormFieldModel) { - this.formValueChanged.emit(field); - } - } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/core/form.model.ts b/ng2-components/ng2-activiti-form/src/components/widgets/core/form.model.ts index 003b2cfc62..09c9100bc6 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/core/form.model.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/core/form.model.ts @@ -43,6 +43,7 @@ export class FormModel { readOnly: boolean = false; tabs: TabModel[] = []; + /** Stores root containers */ fields: FormWidgetModel[] = []; outcomes: FormOutcomeModel[] = []; diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts index 14bbf832f1..e6382ca9e0 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/dynamic-table/dynamic-table.widget.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { Component, Input, ElementRef } from '@angular/core'; +import { Component, ElementRef, OnInit } from '@angular/core'; import { WidgetComponent } from './../widget.component'; import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './../core/index'; @@ -25,11 +25,10 @@ import { DynamicTableModel, DynamicTableRow, DynamicTableColumn } from './../cor templateUrl: './dynamic-table.widget.html', styleUrls: ['./dynamic-table.widget.css'] }) -export class DynamicTableWidget extends WidgetComponent { +export class DynamicTableWidget extends WidgetComponent implements OnInit { ERROR_MODEL_NOT_FOUND = 'Table model not found'; - @Input() content: DynamicTableModel; editMode: boolean = false; @@ -39,6 +38,12 @@ export class DynamicTableWidget extends WidgetComponent { super(); } + ngOnInit() { + if (this.field) { + this.content = new DynamicTableModel(this.field.form, this.field.json); + } + } + isValid() { let result = true; diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/tabs/tabs.widget.html b/ng2-components/ng2-activiti-form/src/components/widgets/tabs/tabs.widget.html index d532485a07..799829fde4 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/tabs/tabs.widget.html +++ b/ng2-components/ng2-activiti-form/src/components/widgets/tabs/tabs.widget.html @@ -13,20 +13,7 @@ [class.is-active]="isFirst" [attr.id]="tab.id">
-
-
- -
-
- -
-
- -
-
- -
-
+
diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.ts b/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.ts index b3d6f4e54d..ea96638258 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/widget.component.ts @@ -79,10 +79,15 @@ export class WidgetComponent implements AfterViewInit { return false; } + /** @deprecated use onFieldChanged instead */ checkVisibility(field: FormFieldModel) { this.fieldChanged.emit(field); } + onFieldChanged(field: FormFieldModel) { + this.fieldChanged.emit(field); + } + protected getHyperlinkUrl(field: FormFieldModel) { let url = WidgetComponent.DEFAULT_HYPERLINK_URL; if (field && field.hyperlinkUrl) { diff --git a/ng2-components/ng2-activiti-form/src/services/form-rendering.service.ts b/ng2-components/ng2-activiti-form/src/services/form-rendering.service.ts index 2edd1fb5b5..d502aa3bcb 100644 --- a/ng2-components/ng2-activiti-form/src/services/form-rendering.service.ts +++ b/ng2-components/ng2-activiti-form/src/services/form-rendering.service.ts @@ -36,7 +36,8 @@ import { FunctionalGroupWidget, DynamicTableWidget, AttachWidget, - UploadWidget + UploadWidget, + ContainerWidget } from './../components/widgets/index'; @Injectable() @@ -57,7 +58,9 @@ export class FormRenderingService { 'typeahead': DefaultTypeResolver.fromType(TypeaheadWidget), 'people': DefaultTypeResolver.fromType(PeopleWidget), 'functional-group': DefaultTypeResolver.fromType(FunctionalGroupWidget), - 'dynamic-table': DefaultTypeResolver.fromType(DynamicTableWidget) + 'dynamic-table': DefaultTypeResolver.fromType(DynamicTableWidget), + 'container': DefaultTypeResolver.fromType(ContainerWidget), + 'group': DefaultTypeResolver.fromType(ContainerWidget) }; constructor() {