mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
Re Added visibility feature
This commit is contained in:
parent
c4f6276b69
commit
de62e8181e
@ -4,7 +4,7 @@ module.exports = function (config) {
|
||||
var configuration = {
|
||||
basePath: '.',
|
||||
|
||||
frameworks: [/*'jasmine-ajax',*/ 'jasmine'],
|
||||
frameworks: ['jasmine-ajax', 'jasmine'],
|
||||
|
||||
files: [
|
||||
// paths loaded by Karma
|
||||
@ -63,7 +63,7 @@ module.exports = function (config) {
|
||||
plugins: [
|
||||
'karma-jasmine',
|
||||
'karma-coverage',
|
||||
//'karma-jasmine-ajax',
|
||||
'karma-jasmine-ajax',
|
||||
'karma-chrome-launcher',
|
||||
'karma-mocha-reporter',
|
||||
'karma-jasmine-html-reporter'
|
||||
|
@ -81,6 +81,7 @@
|
||||
"karma-coveralls": "1.1.2",
|
||||
"karma-jasmine": "1.0.2",
|
||||
"karma-jasmine-html-reporter": "0.2.0",
|
||||
"karma-jasmine-ajax": "0.1.13",
|
||||
"karma-mocha-reporter": "2.0.3",
|
||||
"license-check": "1.1.5",
|
||||
"remap-istanbul": "0.6.3",
|
||||
|
@ -13,7 +13,7 @@
|
||||
</div>
|
||||
|
||||
<div *ngIf="!form.hasTabs() && form.hasFields()">
|
||||
<container-widget *ngFor="let field of form.fields" [content]="field"></container-widget>
|
||||
<container-widget *ngFor="let field of form.fields" [content]="field" (formValueChanged)="checkVisibility($event);"></container-widget>
|
||||
</div>
|
||||
</div>
|
||||
<div *ngIf="form.hasOutcomes()" class="mdl-card__actions mdl-card--border">
|
||||
|
@ -35,7 +35,7 @@ describe('ActivitiForm', () => {
|
||||
window['componentHandler'] = componentHandler;
|
||||
|
||||
formService = new FormService(null, null, null);
|
||||
formComponent = new ActivitiForm(formService);
|
||||
formComponent = new ActivitiForm(formService, null);
|
||||
});
|
||||
|
||||
it('should upgrade MDL content on view checked', () => {
|
||||
|
@ -26,7 +26,7 @@ import {
|
||||
import { MATERIAL_DESIGN_DIRECTIVES } from 'ng2-alfresco-core';
|
||||
|
||||
import { FormService } from './../services/form.service';
|
||||
import { FormModel, FormOutcomeModel, FormValues } from './widgets/core/index';
|
||||
import { FormModel, FormOutcomeModel, FormValues, FormFieldModel } from './widgets/core/index';
|
||||
|
||||
import { TabsWidget } from './widgets/tabs/tabs.widget';
|
||||
import { ContainerWidget } from './widgets/container/container.widget';
|
||||
@ -34,6 +34,8 @@ import { ContainerWidget } from './widgets/container/container.widget';
|
||||
declare let __moduleName: string;
|
||||
declare var componentHandler;
|
||||
|
||||
import { WidgetVisibilityService } from './../services/widget-visibility.service';
|
||||
|
||||
/**
|
||||
* @Input
|
||||
* ActivitiForm can show 3 forms searching by 3 type of params:
|
||||
@ -70,7 +72,7 @@ declare var componentHandler;
|
||||
templateUrl: './activiti-form.component.html',
|
||||
styleUrls: ['./activiti-form.component.css'],
|
||||
directives: [MATERIAL_DESIGN_DIRECTIVES, ContainerWidget, TabsWidget],
|
||||
providers: [FormService]
|
||||
providers: [FormService, WidgetVisibilityService]
|
||||
})
|
||||
export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
|
||||
@ -118,7 +120,8 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
|
||||
debugMode: boolean = false;
|
||||
|
||||
constructor(private formService: FormService) {
|
||||
constructor(private formService: FormService,
|
||||
private visibilityService: WidgetVisibilityService) {
|
||||
}
|
||||
|
||||
hasForm(): boolean {
|
||||
@ -220,6 +223,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
loadForm() {
|
||||
if (this.taskId) {
|
||||
this.getFormByTaskId(this.taskId);
|
||||
this.visibilityService.getTaskProcessVariableModelsForTask(this.taskId);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -334,4 +338,8 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
|
||||
new FormOutcomeModel(form, { id: '$custom', name: FormOutcomeModel.SAVE_ACTION, isSystem: true })
|
||||
];
|
||||
}
|
||||
|
||||
checkVisibility(field: FormFieldModel) {
|
||||
this.visibilityService.updateVisibilityForForm(field.form);
|
||||
}
|
||||
}
|
||||
|
1
ng2-components/ng2-activiti-form/src/components/widgets/.gitignore
vendored
Normal file
1
ng2-components/ng2-activiti-form/src/components/widgets/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/widget.model.ts
|
@ -3,6 +3,7 @@
|
||||
[attr.id]="field.id"
|
||||
class="mdl-checkbox__input"
|
||||
[(ngModel)]="field.value"
|
||||
(ngModelChange)="checkVisibility(field)"
|
||||
[disabled]="field.readOnly">
|
||||
<span class="mdl-checkbox__label">{{field.name}}</span>
|
||||
</label>
|
||||
|
@ -15,33 +15,33 @@
|
||||
<div *ngFor="let col of content.columns" class="mdl-cell mdl-cell--{{col.size}}-col">
|
||||
<div class="mdl-grid" *ngIf="col.hasFields()">
|
||||
<div *ngFor="let field of col.fields" class="mdl-cell mdl-cell--12-col">
|
||||
<div [ngSwitch]="field.type">
|
||||
<div [ngSwitch]="field.type" [hidden]="!field.isVisible">
|
||||
<div *ngSwitchCase="'integer'">
|
||||
<number-widget [field]="field"></number-widget>
|
||||
<number-widget [field]="field" (fieldChanged)="fieldChanged($event);"></number-widget>
|
||||
</div>
|
||||
<div *ngSwitchCase="'text'">
|
||||
<text-widget [field]="field"></text-widget>
|
||||
<text-widget [field]="field" (fieldChanged)="fieldChanged($event);"></text-widget>
|
||||
</div>
|
||||
<div *ngSwitchCase="'multi-line-text'">
|
||||
<multiline-text-widget [field]="field"></multiline-text-widget>
|
||||
<multiline-text-widget [field]="field" (fieldChanged)="fieldChanged($event);"></multiline-text-widget>
|
||||
</div>
|
||||
<div *ngSwitchCase="'boolean'">
|
||||
<checkbox-widget [field]="field"></checkbox-widget>
|
||||
<checkbox-widget [field]="field" (fieldChanged)="fieldChanged($event);"></checkbox-widget>
|
||||
</div>
|
||||
<div *ngSwitchCase="'dropdown'">
|
||||
<dropdown-widget [field]="field"></dropdown-widget>
|
||||
<dropdown-widget [field]="field" (fieldChanged)="fieldChanged($event);"></dropdown-widget>
|
||||
</div>
|
||||
<div *ngSwitchCase="'hyperlink'">
|
||||
<hyperlink-widget [field]="field"></hyperlink-widget>
|
||||
<hyperlink-widget [field]="field" (fieldChanged)="fieldChanged($event);"></hyperlink-widget>
|
||||
</div>
|
||||
<div *ngSwitchCase="'radio-buttons'">
|
||||
<radio-buttons-widget [field]="field"></radio-buttons-widget>
|
||||
<radio-buttons-widget [field]="field" (fieldChanged)="fieldChanged($event);"></radio-buttons-widget>
|
||||
</div>
|
||||
<div *ngSwitchCase="'readonly'">
|
||||
<display-value-widget [field]="field"></display-value-widget>
|
||||
<display-value-widget [field]="field" (fieldChanged)="fieldChanged($event);"></display-value-widget>
|
||||
</div>
|
||||
<div *ngSwitchCase="'readonly-text'">
|
||||
<display-text-widget [field]="field"></display-text-widget>
|
||||
<display-text-widget [field]="field" (fieldChanged)="fieldChanged($event);"></display-text-widget>
|
||||
</div>
|
||||
<div *ngSwitchDefault>
|
||||
<span>UNKNOWN WIDGET TYPE: {{field.type}}</span>
|
||||
|
@ -15,11 +15,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Component, Input, AfterViewInit } from '@angular/core';
|
||||
import { Component, Input, AfterViewInit, Output, EventEmitter } from '@angular/core';
|
||||
import { ContainerModel } from './../core/index';
|
||||
|
||||
import { MATERIAL_DESIGN_DIRECTIVES } from 'ng2-alfresco-core';
|
||||
import { PRIMITIVE_WIDGET_DIRECTIVES } from './../index';
|
||||
import { FormFieldModel } from '../core/index';
|
||||
|
||||
declare let __moduleName: string;
|
||||
declare var componentHandler;
|
||||
@ -39,6 +40,9 @@ export class ContainerWidget implements AfterViewInit {
|
||||
@Input()
|
||||
content: ContainerModel;
|
||||
|
||||
@Output()
|
||||
formValueChanged: EventEmitter<FormFieldModel> = new EventEmitter<FormFieldModel>();
|
||||
|
||||
onExpanderClicked() {
|
||||
if (this.content && this.content.isCollapsible()) {
|
||||
this.content.isExpanded = !this.content.isExpanded;
|
||||
@ -58,4 +62,8 @@ export class ContainerWidget implements AfterViewInit {
|
||||
return false;
|
||||
}
|
||||
|
||||
fieldChanged(field: FormFieldModel) {
|
||||
this.formValueChanged.emit(field);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import { FormFieldOption } from './form-field-option';
|
||||
import { FormFieldTypes } from './form-field-types';
|
||||
import { FormFieldMetadata } from './form-field-metadata';
|
||||
import { FormModel } from './form.model';
|
||||
import { WidgetVisibilityModel } from '../../../models/widget-visibility.model';
|
||||
|
||||
export class FormFieldModel extends FormWidgetModel {
|
||||
|
||||
@ -45,6 +46,8 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
params: FormFieldMetadata = {};
|
||||
hyperlinkUrl: string;
|
||||
displayText: string;
|
||||
isVisible: boolean = true;
|
||||
visibilityCondition: WidgetVisibilityModel = null;
|
||||
|
||||
get value(): any {
|
||||
return this._value;
|
||||
@ -86,6 +89,7 @@ export class FormFieldModel extends FormWidgetModel {
|
||||
this.params = <FormFieldMetadata> json.params || {};
|
||||
this.hyperlinkUrl = json.hyperlinkUrl;
|
||||
this.displayText = json.displayText;
|
||||
this.visibilityCondition = <WidgetVisibilityModel> json.visibilityCondition;
|
||||
|
||||
this._value = this.parseValue(json);
|
||||
this.updateForm();
|
||||
|
@ -3,6 +3,7 @@
|
||||
type="text"
|
||||
[attr.id]="field.id"
|
||||
[(ngModel)]="field.value"
|
||||
(ngModelChange)="checkVisibility(field)"
|
||||
disabled>
|
||||
<label class="mdl-textfield__label" [attr.for]="field.id">{{field.name}}</label>
|
||||
</div>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<div class="dropdown-widget">
|
||||
<select [(ngModel)]="field.value">
|
||||
<select [(ngModel)]="field.value" (ngModelChange)="checkVisibility(field)">
|
||||
<option *ngFor="let opt of field.options" [value]="opt.id">{{opt.name}}</option>
|
||||
</select>
|
||||
</div>
|
||||
|
@ -4,6 +4,7 @@
|
||||
rows= "3"
|
||||
[attr.id]="field.id"
|
||||
[(ngModel)]="field.value"
|
||||
(ngModelChange)="checkVisibility(field)"
|
||||
[disabled]="field.readOnly">
|
||||
</textarea>
|
||||
<label class="mdl-textfield__label" [attr.for]="field.id">{{field.name}}</label>
|
||||
|
@ -4,6 +4,7 @@
|
||||
pattern="-?[0-9]*(\.[0-9]+)?"
|
||||
[attr.id]="field.id"
|
||||
[(ngModel)]="field.value"
|
||||
(ngModelChange)="checkVisibility(field)"
|
||||
[disabled]="field.readOnly">
|
||||
<label class="mdl-textfield__label" [attr.for]="field.id">{{field.name}}</label>
|
||||
<span class="mdl-textfield__error">Input is not a number!</span>
|
||||
|
@ -3,6 +3,7 @@
|
||||
type="text"
|
||||
[attr.id]="field.id"
|
||||
[(ngModel)]="field.value"
|
||||
(ngModelChange)="checkVisibility(field)"
|
||||
[disabled]="field.readOnly">
|
||||
<label class="mdl-textfield__label" [attr.for]="field.id">{{field.name}}</label>
|
||||
</div>
|
||||
|
@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Input, AfterViewInit } from '@angular/core';
|
||||
import { Input, AfterViewInit, Output, EventEmitter } from '@angular/core';
|
||||
import { FormFieldModel } from './core/index';
|
||||
|
||||
declare let __moduleName: string;
|
||||
@ -29,6 +29,9 @@ export class WidgetComponent implements AfterViewInit {
|
||||
@Input()
|
||||
field: FormFieldModel;
|
||||
|
||||
@Output()
|
||||
fieldChanged: EventEmitter<FormFieldModel> = new EventEmitter<FormFieldModel>();
|
||||
|
||||
hasField() {
|
||||
return this.field ? true : false;
|
||||
}
|
||||
@ -46,4 +49,8 @@ export class WidgetComponent implements AfterViewInit {
|
||||
return false;
|
||||
}
|
||||
|
||||
checkVisibility(field: FormFieldModel) {
|
||||
this.fieldChanged.emit(field);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,22 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export class TaskProcessVariableModel {
|
||||
id: string;
|
||||
type: string;
|
||||
value: string;
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*!
|
||||
* @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.
|
||||
*/
|
||||
|
||||
export class WidgetVisibilityModel {
|
||||
leftFormFieldId: string;
|
||||
leftRestResponseId: string;
|
||||
nextCondition: WidgetVisibilityModel;
|
||||
nextConditionOperator: string;
|
||||
operator: string;
|
||||
rightFormFieldId: string;
|
||||
rightRestResponseId: string;
|
||||
rightType: string;
|
||||
rightValue: string;
|
||||
}
|
@ -19,8 +19,9 @@ import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/
|
||||
import { WidgetVisibilityService } from './widget-visibility.service';
|
||||
import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
||||
import { HTTP_PROVIDERS } from '@angular/http';
|
||||
import { VisibilityFormWidget, IProcessVariable } from '../components/widgets/widget-visibility.model';
|
||||
import { FormModel, FormValues, FormFieldModel } from './../components/widgets/widget.model';
|
||||
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
||||
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
||||
import { FormModel, FormFieldModel, FormValues } from '../components/widgets/core/index';
|
||||
|
||||
declare let AlfrescoApi: any;
|
||||
declare let jasmine: any;
|
||||
@ -28,7 +29,7 @@ declare let jasmine: any;
|
||||
describe('WidgetVisibilityService', () => {
|
||||
let service;
|
||||
|
||||
let fakeProcessVariables = [
|
||||
let 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'}
|
||||
@ -122,7 +123,7 @@ describe('WidgetVisibilityService', () => {
|
||||
|
||||
let formValues: FormValues = { 'test_1': 'value_1', 'test_2': 'value_2', 'test_3': 'value_1' };
|
||||
|
||||
let visibilityObjTest: VisibilityFormWidget = {
|
||||
let visibilityObjTest: WidgetVisibilityModel = {
|
||||
leftFormFieldId : '',
|
||||
leftRestResponseId : '',
|
||||
nextCondition : null,
|
||||
@ -134,7 +135,7 @@ describe('WidgetVisibilityService', () => {
|
||||
rightValue : null
|
||||
};
|
||||
|
||||
let chainedVisibilityObj: VisibilityFormWidget = {
|
||||
let chainedVisibilityObj: WidgetVisibilityModel = {
|
||||
leftFormFieldId : '',
|
||||
leftRestResponseId : '',
|
||||
nextCondition : null,
|
||||
@ -167,8 +168,8 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('should return the process variables for task', (done) => {
|
||||
service.getProcessVariablesForTask(9999).subscribe(
|
||||
(res: IProcessVariable[]) => {
|
||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||
(res: TaskProcessVariableModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(3);
|
||||
expect(res[0].id).toEqual('TEST_VAR_1');
|
||||
@ -181,7 +182,7 @@ describe('WidgetVisibilityService', () => {
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeProcessVariables)
|
||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||
});
|
||||
});
|
||||
|
||||
@ -266,15 +267,15 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('should be able to retrieve the value of a process variable', (done) => {
|
||||
service.getProcessVariablesForTask(9999).subscribe(
|
||||
(res: IProcessVariable[]) => {
|
||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||
(res: TaskProcessVariableModel[]) => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeProcessVariables)
|
||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||
});
|
||||
let formTest = new FormModel(fakeFormJson);
|
||||
|
||||
@ -285,15 +286,15 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('should be able to retrieve the value of a form variable', (done) => {
|
||||
service.getProcessVariablesForTask(9999).subscribe(
|
||||
(res: IProcessVariable[]) => {
|
||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||
(res: TaskProcessVariableModel[]) => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeProcessVariables)
|
||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||
});
|
||||
let formTest = new FormModel(fakeFormJson);
|
||||
|
||||
@ -304,15 +305,15 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('should return null if the variable does not exist', (done) => {
|
||||
service.getProcessVariablesForTask(9999).subscribe(
|
||||
(res: IProcessVariable[]) => {
|
||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||
(res: TaskProcessVariableModel[]) => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeProcessVariables)
|
||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||
});
|
||||
let formTest = new FormModel(fakeFormJson);
|
||||
|
||||
@ -385,15 +386,15 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('should retrieve the value for the right field when it is a process variable', (done) => {
|
||||
service.getProcessVariablesForTask(9999).subscribe(
|
||||
(res: IProcessVariable[]) => {
|
||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||
(res: TaskProcessVariableModel[]) => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeProcessVariables)
|
||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||
});
|
||||
let formTest = new FormModel(fakeFormJson);
|
||||
visibilityObjTest.rightRestResponseId = 'TEST_VAR_2';
|
||||
@ -463,15 +464,15 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('should retrieve the value for the left field when it is a process variable', (done) => {
|
||||
service.getProcessVariablesForTask(9999).subscribe(
|
||||
(res: IProcessVariable[]) => {
|
||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||
(res: TaskProcessVariableModel[]) => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeProcessVariables)
|
||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||
});
|
||||
let formTest = new FormModel(fakeFormJson);
|
||||
visibilityObjTest.leftRestResponseId = 'TEST_VAR_2';
|
||||
@ -589,15 +590,15 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('should evaluate the visibility for the field with single visibility condition between form value and process var', (done) => {
|
||||
service.getProcessVariablesForTask(9999).subscribe(
|
||||
(res: IProcessVariable[]) => {
|
||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||
(res: TaskProcessVariableModel[]) => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeProcessVariables)
|
||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||
});
|
||||
let formTest = new FormModel(fakeFormJson);
|
||||
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
||||
@ -612,15 +613,15 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('should evaluate visibility with multiple conditions', (done) => {
|
||||
service.getProcessVariablesForTask(9999).subscribe(
|
||||
(res: IProcessVariable[]) => {
|
||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||
(res: TaskProcessVariableModel[]) => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeProcessVariables)
|
||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||
});
|
||||
let formTest = new FormModel(fakeFormJson);
|
||||
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
||||
@ -639,15 +640,15 @@ describe('WidgetVisibilityService', () => {
|
||||
});
|
||||
|
||||
it('should return true evaluating a proper condition for a field', (done) => {
|
||||
service.getProcessVariablesForTask(9999).subscribe(
|
||||
(res: IProcessVariable[]) => {
|
||||
service.getTaskProcessVariableModelsForTask(9999).subscribe(
|
||||
(res: TaskProcessVariableModel[]) => {
|
||||
done();
|
||||
}
|
||||
);
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeProcessVariables)
|
||||
responseText: JSON.stringify(fakeTaskProcessVariableModels)
|
||||
});
|
||||
let formTest = new FormModel(fakeFormJson);
|
||||
visibilityObjTest.leftFormFieldId = 'LEFT_FORM_FIELD_ID';
|
||||
|
@ -19,13 +19,14 @@ 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/widget.model';
|
||||
import { VisibilityFormWidget, IProcessVariable } from './../components/widgets/widget-visibility.model';
|
||||
import { FormModel, FormFieldModel } from '../components/widgets/core/index';
|
||||
import { WidgetVisibilityModel } from '../models/widget-visibility.model';
|
||||
import { TaskProcessVariableModel } from '../models/task-process-variable.model';
|
||||
|
||||
@Injectable()
|
||||
export class WidgetVisibilityService {
|
||||
|
||||
private processVarList: IProcessVariable[];
|
||||
private processVarList: TaskProcessVariableModel[];
|
||||
|
||||
constructor(private http: Http,
|
||||
private alfrescoSettingsService: AlfrescoSettingsService) {
|
||||
@ -54,7 +55,7 @@ export class WidgetVisibilityService {
|
||||
}
|
||||
}
|
||||
|
||||
public getVisiblityForField(form: FormModel, visibilityObj: VisibilityFormWidget): boolean {
|
||||
public getVisiblityForField(form: FormModel, visibilityObj: WidgetVisibilityModel): boolean {
|
||||
let isLeftFieldPresent = visibilityObj.leftFormFieldId || visibilityObj.leftRestResponseId;
|
||||
if ( !isLeftFieldPresent ) {
|
||||
return true;
|
||||
@ -63,7 +64,7 @@ export class WidgetVisibilityService {
|
||||
}
|
||||
}
|
||||
|
||||
private evaluateVisibilityForField(form: FormModel, visibilityObj: VisibilityFormWidget): boolean {
|
||||
private 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);
|
||||
@ -78,14 +79,14 @@ export class WidgetVisibilityService {
|
||||
}
|
||||
}
|
||||
|
||||
private getLeftValue(form: FormModel, visibilityObj: VisibilityFormWidget) {
|
||||
private getLeftValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
||||
if ( visibilityObj.leftRestResponseId ) {
|
||||
return this.getValueFromVariable(form, visibilityObj.leftRestResponseId);
|
||||
}
|
||||
return this.getValueOField(form, visibilityObj.leftFormFieldId);
|
||||
}
|
||||
|
||||
private getRightValue(form: FormModel, visibilityObj: VisibilityFormWidget) {
|
||||
private getRightValue(form: FormModel, visibilityObj: WidgetVisibilityModel) {
|
||||
let valueFound = null;
|
||||
if ( visibilityObj.rightRestResponseId ) {
|
||||
valueFound = this.getValueFromVariable(form, visibilityObj.rightRestResponseId);
|
||||
@ -170,19 +171,19 @@ export class WidgetVisibilityService {
|
||||
return null;
|
||||
}
|
||||
|
||||
getProcessVariablesForTask(taskId: string): Observable<IProcessVariable[]> {
|
||||
getTaskProcessVariableModelsForTask(taskId: string): Observable<TaskProcessVariableModel[]> {
|
||||
let url = `${this.alfrescoSettingsService.getBPMApiBaseUrl()}/app/rest/task-forms/${taskId}/variables`;
|
||||
let options = this.getRequestOptions();
|
||||
return this.http
|
||||
.get(url, options)
|
||||
.map( (response: Response) => this.processVarList = <IProcessVariable[]> response.json())
|
||||
.map( (response: Response) => this.processVarList = <TaskProcessVariableModel[]> response.json())
|
||||
.catch(this.handleError);
|
||||
}
|
||||
|
||||
getProcessVariableForTaskByName(taskId: string, processVarName: string): Observable<IProcessVariable> {
|
||||
return this.getProcessVariablesForTask(taskId)
|
||||
getTaskProcessVariableModelForTaskByName(taskId: string, processVarName: string): Observable<TaskProcessVariableModel> {
|
||||
return this.getTaskProcessVariableModelsForTask(taskId)
|
||||
.map(
|
||||
(variables: IProcessVariable[]) =>
|
||||
(variables: TaskProcessVariableModel[]) =>
|
||||
variables.find(variable => variable.id === processVarName));
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user