diff --git a/demo-shell-ng2/app/components/form/form-list-demo.component.ts b/demo-shell-ng2/app/components/form/form-list-demo.component.ts index 162b04084b..90b9eb930f 100644 --- a/demo-shell-ng2/app/components/form/form-list-demo.component.ts +++ b/demo-shell-ng2/app/components/form/form-list-demo.component.ts @@ -66,8 +66,8 @@ export class FormListDemoComponent { onRowDblClick(event: CustomEvent) { let rowForm = event.detail.value.obj; - this.formService.getFormDefinitionById(rowForm.id).subscribe((definition) => { - let form = this.formService.parseForm(definition); + this.formService.getFormDefinitionById(rowForm.id).subscribe((formModel) => { + let form = this.formService.parseForm(formModel.formDefinition); this.form = form; }); diff --git a/ng2-components/ng2-activiti-form/src/services/assets/form.service.mock.ts b/ng2-components/ng2-activiti-form/src/services/assets/form.service.mock.ts new file mode 100644 index 0000000000..a71b1cd4b2 --- /dev/null +++ b/ng2-components/ng2-activiti-form/src/services/assets/form.service.mock.ts @@ -0,0 +1,246 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export let formModelTabs = { + id: 16, + name: 'start event', + description: '', + version: 2, + lastUpdatedBy: 4, + lastUpdatedByFullName: 'User Test', + lastUpdated: '2017-10-04T13:00:03.030+0000', + stencilSetId: null, + referenceId: null, + formDefinition: { + tabs: [], + fields: [ + { + fieldType: 'ContainerRepresentation', + id: '1507037668653', + name: 'Label', + type: 'container', + value: null, + required: false, + readOnly: false, + overrideId: false, + colspan: 1, + placeholder: null, + minLength: 0, + maxLength: 0, + minValue: null, + maxValue: null, + regexPattern: null, + optionType: null, + hasEmptyValue: null, + options: null, + restUrl: null, + restResponsePath: null, + restIdProperty: null, + restLabelProperty: null, + tab: null, + className: null, + dateDisplayFormat: null, + layout: null, + sizeX: 2, + sizeY: 1, + row: -1, + col: -1, + visibilityCondition: null, + numberOfColumns: 2, + fields: { + '1': [ + { + fieldType: 'AmountFieldRepresentation', + id: 'label', + name: 'Label', + type: 'amount', + value: null, + required: false, + readOnly: false, + overrideId: false, + colspan: 1, + placeholder: null, + minLength: 0, + maxLength: 0, + minValue: null, + maxValue: null, + regexPattern: null, + optionType: null, + hasEmptyValue: null, + options: null, + restUrl: null, + restResponsePath: null, + restIdProperty: null, + restLabelProperty: null, + tab: null, + className: null, + params: { + existingColspan: 1, + maxColspan: 2 + }, + dateDisplayFormat: null, + layout: { + row: -1, + column: -1, + colspan: 1 + }, + sizeX: 1, + sizeY: 1, + row: -1, + col: -1, + visibilityCondition: null, + enableFractions: false, + currency: null + } + ], + '2': [ + { + fieldType: 'FormFieldRepresentation', + id: 'label1', + name: 'Label1', + type: 'date', + value: null, + required: false, + readOnly: false, + overrideId: false, + colspan: 1, + placeholder: null, + minLength: 0, + maxLength: 0, + minValue: null, + maxValue: null, + regexPattern: null, + optionType: null, + hasEmptyValue: null, + options: null, + restUrl: null, + restResponsePath: null, + restIdProperty: null, + restLabelProperty: null, + tab: null, + className: null, + params: { + existingColspan: 1, + maxColspan: 1 + }, + dateDisplayFormat: null, + layout: { + row: -1, + column: -1, + colspan: 1 + }, + sizeX: 1, + sizeY: 1, + row: -1, + col: -1, + visibilityCondition: null + } + ] + } + }, + { + fieldType: 'ContainerRepresentation', + id: '1507037670167', + name: 'Label', + type: 'container', + value: null, + required: false, + readOnly: false, + overrideId: false, + colspan: 1, + placeholder: null, + minLength: 0, + maxLength: 0, + minValue: null, + maxValue: null, + regexPattern: null, + optionType: null, + hasEmptyValue: null, + options: null, + restUrl: null, + restResponsePath: null, + restIdProperty: null, + restLabelProperty: null, + tab: null, + className: null, + dateDisplayFormat: null, + layout: null, + sizeX: 2, + sizeY: 1, + row: -1, + col: -1, + visibilityCondition: null, + numberOfColumns: 2, + fields: { + '1': [ + { + fieldType: 'FormFieldRepresentation', + id: 'label2', + name: 'Label2', + type: 'boolean', + value: null, + required: false, + readOnly: false, + overrideId: false, + colspan: 1, + placeholder: null, + minLength: 0, + maxLength: 0, + minValue: null, + maxValue: null, + regexPattern: null, + optionType: null, + hasEmptyValue: null, + options: null, + restUrl: null, + restResponsePath: null, + restIdProperty: null, + restLabelProperty: null, + tab: null, + className: null, + params: { + existingColspan: 1, + maxColspan: 2 + }, + dateDisplayFormat: null, + layout: { + row: -1, + column: -1, + colspan: 1 + }, + sizeX: 1, + sizeY: 1, + row: -1, + col: -1, + visibilityCondition: null + } + ], + '2': [] + } + } + ], + outcomes: [], + javascriptEvents: [], + className: '', + style: '', + customFieldTemplates: {}, + metadata: {}, + variables: [], + customFieldsValueInfo: {}, + gridsterForm: false + } + }; diff --git a/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts b/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts index b287292964..52ebf74e0c 100644 --- a/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts +++ b/ng2-components/ng2-activiti-form/src/services/form.service.spec.ts @@ -20,6 +20,7 @@ import { Response, ResponseOptions } from '@angular/http'; import { AlfrescoApiService, CoreModule, LogService } from 'ng2-alfresco-core'; import { Observable } from 'rxjs/Rx'; import { FormDefinitionModel } from '../models/form-definition.model'; +import { formModelTabs } from './assets/form.service.mock'; import { EcmModelService } from './ecm-model.service'; import { FormService } from './form.service'; @@ -513,6 +514,12 @@ describe('Form service', () => { }); }); + it('should parse a Form Definition with tabs', () => { + expect(formModelTabs.formDefinition).toBeDefined(); + const formParsed = service.parseForm(formModelTabs); + expect(formParsed).toBeDefined(); + }); + it('should create a Form form a Node', (done) => { let nameForm = 'testNode'; diff --git a/ng2-components/ng2-activiti-form/src/services/form.service.ts b/ng2-components/ng2-activiti-form/src/services/form.service.ts index a32eba9ae0..c47061dbdc 100644 --- a/ng2-components/ng2-activiti-form/src/services/form.service.ts +++ b/ng2-components/ng2-activiti-form/src/services/form.service.ts @@ -90,7 +90,7 @@ export class FormService { parseForm(json: any, data?: FormValues, readOnly: boolean = false): FormModel { if (json) { - let form = new FormModel(json.formDefinition, data, readOnly, this); + let form = new FormModel(json, data, readOnly, this); if (!json.fields) { form.outcomes = [ new FormOutcomeModel(form, {