mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
Merge pull request #855 from Alfresco/dev-valbano-545
Add fix for tests and visibility
This commit is contained in:
commit
d20a750816
@ -10,7 +10,7 @@
|
||||
</div>
|
||||
<div class="mdl-card__media">
|
||||
<div *ngIf="form.hasTabs()">
|
||||
<tabs-widget [tabs]="form.tabs"></tabs-widget>
|
||||
<tabs-widget [tabs]="form.tabs" (formTabChanged)="checkVisibility($event);"></tabs-widget>
|
||||
</div>
|
||||
|
||||
<div *ngIf="!form.hasTabs() && form.hasFields()">
|
||||
|
@ -31,6 +31,7 @@ describe('TabModel', () => {
|
||||
let model = new TabModel(null, json);
|
||||
expect(model.id).toBe(json.id);
|
||||
expect(model.title).toBe(json.title);
|
||||
expect(model.isVisible).toBe(true);
|
||||
expect(model.visibilityCondition).toBe(json.visibilityCondition);
|
||||
});
|
||||
|
||||
@ -38,6 +39,8 @@ describe('TabModel', () => {
|
||||
let model = new TabModel(null, null);
|
||||
expect(model.id).toBeUndefined();
|
||||
expect(model.title).toBeUndefined();
|
||||
expect(model.isVisible).toBeDefined();
|
||||
expect(model.isVisible).toBe(true);
|
||||
expect(model.visibilityCondition).toBeUndefined();
|
||||
});
|
||||
|
||||
|
@ -23,6 +23,7 @@ export class TabModel extends FormWidgetModel {
|
||||
|
||||
id: string;
|
||||
title: string;
|
||||
isVisible: boolean = true;
|
||||
visibilityCondition: any;
|
||||
|
||||
fields: ContainerModel[] = [];
|
||||
|
@ -13,8 +13,9 @@
|
||||
[attr.id]="tab.id">
|
||||
<container-widget
|
||||
*ngFor="let field of tab.fields"
|
||||
[content]="field">
|
||||
[content]="field" (formValueChanged)="tabChanged($event);">
|
||||
</container-widget>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
-
|
||||
|
@ -15,8 +15,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, Input, AfterViewInit } from '@angular/core';
|
||||
import { TabModel } from './../core/index';
|
||||
import { Component, Input, AfterViewInit, EventEmitter, Output } from '@angular/core';
|
||||
import { TabModel, FormFieldModel } from './../core/index';
|
||||
|
||||
declare let __moduleName: string;
|
||||
declare var componentHandler;
|
||||
@ -31,6 +31,9 @@ export class TabsWidget implements AfterViewInit {
|
||||
@Input()
|
||||
tabs: TabModel[] = [];
|
||||
|
||||
@Output()
|
||||
formTabChanged: EventEmitter<FormFieldModel> = new EventEmitter<FormFieldModel>();
|
||||
|
||||
hasTabs() {
|
||||
return this.tabs && this.tabs.length > 0;
|
||||
}
|
||||
@ -47,4 +50,9 @@ export class TabsWidget implements AfterViewInit {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
tabChanged( field: FormFieldModel ) {
|
||||
this.formTabChanged.emit(field);
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,7 +19,7 @@ import { Injectable } from '@angular/core';
|
||||
import { Response, Http, Headers, RequestOptions } from '@angular/http';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||
import { FormModel, FormFieldModel } from '../components/widgets/core/index';
|
||||
import { FormModel, FormFieldModel, TabModel } from '../components/widgets/core/index';
|
||||
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
||||
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
||||
|
||||
@ -33,6 +33,9 @@ export class WidgetVisibilityService {
|
||||
}
|
||||
|
||||
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(
|
||||
@ -55,16 +58,22 @@ export class WidgetVisibilityService {
|
||||
}
|
||||
}
|
||||
|
||||
public refreshVisibilityForTab(tab: TabModel) {
|
||||
if ( tab.visibilityCondition ) {
|
||||
tab.isVisible = this.getVisiblityForField(tab.form, tab.visibilityCondition);
|
||||
}
|
||||
}
|
||||
|
||||
public getVisiblityForField(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
||||
let isLeftFieldPresent = visibilityObj.leftFormFieldId || visibilityObj.leftRestResponseId;
|
||||
if ( !isLeftFieldPresent ) {
|
||||
if ( !isLeftFieldPresent || isLeftFieldPresent === 'null' ) {
|
||||
return true;
|
||||
}else {
|
||||
return this.evaluateVisibilityForField(form, visibilityObj);
|
||||
}
|
||||
}
|
||||
|
||||
private evaluateVisibilityForField(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
||||
evaluateVisibilityForField(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
||||
let leftValue = this.getLeftValue(form, visibilityObj);
|
||||
let rightValue = this.getRightValue(form, visibilityObj);
|
||||
let actualResult = this.evaluateCondition(leftValue, rightValue, visibilityObj.operator);
|
||||
@ -79,14 +88,14 @@ export class WidgetVisibilityService {
|
||||
}
|
||||
}
|
||||
|
||||
private getLeftValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
||||
getLeftValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
||||
if ( visibilityObj.leftRestResponseId ) {
|
||||
return this.getValueFromVariable(form, visibilityObj.leftRestResponseId, this.processVarList);
|
||||
}
|
||||
return this.getValueOField(form, visibilityObj.leftFormFieldId);
|
||||
}
|
||||
|
||||
private getRightValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
||||
getRightValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
||||
let valueFound = null;
|
||||
if ( visibilityObj.rightRestResponseId ) {
|
||||
valueFound = this.getValueFromVariable(form, visibilityObj.rightRestResponseId, this.processVarList);
|
||||
@ -98,14 +107,14 @@ export class WidgetVisibilityService {
|
||||
return valueFound;
|
||||
}
|
||||
|
||||
private getValueOField(form: FormModel, field: string) {
|
||||
getValueOField(form: FormModel, field: string) {
|
||||
let value = form.values[field] ?
|
||||
form.values[field] :
|
||||
this.getFormValueByName(form, field);
|
||||
return value;
|
||||
}
|
||||
|
||||
private getFormValueByName(form: FormModel, name: string) {
|
||||
getFormValueByName(form: FormModel, name: string) {
|
||||
for (let columns of form.json.fields) {
|
||||
for ( let i in columns.fields ) {
|
||||
if ( columns.fields.hasOwnProperty( i ) ) {
|
||||
@ -118,7 +127,7 @@ export class WidgetVisibilityService {
|
||||
}
|
||||
}
|
||||
|
||||
private getValueFromVariable( form: FormModel, name: string, processVarList: TaskProcessVariableModel[] ) {
|
||||
getValueFromVariable( form: FormModel, name: string, processVarList: TaskProcessVariableModel[] ) {
|
||||
return this.getFormVariableValue(form, name) ||
|
||||
this.getProcessVariableValue(name, processVarList);
|
||||
}
|
||||
@ -141,30 +150,30 @@ export class WidgetVisibilityService {
|
||||
}
|
||||
}
|
||||
|
||||
private evaluateLogicalOperation(logicOp, previousValue, newValue): boolean {
|
||||
evaluateLogicalOperation(logicOp, previousValue, newValue): boolean {
|
||||
switch ( logicOp ) {
|
||||
case 'and':
|
||||
return previousValue && newValue;
|
||||
case 'or' :
|
||||
return previousValue || newValue;
|
||||
case 'and not':
|
||||
case 'and-not':
|
||||
return previousValue && !newValue;
|
||||
case 'or not':
|
||||
case 'or-not':
|
||||
return previousValue || !newValue;
|
||||
default:
|
||||
console.error( 'NO valid operation!' );
|
||||
console.error( 'NO valid operation! wrong op request : ' + logicOp );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private evaluateCondition(leftValue, rightValue, operator): boolean {
|
||||
evaluateCondition(leftValue, rightValue, operator): boolean {
|
||||
switch ( operator ) {
|
||||
case '==':
|
||||
return leftValue + '' === rightValue;
|
||||
return String(leftValue) === String(rightValue);
|
||||
case '<':
|
||||
return leftValue < rightValue;
|
||||
case '!=':
|
||||
return leftValue + '' !== rightValue;
|
||||
return String(leftValue) !== String(rightValue);
|
||||
case '>':
|
||||
return leftValue > rightValue;
|
||||
case '>=':
|
||||
|
Loading…
x
Reference in New Issue
Block a user