mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
Merge pull request #868 from Alfresco/dev-valbano-856
Added fix for visibility on dropdown
This commit is contained in:
@@ -34,7 +34,7 @@ describe('ActivitiForm', () => {
|
|||||||
'upgradeAllRegistered'
|
'upgradeAllRegistered'
|
||||||
]);
|
]);
|
||||||
visibilityService = jasmine.createSpyObj('WidgetVisibilityService', [
|
visibilityService = jasmine.createSpyObj('WidgetVisibilityService', [
|
||||||
'updateVisibilityForForm', 'getTaskProcessVariableModelsForTask'
|
'refreshVisibility', 'getTaskProcessVariable'
|
||||||
]);
|
]);
|
||||||
window['componentHandler'] = componentHandler;
|
window['componentHandler'] = componentHandler;
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ describe('ActivitiForm', () => {
|
|||||||
formComponent.loadForm();
|
formComponent.loadForm();
|
||||||
|
|
||||||
expect(formComponent.getFormByTaskId).toHaveBeenCalledWith(taskId);
|
expect(formComponent.getFormByTaskId).toHaveBeenCalledWith(taskId);
|
||||||
expect(visibilityService.getTaskProcessVariableModelsForTask).toHaveBeenCalledWith(taskId);
|
expect(visibilityService.getTaskProcessVariable).toHaveBeenCalledWith(taskId);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should get form definition by form id on load', () => {
|
it('should get form definition by form id on load', () => {
|
||||||
@@ -623,15 +623,15 @@ describe('ActivitiForm', () => {
|
|||||||
it('should check visibility only if field with form provided', () => {
|
it('should check visibility only if field with form provided', () => {
|
||||||
|
|
||||||
formComponent.checkVisibility(null);
|
formComponent.checkVisibility(null);
|
||||||
expect(visibilityService.updateVisibilityForForm).not.toHaveBeenCalled();
|
expect(visibilityService.refreshVisibility).not.toHaveBeenCalled();
|
||||||
|
|
||||||
let field = new FormFieldModel(null);
|
let field = new FormFieldModel(null);
|
||||||
formComponent.checkVisibility(field);
|
formComponent.checkVisibility(field);
|
||||||
expect(visibilityService.updateVisibilityForForm).not.toHaveBeenCalled();
|
expect(visibilityService.refreshVisibility).not.toHaveBeenCalled();
|
||||||
|
|
||||||
field = new FormFieldModel(new FormModel());
|
field = new FormFieldModel(new FormModel());
|
||||||
formComponent.checkVisibility(field);
|
formComponent.checkVisibility(field);
|
||||||
expect(visibilityService.updateVisibilityForForm).toHaveBeenCalledWith(field.form);
|
expect(visibilityService.refreshVisibility).toHaveBeenCalledWith(field.form);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@@ -277,7 +277,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
|||||||
loadForm() {
|
loadForm() {
|
||||||
if (this.taskId) {
|
if (this.taskId) {
|
||||||
this.getFormByTaskId(this.taskId);
|
this.getFormByTaskId(this.taskId);
|
||||||
this.visibilityService.getTaskProcessVariableModelsForTask(this.taskId);
|
this.visibilityService.getTaskProcessVariable(this.taskId);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,7 +414,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
|||||||
|
|
||||||
checkVisibility(field: FormFieldModel) {
|
checkVisibility(field: FormFieldModel) {
|
||||||
if (field && field.form) {
|
if (field && field.form) {
|
||||||
this.visibilityService.updateVisibilityForForm(field.form);
|
this.visibilityService.refreshVisibility(field.form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -0,0 +1,97 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { FormModel, FormValues } from '../../components/widgets/core/index';
|
||||||
|
|
||||||
|
export var formTest = new FormModel({});
|
||||||
|
|
||||||
|
export var fakeTaskProcessVariableModels = [
|
||||||
|
{id: 'TEST_VAR_1', type: 'string', value: 'test_value_1'},
|
||||||
|
{id: 'TEST_VAR_2', type: 'string', value: 'test_value_2'},
|
||||||
|
{id: 'TEST_VAR_3', type: 'string', value: 'test_value_3'}
|
||||||
|
];
|
||||||
|
|
||||||
|
export var formValues: FormValues = {
|
||||||
|
'test_1': 'value_1',
|
||||||
|
'test_2': 'value_2',
|
||||||
|
'test_3': 'value_1',
|
||||||
|
'test_4': 'dropdown_id',
|
||||||
|
'test_5': 'dropdown_label',
|
||||||
|
'dropdown': {'id': 'dropdown_id', 'name': 'dropdown_label'}
|
||||||
|
};
|
||||||
|
|
||||||
|
export var fakeFormJson = {
|
||||||
|
id: '9999',
|
||||||
|
name: 'FORM_VISIBILITY',
|
||||||
|
processDefinitionId: 'PROCESS_TEST:9:9999',
|
||||||
|
processDefinitionName: 'PROCESS_TEST',
|
||||||
|
processDefinitionKey: 'PROCESS_TEST',
|
||||||
|
taskId: '999',
|
||||||
|
taskName: 'TEST',
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
fieldType: 'ContainerRepresentation',
|
||||||
|
id: '000000000000000000',
|
||||||
|
name: 'Label',
|
||||||
|
type: 'container',
|
||||||
|
value: null,
|
||||||
|
numberOfColumns: 2,
|
||||||
|
fields: {
|
||||||
|
1: [
|
||||||
|
{
|
||||||
|
fieldType: 'FormFieldRepresentation',
|
||||||
|
id: 'FIELD_TEST',
|
||||||
|
name: 'FIELD_TEST',
|
||||||
|
type: 'text',
|
||||||
|
value: 'RIGHT_FORM_FIELD_VALUE',
|
||||||
|
visibilityCondition: null,
|
||||||
|
isVisible: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldType: 'FormFieldRepresentation',
|
||||||
|
id: 'FIELD_WITH_CONDITION',
|
||||||
|
name: 'FIELD_WITH_CONDITION',
|
||||||
|
type: 'text',
|
||||||
|
value: 'field_with_condition_value',
|
||||||
|
visibilityCondition: null,
|
||||||
|
isVisible: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
fieldType: 'FormFieldRepresentation',
|
||||||
|
id: 'LEFT_FORM_FIELD_ID',
|
||||||
|
name: 'LEFT_FORM_FIELD_NAME',
|
||||||
|
type: 'text',
|
||||||
|
value: 'LEFT_FORM_FIELD_VALUE',
|
||||||
|
visibilityCondition: null,
|
||||||
|
isVisible: true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
2: [
|
||||||
|
{
|
||||||
|
fieldType: 'FormFieldRepresentation',
|
||||||
|
id: 'RIGHT_FORM_FIELD_ID',
|
||||||
|
name: 'RIGHT_FORM_FIELD_NAME',
|
||||||
|
type: 'text',
|
||||||
|
value: 'RIGHT_FORM_FIELD_VALUE',
|
||||||
|
visibilityCondition: null,
|
||||||
|
isVisible: true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
File diff suppressed because it is too large
Load Diff
@@ -18,7 +18,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { Response, Http, Headers, RequestOptions } from '@angular/http';
|
import { Response, Http, Headers, RequestOptions } from '@angular/http';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
|
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||||
import { FormModel, FormFieldModel, TabModel } from '../components/widgets/core/index';
|
import { FormModel, FormFieldModel, TabModel } from '../components/widgets/core/index';
|
||||||
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
||||||
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
||||||
@@ -29,59 +29,51 @@ export class WidgetVisibilityService {
|
|||||||
private processVarList: TaskProcessVariableModel[];
|
private processVarList: TaskProcessVariableModel[];
|
||||||
|
|
||||||
constructor(private http: Http,
|
constructor(private http: Http,
|
||||||
private alfrescoSettingsService: AlfrescoSettingsService) {
|
private alfrescoSettingsService: AlfrescoSettingsService,
|
||||||
|
private authService: AlfrescoAuthenticationService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateVisibilityForForm(form: FormModel) {
|
public refreshVisibility(form: FormModel) {
|
||||||
if (form && form.tabs && form.tabs.length > 0) {
|
if (form && form.tabs && form.tabs.length > 0) {
|
||||||
form.tabs.map( tabModel => this.refreshVisibilityForTab(tabModel) );
|
form.tabs.map(tabModel => this.refreshTabVisibility(tabModel));
|
||||||
}
|
}
|
||||||
if (form && form.fields.length > 0) {
|
if (form && form.fields.length > 0) {
|
||||||
form.fields
|
form.fields.map(contModel =>
|
||||||
.map(
|
contModel.columns.map(contColModel =>
|
||||||
contModel =>
|
contColModel.fields.map(field => this.refreshFieldVisibility(field))));
|
||||||
contModel.columns
|
|
||||||
.map(
|
|
||||||
contColModel =>
|
|
||||||
contColModel
|
|
||||||
.fields.map(
|
|
||||||
field =>
|
|
||||||
this.refreshVisibilityForField(field) )
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public refreshVisibilityForField(field: FormFieldModel) {
|
refreshFieldVisibility(field: FormFieldModel) {
|
||||||
if (field.visibilityCondition) {
|
if (field.visibilityCondition) {
|
||||||
field.isVisible = this.getVisiblityForField(field.form, field.visibilityCondition);
|
field.isVisible = this.evaluateVisibility(field.form, field.visibilityCondition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public refreshVisibilityForTab(tab: TabModel) {
|
refreshTabVisibility(tab: TabModel) {
|
||||||
if (tab.visibilityCondition) {
|
if (tab.visibilityCondition) {
|
||||||
tab.isVisible = this.getVisiblityForField(tab.form, tab.visibilityCondition);
|
tab.isVisible = this.evaluateVisibility(tab.form, tab.visibilityCondition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getVisiblityForField(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
evaluateVisibility(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
||||||
let isLeftFieldPresent = visibilityObj.leftFormFieldId || visibilityObj.leftRestResponseId;
|
let isLeftFieldPresent = visibilityObj.leftFormFieldId || visibilityObj.leftRestResponseId;
|
||||||
if (!isLeftFieldPresent || isLeftFieldPresent === 'null') {
|
if (!isLeftFieldPresent || isLeftFieldPresent === 'null') {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return this.evaluateVisibilityForField(form, visibilityObj);
|
return this.isFieldVisible(form, visibilityObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluateVisibilityForField(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
isFieldVisible(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
||||||
let leftValue = this.getLeftValue(form, visibilityObj);
|
let leftValue = this.getLeftValue(form, visibilityObj);
|
||||||
let rightValue = this.getRightValue(form, visibilityObj);
|
let rightValue = this.getRightValue(form, visibilityObj);
|
||||||
let actualResult = this.evaluateCondition(leftValue, rightValue, visibilityObj.operator);
|
let actualResult = this.evaluateCondition(leftValue, rightValue, visibilityObj.operator);
|
||||||
if (visibilityObj.nextCondition) {
|
if (visibilityObj.nextCondition) {
|
||||||
return this.evaluateLogicalOperation(visibilityObj.nextConditionOperator,
|
return this.evaluateLogicalOperation(
|
||||||
|
visibilityObj.nextConditionOperator,
|
||||||
actualResult,
|
actualResult,
|
||||||
this.evaluateVisibilityForField(
|
this.isFieldVisible(form, visibilityObj.nextCondition)
|
||||||
form, visibilityObj.nextCondition)
|
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return actualResult;
|
return actualResult;
|
||||||
@@ -90,63 +82,78 @@ export class WidgetVisibilityService {
|
|||||||
|
|
||||||
getLeftValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
getLeftValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
||||||
if (visibilityObj.leftRestResponseId) {
|
if (visibilityObj.leftRestResponseId) {
|
||||||
return this.getValueFromVariable(form, visibilityObj.leftRestResponseId, this.processVarList);
|
return this.getVariableValue(form, visibilityObj.leftRestResponseId, this.processVarList);
|
||||||
}
|
}
|
||||||
return this.getValueOField(form, visibilityObj.leftFormFieldId);
|
return this.getFormValue(form, visibilityObj.leftFormFieldId);
|
||||||
}
|
}
|
||||||
|
|
||||||
getRightValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
getRightValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
||||||
let valueFound = null;
|
let valueFound = null;
|
||||||
if (visibilityObj.rightRestResponseId) {
|
if (visibilityObj.rightRestResponseId) {
|
||||||
valueFound = this.getValueFromVariable(form, visibilityObj.rightRestResponseId, this.processVarList);
|
valueFound = this.getVariableValue(form, visibilityObj.rightRestResponseId, this.processVarList);
|
||||||
} else if (visibilityObj.rightFormFieldId) {
|
} else if (visibilityObj.rightFormFieldId) {
|
||||||
valueFound = this.getValueOField(form, visibilityObj.rightFormFieldId);
|
valueFound = this.getFormValue(form, visibilityObj.rightFormFieldId);
|
||||||
} else {
|
} else {
|
||||||
valueFound = visibilityObj.rightValue;
|
valueFound = visibilityObj.rightValue;
|
||||||
}
|
}
|
||||||
return valueFound;
|
return valueFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
getValueOField(form: FormModel, field: string) {
|
getFormValue(form: FormModel, field: string) {
|
||||||
let value = form.values[field] ?
|
let value = this.getValue(form.values, field);
|
||||||
form.values[field] :
|
value = value && value.id ? value.id : value;
|
||||||
this.getFormValueByName(form, field);
|
return value ? value : this.searchForm(form, field);
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormValueByName(form: FormModel, name: string) {
|
getValue(values: any, fieldName: string) {
|
||||||
for (let columns of form.json.fields) {
|
return this.getFieldValue(values, fieldName) ||
|
||||||
|
this.getDropDownName(values, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFieldValue(valueList: any, fieldName: string) {
|
||||||
|
return fieldName ? valueList[fieldName] : fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
getDropDownName(valueList: any, fieldName: string) {
|
||||||
|
let dropDownFilterByName;
|
||||||
|
if (fieldName && fieldName.indexOf('_LABEL') > 0) {
|
||||||
|
dropDownFilterByName = fieldName.substring(0, fieldName.length - 6);
|
||||||
|
}
|
||||||
|
return ( dropDownFilterByName && valueList[dropDownFilterByName] ) ?
|
||||||
|
valueList[dropDownFilterByName].name : dropDownFilterByName;
|
||||||
|
}
|
||||||
|
|
||||||
|
searchForm(form: FormModel, name: string) {
|
||||||
|
let res;
|
||||||
|
form.json.fields.forEach(columns => {
|
||||||
for (let i in columns.fields) {
|
for (let i in columns.fields) {
|
||||||
if (columns.fields.hasOwnProperty(i)) {
|
if (columns.fields.hasOwnProperty(i)) {
|
||||||
let res = columns.fields[i].find(field => field.id === name);
|
res = columns.fields[i].find(field => field.id === name);
|
||||||
if (res) {
|
if (res) {
|
||||||
return res.value;
|
return res.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
return res ? res.value : res;
|
||||||
}
|
}
|
||||||
|
|
||||||
getValueFromVariable( form: FormModel, name: string, processVarList: TaskProcessVariableModel[] ) {
|
getVariableValue(form: FormModel, name: string, processVarList: TaskProcessVariableModel[]) {
|
||||||
return this.getFormVariableValue(form, name) ||
|
return this.getFormVariableValue(form, name) ||
|
||||||
this.getProcessVariableValue(name, processVarList);
|
this.getProcessVariableValue(name, processVarList);
|
||||||
}
|
}
|
||||||
|
|
||||||
private getFormVariableValue(form: FormModel, name: string) {
|
private getFormVariableValue(form: FormModel, name: string) {
|
||||||
if (form.json.variables) {
|
if (form.json.variables) {
|
||||||
let variableFromForm = form.json.variables.find(formVar => formVar.name === name);
|
let formVariable = form.json.variables.find(formVar => formVar.name === name);
|
||||||
if ( variableFromForm ) {
|
return formVariable ? formVariable.value : formVariable;
|
||||||
return variableFromForm ? variableFromForm.value : variableFromForm;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getProcessVariableValue(name: string, processVarList: TaskProcessVariableModel[]) {
|
private getProcessVariableValue(name: string, processVarList: TaskProcessVariableModel[]) {
|
||||||
if (this.processVarList) {
|
if (this.processVarList) {
|
||||||
let variableFromProcess = this.processVarList.find(variable => variable.id === name);
|
let processVariable = this.processVarList.find(variable => variable.id === name);
|
||||||
if ( variableFromProcess ) {
|
return processVariable ? processVariable.value : processVariable;
|
||||||
return variableFromProcess ? variableFromProcess.value : variableFromProcess;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,11 +176,11 @@ export class WidgetVisibilityService {
|
|||||||
evaluateCondition(leftValue, rightValue, operator): boolean {
|
evaluateCondition(leftValue, rightValue, operator): boolean {
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case '==':
|
case '==':
|
||||||
return String(leftValue) === String(rightValue);
|
return leftValue + '' === rightValue + '';
|
||||||
case '<':
|
case '<':
|
||||||
return leftValue < rightValue;
|
return leftValue < rightValue;
|
||||||
case '!=':
|
case '!=':
|
||||||
return String(leftValue) !== String(rightValue);
|
return leftValue + '' !== rightValue + '';
|
||||||
case '>':
|
case '>':
|
||||||
return leftValue > rightValue;
|
return leftValue > rightValue;
|
||||||
case '>=':
|
case '>=':
|
||||||
@@ -191,7 +198,7 @@ export class WidgetVisibilityService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
getTaskProcessVariableModelsForTask(taskId: string): Observable<TaskProcessVariableModel[]> {
|
getTaskProcessVariable(taskId: string): Observable<TaskProcessVariableModel[]> {
|
||||||
let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/task-forms/${taskId}/variables`;
|
let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/task-forms/${taskId}/variables`;
|
||||||
let options = this.getRequestOptions();
|
let options = this.getRequestOptions();
|
||||||
return this.http
|
return this.http
|
||||||
@@ -200,17 +207,11 @@ export class WidgetVisibilityService {
|
|||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
getTaskProcessVariableModelForTaskByName(taskId: string, processVarName: string): Observable<TaskProcessVariableModel> {
|
|
||||||
return this.getTaskProcessVariableModelsForTask(taskId)
|
|
||||||
.map(
|
|
||||||
(variables: TaskProcessVariableModel[]) =>
|
|
||||||
variables.find(variable => variable.id === processVarName));
|
|
||||||
}
|
|
||||||
|
|
||||||
private getHeaders(): Headers {
|
private getHeaders(): Headers {
|
||||||
return new Headers({
|
return new Headers({
|
||||||
'Accept': 'application/json',
|
'Accept': 'application/json',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json',
|
||||||
|
'Authorization': this.authService.getTicketBpm()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user