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>
|
||||||
<div class="mdl-card__media">
|
<div class="mdl-card__media">
|
||||||
<div *ngIf="form.hasTabs()">
|
<div *ngIf="form.hasTabs()">
|
||||||
<tabs-widget [tabs]="form.tabs"></tabs-widget>
|
<tabs-widget [tabs]="form.tabs" (formTabChanged)="checkVisibility($event);"></tabs-widget>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div *ngIf="!form.hasTabs() && form.hasFields()">
|
<div *ngIf="!form.hasTabs() && form.hasFields()">
|
||||||
|
@ -31,6 +31,7 @@ describe('TabModel', () => {
|
|||||||
let model = new TabModel(null, json);
|
let model = new TabModel(null, json);
|
||||||
expect(model.id).toBe(json.id);
|
expect(model.id).toBe(json.id);
|
||||||
expect(model.title).toBe(json.title);
|
expect(model.title).toBe(json.title);
|
||||||
|
expect(model.isVisible).toBe(true);
|
||||||
expect(model.visibilityCondition).toBe(json.visibilityCondition);
|
expect(model.visibilityCondition).toBe(json.visibilityCondition);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -38,6 +39,8 @@ describe('TabModel', () => {
|
|||||||
let model = new TabModel(null, null);
|
let model = new TabModel(null, null);
|
||||||
expect(model.id).toBeUndefined();
|
expect(model.id).toBeUndefined();
|
||||||
expect(model.title).toBeUndefined();
|
expect(model.title).toBeUndefined();
|
||||||
|
expect(model.isVisible).toBeDefined();
|
||||||
|
expect(model.isVisible).toBe(true);
|
||||||
expect(model.visibilityCondition).toBeUndefined();
|
expect(model.visibilityCondition).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ export class TabModel extends FormWidgetModel {
|
|||||||
|
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
isVisible: boolean = true;
|
||||||
visibilityCondition: any;
|
visibilityCondition: any;
|
||||||
|
|
||||||
fields: ContainerModel[] = [];
|
fields: ContainerModel[] = [];
|
||||||
|
@ -13,8 +13,9 @@
|
|||||||
[attr.id]="tab.id">
|
[attr.id]="tab.id">
|
||||||
<container-widget
|
<container-widget
|
||||||
*ngFor="let field of tab.fields"
|
*ngFor="let field of tab.fields"
|
||||||
[content]="field">
|
[content]="field" (formValueChanged)="tabChanged($event);">
|
||||||
</container-widget>
|
</container-widget>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
-
|
||||||
|
@ -15,8 +15,8 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Input, AfterViewInit } from '@angular/core';
|
import { Component, Input, AfterViewInit, EventEmitter, Output } from '@angular/core';
|
||||||
import { TabModel } from './../core/index';
|
import { TabModel, FormFieldModel } from './../core/index';
|
||||||
|
|
||||||
declare let __moduleName: string;
|
declare let __moduleName: string;
|
||||||
declare var componentHandler;
|
declare var componentHandler;
|
||||||
@ -31,6 +31,9 @@ export class TabsWidget implements AfterViewInit {
|
|||||||
@Input()
|
@Input()
|
||||||
tabs: TabModel[] = [];
|
tabs: TabModel[] = [];
|
||||||
|
|
||||||
|
@Output()
|
||||||
|
formTabChanged: EventEmitter<FormFieldModel> = new EventEmitter<FormFieldModel>();
|
||||||
|
|
||||||
hasTabs() {
|
hasTabs() {
|
||||||
return this.tabs && this.tabs.length > 0;
|
return this.tabs && this.tabs.length > 0;
|
||||||
}
|
}
|
||||||
@ -47,4 +50,9 @@ export class TabsWidget implements AfterViewInit {
|
|||||||
}
|
}
|
||||||
return false;
|
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 { 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 } 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';
|
||||||
|
|
||||||
@ -33,6 +33,9 @@ export class WidgetVisibilityService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public updateVisibilityForForm(form: FormModel) {
|
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 ) {
|
if ( form && form.fields.length > 0 ) {
|
||||||
form.fields
|
form.fields
|
||||||
.map(
|
.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 {
|
public getVisiblityForField(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
||||||
let isLeftFieldPresent = visibilityObj.leftFormFieldId || visibilityObj.leftRestResponseId;
|
let isLeftFieldPresent = visibilityObj.leftFormFieldId || visibilityObj.leftRestResponseId;
|
||||||
if ( !isLeftFieldPresent ) {
|
if ( !isLeftFieldPresent || isLeftFieldPresent === 'null' ) {
|
||||||
return true;
|
return true;
|
||||||
}else {
|
}else {
|
||||||
return this.evaluateVisibilityForField(form, visibilityObj);
|
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 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);
|
||||||
@ -79,14 +88,14 @@ export class WidgetVisibilityService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
private 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);
|
||||||
@ -98,14 +107,14 @@ export class WidgetVisibilityService {
|
|||||||
return valueFound;
|
return valueFound;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getValueOField(form: FormModel, field: string) {
|
getValueOField(form: FormModel, field: string) {
|
||||||
let value = form.values[field] ?
|
let value = form.values[field] ?
|
||||||
form.values[field] :
|
form.values[field] :
|
||||||
this.getFormValueByName(form, field);
|
this.getFormValueByName(form, field);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private 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 ) ) {
|
||||||
@ -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) ||
|
return this.getFormVariableValue(form, name) ||
|
||||||
this.getProcessVariableValue(name, processVarList);
|
this.getProcessVariableValue(name, processVarList);
|
||||||
}
|
}
|
||||||
@ -141,30 +150,30 @@ export class WidgetVisibilityService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private 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' :
|
||||||
return previousValue || newValue;
|
return previousValue || newValue;
|
||||||
case 'and not':
|
case 'and-not':
|
||||||
return previousValue && !newValue;
|
return previousValue && !newValue;
|
||||||
case 'or not':
|
case 'or-not':
|
||||||
return previousValue || !newValue;
|
return previousValue || !newValue;
|
||||||
default:
|
default:
|
||||||
console.error( 'NO valid operation!' );
|
console.error( 'NO valid operation! wrong op request : ' + logicOp );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private evaluateCondition(leftValue, rightValue, operator): boolean {
|
evaluateCondition(leftValue, rightValue, operator): boolean {
|
||||||
switch ( operator ) {
|
switch ( operator ) {
|
||||||
case '==':
|
case '==':
|
||||||
return leftValue + '' === rightValue;
|
return String(leftValue) === String(rightValue);
|
||||||
case '<':
|
case '<':
|
||||||
return leftValue < rightValue;
|
return leftValue < rightValue;
|
||||||
case '!=':
|
case '!=':
|
||||||
return leftValue + '' !== rightValue;
|
return String(leftValue) !== String(rightValue);
|
||||||
case '>':
|
case '>':
|
||||||
return leftValue > rightValue;
|
return leftValue > rightValue;
|
||||||
case '>=':
|
case '>=':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user