mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
Added fix for visibility on dropdown
This commit is contained in:
parent
8b1b5e9926
commit
82632e5e89
File diff suppressed because it is too large
Load Diff
@ -15,13 +15,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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} 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';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class WidgetVisibilityService {
|
export class WidgetVisibilityService {
|
||||||
@ -30,66 +30,66 @@ export class WidgetVisibilityService {
|
|||||||
|
|
||||||
constructor(private http: Http,
|
constructor(private http: Http,
|
||||||
private alfrescoSettingsService: AlfrescoSettingsService) {
|
private alfrescoSettingsService: AlfrescoSettingsService) {
|
||||||
}
|
|
||||||
|
|
||||||
public updateVisibilityForForm(form: FormModel) {
|
|
||||||
if ( form && form.tabs && form.tabs.length > 0) {
|
|
||||||
form.tabs.map( tabModel => this.refreshVisibilityForTab(tabModel) );
|
|
||||||
}
|
|
||||||
if ( form && form.fields.length > 0 ) {
|
|
||||||
form.fields
|
|
||||||
.map(
|
|
||||||
contModel =>
|
|
||||||
contModel.columns
|
|
||||||
.map(
|
|
||||||
contColModel =>
|
|
||||||
contColModel
|
|
||||||
.fields.map(
|
|
||||||
field =>
|
|
||||||
this.refreshVisibilityForField(field) )
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public refreshVisibilityForField(field: FormFieldModel) {
|
public updateVisibilityForForm(form: FormModel) {
|
||||||
if ( field.visibilityCondition ) {
|
if (form && form.tabs && form.tabs.length > 0) {
|
||||||
|
form.tabs.map(tabModel => this.refreshVisibilityForTab(tabModel));
|
||||||
|
}
|
||||||
|
if (form && form.fields.length > 0) {
|
||||||
|
form.fields
|
||||||
|
.map(
|
||||||
|
contModel =>
|
||||||
|
contModel.columns
|
||||||
|
.map(
|
||||||
|
contColModel =>
|
||||||
|
contColModel
|
||||||
|
.fields.map(
|
||||||
|
field =>
|
||||||
|
this.refreshVisibilityForField(field))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
refreshVisibilityForField(field: FormFieldModel) {
|
||||||
|
if (field.visibilityCondition) {
|
||||||
field.isVisible = this.getVisiblityForField(field.form, field.visibilityCondition);
|
field.isVisible = this.getVisiblityForField(field.form, field.visibilityCondition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public refreshVisibilityForTab(tab: TabModel) {
|
refreshVisibilityForTab(tab: TabModel) {
|
||||||
if ( tab.visibilityCondition ) {
|
if (tab.visibilityCondition) {
|
||||||
tab.isVisible = this.getVisiblityForField(tab.form, tab.visibilityCondition);
|
tab.isVisible = this.getVisiblityForField(tab.form, tab.visibilityCondition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getVisiblityForField(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
getVisiblityForField(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.evaluateVisibilityForField(form, visibilityObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluateVisibilityForField(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
evaluateVisibilityForField(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.evaluateVisibilityForField(
|
||||||
form, visibilityObj.nextCondition)
|
form, visibilityObj.nextCondition)
|
||||||
);
|
);
|
||||||
}else {
|
} else {
|
||||||
return actualResult;
|
return actualResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.getValueFromVariable(form, visibilityObj.leftRestResponseId, this.processVarList);
|
||||||
}
|
}
|
||||||
return this.getValueOField(form, visibilityObj.leftFormFieldId);
|
return this.getValueOField(form, visibilityObj.leftFormFieldId);
|
||||||
@ -97,61 +97,78 @@ export class WidgetVisibilityService {
|
|||||||
|
|
||||||
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.getValueFromVariable(form, visibilityObj.rightRestResponseId, this.processVarList);
|
||||||
}else if ( visibilityObj.rightFormFieldId ) {
|
} else if (visibilityObj.rightFormFieldId) {
|
||||||
valueFound = this.getValueOField(form, visibilityObj.rightFormFieldId);
|
valueFound = this.getValueOField(form, visibilityObj.rightFormFieldId);
|
||||||
}else {
|
} else {
|
||||||
valueFound = visibilityObj.rightValue;
|
valueFound = visibilityObj.rightValue;
|
||||||
}
|
}
|
||||||
return valueFound;
|
return valueFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
getValueOField(form: FormModel, field: string) {
|
getValueOField(form: FormModel, field: string) {
|
||||||
let value = form.values[field] ?
|
let value = this.getValueFromFormValues(form.values, field);
|
||||||
form.values[field] :
|
value = value && value.id ? value.id : value;
|
||||||
this.getFormValueByName(form, field);
|
return value ? value : this.getFormValueByName(form, field);
|
||||||
return value;
|
}
|
||||||
|
|
||||||
|
getValueFromFormValues(values: any, fieldName: string) {
|
||||||
|
return this.getFieldValue(values, fieldName) ||
|
||||||
|
this.getDropDownValueForLabel(values, fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
|
getFieldValue(valueList: any, fieldName: string) {
|
||||||
|
return fieldName ? valueList[fieldName] : fieldName;
|
||||||
|
}
|
||||||
|
|
||||||
|
getDropDownValueForLabel(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;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormValueByName(form: FormModel, name: string) {
|
getFormValueByName(form: FormModel, name: string) {
|
||||||
for (let columns of form.json.fields) {
|
for (let columns of form.json.fields) {
|
||||||
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);
|
let res = columns.fields[i].find(field => field.id === name);
|
||||||
if ( res ) {
|
if (res) {
|
||||||
return res.value;
|
return res.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getValueFromVariable( form: FormModel, name: string, processVarList: TaskProcessVariableModel[] ) {
|
getValueFromVariable(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 variableFromForm = form.json.variables.find(formVar => formVar.name === name);
|
||||||
if ( variableFromForm ) {
|
if (variableFromForm) {
|
||||||
return variableFromForm ? variableFromForm.value : variableFromForm;
|
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 variableFromProcess = this.processVarList.find(variable => variable.id === name);
|
||||||
if ( variableFromProcess ) {
|
if (variableFromProcess) {
|
||||||
return variableFromProcess ? variableFromProcess.value : variableFromProcess;
|
return variableFromProcess ? variableFromProcess.value : variableFromProcess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluateLogicalOperation(logicOp, previousValue, newValue): boolean {
|
evaluateLogicalOperation(logicOp, previousValue, newValue): boolean {
|
||||||
switch ( logicOp ) {
|
switch (logicOp) {
|
||||||
case 'and':
|
case 'and':
|
||||||
return previousValue && newValue;
|
return previousValue && newValue;
|
||||||
case 'or' :
|
case 'or' :
|
||||||
@ -161,13 +178,13 @@ export class WidgetVisibilityService {
|
|||||||
case 'or-not':
|
case 'or-not':
|
||||||
return previousValue || !newValue;
|
return previousValue || !newValue;
|
||||||
default:
|
default:
|
||||||
console.error( 'NO valid operation! wrong op request : ' + logicOp );
|
console.error('NO valid operation! wrong op request : ' + logicOp);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluateCondition(leftValue, rightValue, operator): boolean {
|
evaluateCondition(leftValue, rightValue, operator): boolean {
|
||||||
switch ( operator ) {
|
switch (operator) {
|
||||||
case '==':
|
case '==':
|
||||||
return String(leftValue) === String(rightValue);
|
return String(leftValue) === String(rightValue);
|
||||||
case '<':
|
case '<':
|
||||||
@ -185,7 +202,7 @@ export class WidgetVisibilityService {
|
|||||||
case '!empty':
|
case '!empty':
|
||||||
return leftValue ? leftValue !== '' : false;
|
return leftValue ? leftValue !== '' : false;
|
||||||
default:
|
default:
|
||||||
console.error( 'NO valid operation!' );
|
console.error('NO valid operation!');
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
@ -196,17 +213,10 @@ export class WidgetVisibilityService {
|
|||||||
let options = this.getRequestOptions();
|
let options = this.getRequestOptions();
|
||||||
return this.http
|
return this.http
|
||||||
.get(url, options)
|
.get(url, options)
|
||||||
.map( (response: Response) => this.processVarList = <TaskProcessVariableModel[]> response.json())
|
.map((response: Response) => this.processVarList = <TaskProcessVariableModel[]> response.json())
|
||||||
.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',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user