mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2026-09-09 18:03:21 +00:00
[ADF-1671] visibility fix use id instead of name during comparison (#2441)
* visibility fix use id instead of name during comparison * fix tslint problems
This commit is contained in:
committed by
Denys Vuika
parent
3cd5eafdde
commit
48f0ccfc4f
@@ -353,14 +353,14 @@ describe('WidgetVisibilityService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to retrieve a field value searching in the form', () => {
|
it('should be able to retrieve a field value searching in the form', () => {
|
||||||
let formValue = service.searchForm(stubFormWithFields, 'FIELD_WITH_CONDITION');
|
let formValue = service.searchValueInForm(stubFormWithFields, 'FIELD_WITH_CONDITION');
|
||||||
|
|
||||||
expect(formValue).not.toBeNull();
|
expect(formValue).not.toBeNull();
|
||||||
expect(formValue).toBe('field_with_condition_value');
|
expect(formValue).toBe('field_with_condition_value');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return empty string if the field value is not in the form', () => {
|
it('should return empty string if the field value is not in the form', () => {
|
||||||
let formValue = service.searchForm(stubFormWithFields, 'FIELD_MYSTERY');
|
let formValue = service.searchValueInForm(stubFormWithFields, 'FIELD_MYSTERY');
|
||||||
|
|
||||||
expect(formValue).not.toBeUndefined();
|
expect(formValue).not.toBeUndefined();
|
||||||
expect(formValue).toBe('');
|
expect(formValue).toBe('');
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import { Injectable } from '@angular/core';
|
|||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import { AlfrescoApiService, LogService } from 'ng2-alfresco-core';
|
import { AlfrescoApiService, LogService } from 'ng2-alfresco-core';
|
||||||
import { Observable } from 'rxjs/Rx';
|
import { Observable } from 'rxjs/Rx';
|
||||||
import { ContainerColumnModel, ContainerModel, FormFieldModel, FormModel, TabModel } from '../components/widgets/core/index';
|
import { FormFieldModel, FormModel, TabModel } from '../components/widgets/core/index';
|
||||||
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
||||||
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
||||||
|
|
||||||
@@ -98,43 +98,46 @@ export class WidgetVisibilityService {
|
|||||||
return valueFound;
|
return valueFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFormValue(form: FormModel, field: string) {
|
getFormValue(form: FormModel, fieldId: string) {
|
||||||
let value = this.getFieldValue(form.values, field);
|
let value = this.getFieldValue(form.values, fieldId);
|
||||||
return value ? value : this.searchForm(form, field);
|
|
||||||
|
if (!value) {
|
||||||
|
value = this.searchValueInForm(form, fieldId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
getFieldValue(valueList: any, fieldName: string) {
|
getFieldValue(valueList: any, fieldId: string) {
|
||||||
let dropDownFilterByName, valueFound = '';
|
let dropDownFilterByName, valueFound;
|
||||||
if (fieldName && fieldName.indexOf('_LABEL') > 0) {
|
if (fieldId && fieldId.indexOf('_LABEL') > 0) {
|
||||||
dropDownFilterByName = fieldName.substring(0, fieldName.length - 6);
|
dropDownFilterByName = fieldId.substring(0, fieldId.length - 6);
|
||||||
if (valueList[dropDownFilterByName]) {
|
if (valueList[dropDownFilterByName]) {
|
||||||
valueFound = valueList[dropDownFilterByName].name;
|
valueFound = valueList[dropDownFilterByName].name;
|
||||||
}
|
}
|
||||||
} else if (valueList[fieldName] && valueList[fieldName].id) {
|
} else if (valueList[fieldId] && valueList[fieldId].id) {
|
||||||
valueFound = valueList[fieldName].id;
|
valueFound = valueList[fieldId].id;
|
||||||
} else {
|
} else {
|
||||||
valueFound = valueList[fieldName];
|
valueFound = valueList[fieldId];
|
||||||
}
|
}
|
||||||
return valueFound;
|
return valueFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
searchForm(form: FormModel, name: string) {
|
searchValueInForm(form: FormModel, fieldId: string) {
|
||||||
let fieldValue = '';
|
let fieldValue = '';
|
||||||
form.fields.forEach((containerModel: ContainerModel) => {
|
form.getFormFields().forEach((formField: FormFieldModel) => {
|
||||||
containerModel.field.columns.forEach((containerColumnModel: ContainerColumnModel) => {
|
if (this.isSearchedField(formField, fieldId)) {
|
||||||
let fieldFound = containerColumnModel.fields.find(field => this.isSearchedField(field, name));
|
fieldValue = this.getObjectValue(formField);
|
||||||
if (fieldFound) {
|
if (!fieldValue) {
|
||||||
fieldValue = this.getObjectValue(fieldFound);
|
if (formField.value && formField.value.id) {
|
||||||
if (!fieldValue) {
|
fieldValue = formField.value.id;
|
||||||
if (fieldFound.value && fieldFound.value.id) {
|
} else {
|
||||||
fieldValue = fieldFound.value.id;
|
fieldValue = formField.value;
|
||||||
} else {
|
|
||||||
fieldValue = fieldFound.value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return fieldValue;
|
return fieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,18 +150,19 @@ export class WidgetVisibilityService {
|
|||||||
if (option) {
|
if (option) {
|
||||||
value = option.name;
|
value = option.name;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
value = field.value;
|
value = field.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private isSearchedField(field: FormFieldModel, fieldToFind: string) {
|
private isSearchedField(field: FormFieldModel, fieldToFind: string): boolean {
|
||||||
let forrmattedFieldName = this.removeLabel(field, fieldToFind);
|
let formattedFieldName = this.removeLabel(field, fieldToFind);
|
||||||
return field.name ? field.name.toUpperCase() === forrmattedFieldName.toUpperCase() : false;
|
return field.id ? field.id.toUpperCase() === formattedFieldName.toUpperCase() : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private removeLabel(field: FormFieldModel, fieldToFind) {
|
private removeLabel(field: FormFieldModel, fieldToFind): string {
|
||||||
let formattedFieldName = fieldToFind || '';
|
let formattedFieldName = fieldToFind || '';
|
||||||
if (field.fieldType === 'RestFieldRepresentation' && fieldToFind.indexOf('_LABEL') > 0) {
|
if (field.fieldType === 'RestFieldRepresentation' && fieldToFind.indexOf('_LABEL') > 0) {
|
||||||
formattedFieldName = fieldToFind.substring(0, fieldToFind.length - 6);
|
formattedFieldName = fieldToFind.substring(0, fieldToFind.length - 6);
|
||||||
|
|||||||
Reference in New Issue
Block a user