mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-4468] FormCloud - Be able to display the value of a form variables (#4676)
* Fix the value passed as processDefinition Be sure we fetch the form variables * * Rename formId to formKey. * * Reverted form Changes * * Fixed failing unit test * Fix the value passed as processDefinition Be sure we fetch the form variables * * Fixed failing unit test * * Rename formId to formKey. * * Reverted form Changes * * Fixed failing unit test * Fix form representation structure * Refactor form models * Change tslint config * Fix lint * Refactor form models * Remove duplicated export * improve variable names * Update form mock
This commit is contained in:
committed by
Eugenio Romano
parent
051e8df091
commit
63f00e21cf
@@ -30,7 +30,6 @@ export abstract class FormBaseModel {
|
||||
static START_PROCESS_OUTCOME: string = '$startProcess';
|
||||
|
||||
json: any;
|
||||
isValid: boolean;
|
||||
|
||||
values: FormValues = {};
|
||||
tabs: TabModel[] = [];
|
||||
@@ -41,6 +40,8 @@ export abstract class FormBaseModel {
|
||||
readOnly: boolean = false;
|
||||
taskName;
|
||||
|
||||
isValid: boolean = true;
|
||||
|
||||
hasTabs(): boolean {
|
||||
return this.tabs && this.tabs.length > 0;
|
||||
}
|
||||
@@ -77,8 +78,11 @@ export abstract class FormBaseModel {
|
||||
return formFieldModel;
|
||||
}
|
||||
|
||||
markAsInvalid() {
|
||||
this.isValid = false;
|
||||
}
|
||||
|
||||
abstract validateForm();
|
||||
abstract validateField(field: FormFieldModel);
|
||||
abstract onFormFieldChanged(field: FormFieldModel);
|
||||
abstract markAsInvalid();
|
||||
}
|
||||
|
@@ -68,7 +68,7 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
visibilityCondition: WidgetVisibilityModel = null;
|
||||
enableFractions: boolean = false;
|
||||
currency: string = null;
|
||||
dateDisplayFormat: string = this.dateDisplayFormat || this.defaultDateFormat;
|
||||
dateDisplayFormat: string = this.defaultDateFormat;
|
||||
|
||||
// container model members
|
||||
numberOfColumns: number = 1;
|
||||
|
@@ -35,7 +35,10 @@ describe('FormModel', () => {
|
||||
});
|
||||
|
||||
it('should store original json', () => {
|
||||
const json = {};
|
||||
const json = {
|
||||
id: '<id>',
|
||||
name: '<name>'
|
||||
};
|
||||
const form = new FormModel(json);
|
||||
expect(form.json).toBe(json);
|
||||
});
|
||||
|
@@ -43,11 +43,6 @@ export class FormModel extends FormBaseModel {
|
||||
readonly taskId: string;
|
||||
readonly taskName: string = FormModel.UNSET_TASK_NAME;
|
||||
processDefinitionId: string;
|
||||
private _isValid: boolean = true;
|
||||
|
||||
get isValid(): boolean {
|
||||
return this._isValid;
|
||||
}
|
||||
|
||||
customFieldTemplates: FormFieldTemplates = {};
|
||||
fieldValidators: FormFieldValidator[] = [...FORM_FIELD_VALIDATORS];
|
||||
@@ -55,33 +50,33 @@ export class FormModel extends FormBaseModel {
|
||||
|
||||
processVariables: any;
|
||||
|
||||
constructor(json?: any, formValues?: FormValues, readOnly: boolean = false, protected formService?: FormService) {
|
||||
constructor(formRepresentationJSON?: any, formValues?: FormValues, readOnly: boolean = false, protected formService?: FormService) {
|
||||
super();
|
||||
this.readOnly = readOnly;
|
||||
|
||||
if (json) {
|
||||
this.json = json;
|
||||
if (formRepresentationJSON) {
|
||||
this.json = formRepresentationJSON;
|
||||
|
||||
this.id = json.id;
|
||||
this.name = json.name;
|
||||
this.taskId = json.taskId;
|
||||
this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME;
|
||||
this.processDefinitionId = json.processDefinitionId;
|
||||
this.customFieldTemplates = json.customFieldTemplates || {};
|
||||
this.selectedOutcome = json.selectedOutcome || {};
|
||||
this.className = json.className || '';
|
||||
this.id = formRepresentationJSON.id;
|
||||
this.name = formRepresentationJSON.name;
|
||||
this.taskId = formRepresentationJSON.taskId;
|
||||
this.taskName = formRepresentationJSON.taskName || formRepresentationJSON.name || FormModel.UNSET_TASK_NAME;
|
||||
this.processDefinitionId = formRepresentationJSON.processDefinitionId;
|
||||
this.customFieldTemplates = formRepresentationJSON.customFieldTemplates || {};
|
||||
this.selectedOutcome = formRepresentationJSON.selectedOutcome || {};
|
||||
this.className = formRepresentationJSON.className || '';
|
||||
|
||||
const tabCache: FormWidgetModelCache<TabModel> = {};
|
||||
|
||||
this.processVariables = json.processVariables;
|
||||
this.processVariables = formRepresentationJSON.processVariables;
|
||||
|
||||
this.tabs = (json.tabs || []).map((t) => {
|
||||
this.tabs = (formRepresentationJSON.tabs || []).map((t) => {
|
||||
const model = new TabModel(this, t);
|
||||
tabCache[model.id] = model;
|
||||
return model;
|
||||
});
|
||||
|
||||
this.fields = this.parseRootFields(json);
|
||||
this.fields = this.parseRootFields(formRepresentationJSON);
|
||||
|
||||
if (formValues) {
|
||||
this.loadData(formValues);
|
||||
@@ -97,7 +92,7 @@ export class FormModel extends FormBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
if (json.fields) {
|
||||
if (formRepresentationJSON.fields) {
|
||||
const saveOutcome = new FormOutcomeModel(this, {
|
||||
id: FormModel.SAVE_OUTCOME,
|
||||
name: 'SAVE',
|
||||
@@ -114,7 +109,7 @@ export class FormModel extends FormBaseModel {
|
||||
isSystem: true
|
||||
});
|
||||
|
||||
const customOutcomes = (json.outcomes || []).map((obj) => new FormOutcomeModel(this, obj));
|
||||
const customOutcomes = (formRepresentationJSON.outcomes || []).map((obj) => new FormOutcomeModel(this, obj));
|
||||
|
||||
this.outcomes = [saveOutcome].concat(
|
||||
customOutcomes.length > 0 ? customOutcomes : [completeOutcome, startProcessOutcome]
|
||||
@@ -132,10 +127,6 @@ export class FormModel extends FormBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
markAsInvalid() {
|
||||
this._isValid = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates entire form and all form fields.
|
||||
*
|
||||
@@ -153,10 +144,10 @@ export class FormModel extends FormBaseModel {
|
||||
}
|
||||
}
|
||||
|
||||
this._isValid = errorsField.length > 0 ? false : true;
|
||||
this.isValid = errorsField.length > 0 ? false : true;
|
||||
|
||||
if (this.formService) {
|
||||
validateFormEvent.isValid = this._isValid;
|
||||
validateFormEvent.isValid = this.isValid;
|
||||
validateFormEvent.errorsField = errorsField;
|
||||
this.formService.validateForm.next(validateFormEvent);
|
||||
}
|
||||
@@ -181,7 +172,7 @@ export class FormModel extends FormBaseModel {
|
||||
}
|
||||
|
||||
if (!validateFieldEvent.isValid) {
|
||||
this._isValid = false;
|
||||
this.markAsInvalid();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -190,7 +181,7 @@ export class FormModel extends FormBaseModel {
|
||||
}
|
||||
|
||||
if (!field.validate()) {
|
||||
this._isValid = false;
|
||||
this.markAsInvalid();
|
||||
}
|
||||
|
||||
this.validateForm();
|
||||
|
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
export * from './components/form-base.component';
|
||||
export * from './components/form-base.model';
|
||||
export * from './components/form-list.component';
|
||||
export * from './components/widgets/content/content.widget';
|
||||
export * from './components/form-renderer.component';
|
||||
|
@@ -215,14 +215,7 @@ export class WidgetVisibilityService {
|
||||
}
|
||||
|
||||
private getFormVariables(form: FormModel): any[] {
|
||||
let variables;
|
||||
if (form.json.formRepresentation) {
|
||||
variables = form.json.formRepresentation.formDefinition.variables;
|
||||
} else {
|
||||
variables = form.json.variables;
|
||||
}
|
||||
|
||||
return variables;
|
||||
return form.json.variables;
|
||||
}
|
||||
|
||||
private getProcessVariableValue(name: string, processVarList: TaskProcessVariableModel[]): string {
|
||||
|
Reference in New Issue
Block a user