mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-06-30 18:15:11 +00:00
[ACTIVITI-3720] cloud form support for form variable mapping (#5044)
* universal form model * parse variables correctly * turn group model into interface * remove console.log * interface instead of class * update form id type * improved form variable parsing * improved variable conversion * fix cloud tests * fix typings and code bugs
This commit is contained in:
parent
53dc5f0b91
commit
2360ccc6d5
@ -16,8 +16,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, OnDestroy, OnInit } from '@angular/core';
|
import { Component, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { FormFieldModel, NotificationService, FormRenderingService, CoreAutomationService } from '@alfresco/adf-core';
|
import { FormFieldModel, NotificationService, FormRenderingService, CoreAutomationService, FormModel } from '@alfresco/adf-core';
|
||||||
import { FormCloud, FormCloudService, UploadCloudWidgetComponent } from '@alfresco/adf-process-services-cloud';
|
import { FormCloudService, UploadCloudWidgetComponent } from '@alfresco/adf-process-services-cloud';
|
||||||
import { Subscription } from 'rxjs';
|
import { Subscription } from 'rxjs';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -26,7 +26,7 @@ import { Subscription } from 'rxjs';
|
|||||||
})
|
})
|
||||||
export class FormCloudDemoComponent implements OnInit, OnDestroy {
|
export class FormCloudDemoComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
form: FormCloud;
|
form: FormModel;
|
||||||
errorFields: FormFieldModel[] = [];
|
errorFields: FormFieldModel[] = [];
|
||||||
formConfig: string;
|
formConfig: string;
|
||||||
editor: any;
|
editor: any;
|
||||||
|
@ -15,8 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FormBaseModel } from './form-base.model';
|
import { FormOutcomeModel, FormFieldValidator, FormFieldModel, FormOutcomeEvent, FormModel } from './widgets';
|
||||||
import { FormOutcomeModel, FormFieldValidator, FormFieldModel, FormOutcomeEvent } from './widgets';
|
|
||||||
import { EventEmitter, Input, Output } from '@angular/core';
|
import { EventEmitter, Input, Output } from '@angular/core';
|
||||||
|
|
||||||
export abstract class FormBaseComponent {
|
export abstract class FormBaseComponent {
|
||||||
@ -92,7 +91,7 @@ export abstract class FormBaseComponent {
|
|||||||
@Output()
|
@Output()
|
||||||
error: EventEmitter<any> = new EventEmitter<any>();
|
error: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
form: FormBaseModel;
|
form: FormModel;
|
||||||
|
|
||||||
getParsedFormDefinition(): FormBaseComponent {
|
getParsedFormDefinition(): FormBaseComponent {
|
||||||
return this;
|
return this;
|
||||||
@ -208,7 +207,7 @@ export abstract class FormBaseComponent {
|
|||||||
|
|
||||||
abstract completeTaskForm(outcome?: string);
|
abstract completeTaskForm(outcome?: string);
|
||||||
|
|
||||||
protected abstract onTaskSaved(form: FormBaseModel);
|
protected abstract onTaskSaved(form: FormModel);
|
||||||
|
|
||||||
protected abstract storeFormAsMetadata();
|
protected abstract storeFormAsMetadata();
|
||||||
|
|
||||||
|
@ -1,88 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @license
|
|
||||||
* Copyright 2019 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { FormValues } from './widgets/core/form-values';
|
|
||||||
import { TabModel } from './widgets/core/tab.model';
|
|
||||||
import { FormWidgetModel } from './widgets/core/form-widget.model';
|
|
||||||
import { FormOutcomeModel } from './widgets/core/form-outcome.model';
|
|
||||||
import { FormFieldModel } from './widgets/core/form-field.model';
|
|
||||||
import { ContainerModel } from './widgets/core/container.model';
|
|
||||||
|
|
||||||
export abstract class FormBaseModel {
|
|
||||||
|
|
||||||
static UNSET_TASK_NAME: string = 'Nameless task';
|
|
||||||
static SAVE_OUTCOME: string = '$save';
|
|
||||||
static COMPLETE_OUTCOME: string = '$complete';
|
|
||||||
static START_PROCESS_OUTCOME: string = '$startProcess';
|
|
||||||
|
|
||||||
json: any;
|
|
||||||
|
|
||||||
values: FormValues = {};
|
|
||||||
tabs: TabModel[] = [];
|
|
||||||
fields: FormWidgetModel[] = [];
|
|
||||||
outcomes: FormOutcomeModel[] = [];
|
|
||||||
|
|
||||||
className: string;
|
|
||||||
readOnly: boolean = false;
|
|
||||||
taskName;
|
|
||||||
|
|
||||||
isValid: boolean = true;
|
|
||||||
|
|
||||||
hasTabs(): boolean {
|
|
||||||
return this.tabs && this.tabs.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasFields(): boolean {
|
|
||||||
return this.fields && this.fields.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasOutcomes(): boolean {
|
|
||||||
return this.outcomes && this.outcomes.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
getFieldById(fieldId: string): FormFieldModel {
|
|
||||||
return this.getFormFields().find((field) => field.id === fieldId);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: consider evaluating and caching once the form is loaded
|
|
||||||
getFormFields(): FormFieldModel[] {
|
|
||||||
const formFieldModel: FormFieldModel[] = [];
|
|
||||||
|
|
||||||
for (let i = 0; i < this.fields.length; i++) {
|
|
||||||
const field = this.fields[i];
|
|
||||||
|
|
||||||
if (field instanceof ContainerModel) {
|
|
||||||
const container = <ContainerModel> field;
|
|
||||||
formFieldModel.push(container.field);
|
|
||||||
|
|
||||||
container.field.columns.forEach((column) => {
|
|
||||||
formFieldModel.push(...column.fields);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return formFieldModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
markAsInvalid() {
|
|
||||||
this.isValid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract validateForm();
|
|
||||||
abstract validateField(field: FormFieldModel);
|
|
||||||
abstract onFormFieldChanged(field: FormFieldModel);
|
|
||||||
}
|
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, ViewEncapsulation, Input } from '@angular/core';
|
import { Component, ViewEncapsulation, Input } from '@angular/core';
|
||||||
import { FormBaseModel } from './form-base.model';
|
import { FormModel } from './widgets/core/form.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-form-renderer',
|
selector: 'adf-form-renderer',
|
||||||
@ -31,7 +31,7 @@ export class FormRendererComponent {
|
|||||||
showDebugButton: boolean = false;
|
showDebugButton: boolean = false;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
formDefinition: FormBaseModel;
|
formDefinition: FormModel;
|
||||||
|
|
||||||
debugMode: boolean;
|
debugMode: boolean;
|
||||||
|
|
||||||
|
@ -15,71 +15,98 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* tslint:disable:component-selector */
|
|
||||||
|
|
||||||
import { FormFieldEvent } from './../../../events/form-field.event';
|
import { FormFieldEvent } from './../../../events/form-field.event';
|
||||||
import { ValidateFormFieldEvent } from './../../../events/validate-form-field.event';
|
import { ValidateFormFieldEvent } from './../../../events/validate-form-field.event';
|
||||||
import { ValidateFormEvent } from './../../../events/validate-form.event';
|
import { ValidateFormEvent } from './../../../events/validate-form.event';
|
||||||
import { FormService } from './../../../services/form.service';
|
import { FormService } from './../../../services/form.service';
|
||||||
import { ContainerModel } from './container.model';
|
import { ContainerModel } from './container.model';
|
||||||
import { FormFieldTemplates } from './form-field-templates';
|
|
||||||
import { FormFieldTypes } from './form-field-types';
|
import { FormFieldTypes } from './form-field-types';
|
||||||
import { FormFieldModel } from './form-field.model';
|
import { FormFieldModel } from './form-field.model';
|
||||||
import { FormOutcomeModel } from './form-outcome.model';
|
|
||||||
import { FormValues } from './form-values';
|
import { FormValues } from './form-values';
|
||||||
import { FormWidgetModel, FormWidgetModelCache } from './form-widget.model';
|
import { FormWidgetModel, FormWidgetModelCache } from './form-widget.model';
|
||||||
import { TabModel } from './tab.model';
|
import { TabModel } from './tab.model';
|
||||||
|
|
||||||
import {
|
|
||||||
FORM_FIELD_VALIDATORS,
|
|
||||||
FormFieldValidator
|
|
||||||
} from './form-field-validator';
|
|
||||||
import { FormBaseModel } from '../../form-base.model';
|
|
||||||
import { FormVariableModel } from './form-variable.model';
|
import { FormVariableModel } from './form-variable.model';
|
||||||
import { ProcessVariableModel } from './process-variable.model';
|
import { ProcessVariableModel } from './process-variable.model';
|
||||||
|
import { FormOutcomeModel } from './form-outcome.model';
|
||||||
|
import { FormFieldValidator, FORM_FIELD_VALIDATORS } from './form-field-validator';
|
||||||
|
import { FormFieldTemplates } from './form-field-templates';
|
||||||
|
|
||||||
export class FormModel extends FormBaseModel {
|
export interface FormRepresentationModel {
|
||||||
|
[key: string]: any;
|
||||||
|
|
||||||
readonly id: number;
|
id?: string | number;
|
||||||
|
name?: string;
|
||||||
|
taskId?: string;
|
||||||
|
taskName?: string;
|
||||||
|
processDefinitionId?: string;
|
||||||
|
customFieldTemplates?: {
|
||||||
|
[key: string]: string
|
||||||
|
};
|
||||||
|
selectedOutcome?: string;
|
||||||
|
fields?: any[];
|
||||||
|
tabs?: any[];
|
||||||
|
outcomes?: any[];
|
||||||
|
formDefinition?: {
|
||||||
|
fields?: any[];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export class FormModel {
|
||||||
|
|
||||||
|
static UNSET_TASK_NAME: string = 'Nameless task';
|
||||||
|
static SAVE_OUTCOME: string = '$save';
|
||||||
|
static COMPLETE_OUTCOME: string = '$complete';
|
||||||
|
static START_PROCESS_OUTCOME: string = '$startProcess';
|
||||||
|
|
||||||
|
readonly id: string | number;
|
||||||
readonly name: string;
|
readonly name: string;
|
||||||
readonly taskId: string;
|
readonly taskId: string;
|
||||||
readonly taskName: string = FormModel.UNSET_TASK_NAME;
|
readonly taskName = FormModel.UNSET_TASK_NAME;
|
||||||
processDefinitionId: string;
|
readonly processDefinitionId: string;
|
||||||
|
|
||||||
customFieldTemplates: FormFieldTemplates = {};
|
|
||||||
fieldValidators: FormFieldValidator[] = [...FORM_FIELD_VALIDATORS];
|
|
||||||
readonly selectedOutcome: string;
|
readonly selectedOutcome: string;
|
||||||
|
|
||||||
|
json: FormRepresentationModel;
|
||||||
|
nodeId: string;
|
||||||
|
contentHost: string;
|
||||||
|
values: FormValues = {};
|
||||||
|
tabs: TabModel[] = [];
|
||||||
|
fields: FormWidgetModel[] = [];
|
||||||
|
outcomes: FormOutcomeModel[] = [];
|
||||||
|
fieldValidators: FormFieldValidator[] = [...FORM_FIELD_VALIDATORS];
|
||||||
|
customFieldTemplates: FormFieldTemplates = {};
|
||||||
|
|
||||||
|
className: string;
|
||||||
|
readOnly = false;
|
||||||
|
isValid = true;
|
||||||
processVariables: ProcessVariableModel[] = [];
|
processVariables: ProcessVariableModel[] = [];
|
||||||
variables: FormVariableModel[] = [];
|
variables: FormVariableModel[] = [];
|
||||||
|
|
||||||
constructor(formRepresentationJSON?: any, formValues?: FormValues, readOnly: boolean = false, protected formService?: FormService) {
|
constructor(json?: FormRepresentationModel, formValues?: FormValues, readOnly: boolean = false, protected formService?: FormService) {
|
||||||
super();
|
|
||||||
this.readOnly = readOnly;
|
this.readOnly = readOnly;
|
||||||
|
this.json = json;
|
||||||
|
|
||||||
if (formRepresentationJSON) {
|
if (json) {
|
||||||
this.json = formRepresentationJSON;
|
this.id = json.id;
|
||||||
|
this.name = json.name;
|
||||||
this.id = formRepresentationJSON.id;
|
this.taskId = json.taskId;
|
||||||
this.name = formRepresentationJSON.name;
|
this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME;
|
||||||
this.taskId = formRepresentationJSON.taskId;
|
this.processDefinitionId = json.processDefinitionId;
|
||||||
this.taskName = formRepresentationJSON.taskName || formRepresentationJSON.name || FormModel.UNSET_TASK_NAME;
|
this.customFieldTemplates = json.customFieldTemplates || {};
|
||||||
this.processDefinitionId = formRepresentationJSON.processDefinitionId;
|
this.selectedOutcome = json.selectedOutcome;
|
||||||
this.customFieldTemplates = formRepresentationJSON.customFieldTemplates || {};
|
this.className = json.className || '';
|
||||||
this.selectedOutcome = formRepresentationJSON.selectedOutcome || {};
|
this.variables = json.variables || [];
|
||||||
this.className = formRepresentationJSON.className || '';
|
this.processVariables = json.processVariables || [];
|
||||||
this.variables = formRepresentationJSON.variables || [];
|
|
||||||
this.processVariables = formRepresentationJSON.processVariables || [];
|
|
||||||
|
|
||||||
const tabCache: FormWidgetModelCache<TabModel> = {};
|
const tabCache: FormWidgetModelCache<TabModel> = {};
|
||||||
|
|
||||||
this.tabs = (formRepresentationJSON.tabs || []).map((t) => {
|
this.tabs = (json.tabs || []).map((tabJson) => {
|
||||||
const model = new TabModel(this, t);
|
const model = new TabModel(this, tabJson);
|
||||||
tabCache[model.id] = model;
|
tabCache[model.id] = model;
|
||||||
return model;
|
return model;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.fields = this.parseRootFields(formRepresentationJSON);
|
this.fields = this.parseRootFields(json);
|
||||||
|
|
||||||
if (formValues) {
|
if (formValues) {
|
||||||
this.loadData(formValues);
|
this.loadData(formValues);
|
||||||
@ -95,29 +122,7 @@ export class FormModel extends FormBaseModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (formRepresentationJSON.fields) {
|
this.parseOutcomes();
|
||||||
const saveOutcome = new FormOutcomeModel(this, {
|
|
||||||
id: FormModel.SAVE_OUTCOME,
|
|
||||||
name: 'SAVE',
|
|
||||||
isSystem: true
|
|
||||||
});
|
|
||||||
const completeOutcome = new FormOutcomeModel(this, {
|
|
||||||
id: FormModel.COMPLETE_OUTCOME,
|
|
||||||
name: 'COMPLETE',
|
|
||||||
isSystem: true
|
|
||||||
});
|
|
||||||
const startProcessOutcome = new FormOutcomeModel(this, {
|
|
||||||
id: FormModel.START_PROCESS_OUTCOME,
|
|
||||||
name: 'START PROCESS',
|
|
||||||
isSystem: true
|
|
||||||
});
|
|
||||||
|
|
||||||
const customOutcomes = (formRepresentationJSON.outcomes || []).map((obj) => new FormOutcomeModel(this, obj));
|
|
||||||
|
|
||||||
this.outcomes = [saveOutcome].concat(
|
|
||||||
customOutcomes.length > 0 ? customOutcomes : [completeOutcome, startProcessOutcome]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.validateForm();
|
this.validateForm();
|
||||||
@ -125,6 +130,7 @@ export class FormModel extends FormBaseModel {
|
|||||||
|
|
||||||
onFormFieldChanged(field: FormFieldModel) {
|
onFormFieldChanged(field: FormFieldModel) {
|
||||||
this.validateField(field);
|
this.validateField(field);
|
||||||
|
|
||||||
if (this.formService) {
|
if (this.formService) {
|
||||||
this.formService.formFieldValueChanged.next(new FormFieldEvent(this, field));
|
this.formService.formFieldValueChanged.next(new FormFieldEvent(this, field));
|
||||||
}
|
}
|
||||||
@ -223,8 +229,10 @@ export class FormModel extends FormBaseModel {
|
|||||||
// Typically used when form definition and form data coming from different sources
|
// Typically used when form definition and form data coming from different sources
|
||||||
private loadData(formValues: FormValues) {
|
private loadData(formValues: FormValues) {
|
||||||
for (const field of this.getFormFields()) {
|
for (const field of this.getFormFields()) {
|
||||||
if (formValues[field.id]) {
|
const variableId = `variables.${field.name}`;
|
||||||
field.json.value = formValues[field.id];
|
|
||||||
|
if (formValues[variableId] || formValues[field.id]) {
|
||||||
|
field.json.value = formValues[variableId] || formValues[field.id];
|
||||||
field.value = field.parseValue(field.json);
|
field.value = field.parseValue(field.json);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -253,15 +261,8 @@ export class FormModel extends FormBaseModel {
|
|||||||
getFormVariableValue(identifier: string): any {
|
getFormVariableValue(identifier: string): any {
|
||||||
const variable = this.getFormVariable(identifier);
|
const variable = this.getFormVariable(identifier);
|
||||||
|
|
||||||
if (variable) {
|
if (variable && variable.hasOwnProperty('value')) {
|
||||||
switch (variable.type) {
|
return this.parseValue(variable.type, variable.value);
|
||||||
case 'date':
|
|
||||||
return `${variable.value}T00:00:00.000Z`;
|
|
||||||
case 'boolean':
|
|
||||||
return JSON.parse(variable.value);
|
|
||||||
default:
|
|
||||||
return variable.value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
@ -280,15 +281,98 @@ export class FormModel extends FormBaseModel {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (variable) {
|
if (variable) {
|
||||||
switch (variable.type) {
|
return this.parseValue(variable.type, variable.value);
|
||||||
case 'boolean':
|
|
||||||
return JSON.parse(variable.value);
|
|
||||||
default:
|
|
||||||
return variable.value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected parseValue(type: string, value: any): any {
|
||||||
|
if (type && value) {
|
||||||
|
switch (type) {
|
||||||
|
case 'date':
|
||||||
|
return value
|
||||||
|
? `${value}T00:00:00.000Z`
|
||||||
|
: undefined;
|
||||||
|
case 'boolean':
|
||||||
|
return typeof value === 'string'
|
||||||
|
? JSON.parse(value)
|
||||||
|
: value;
|
||||||
|
default:
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasTabs(): boolean {
|
||||||
|
return this.tabs && this.tabs.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasFields(): boolean {
|
||||||
|
return this.fields && this.fields.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
hasOutcomes(): boolean {
|
||||||
|
return this.outcomes && this.outcomes.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
getFieldById(fieldId: string): FormFieldModel {
|
||||||
|
return this.getFormFields().find((field) => field.id === fieldId);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFormFields(): FormFieldModel[] {
|
||||||
|
const formFieldModel: FormFieldModel[] = [];
|
||||||
|
|
||||||
|
for (let i = 0; i < this.fields.length; i++) {
|
||||||
|
const field = this.fields[i];
|
||||||
|
|
||||||
|
if (field instanceof ContainerModel) {
|
||||||
|
const container = <ContainerModel> field;
|
||||||
|
formFieldModel.push(container.field);
|
||||||
|
|
||||||
|
container.field.columns.forEach((column) => {
|
||||||
|
formFieldModel.push(...column.fields);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return formFieldModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
markAsInvalid(): void {
|
||||||
|
this.isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected parseOutcomes() {
|
||||||
|
if (this.json.fields) {
|
||||||
|
const saveOutcome = new FormOutcomeModel(<any> this, {
|
||||||
|
id: FormModel.SAVE_OUTCOME,
|
||||||
|
name: 'SAVE',
|
||||||
|
isSystem: true
|
||||||
|
});
|
||||||
|
const completeOutcome = new FormOutcomeModel(<any> this, {
|
||||||
|
id: FormModel.COMPLETE_OUTCOME,
|
||||||
|
name: 'COMPLETE',
|
||||||
|
isSystem: true
|
||||||
|
});
|
||||||
|
const startProcessOutcome = new FormOutcomeModel(<any> this, {
|
||||||
|
id: FormModel.START_PROCESS_OUTCOME,
|
||||||
|
name: 'START PROCESS',
|
||||||
|
isSystem: true
|
||||||
|
});
|
||||||
|
|
||||||
|
const customOutcomes = (this.json.outcomes || []).map(
|
||||||
|
(obj) => new FormOutcomeModel(<any> this, obj)
|
||||||
|
);
|
||||||
|
|
||||||
|
this.outcomes = [saveOutcome].concat(
|
||||||
|
customOutcomes.length > 0
|
||||||
|
? customOutcomes
|
||||||
|
: [completeOutcome, startProcessOutcome]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,24 +15,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* tslint:disable:component-selector */
|
export interface GroupModel {
|
||||||
|
externalId?: string;
|
||||||
export class GroupModel {
|
groups?: any;
|
||||||
|
id?: string;
|
||||||
externalId: string;
|
name?: string;
|
||||||
groups: any;
|
status?: string;
|
||||||
id: string;
|
|
||||||
name: string;
|
|
||||||
status: string;
|
|
||||||
|
|
||||||
constructor(json?: any) {
|
|
||||||
if (json) {
|
|
||||||
this.externalId = json.externalId;
|
|
||||||
this.groups = json.groups;
|
|
||||||
this.id = json.id;
|
|
||||||
this.name = json.name;
|
|
||||||
this.status = json.status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ describe('FunctionalGroupWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should setup text from underlying field on init', () => {
|
it('should setup text from underlying field on init', () => {
|
||||||
const group = new GroupModel({ name: 'group-1'});
|
const group: GroupModel = { name: 'group-1'};
|
||||||
widget.field.value = group;
|
widget.field.value = group;
|
||||||
|
|
||||||
spyOn(formService, 'getWorkflowGroups').and.returnValue(
|
spyOn(formService, 'getWorkflowGroups').and.returnValue(
|
||||||
@ -81,7 +81,7 @@ describe('FunctionalGroupWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should update values on item click', () => {
|
it('should update values on item click', () => {
|
||||||
const item = new GroupModel({ name: 'group-1' });
|
const item: GroupModel = { name: 'group-1' };
|
||||||
|
|
||||||
widget.onItemClick(item, null);
|
widget.onItemClick(item, null);
|
||||||
expect(widget.field.value).toBe(item);
|
expect(widget.field.value).toBe(item);
|
||||||
@ -96,8 +96,8 @@ describe('FunctionalGroupWidgetComponent', () => {
|
|||||||
|
|
||||||
it('should flush selected value', () => {
|
it('should flush selected value', () => {
|
||||||
const groups: GroupModel[] = [
|
const groups: GroupModel[] = [
|
||||||
new GroupModel({ id: '1', name: 'group 1' }),
|
{ id: '1', name: 'group 1' },
|
||||||
new GroupModel({ id: '2', name: 'group 2' })
|
{ id: '2', name: 'group 2' }
|
||||||
];
|
];
|
||||||
|
|
||||||
widget.groups = groups;
|
widget.groups = groups;
|
||||||
@ -110,8 +110,8 @@ describe('FunctionalGroupWidgetComponent', () => {
|
|||||||
|
|
||||||
it('should be case insensitive when flushing value', () => {
|
it('should be case insensitive when flushing value', () => {
|
||||||
const groups: GroupModel[] = [
|
const groups: GroupModel[] = [
|
||||||
new GroupModel({ id: '1', name: 'group 1' }),
|
{ id: '1', name: 'group 1' },
|
||||||
new GroupModel({ id: '2', name: 'gRoUp 2' })
|
{ id: '2', name: 'gRoUp 2' }
|
||||||
];
|
];
|
||||||
|
|
||||||
widget.groups = groups;
|
widget.groups = groups;
|
||||||
@ -123,10 +123,7 @@ describe('FunctionalGroupWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch groups and show popup on key up', () => {
|
it('should fetch groups and show popup on key up', () => {
|
||||||
const groups: GroupModel[] = [
|
const groups: GroupModel[] = [{}, {}];
|
||||||
new GroupModel(),
|
|
||||||
new GroupModel()
|
|
||||||
];
|
|
||||||
spyOn(formService, 'getWorkflowGroups').and.returnValue(
|
spyOn(formService, 'getWorkflowGroups').and.returnValue(
|
||||||
new Observable((observer) => {
|
new Observable((observer) => {
|
||||||
observer.next(groups);
|
observer.next(groups);
|
||||||
@ -143,10 +140,7 @@ describe('FunctionalGroupWidgetComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch groups with a group filter', () => {
|
it('should fetch groups with a group filter', () => {
|
||||||
const groups: GroupModel[] = [
|
const groups: GroupModel[] = [{}, {}];
|
||||||
new GroupModel(),
|
|
||||||
new GroupModel()
|
|
||||||
];
|
|
||||||
spyOn(formService, 'getWorkflowGroups').and.returnValue(
|
spyOn(formService, 'getWorkflowGroups').and.returnValue(
|
||||||
new Observable((observer) => {
|
new Observable((observer) => {
|
||||||
observer.next(groups);
|
observer.next(groups);
|
||||||
|
@ -60,7 +60,7 @@ export class FunctionalGroupWidgetComponent extends WidgetComponent implements O
|
|||||||
if (this.value) {
|
if (this.value) {
|
||||||
this.formService
|
this.formService
|
||||||
.getWorkflowGroups(this.value, this.groupId)
|
.getWorkflowGroups(this.value, this.groupId)
|
||||||
.subscribe((groupModel: GroupModel[]) => this.groups = groupModel || []);
|
.subscribe(groups => this.groups = groups || []);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -69,10 +69,9 @@ export class FunctionalGroupWidgetComponent extends WidgetComponent implements O
|
|||||||
if (this.value && this.value.length >= this.minTermLength && this.oldValue !== this.value) {
|
if (this.value && this.value.length >= this.minTermLength && this.oldValue !== this.value) {
|
||||||
if (event.keyCode !== ESCAPE && event.keyCode !== ENTER) {
|
if (event.keyCode !== ESCAPE && event.keyCode !== ENTER) {
|
||||||
this.oldValue = this.value;
|
this.oldValue = this.value;
|
||||||
this.formService.getWorkflowGroups(this.value, this.groupId)
|
this.formService
|
||||||
.subscribe((group: GroupModel[]) => {
|
.getWorkflowGroups(this.value, this.groupId)
|
||||||
this.groups = group || [];
|
.subscribe(groups => this.groups = groups || []);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './components/form-base.component';
|
export * from './components/form-base.component';
|
||||||
export * from './components/form-base.model';
|
|
||||||
export * from './components/form-list.component';
|
export * from './components/form-list.component';
|
||||||
export * from './components/widgets/content/content.widget';
|
export * from './components/widgets/content/content.widget';
|
||||||
export * from './components/form-renderer.component';
|
export * from './components/form-renderer.component';
|
||||||
|
@ -21,12 +21,11 @@ import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testin
|
|||||||
import { Observable, of, throwError } from 'rxjs';
|
import { Observable, of, throwError } from 'rxjs';
|
||||||
import {
|
import {
|
||||||
FormFieldModel, FormFieldTypes, FormService, FormOutcomeEvent, FormOutcomeModel, LogService, WidgetVisibilityService,
|
FormFieldModel, FormFieldTypes, FormService, FormOutcomeEvent, FormOutcomeModel, LogService, WidgetVisibilityService,
|
||||||
setupTestBed, AppConfigService, FormRenderingService
|
setupTestBed, AppConfigService, FormRenderingService, FormModel
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
|
import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module';
|
||||||
import { FormCloudService } from '../services/form-cloud.service';
|
import { FormCloudService } from '../services/form-cloud.service';
|
||||||
import { FormCloudComponent } from './form-cloud.component';
|
import { FormCloudComponent } from './form-cloud.component';
|
||||||
import { FormCloud } from '../models/form-cloud.model';
|
|
||||||
import { cloudFormMock, fakeCloudForm } from '../mocks/cloud-form.mock';
|
import { cloudFormMock, fakeCloudForm } from '../mocks/cloud-form.mock';
|
||||||
import { FormCloudRepresentation } from '../models/form-cloud-representation.model';
|
import { FormCloudRepresentation } from '../models/form-cloud-representation.model';
|
||||||
|
|
||||||
@ -53,12 +52,12 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
it('should check form', () => {
|
it('should check form', () => {
|
||||||
expect(formComponent.hasForm()).toBeFalsy();
|
expect(formComponent.hasForm()).toBeFalsy();
|
||||||
formComponent.form = new FormCloud();
|
formComponent.form = new FormModel();
|
||||||
expect(formComponent.hasForm()).toBeTruthy();
|
expect(formComponent.hasForm()).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow title if showTitle is true', () => {
|
it('should allow title if showTitle is true', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
|
|
||||||
expect(formComponent.showTitle).toBeTruthy();
|
expect(formComponent.showTitle).toBeTruthy();
|
||||||
@ -67,7 +66,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not allow title if showTitle is false', () => {
|
it('should not allow title if showTitle is false', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
|
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
formComponent.showTitle = false;
|
formComponent.showTitle = false;
|
||||||
@ -84,14 +83,14 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should enable custom outcome buttons', () => {
|
it('should enable custom outcome buttons', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, { id: 'action1', name: 'Action 1' });
|
const outcome = new FormOutcomeModel(<any> formModel, { id: 'action1', name: 'Action 1' });
|
||||||
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy();
|
expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should allow controlling [complete] button visibility', () => {
|
it('should allow controlling [complete] button visibility', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, { id: '$save', name: FormOutcomeModel.SAVE_ACTION });
|
const outcome = new FormOutcomeModel(<any> formModel, { id: '$save', name: FormOutcomeModel.SAVE_ACTION });
|
||||||
|
|
||||||
@ -103,7 +102,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show only [complete] button with readOnly form ', () => {
|
it('should show only [complete] button with readOnly form ', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
formModel.readOnly = true;
|
formModel.readOnly = true;
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, { id: '$complete', name: FormOutcomeModel.COMPLETE_ACTION });
|
const outcome = new FormOutcomeModel(<any> formModel, { id: '$complete', name: FormOutcomeModel.COMPLETE_ACTION });
|
||||||
@ -113,7 +112,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not show [save] button with readOnly form ', () => {
|
it('should not show [save] button with readOnly form ', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
formModel.readOnly = true;
|
formModel.readOnly = true;
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, { id: '$save', name: FormOutcomeModel.SAVE_ACTION });
|
const outcome = new FormOutcomeModel(<any> formModel, { id: '$save', name: FormOutcomeModel.SAVE_ACTION });
|
||||||
@ -123,7 +122,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show [custom-outcome] button with readOnly form and selected custom-outcome', () => {
|
it('should show [custom-outcome] button with readOnly form and selected custom-outcome', () => {
|
||||||
const formModel = new FormCloud({ selectedOutcome: 'custom-outcome' });
|
const formModel = new FormModel({ selectedOutcome: 'custom-outcome' });
|
||||||
formModel.readOnly = true;
|
formModel.readOnly = true;
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
let outcome = new FormOutcomeModel(<any> formModel, { id: '$customoutome', name: 'custom-outcome' });
|
let outcome = new FormOutcomeModel(<any> formModel, { id: '$customoutome', name: 'custom-outcome' });
|
||||||
@ -137,7 +136,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should allow controlling [save] button visibility', () => {
|
it('should allow controlling [save] button visibility', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
formModel.readOnly = false;
|
formModel.readOnly = false;
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, { id: '$save', name: FormOutcomeModel.COMPLETE_ACTION });
|
const outcome = new FormOutcomeModel(<any> formModel, { id: '$save', name: FormOutcomeModel.COMPLETE_ACTION });
|
||||||
@ -164,7 +163,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of({}));
|
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
|
||||||
spyOn(formCloudService, 'getTask').and.callFake((currentTaskId) => {
|
spyOn(formCloudService, 'getTask').and.callFake((currentTaskId) => {
|
||||||
return new Observable((observer) => {
|
return new Observable((observer) => {
|
||||||
observer.next({ formRepresentation: { taskId: currentTaskId } });
|
observer.next({ formRepresentation: { taskId: currentTaskId } });
|
||||||
@ -189,7 +188,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of({}));
|
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
|
||||||
|
|
||||||
formComponent.appName = 'test-app';
|
formComponent.appName = 'test-app';
|
||||||
formComponent.taskId = null;
|
formComponent.taskId = null;
|
||||||
@ -239,7 +238,7 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
it('should call the process storage to retrieve the folder with only the taskId', fakeAsync(() => {
|
it('should call the process storage to retrieve the folder with only the taskId', fakeAsync(() => {
|
||||||
spyOn(formCloudService, 'getTaskForm').and.returnValue(of(cloudFormMock));
|
spyOn(formCloudService, 'getTaskForm').and.returnValue(of(cloudFormMock));
|
||||||
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of({list: { entries: []}}));
|
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
|
||||||
spyOn(formCloudService, 'getProcessStorageFolderTask')
|
spyOn(formCloudService, 'getProcessStorageFolderTask')
|
||||||
.and.returnValue( of({nodeId : '123', path: '/a/path/type', type: 'fakeType'}));
|
.and.returnValue( of({nodeId : '123', path: '/a/path/type', type: 'fakeType'}));
|
||||||
const taskId = '<task id>';
|
const taskId = '<task id>';
|
||||||
@ -258,7 +257,7 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
it('should call the process storage to retrieve the folder with taskId and processInstanceId', fakeAsync(() => {
|
it('should call the process storage to retrieve the folder with taskId and processInstanceId', fakeAsync(() => {
|
||||||
spyOn(formCloudService, 'getTaskForm').and.returnValue(of(cloudFormMock));
|
spyOn(formCloudService, 'getTaskForm').and.returnValue(of(cloudFormMock));
|
||||||
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of({list: { entries: []}}));
|
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
|
||||||
spyOn(formCloudService, 'getProcessStorageFolderTask')
|
spyOn(formCloudService, 'getProcessStorageFolderTask')
|
||||||
.and.returnValue( of({nodeId : '123', path: '/a/path/type', type: 'fakeType'}));
|
.and.returnValue( of({nodeId : '123', path: '/a/path/type', type: 'fakeType'}));
|
||||||
const taskId = '<task id>';
|
const taskId = '<task id>';
|
||||||
@ -311,7 +310,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should complete form on custom outcome click', () => {
|
it('should complete form on custom outcome click', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
const outcomeName = 'Custom Action';
|
const outcomeName = 'Custom Action';
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, { id: 'custom1', name: outcomeName });
|
const outcome = new FormOutcomeModel(<any> formModel, { id: 'custom1', name: outcomeName });
|
||||||
|
|
||||||
@ -327,7 +326,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should save form on [save] outcome click', () => {
|
it('should save form on [save] outcome click', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, {
|
const outcome = new FormOutcomeModel(<any> formModel, {
|
||||||
id: FormCloudComponent.SAVE_OUTCOME_ID,
|
id: FormCloudComponent.SAVE_OUTCOME_ID,
|
||||||
name: 'Save',
|
name: 'Save',
|
||||||
@ -343,7 +342,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should complete form on [complete] outcome click', () => {
|
it('should complete form on [complete] outcome click', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, {
|
const outcome = new FormOutcomeModel(<any> formModel, {
|
||||||
id: FormCloudComponent.COMPLETE_OUTCOME_ID,
|
id: FormCloudComponent.COMPLETE_OUTCOME_ID,
|
||||||
name: 'Complete',
|
name: 'Complete',
|
||||||
@ -359,7 +358,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should emit form saved event on custom outcome click', () => {
|
it('should emit form saved event on custom outcome click', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, {
|
const outcome = new FormOutcomeModel(<any> formModel, {
|
||||||
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
||||||
name: 'Custom',
|
name: 'Custom',
|
||||||
@ -376,7 +375,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should do nothing when clicking outcome for readonly form', () => {
|
it('should do nothing when clicking outcome for readonly form', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
const outcomeName = 'Custom Action';
|
const outcomeName = 'Custom Action';
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, { id: 'custom1', name: outcomeName });
|
const outcome = new FormOutcomeModel(<any> formModel, { id: 'custom1', name: outcomeName });
|
||||||
|
|
||||||
@ -389,13 +388,13 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should require outcome model when clicking outcome', () => {
|
it('should require outcome model when clicking outcome', () => {
|
||||||
formComponent.form = new FormCloud();
|
formComponent.form = new FormModel();
|
||||||
formComponent.readOnly = false;
|
formComponent.readOnly = false;
|
||||||
expect(formComponent.onOutcomeClicked(null)).toBeFalsy();
|
expect(formComponent.onOutcomeClicked(null)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should require loaded form when clicking outcome', () => {
|
it('should require loaded form when clicking outcome', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
const outcomeName = 'Custom Action';
|
const outcomeName = 'Custom Action';
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, { id: 'custom1', name: outcomeName });
|
const outcome = new FormOutcomeModel(<any> formModel, { id: 'custom1', name: outcomeName });
|
||||||
|
|
||||||
@ -405,7 +404,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not execute unknown system outcome', () => {
|
it('should not execute unknown system outcome', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
const outcome = new FormOutcomeModel(<any> formModel, { id: 'unknown', name: 'Unknown', isSystem: true });
|
const outcome = new FormOutcomeModel(<any> formModel, { id: 'unknown', name: 'Unknown', isSystem: true });
|
||||||
|
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
@ -413,7 +412,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should require custom action name to complete form', () => {
|
it('should require custom action name to complete form', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
let outcome = new FormOutcomeModel(<any> formModel, { id: 'custom' });
|
let outcome = new FormOutcomeModel(<any> formModel, { id: 'custom' });
|
||||||
|
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
@ -429,7 +428,7 @@ describe('FormCloudComponent', () => {
|
|||||||
const taskId = '456';
|
const taskId = '456';
|
||||||
|
|
||||||
spyOn(formCloudService, 'getTask').and.returnValue(of({}));
|
spyOn(formCloudService, 'getTask').and.returnValue(of({}));
|
||||||
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of({}));
|
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
|
||||||
spyOn(formCloudService, 'getTaskForm').and.returnValue(of({ taskId: taskId, selectedOutcome: 'custom-outcome' }));
|
spyOn(formCloudService, 'getTaskForm').and.returnValue(of({ taskId: taskId, selectedOutcome: 'custom-outcome' }));
|
||||||
|
|
||||||
formComponent.formLoaded.subscribe(() => {
|
formComponent.formLoaded.subscribe(() => {
|
||||||
@ -448,7 +447,7 @@ describe('FormCloudComponent', () => {
|
|||||||
const error = 'Some error';
|
const error = 'Some error';
|
||||||
|
|
||||||
spyOn(formCloudService, 'getTask').and.returnValue(of({}));
|
spyOn(formCloudService, 'getTask').and.returnValue(of({}));
|
||||||
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of({}));
|
spyOn(formCloudService, 'getTaskVariables').and.returnValue(of([]));
|
||||||
spyOn(formComponent, 'handleError').and.stub();
|
spyOn(formComponent, 'handleError').and.stub();
|
||||||
spyOn(formCloudService, 'getTaskForm').and.callFake(() => {
|
spyOn(formCloudService, 'getTaskForm').and.callFake(() => {
|
||||||
return throwError(error);
|
return throwError(error);
|
||||||
@ -505,7 +504,7 @@ describe('FormCloudComponent', () => {
|
|||||||
const appName = 'test-app';
|
const appName = 'test-app';
|
||||||
const processInstanceId = '333-444';
|
const processInstanceId = '333-444';
|
||||||
|
|
||||||
const formModel = new FormCloud({
|
const formModel = new FormModel({
|
||||||
id: '23',
|
id: '23',
|
||||||
taskId: taskId,
|
taskId: taskId,
|
||||||
fields: [
|
fields: [
|
||||||
@ -532,7 +531,7 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
const taskId = '123-223';
|
const taskId = '123-223';
|
||||||
const appName = 'test-app';
|
const appName = 'test-app';
|
||||||
const formModel = new FormCloud({
|
const formModel = new FormModel({
|
||||||
id: '23',
|
id: '23',
|
||||||
taskId: taskId,
|
taskId: taskId,
|
||||||
fields: [
|
fields: [
|
||||||
@ -555,7 +554,7 @@ describe('FormCloudComponent', () => {
|
|||||||
formComponent.form = null;
|
formComponent.form = null;
|
||||||
formComponent.saveTaskForm();
|
formComponent.saveTaskForm();
|
||||||
|
|
||||||
formComponent.form = new FormCloud();
|
formComponent.form = new FormModel();
|
||||||
|
|
||||||
formComponent.appName = 'test-app';
|
formComponent.appName = 'test-app';
|
||||||
formComponent.saveTaskForm();
|
formComponent.saveTaskForm();
|
||||||
@ -573,7 +572,7 @@ describe('FormCloudComponent', () => {
|
|||||||
formComponent.form = null;
|
formComponent.form = null;
|
||||||
formComponent.completeTaskForm('save');
|
formComponent.completeTaskForm('save');
|
||||||
|
|
||||||
formComponent.form = new FormCloud();
|
formComponent.form = new FormModel();
|
||||||
formComponent.appName = 'test-app';
|
formComponent.appName = 'test-app';
|
||||||
formComponent.completeTaskForm('complete');
|
formComponent.completeTaskForm('complete');
|
||||||
|
|
||||||
@ -600,7 +599,7 @@ describe('FormCloudComponent', () => {
|
|||||||
const appName = 'test-app';
|
const appName = 'test-app';
|
||||||
const processInstanceId = '333-444';
|
const processInstanceId = '333-444';
|
||||||
|
|
||||||
const formModel = new FormCloud({
|
const formModel = new FormModel({
|
||||||
id: '23',
|
id: '23',
|
||||||
taskId: taskId,
|
taskId: taskId,
|
||||||
fields: [
|
fields: [
|
||||||
@ -646,12 +645,12 @@ describe('FormCloudComponent', () => {
|
|||||||
|
|
||||||
it('should prevent default outcome execution', () => {
|
it('should prevent default outcome execution', () => {
|
||||||
|
|
||||||
const outcome = new FormOutcomeModel(<any> new FormCloud(), {
|
const outcome = new FormOutcomeModel(<any> new FormModel(), {
|
||||||
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
||||||
name: 'Custom'
|
name: 'Custom'
|
||||||
});
|
});
|
||||||
|
|
||||||
formComponent.form = new FormCloud();
|
formComponent.form = new FormModel();
|
||||||
formComponent.executeOutcome.subscribe((event: FormOutcomeEvent) => {
|
formComponent.executeOutcome.subscribe((event: FormOutcomeEvent) => {
|
||||||
expect(event.outcome).toBe(outcome);
|
expect(event.outcome).toBe(outcome);
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
@ -663,12 +662,12 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not prevent default outcome execution', () => {
|
it('should not prevent default outcome execution', () => {
|
||||||
const outcome = new FormOutcomeModel(<any> new FormCloud(), {
|
const outcome = new FormOutcomeModel(<any> new FormModel(), {
|
||||||
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
||||||
name: 'Custom'
|
name: 'Custom'
|
||||||
});
|
});
|
||||||
|
|
||||||
formComponent.form = new FormCloud();
|
formComponent.form = new FormModel();
|
||||||
formComponent.executeOutcome.subscribe((event: FormOutcomeEvent) => {
|
formComponent.executeOutcome.subscribe((event: FormOutcomeEvent) => {
|
||||||
expect(event.outcome).toBe(outcome);
|
expect(event.outcome).toBe(outcome);
|
||||||
expect(event.defaultPrevented).toBeFalsy();
|
expect(event.defaultPrevented).toBeFalsy();
|
||||||
@ -691,17 +690,17 @@ describe('FormCloudComponent', () => {
|
|||||||
formComponent.checkVisibility(field);
|
formComponent.checkVisibility(field);
|
||||||
expect(visibilityService.refreshVisibility).not.toHaveBeenCalled();
|
expect(visibilityService.refreshVisibility).not.toHaveBeenCalled();
|
||||||
|
|
||||||
field = new FormFieldModel(<any> new FormCloud());
|
field = new FormFieldModel(<any> new FormModel());
|
||||||
formComponent.checkVisibility(field);
|
formComponent.checkVisibility(field);
|
||||||
expect(visibilityService.refreshVisibility).toHaveBeenCalledWith(field.form);
|
expect(visibilityService.refreshVisibility).toHaveBeenCalledWith(field.form);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should disable outcome buttons for readonly form', () => {
|
it('should disable outcome buttons for readonly form', () => {
|
||||||
const formModel = new FormCloud();
|
const formModel = new FormModel();
|
||||||
formModel.readOnly = true;
|
formModel.readOnly = true;
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
|
|
||||||
const outcome = new FormOutcomeModel(<any> new FormCloud(), {
|
const outcome = new FormOutcomeModel(<any> new FormModel(), {
|
||||||
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
||||||
name: 'Custom'
|
name: 'Custom'
|
||||||
});
|
});
|
||||||
@ -710,12 +709,12 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should require outcome to eval button state', () => {
|
it('should require outcome to eval button state', () => {
|
||||||
formComponent.form = new FormCloud();
|
formComponent.form = new FormModel();
|
||||||
expect(formComponent.isOutcomeButtonEnabled(null)).toBeFalsy();
|
expect(formComponent.isOutcomeButtonEnabled(null)).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should disable complete outcome button when disableCompleteButton is true', () => {
|
it('should disable complete outcome button when disableCompleteButton is true', () => {
|
||||||
const formModel = new FormCloud(cloudFormMock);
|
const formModel = new FormModel(cloudFormMock);
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
formComponent.disableCompleteButton = true;
|
formComponent.disableCompleteButton = true;
|
||||||
|
|
||||||
@ -730,7 +729,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should disable save outcome button when disableSaveButton is true', () => {
|
it('should disable save outcome button when disableSaveButton is true', () => {
|
||||||
const formModel = new FormCloud(cloudFormMock);
|
const formModel = new FormModel(cloudFormMock);
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
formComponent.disableSaveButton = true;
|
formComponent.disableSaveButton = true;
|
||||||
|
|
||||||
@ -745,7 +744,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should disable start process outcome button when disableStartProcessButton is true', () => {
|
it('should disable start process outcome button when disableStartProcessButton is true', () => {
|
||||||
const formModel = new FormCloud(cloudFormMock);
|
const formModel = new FormModel(cloudFormMock);
|
||||||
formComponent.form = formModel;
|
formComponent.form = formModel;
|
||||||
formComponent.disableStartProcessButton = true;
|
formComponent.disableStartProcessButton = true;
|
||||||
|
|
||||||
@ -764,17 +763,17 @@ describe('FormCloudComponent', () => {
|
|||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
const outcome = new FormOutcomeModel(<any> new FormCloud(), {
|
const outcome = new FormOutcomeModel(<any> new FormModel(), {
|
||||||
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
id: FormCloudComponent.CUSTOM_OUTCOME_ID,
|
||||||
name: 'Custom'
|
name: 'Custom'
|
||||||
});
|
});
|
||||||
|
|
||||||
formComponent.form = new FormCloud();
|
formComponent.form = new FormModel();
|
||||||
formComponent.onOutcomeClicked(outcome);
|
formComponent.onOutcomeClicked(outcome);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should refresh form values when data is changed', (done) => {
|
it('should refresh form values when data is changed', (done) => {
|
||||||
formComponent.form = new FormCloud(JSON.parse(JSON.stringify(cloudFormMock)));
|
formComponent.form = new FormModel(JSON.parse(JSON.stringify(cloudFormMock)));
|
||||||
formComponent.formCloudRepresentationJSON = new FormCloudRepresentation(JSON.parse(JSON.stringify(cloudFormMock)));
|
formComponent.formCloudRepresentationJSON = new FormCloudRepresentation(JSON.parse(JSON.stringify(cloudFormMock)));
|
||||||
let formFields = formComponent.form.getFormFields();
|
let formFields = formComponent.form.getFormFields();
|
||||||
|
|
||||||
@ -803,7 +802,7 @@ describe('FormCloudComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should refresh radio buttons value when id is given to data', () => {
|
it('should refresh radio buttons value when id is given to data', () => {
|
||||||
formComponent.form = new FormCloud(JSON.parse(JSON.stringify(cloudFormMock)));
|
formComponent.form = new FormModel(JSON.parse(JSON.stringify(cloudFormMock)));
|
||||||
formComponent.formCloudRepresentationJSON = new FormCloudRepresentation(JSON.parse(JSON.stringify(cloudFormMock)));
|
formComponent.formCloudRepresentationJSON = new FormCloudRepresentation(JSON.parse(JSON.stringify(cloudFormMock)));
|
||||||
let formFields = formComponent.form.getFormFields();
|
let formFields = formComponent.form.getFormFields();
|
||||||
let radioFieldById = formFields.find((field) => field.id === 'radiobuttons1');
|
let radioFieldById = formFields.find((field) => field.id === 'radiobuttons1');
|
||||||
|
@ -32,14 +32,16 @@ import {
|
|||||||
NotificationService,
|
NotificationService,
|
||||||
FormRenderingService,
|
FormRenderingService,
|
||||||
FORM_FIELD_VALIDATORS,
|
FORM_FIELD_VALIDATORS,
|
||||||
FormFieldValidator
|
FormFieldValidator,
|
||||||
|
FormValues,
|
||||||
|
FormModel
|
||||||
} from '@alfresco/adf-core';
|
} from '@alfresco/adf-core';
|
||||||
import { FormCloudService } from '../services/form-cloud.service';
|
import { FormCloudService } from '../services/form-cloud.service';
|
||||||
import { FormCloud } from '../models/form-cloud.model';
|
|
||||||
import { TaskVariableCloud } from '../models/task-variable-cloud.model';
|
import { TaskVariableCloud } from '../models/task-variable-cloud.model';
|
||||||
import { DropdownCloudWidgetComponent } from './dropdown-cloud/dropdown-cloud.widget';
|
import { DropdownCloudWidgetComponent } from './dropdown-cloud/dropdown-cloud.widget';
|
||||||
import { AttachFileCloudWidgetComponent } from './attach-file-cloud-widget/attach-file-cloud-widget.component';
|
import { AttachFileCloudWidgetComponent } from './attach-file-cloud-widget/attach-file-cloud-widget.component';
|
||||||
import { DateCloudWidgetComponent } from './date-cloud/date-cloud.widget';
|
import { DateCloudWidgetComponent } from './date-cloud/date-cloud.widget';
|
||||||
|
import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-cloud-form',
|
selector: 'adf-cloud-form',
|
||||||
@ -61,7 +63,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
|
|
||||||
/** Underlying form model instance. */
|
/** Underlying form model instance. */
|
||||||
@Input()
|
@Input()
|
||||||
form: FormCloud;
|
form: FormModel;
|
||||||
|
|
||||||
/** Task id to fetch corresponding form and values. */
|
/** Task id to fetch corresponding form and values. */
|
||||||
@Input()
|
@Input()
|
||||||
@ -76,22 +78,22 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
|
|
||||||
/** Emitted when the form is submitted with the `Save` or custom outcomes. */
|
/** Emitted when the form is submitted with the `Save` or custom outcomes. */
|
||||||
@Output()
|
@Output()
|
||||||
formSaved: EventEmitter<FormCloud> = new EventEmitter<FormCloud>();
|
formSaved = new EventEmitter<FormModel>();
|
||||||
|
|
||||||
/** Emitted when the form is submitted with the `Complete` outcome. */
|
/** Emitted when the form is submitted with the `Complete` outcome. */
|
||||||
@Output()
|
@Output()
|
||||||
formCompleted: EventEmitter<FormCloud> = new EventEmitter<FormCloud>();
|
formCompleted = new EventEmitter<FormModel>();
|
||||||
|
|
||||||
/** Emitted when the form is loaded or reloaded. */
|
/** Emitted when the form is loaded or reloaded. */
|
||||||
@Output()
|
@Output()
|
||||||
formLoaded: EventEmitter<FormCloud> = new EventEmitter<FormCloud>();
|
formLoaded = new EventEmitter<FormModel>();
|
||||||
|
|
||||||
/** Emitted when form values are refreshed due to a data property change. */
|
/** Emitted when form values are refreshed due to a data property change. */
|
||||||
@Output()
|
@Output()
|
||||||
formDataRefreshed: EventEmitter<FormCloud> = new EventEmitter<FormCloud>();
|
formDataRefreshed = new EventEmitter<FormModel>();
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
formContentClicked: EventEmitter<string> = new EventEmitter<string>();
|
formContentClicked = new EventEmitter<string>();
|
||||||
|
|
||||||
protected subscriptions: Subscription[] = [];
|
protected subscriptions: Subscription[] = [];
|
||||||
nodeId: string;
|
nodeId: string;
|
||||||
@ -162,24 +164,24 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
findProcessVariablesByTaskId(appName: string, taskId: string): Observable<any> {
|
findProcessVariablesByTaskId(appName: string, taskId: string): Observable<TaskVariableCloud[]> {
|
||||||
return this.formCloudService.getTask(appName, taskId).pipe(
|
return this.formCloudService.getTask(appName, taskId).pipe(
|
||||||
switchMap((task: any) => {
|
switchMap(task => {
|
||||||
if (this.isAProcessTask(task)) {
|
if (this.isAProcessTask(task)) {
|
||||||
return this.formCloudService.getTaskVariables(appName, taskId);
|
return this.formCloudService.getTaskVariables(appName, taskId);
|
||||||
} else {
|
} else {
|
||||||
return of({});
|
return of([]);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
isAProcessTask(taskRepresentation) {
|
isAProcessTask(taskRepresentation: TaskDetailsCloudModel): boolean {
|
||||||
return taskRepresentation.processDefinitionId && taskRepresentation.processDefinitionDeploymentId !== 'null';
|
return taskRepresentation.processDefinitionId && taskRepresentation.processDefinitionDeploymentId !== 'null';
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormByTaskId(appName: string, taskId: string): Promise<FormCloud> {
|
getFormByTaskId(appName: string, taskId: string): Promise<FormModel> {
|
||||||
return new Promise<FormCloud>(resolve => {
|
return new Promise<FormModel>(resolve => {
|
||||||
forkJoin(this.formCloudService.getTaskForm(appName, taskId),
|
forkJoin(this.formCloudService.getTaskForm(appName, taskId),
|
||||||
this.formCloudService.getTaskVariables(appName, taskId))
|
this.formCloudService.getTaskVariables(appName, taskId))
|
||||||
.pipe(takeUntil(this.onDestroy$))
|
.pipe(takeUntil(this.onDestroy$))
|
||||||
@ -255,7 +257,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
saveTaskForm() {
|
saveTaskForm() {
|
||||||
if (this.form && this.appName && this.taskId) {
|
if (this.form && this.appName && this.taskId) {
|
||||||
this.formCloudService
|
this.formCloudService
|
||||||
.saveTaskForm(this.appName, this.taskId, this.processInstanceId, this.form.id, this.form.values)
|
.saveTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values)
|
||||||
.pipe(takeUntil(this.onDestroy$))
|
.pipe(takeUntil(this.onDestroy$))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
() => {
|
() => {
|
||||||
@ -269,7 +271,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
completeTaskForm(outcome?: string) {
|
completeTaskForm(outcome?: string) {
|
||||||
if (this.form && this.appName && this.taskId) {
|
if (this.form && this.appName && this.taskId) {
|
||||||
this.formCloudService
|
this.formCloudService
|
||||||
.completeTaskForm(this.appName, this.taskId, this.processInstanceId, this.form.id, this.form.values, outcome)
|
.completeTaskForm(this.appName, this.taskId, this.processInstanceId, `${this.form.id}`, this.form.values, outcome)
|
||||||
.pipe(takeUntil(this.onDestroy$))
|
.pipe(takeUntil(this.onDestroy$))
|
||||||
.subscribe(
|
.subscribe(
|
||||||
() => {
|
() => {
|
||||||
@ -280,9 +282,14 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
parseForm(formCloudRepresentationJSON: any): FormCloud {
|
parseForm(formCloudRepresentationJSON: any): FormModel {
|
||||||
if (formCloudRepresentationJSON) {
|
if (formCloudRepresentationJSON) {
|
||||||
const form = new FormCloud(formCloudRepresentationJSON, this.data, this.readOnly, this.formCloudService);
|
const formValues: FormValues = {};
|
||||||
|
(this.data || []).forEach(variable => {
|
||||||
|
formValues[variable.name] = variable.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = new FormModel(formCloudRepresentationJSON, formValues, this.readOnly);
|
||||||
if (!form || !form.fields.length) {
|
if (!form || !form.fields.length) {
|
||||||
form.outcomes = this.getFormDefinitionOutcomes(form);
|
form.outcomes = this.getFormDefinitionOutcomes(form);
|
||||||
}
|
}
|
||||||
@ -298,7 +305,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
* Get custom set of outcomes for a Form Definition.
|
* Get custom set of outcomes for a Form Definition.
|
||||||
* @param form Form definition model.
|
* @param form Form definition model.
|
||||||
*/
|
*/
|
||||||
getFormDefinitionOutcomes(form: FormCloud): FormOutcomeModel[] {
|
getFormDefinitionOutcomes(form: FormModel): FormOutcomeModel[] {
|
||||||
return [
|
return [
|
||||||
new FormOutcomeModel(<any> form, { id: '$save', name: FormOutcomeModel.SAVE_ACTION, isSystem: true })
|
new FormOutcomeModel(<any> form, { id: '$save', name: FormOutcomeModel.SAVE_ACTION, isSystem: true })
|
||||||
];
|
];
|
||||||
@ -316,15 +323,15 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
this.onFormDataRefreshed(this.form);
|
this.onFormDataRefreshed(this.form);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onFormLoaded(form: FormCloud) {
|
protected onFormLoaded(form: FormModel) {
|
||||||
this.formLoaded.emit(form);
|
this.formLoaded.emit(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onFormDataRefreshed(form: FormCloud) {
|
protected onFormDataRefreshed(form: FormModel) {
|
||||||
this.formDataRefreshed.emit(form);
|
this.formDataRefreshed.emit(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onTaskSaved(form: FormCloud) {
|
protected onTaskSaved(form: FormModel) {
|
||||||
this.formSaved.emit(form);
|
this.formSaved.emit(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -332,7 +339,7 @@ export class FormCloudComponent extends FormBaseComponent implements OnChanges,
|
|||||||
this.handleError(error);
|
this.handleError(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected onTaskCompleted(form: FormCloud) {
|
protected onTaskCompleted(form: FormModel) {
|
||||||
this.formCompleted.emit(form);
|
this.formCompleted.emit(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,22 +15,14 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { FormCloudService } from '../services/form-cloud.service';
|
import { TabModel, FormFieldModel, ContainerModel, FormOutcomeModel, FormFieldTypes, FormModel } from '@alfresco/adf-core';
|
||||||
import { FormCloud } from './form-cloud.model';
|
|
||||||
import { TabModel, FormFieldModel, ContainerModel, FormOutcomeModel, FormFieldTypes, AppConfigService } from '@alfresco/adf-core';
|
|
||||||
import { FormCloudRepresentation } from './form-cloud-representation.model';
|
import { FormCloudRepresentation } from './form-cloud-representation.model';
|
||||||
|
|
||||||
describe('FormCloud', () => {
|
describe('FormCloud', () => {
|
||||||
|
|
||||||
let formCloudService: FormCloudService;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
formCloudService = new FormCloudService(null, new AppConfigService(null), null);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should store original json', () => {
|
it('should store original json', () => {
|
||||||
const formRepresentation = {fields: []};
|
const formRepresentation = {fields: []};
|
||||||
const form = new FormCloud(formRepresentation);
|
const form = new FormModel(formRepresentation);
|
||||||
expect(form.json).toEqual(formRepresentation);
|
expect(form.json).toEqual(formRepresentation);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -41,7 +33,7 @@ describe('FormCloud', () => {
|
|||||||
taskId: '<task-id>',
|
taskId: '<task-id>',
|
||||||
taskName: '<task-name>'
|
taskName: '<task-name>'
|
||||||
};
|
};
|
||||||
const form = new FormCloud(formRepresentation);
|
const form = new FormModel(formRepresentation);
|
||||||
|
|
||||||
Object.keys(formRepresentation).forEach((key) => {
|
Object.keys(formRepresentation).forEach((key) => {
|
||||||
expect(form[key]).toEqual(form[key]);
|
expect(form[key]).toEqual(form[key]);
|
||||||
@ -54,17 +46,17 @@ describe('FormCloud', () => {
|
|||||||
name: '<name>',
|
name: '<name>',
|
||||||
formDefinition: {}
|
formDefinition: {}
|
||||||
};
|
};
|
||||||
const form = new FormCloud(formRepresentation);
|
const form = new FormModel(formRepresentation);
|
||||||
expect(form.taskName).toBe(formRepresentation.name);
|
expect(form.taskName).toBe(formRepresentation.name);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set readonly state from params', () => {
|
it('should set readonly state from params', () => {
|
||||||
const form = new FormCloud({}, null, true);
|
const form = new FormModel({}, null, true);
|
||||||
expect(form.readOnly).toBeTruthy();
|
expect(form.readOnly).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should check tabs', () => {
|
it('should check tabs', () => {
|
||||||
const form = new FormCloud();
|
const form = new FormModel();
|
||||||
|
|
||||||
form.tabs = null;
|
form.tabs = null;
|
||||||
expect(form.hasTabs()).toBeFalsy();
|
expect(form.hasTabs()).toBeFalsy();
|
||||||
@ -77,7 +69,7 @@ describe('FormCloud', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should check fields', () => {
|
it('should check fields', () => {
|
||||||
const form = new FormCloud();
|
const form = new FormModel();
|
||||||
|
|
||||||
form.fields = null;
|
form.fields = null;
|
||||||
expect(form.hasFields()).toBeFalsy();
|
expect(form.hasFields()).toBeFalsy();
|
||||||
@ -91,7 +83,7 @@ describe('FormCloud', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should check outcomes', () => {
|
it('should check outcomes', () => {
|
||||||
const form = new FormCloud();
|
const form = new FormModel();
|
||||||
|
|
||||||
form.outcomes = null;
|
form.outcomes = null;
|
||||||
expect(form.hasOutcomes()).toBeFalsy();
|
expect(form.hasOutcomes()).toBeFalsy();
|
||||||
@ -111,7 +103,7 @@ describe('FormCloud', () => {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const form = new FormCloud(formRepresentation);
|
const form = new FormModel(formRepresentation);
|
||||||
expect(form.tabs.length).toBe(2);
|
expect(form.tabs.length).toBe(2);
|
||||||
expect(form.tabs[0].id).toBe('tab1');
|
expect(form.tabs[0].id).toBe('tab1');
|
||||||
expect(form.tabs[1].id).toBe('tab2');
|
expect(form.tabs[1].id).toBe('tab2');
|
||||||
@ -131,7 +123,7 @@ describe('FormCloud', () => {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const form = new FormCloud(formRepresentation);
|
const form = new FormModel(formRepresentation);
|
||||||
expect(form.fields.length).toBe(2);
|
expect(form.fields.length).toBe(2);
|
||||||
expect(form.fields[0].id).toBe('field1');
|
expect(form.fields[0].id).toBe('field1');
|
||||||
expect(form.fields[1].id).toBe('field2');
|
expect(form.fields[1].id).toBe('field2');
|
||||||
@ -142,7 +134,7 @@ describe('FormCloud', () => {
|
|||||||
fields: null
|
fields: null
|
||||||
};
|
};
|
||||||
|
|
||||||
const form = new FormCloud(formRepresentation);
|
const form = new FormModel(formRepresentation);
|
||||||
expect(form.fields).toBeDefined();
|
expect(form.fields).toBeDefined();
|
||||||
expect(form.fields.length).toBe(0);
|
expect(form.fields.length).toBe(0);
|
||||||
});
|
});
|
||||||
@ -161,7 +153,7 @@ describe('FormCloud', () => {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const form = new FormCloud(formRepresentation);
|
const form = new FormModel(formRepresentation);
|
||||||
expect(form.tabs.length).toBe(2);
|
expect(form.tabs.length).toBe(2);
|
||||||
expect(form.fields.length).toBe(4);
|
expect(form.fields.length).toBe(4);
|
||||||
|
|
||||||
@ -182,16 +174,16 @@ describe('FormCloud', () => {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const form = new FormCloud(formRepresentation);
|
const form = new FormModel(formRepresentation);
|
||||||
expect(form.outcomes.length).toBe(3);
|
expect(form.outcomes.length).toBe(3);
|
||||||
|
|
||||||
expect(form.outcomes[0].id).toBe(FormCloud.SAVE_OUTCOME);
|
expect(form.outcomes[0].id).toBe(FormModel.SAVE_OUTCOME);
|
||||||
expect(form.outcomes[0].isSystem).toBeTruthy();
|
expect(form.outcomes[0].isSystem).toBeTruthy();
|
||||||
|
|
||||||
expect(form.outcomes[1].id).toBe(FormCloud.COMPLETE_OUTCOME);
|
expect(form.outcomes[1].id).toBe(FormModel.COMPLETE_OUTCOME);
|
||||||
expect(form.outcomes[1].isSystem).toBeTruthy();
|
expect(form.outcomes[1].isSystem).toBeTruthy();
|
||||||
|
|
||||||
expect(form.outcomes[2].id).toBe(FormCloud.START_PROCESS_OUTCOME);
|
expect(form.outcomes[2].id).toBe(FormModel.START_PROCESS_OUTCOME);
|
||||||
expect(form.outcomes[2].isSystem).toBeTruthy();
|
expect(form.outcomes[2].isSystem).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -199,7 +191,7 @@ describe('FormCloud', () => {
|
|||||||
const formRepresentation = {
|
const formRepresentation = {
|
||||||
fields: null
|
fields: null
|
||||||
};
|
};
|
||||||
const form = new FormCloud(formRepresentation);
|
const form = new FormModel(formRepresentation);
|
||||||
expect(form.outcomes.length).toBe(0);
|
expect(form.outcomes.length).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -213,10 +205,10 @@ describe('FormCloud', () => {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const form = new FormCloud(formRepresentation);
|
const form = new FormModel(formRepresentation);
|
||||||
expect(form.outcomes.length).toBe(2);
|
expect(form.outcomes.length).toBe(2);
|
||||||
|
|
||||||
expect(form.outcomes[0].id).toBe(FormCloud.SAVE_OUTCOME);
|
expect(form.outcomes[0].id).toBe(FormModel.SAVE_OUTCOME);
|
||||||
expect(form.outcomes[0].isSystem).toBeTruthy();
|
expect(form.outcomes[0].isSystem).toBeTruthy();
|
||||||
|
|
||||||
expect(form.outcomes[1].id).toBe('custom-1');
|
expect(form.outcomes[1].id).toBe('custom-1');
|
||||||
@ -224,7 +216,7 @@ describe('FormCloud', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should get field by id', () => {
|
it('should get field by id', () => {
|
||||||
const form = new FormCloud({}, null, false, formCloudService);
|
const form = new FormModel({}, null, false);
|
||||||
const field: any = { id: 'field1' };
|
const field: any = { id: 'field1' };
|
||||||
spyOn(form, 'getFormFields').and.returnValue([field]);
|
spyOn(form, 'getFormFields').and.returnValue([field]);
|
||||||
|
|
||||||
|
@ -1,212 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @license
|
|
||||||
* Copyright 2019 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import {
|
|
||||||
TabModel, FormWidgetModel, FormOutcomeModel, FormValues,
|
|
||||||
FormWidgetModelCache, FormFieldModel, ContainerModel, FormFieldTypes,
|
|
||||||
ValidateFormFieldEvent, FormFieldValidator, FormFieldTemplates, FormBaseModel, FORM_FIELD_VALIDATORS } from '@alfresco/adf-core';
|
|
||||||
import { FormCloudService } from '../services/form-cloud.service';
|
|
||||||
import { TaskVariableCloud } from './task-variable-cloud.model';
|
|
||||||
|
|
||||||
export class FormCloud extends FormBaseModel {
|
|
||||||
|
|
||||||
static SAVE_OUTCOME: string = '$save';
|
|
||||||
static COMPLETE_OUTCOME: string = '$complete';
|
|
||||||
static START_PROCESS_OUTCOME: string = '$startProcess';
|
|
||||||
|
|
||||||
readonly id: string;
|
|
||||||
nodeId: string;
|
|
||||||
contentHost: string;
|
|
||||||
readonly name: string;
|
|
||||||
readonly taskId: string;
|
|
||||||
readonly taskName: string;
|
|
||||||
|
|
||||||
readonly selectedOutcome: string;
|
|
||||||
|
|
||||||
readOnly: boolean;
|
|
||||||
processDefinitionId: any;
|
|
||||||
className: string;
|
|
||||||
values: FormValues = {};
|
|
||||||
|
|
||||||
tabs: TabModel[] = [];
|
|
||||||
fields: FormWidgetModel[] = [];
|
|
||||||
outcomes: FormOutcomeModel[] = [];
|
|
||||||
customFieldTemplates: FormFieldTemplates = {};
|
|
||||||
fieldValidators: FormFieldValidator[] = [...FORM_FIELD_VALIDATORS];
|
|
||||||
|
|
||||||
constructor(formCloudRepresentationJSON?: any, formData?: TaskVariableCloud[], readOnly: boolean = false, protected formService?: FormCloudService) {
|
|
||||||
super();
|
|
||||||
this.readOnly = readOnly;
|
|
||||||
|
|
||||||
if (formCloudRepresentationJSON) {
|
|
||||||
this.json = formCloudRepresentationJSON;
|
|
||||||
this.id = formCloudRepresentationJSON.id;
|
|
||||||
this.name = formCloudRepresentationJSON.name;
|
|
||||||
this.taskId = formCloudRepresentationJSON.taskId;
|
|
||||||
this.taskName = formCloudRepresentationJSON.taskName || formCloudRepresentationJSON.name;
|
|
||||||
this.processDefinitionId = formCloudRepresentationJSON.processDefinitionId;
|
|
||||||
this.selectedOutcome = formCloudRepresentationJSON.selectedOutcome || '';
|
|
||||||
|
|
||||||
const tabCache: FormWidgetModelCache<TabModel> = {};
|
|
||||||
|
|
||||||
this.tabs = (formCloudRepresentationJSON.tabs || []).map((t) => {
|
|
||||||
const model = new TabModel(<any> this, t);
|
|
||||||
tabCache[model.id] = model;
|
|
||||||
return model;
|
|
||||||
});
|
|
||||||
|
|
||||||
this.fields = this.parseRootFields(formCloudRepresentationJSON);
|
|
||||||
|
|
||||||
if (formData && formData.length > 0) {
|
|
||||||
this.loadData(formData);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < this.fields.length; i++) {
|
|
||||||
const field = this.fields[i];
|
|
||||||
if (field.tab) {
|
|
||||||
const tab = tabCache[field.tab];
|
|
||||||
if (tab) {
|
|
||||||
tab.fields.push(field);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (formCloudRepresentationJSON.fields) {
|
|
||||||
const saveOutcome = new FormOutcomeModel(<any> this, {
|
|
||||||
id: FormCloud.SAVE_OUTCOME,
|
|
||||||
name: 'SAVE',
|
|
||||||
isSystem: true
|
|
||||||
});
|
|
||||||
const completeOutcome = new FormOutcomeModel(<any> this, {
|
|
||||||
id: FormCloud.COMPLETE_OUTCOME,
|
|
||||||
name: 'COMPLETE',
|
|
||||||
isSystem: true
|
|
||||||
});
|
|
||||||
const startProcessOutcome = new FormOutcomeModel(<any> this, {
|
|
||||||
id: FormCloud.START_PROCESS_OUTCOME,
|
|
||||||
name: 'START PROCESS',
|
|
||||||
isSystem: true
|
|
||||||
});
|
|
||||||
|
|
||||||
const customOutcomes = (formCloudRepresentationJSON.outcomes || []).map((obj) => new FormOutcomeModel(<any> this, obj));
|
|
||||||
|
|
||||||
this.outcomes = [saveOutcome].concat(
|
|
||||||
customOutcomes.length > 0 ? customOutcomes : [completeOutcome, startProcessOutcome]
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.validateForm();
|
|
||||||
}
|
|
||||||
|
|
||||||
hasTabs(): boolean {
|
|
||||||
return this.tabs && this.tabs.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasFields(): boolean {
|
|
||||||
return this.fields && this.fields.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
hasOutcomes(): boolean {
|
|
||||||
return this.outcomes && this.outcomes.length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
onFormFieldChanged(field: FormFieldModel) {
|
|
||||||
this.validateField(field);
|
|
||||||
}
|
|
||||||
|
|
||||||
validateForm() {
|
|
||||||
const errorsField: FormFieldModel[] = [];
|
|
||||||
|
|
||||||
const fields = this.getFormFields();
|
|
||||||
for (let i = 0; i < fields.length; i++) {
|
|
||||||
if (!fields[i].validate()) {
|
|
||||||
errorsField.push(fields[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.isValid = errorsField.length > 0 ? false : true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates a specific form field, triggers form validation.
|
|
||||||
*
|
|
||||||
* @param field Form field to validate.
|
|
||||||
* @memberof FormCloud
|
|
||||||
*/
|
|
||||||
validateField(field: FormFieldModel) {
|
|
||||||
if (!field) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const validateFieldEvent = new ValidateFormFieldEvent(<any> this, field);
|
|
||||||
|
|
||||||
if (!validateFieldEvent.isValid) {
|
|
||||||
this.isValid = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (validateFieldEvent.defaultPrevented) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!field.validate()) {
|
|
||||||
this.isValid = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.validateForm();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activiti supports 3 types of root fields: container|group|dynamic-table
|
|
||||||
private parseRootFields(json: any): FormWidgetModel[] {
|
|
||||||
let fields = [];
|
|
||||||
|
|
||||||
if (json.fields) {
|
|
||||||
fields = json.fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
const formWidgetModel: FormWidgetModel[] = [];
|
|
||||||
|
|
||||||
for (const field of fields) {
|
|
||||||
if (field.type === FormFieldTypes.DISPLAY_VALUE) {
|
|
||||||
// workaround for dynamic table on a completed/readonly form
|
|
||||||
if (field.params) {
|
|
||||||
const originalField = field.params['field'];
|
|
||||||
if (originalField.type === FormFieldTypes.DYNAMIC_TABLE) {
|
|
||||||
formWidgetModel.push(new ContainerModel(new FormFieldModel(<any> this, field)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
formWidgetModel.push(new ContainerModel(new FormFieldModel(<any> this, field)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return formWidgetModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loads external data and overrides field values
|
|
||||||
// Typically used when form definition and form data coming from different sources
|
|
||||||
private loadData(formData: TaskVariableCloud[]) {
|
|
||||||
for (const field of this.getFormFields()) {
|
|
||||||
const fieldValue = formData.find((value) => { return value.name === field.id; });
|
|
||||||
if (fieldValue) {
|
|
||||||
field.json.value = fieldValue.value;
|
|
||||||
field.value = field.parseValue(field.json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,21 +15,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export class FormDefinitionSelectorCloudModel {
|
export interface FormDefinitionSelectorCloudModel {
|
||||||
|
id?: number;
|
||||||
id: number;
|
name?: string;
|
||||||
name: string;
|
description?: string;
|
||||||
description: string;
|
version?: string;
|
||||||
version: string;
|
standAlone?: string;
|
||||||
standAlone: string;
|
|
||||||
|
|
||||||
constructor(obj?: any) {
|
|
||||||
if (obj) {
|
|
||||||
this.id = obj.id || null;
|
|
||||||
this.name = obj.name || null;
|
|
||||||
this.description = obj.description || null;
|
|
||||||
this.version = obj.version || null;
|
|
||||||
this.standAlone = obj.standAlone || null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './models/form-cloud.model';
|
|
||||||
export * from './models/task-variable-cloud.model';
|
export * from './models/task-variable-cloud.model';
|
||||||
export * from './models/form-definition-selector-cloud.model';
|
export * from './models/form-definition-selector-cloud.model';
|
||||||
|
|
||||||
|
@ -16,12 +16,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { AlfrescoApiService, LogService, FormValues, AppConfigService, FormOutcomeModel, FormFieldOption } from '@alfresco/adf-core';
|
import { AlfrescoApiService, LogService, FormValues, AppConfigService, FormOutcomeModel, FormFieldOption, FormModel } from '@alfresco/adf-core';
|
||||||
import { throwError, Observable, from } from 'rxjs';
|
import { throwError, Observable, from } from 'rxjs';
|
||||||
import { catchError, map, switchMap } from 'rxjs/operators';
|
import { catchError, map, switchMap } from 'rxjs/operators';
|
||||||
import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model';
|
import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model';
|
||||||
import { SaveFormRepresentation, CompleteFormRepresentation } from '@alfresco/js-api';
|
import { SaveFormRepresentation, CompleteFormRepresentation } from '@alfresco/js-api';
|
||||||
import { FormCloud } from '../models/form-cloud.model';
|
|
||||||
import { TaskVariableCloud, ProcessStorageCloudModel } from '../models/task-variable-cloud.model';
|
import { TaskVariableCloud, ProcessStorageCloudModel } from '../models/task-variable-cloud.model';
|
||||||
import { BaseCloudService } from '../../services/base-cloud.service';
|
import { BaseCloudService } from '../../services/base-cloud.service';
|
||||||
|
|
||||||
@ -258,12 +257,17 @@ export class FormCloudService extends BaseCloudService {
|
|||||||
* @param readOnly Toggles whether or not the form should be read-only
|
* @param readOnly Toggles whether or not the form should be read-only
|
||||||
* @returns Form created from the JSON specification
|
* @returns Form created from the JSON specification
|
||||||
*/
|
*/
|
||||||
parseForm(json: any, data?: TaskVariableCloud[], readOnly: boolean = false): FormCloud {
|
parseForm(json: any, data?: TaskVariableCloud[], readOnly: boolean = false): FormModel {
|
||||||
if (json) {
|
if (json) {
|
||||||
const flattenForm = {...json.formRepresentation, ...json.formRepresentation.formDefinition};
|
const flattenForm = {...json.formRepresentation, ...json.formRepresentation.formDefinition};
|
||||||
delete flattenForm.formDefinition;
|
delete flattenForm.formDefinition;
|
||||||
|
|
||||||
const form = new FormCloud(flattenForm, data, readOnly, this);
|
const formValues: FormValues = {};
|
||||||
|
(data || []).forEach(variable => {
|
||||||
|
formValues[variable.name] = variable.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
const form = new FormModel(flattenForm, formValues, readOnly);
|
||||||
if (!json.fields) {
|
if (!json.fields) {
|
||||||
form.outcomes = [
|
form.outcomes = [
|
||||||
new FormOutcomeModel(<any> form, {
|
new FormOutcomeModel(<any> form, {
|
||||||
|
@ -23,13 +23,13 @@ import {
|
|||||||
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
|
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
|
||||||
import { StartProcessCloudService } from '../services/start-process-cloud.service';
|
import { StartProcessCloudService } from '../services/start-process-cloud.service';
|
||||||
import { FormControl, Validators, FormGroup, AbstractControl, FormBuilder, ValidatorFn } from '@angular/forms';
|
import { FormControl, Validators, FormGroup, AbstractControl, FormBuilder, ValidatorFn } from '@angular/forms';
|
||||||
|
import { FormModel } from '@alfresco/adf-core';
|
||||||
import { MatAutocompleteTrigger } from '@angular/material';
|
import { MatAutocompleteTrigger } from '@angular/material';
|
||||||
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
|
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
|
||||||
import { debounceTime, takeUntil } from 'rxjs/operators';
|
import { debounceTime, takeUntil } from 'rxjs/operators';
|
||||||
import { ProcessDefinitionCloud } from '../models/process-definition-cloud.model';
|
import { ProcessDefinitionCloud } from '../models/process-definition-cloud.model';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
import { TaskVariableCloud } from '../../../form/models/task-variable-cloud.model';
|
import { TaskVariableCloud } from '../../../form/models/task-variable-cloud.model';
|
||||||
import { FormCloud } from '../../../form/models/form-cloud.model';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-cloud-start-process',
|
selector: 'adf-cloud-start-process',
|
||||||
@ -74,15 +74,15 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
|
|
||||||
/** Emitted when the process is successfully started. */
|
/** Emitted when the process is successfully started. */
|
||||||
@Output()
|
@Output()
|
||||||
success: EventEmitter<ProcessInstanceCloud> = new EventEmitter<ProcessInstanceCloud>();
|
success = new EventEmitter<ProcessInstanceCloud>();
|
||||||
|
|
||||||
/** Emitted when the starting process is cancelled */
|
/** Emitted when the starting process is cancelled */
|
||||||
@Output()
|
@Output()
|
||||||
cancel: EventEmitter<ProcessInstanceCloud> = new EventEmitter<ProcessInstanceCloud>();
|
cancel = new EventEmitter<ProcessInstanceCloud>();
|
||||||
|
|
||||||
/** Emitted when an error occurs. */
|
/** Emitted when an error occurs. */
|
||||||
@Output()
|
@Output()
|
||||||
error: EventEmitter<ProcessInstanceCloud> = new EventEmitter<ProcessInstanceCloud>();
|
error = new EventEmitter<ProcessInstanceCloud>();
|
||||||
|
|
||||||
processDefinitionList: ProcessDefinitionCloud[] = [];
|
processDefinitionList: ProcessDefinitionCloud[] = [];
|
||||||
processDefinitionCurrent: ProcessDefinitionCloud;
|
processDefinitionCurrent: ProcessDefinitionCloud;
|
||||||
@ -92,8 +92,9 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
filteredProcesses: ProcessDefinitionCloud[] = [];
|
filteredProcesses: ProcessDefinitionCloud[] = [];
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
isFormCloudLoaded = false;
|
isFormCloudLoaded = false;
|
||||||
formCloud: FormCloud;
|
formCloud: FormModel;
|
||||||
protected onDestroy$ = new Subject<boolean>();
|
protected onDestroy$ = new Subject<boolean>();
|
||||||
|
|
||||||
constructor(private startProcessCloudService: StartProcessCloudService,
|
constructor(private startProcessCloudService: StartProcessCloudService,
|
||||||
private formBuilder: FormBuilder) {
|
private formBuilder: FormBuilder) {
|
||||||
}
|
}
|
||||||
@ -128,7 +129,7 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
|
|||||||
return this.processDefinitionCurrent && !!this.processDefinitionCurrent.formKey;
|
return this.processDefinitionCurrent && !!this.processDefinitionCurrent.formKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
onFormLoaded(form: FormCloud) {
|
onFormLoaded(form: FormModel) {
|
||||||
this.isFormCloudLoaded = true;
|
this.isFormCloudLoaded = true;
|
||||||
this.formCloud = form;
|
this.formCloud = form;
|
||||||
}
|
}
|
||||||
|
@ -44,6 +44,7 @@ export class TaskDetailsCloudModel {
|
|||||||
managerOfCandidateGroup: boolean;
|
managerOfCandidateGroup: boolean;
|
||||||
memberOfCandidateGroup: boolean;
|
memberOfCandidateGroup: boolean;
|
||||||
memberOfCandidateUsers: boolean;
|
memberOfCandidateUsers: boolean;
|
||||||
|
processDefinitionDeploymentId?: string;
|
||||||
|
|
||||||
constructor(obj?: any) {
|
constructor(obj?: any) {
|
||||||
if (obj) {
|
if (obj) {
|
||||||
|
@ -19,10 +19,9 @@ import {
|
|||||||
Component, EventEmitter, Input, OnChanges,
|
Component, EventEmitter, Input, OnChanges,
|
||||||
Output, SimpleChanges
|
Output, SimpleChanges
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { FormCloud } from '../../../form/models/form-cloud.model';
|
|
||||||
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
|
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
|
||||||
import { TaskCloudService } from '../../services/task-cloud.service';
|
import { TaskCloudService } from '../../services/task-cloud.service';
|
||||||
import { FormRenderingService, ContentLinkModel } from '@alfresco/adf-core';
|
import { FormRenderingService, FormModel, ContentLinkModel } from '@alfresco/adf-core';
|
||||||
import { AttachFileCloudWidgetComponent } from '../../../form/components/attach-file-cloud-widget/attach-file-cloud-widget.component';
|
import { AttachFileCloudWidgetComponent } from '../../../form/components/attach-file-cloud-widget/attach-file-cloud-widget.component';
|
||||||
import { DropdownCloudWidgetComponent } from '../../../form/components/dropdown-cloud/dropdown-cloud.widget';
|
import { DropdownCloudWidgetComponent } from '../../../form/components/dropdown-cloud/dropdown-cloud.widget';
|
||||||
import { DateCloudWidgetComponent } from '../../../form/components/date-cloud/date-cloud.widget';
|
import { DateCloudWidgetComponent } from '../../../form/components/date-cloud/date-cloud.widget';
|
||||||
@ -64,31 +63,31 @@ export class TaskFormCloudComponent implements OnChanges {
|
|||||||
|
|
||||||
/** Emitted when the form is saved. */
|
/** Emitted when the form is saved. */
|
||||||
@Output()
|
@Output()
|
||||||
formSaved: EventEmitter<FormCloud> = new EventEmitter<FormCloud>();
|
formSaved = new EventEmitter<FormModel>();
|
||||||
|
|
||||||
/** Emitted when the form is submitted with the `Complete` outcome. */
|
/** Emitted when the form is submitted with the `Complete` outcome. */
|
||||||
@Output()
|
@Output()
|
||||||
formCompleted: EventEmitter<FormCloud> = new EventEmitter<FormCloud>();
|
formCompleted = new EventEmitter<FormModel>();
|
||||||
|
|
||||||
/** Emitted when the task is completed. */
|
/** Emitted when the task is completed. */
|
||||||
@Output()
|
@Output()
|
||||||
taskCompleted: EventEmitter<string> = new EventEmitter<string>();
|
taskCompleted = new EventEmitter<string>();
|
||||||
|
|
||||||
/** Emitted when the task is claimed. */
|
/** Emitted when the task is claimed. */
|
||||||
@Output()
|
@Output()
|
||||||
taskClaimed: EventEmitter<string> = new EventEmitter<string>();
|
taskClaimed = new EventEmitter<string>();
|
||||||
|
|
||||||
/** Emitted when the task is unclaimed. */
|
/** Emitted when the task is unclaimed. */
|
||||||
@Output()
|
@Output()
|
||||||
taskUnclaimed: EventEmitter<string> = new EventEmitter<string>();
|
taskUnclaimed = new EventEmitter<string>();
|
||||||
|
|
||||||
/** Emitted when the cancel button is clicked. */
|
/** Emitted when the cancel button is clicked. */
|
||||||
@Output()
|
@Output()
|
||||||
cancelClick: EventEmitter<string> = new EventEmitter<string>();
|
cancelClick = new EventEmitter<string>();
|
||||||
|
|
||||||
/** Emitted when any error occurs. */
|
/** Emitted when any error occurs. */
|
||||||
@Output()
|
@Output()
|
||||||
error: EventEmitter<any> = new EventEmitter<any>();
|
error = new EventEmitter<any>();
|
||||||
|
|
||||||
@Output()
|
@Output()
|
||||||
formContentClicked: EventEmitter<ContentLinkModel> = new EventEmitter();
|
formContentClicked: EventEmitter<ContentLinkModel> = new EventEmitter();
|
||||||
@ -171,11 +170,11 @@ export class TaskFormCloudComponent implements OnChanges {
|
|||||||
this.cancelClick.emit(this.taskId);
|
this.cancelClick.emit(this.taskId);
|
||||||
}
|
}
|
||||||
|
|
||||||
onFormSaved(form: FormCloud) {
|
onFormSaved(form: FormModel) {
|
||||||
this.formSaved.emit(form);
|
this.formSaved.emit(form);
|
||||||
}
|
}
|
||||||
|
|
||||||
onFormCompleted(form: FormCloud) {
|
onFormCompleted(form: FormModel) {
|
||||||
this.formCompleted.emit(form);
|
this.formCompleted.emit(form);
|
||||||
this.taskCompleted.emit(this.taskId);
|
this.taskCompleted.emit(this.taskId);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user