mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
Fix Form Service parseForm (#2440)
This commit is contained in:
parent
337c97d94c
commit
6d3c3316d9
@ -66,8 +66,8 @@ export class FormListDemoComponent {
|
|||||||
onRowDblClick(event: CustomEvent) {
|
onRowDblClick(event: CustomEvent) {
|
||||||
let rowForm = event.detail.value.obj;
|
let rowForm = event.detail.value.obj;
|
||||||
|
|
||||||
this.formService.getFormDefinitionById(rowForm.id).subscribe((definition) => {
|
this.formService.getFormDefinitionById(rowForm.id).subscribe((formModel) => {
|
||||||
let form = this.formService.parseForm(definition);
|
let form = this.formService.parseForm(formModel.formDefinition);
|
||||||
this.form = form;
|
this.form = form;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
};
|
@ -20,6 +20,7 @@ import { Response, ResponseOptions } from '@angular/http';
|
|||||||
import { AlfrescoApiService, CoreModule, LogService } from 'ng2-alfresco-core';
|
import { AlfrescoApiService, CoreModule, LogService } from 'ng2-alfresco-core';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { FormDefinitionModel } from '../models/form-definition.model';
|
import { FormDefinitionModel } from '../models/form-definition.model';
|
||||||
|
import { formModelTabs } from './assets/form.service.mock';
|
||||||
import { EcmModelService } from './ecm-model.service';
|
import { EcmModelService } from './ecm-model.service';
|
||||||
import { FormService } from './form.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) => {
|
it('should create a Form form a Node', (done) => {
|
||||||
|
|
||||||
let nameForm = 'testNode';
|
let nameForm = 'testNode';
|
||||||
|
@ -90,7 +90,7 @@ export class FormService {
|
|||||||
|
|
||||||
parseForm(json: any, data?: FormValues, readOnly: boolean = false): FormModel {
|
parseForm(json: any, data?: FormValues, readOnly: boolean = false): FormModel {
|
||||||
if (json) {
|
if (json) {
|
||||||
let form = new FormModel(json.formDefinition, data, readOnly, this);
|
let form = new FormModel(json, data, readOnly, this);
|
||||||
if (!json.fields) {
|
if (!json.fields) {
|
||||||
form.outcomes = [
|
form.outcomes = [
|
||||||
new FormOutcomeModel(form, {
|
new FormOutcomeModel(form, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user