mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
#1107 Process list refactoring
This commit is contained in:
parent
3f826bf47a
commit
2bcb8e9b04
@ -1,5 +1,5 @@
|
|||||||
<div *ngIf="!filter">{{ 'FILTERS.MESSAGES.NONE' | translate }}</div>
|
<div *ngIf="!requestNode">{{ 'FILTERS.MESSAGES.NONE' | translate }}</div>
|
||||||
<div *ngIf="filter">
|
<div *ngIf="requestNode">
|
||||||
<div *ngIf="!isListEmpty()">
|
<div *ngIf="!isListEmpty()">
|
||||||
<alfresco-datatable
|
<alfresco-datatable
|
||||||
[data]="data"
|
[data]="data"
|
||||||
|
@ -15,40 +15,51 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { DebugElement, SimpleChange } from '@angular/core';
|
import { SimpleChange } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
import { Observable } from 'rxjs/Rx';
|
|
||||||
import { ActivitiProcessInstanceListComponent } from './activiti-processlist.component';
|
|
||||||
import { TranslationMock } from './../assets/translation.service.mock';
|
|
||||||
import { ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
|
|
||||||
import { FilterRepresentationModel } from 'ng2-activiti-tasklist';
|
|
||||||
import { ActivitiProcessService } from '../services/activiti-process.service';
|
|
||||||
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
|
import { AlfrescoTranslationService, CoreModule } from 'ng2-alfresco-core';
|
||||||
import { DataTableModule } from 'ng2-alfresco-datatable';
|
import { DataTableModule } from 'ng2-alfresco-datatable';
|
||||||
|
import { ActivitiProcessInstanceListComponent } from './activiti-processlist.component';
|
||||||
|
import { Observable } from 'rxjs/Rx';
|
||||||
|
import { ObjectDataRow, DataRowEvent, ObjectDataTableAdapter } from 'ng2-alfresco-datatable';
|
||||||
|
import { TranslationMock } from './../assets/translation.service.mock';
|
||||||
|
import { ActivitiProcessService } from '../services/activiti-process.service';
|
||||||
|
|
||||||
describe('ActivitiProcessInstanceListComponent', () => {
|
describe('ActivitiProcessInstanceListComponent', () => {
|
||||||
|
|
||||||
|
let fakeGlobalProcesses = [
|
||||||
|
{
|
||||||
|
id: 1, name: 'fake-long-name-fake-long-name-fake-long-name-fak50-long-name',
|
||||||
|
processDefinitionId: 'fakeprocess:5:7507',
|
||||||
|
processDefinitionKey: 'fakeprocess',
|
||||||
|
processDefinitionName: 'Fake Process Name',
|
||||||
|
description: null, category: null,
|
||||||
|
started: '2017-11-09T12:37:25.184+0000',
|
||||||
|
startedBy: {
|
||||||
|
id: 3, firstName: 'tenant2', lastName: 'tenantLastname', email: 'tenant2@tenant'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2, name: '', description: null, category: null,
|
||||||
|
started: '2015-11-09T12:37:25.184+0000',
|
||||||
|
startedBy: {
|
||||||
|
id: 3, firstName: 'tenant2', lastName: 'tenantLastname', email: 'tenant2@tenant'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
let componentHandler: any;
|
||||||
let fixture: ComponentFixture<ActivitiProcessInstanceListComponent>;
|
let fixture: ComponentFixture<ActivitiProcessInstanceListComponent>;
|
||||||
let component: ActivitiProcessInstanceListComponent;
|
let component: ActivitiProcessInstanceListComponent;
|
||||||
let element: DebugElement;
|
|
||||||
let service: ActivitiProcessService;
|
let service: ActivitiProcessService;
|
||||||
|
|
||||||
let mockFilter = new FilterRepresentationModel({
|
|
||||||
appId: '1',
|
|
||||||
filter: {
|
|
||||||
name: '',
|
|
||||||
state: '',
|
|
||||||
sort: ''
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
CoreModule,
|
CoreModule,
|
||||||
DataTableModule
|
DataTableModule
|
||||||
],
|
],
|
||||||
declarations: [ ActivitiProcessInstanceListComponent ], // declare the test component
|
declarations: [ ActivitiProcessInstanceListComponent ],
|
||||||
providers: [
|
providers: [
|
||||||
ActivitiProcessService,
|
ActivitiProcessService,
|
||||||
{provide: AlfrescoTranslationService, useClass: TranslationMock}
|
{provide: AlfrescoTranslationService, useClass: TranslationMock}
|
||||||
@ -56,8 +67,13 @@ describe('ActivitiProcessInstanceListComponent', () => {
|
|||||||
}).compileComponents().then(() => {
|
}).compileComponents().then(() => {
|
||||||
fixture = TestBed.createComponent(ActivitiProcessInstanceListComponent);
|
fixture = TestBed.createComponent(ActivitiProcessInstanceListComponent);
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
element = fixture.debugElement;
|
service = fixture.debugElement.injector.get(ActivitiProcessService);
|
||||||
service = element.injector.get(ActivitiProcessService);
|
|
||||||
|
componentHandler = jasmine.createSpyObj('componentHandler', [
|
||||||
|
'upgradeAllRegistered',
|
||||||
|
'upgradeElement'
|
||||||
|
]);
|
||||||
|
window['componentHandler'] = componentHandler;
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -80,37 +96,194 @@ describe('ActivitiProcessInstanceListComponent', () => {
|
|||||||
expect(component.data.getColumns().length).toEqual(1);
|
expect(component.data.getColumns().length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fetch process instances when a filter is provided', () => {
|
it('should return an empty process list when no input parameters are passed', () => {
|
||||||
let getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(Observable.of([]));
|
component.ngOnInit();
|
||||||
component.filter = mockFilter;
|
expect(component.data).toBeDefined();
|
||||||
fixture.detectChanges();
|
expect(component.isListEmpty()).toBeTruthy();
|
||||||
expect(getProcessInstancesSpy).toHaveBeenCalled();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT fetch process instances if filter not provided', () => {
|
it('should return the process instances list', (done) => {
|
||||||
let getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(Observable.of([]));
|
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
|
||||||
|
component.appId = '1';
|
||||||
|
component.state = 'open';
|
||||||
|
component.processDefinitionKey = null;
|
||||||
|
component.onSuccess.subscribe( (res) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(component.data).toBeDefined();
|
||||||
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
|
expect(component.data.getRows().length).toEqual(2);
|
||||||
|
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
|
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
|
||||||
|
done();
|
||||||
|
});
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(getProcessInstancesSpy).not.toHaveBeenCalled();
|
});
|
||||||
|
|
||||||
|
it('should return the process instances list filtered by processDefinitionKey', (done) => {
|
||||||
|
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
|
||||||
|
component.appId = '1';
|
||||||
|
component.state = 'open';
|
||||||
|
component.processDefinitionKey = 'fakeprocess';
|
||||||
|
component.onSuccess.subscribe( (res) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(component.data).toBeDefined();
|
||||||
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
|
expect(component.data.getRows().length).toEqual(2);
|
||||||
|
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
|
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a currentId null when the processList is empty', () => {
|
||||||
|
component.selectFirst();
|
||||||
|
expect(component.getCurrentId()).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an exception when the response is wrong', (done) => {
|
||||||
|
spyOn(service, 'getProcessInstances').and.returnValue(Observable.throw('Fake server error'));
|
||||||
|
component.state = 'open';
|
||||||
|
component.onError.subscribe( (err) => {
|
||||||
|
expect(err).toBeDefined();
|
||||||
|
expect(err).toBe('Fake server error');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
fixture.detectChanges();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload processes when reload() is called', (done) => {
|
||||||
|
spyOn(service, 'getProcessInstances').and.returnValue(Observable.throw('Fake server error'));
|
||||||
|
component.state = 'open';
|
||||||
|
component.ngOnInit();
|
||||||
|
component.onSuccess.subscribe( (res) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(component.data).toBeDefined();
|
||||||
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
|
expect(component.data.getRows().length).toEqual(2);
|
||||||
|
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
|
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
component.reload();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit row click event', (done) => {
|
||||||
|
let row = new ObjectDataRow({
|
||||||
|
id: 999
|
||||||
|
});
|
||||||
|
let rowEvent = <DataRowEvent> {value: row};
|
||||||
|
|
||||||
|
component.rowClick.subscribe(taskId => {
|
||||||
|
expect(taskId).toEqual(999);
|
||||||
|
expect(component.getCurrentId()).toEqual(999);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.onRowClick(rowEvent);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('component changes', () => {
|
describe('component changes', () => {
|
||||||
|
|
||||||
it('should fetch new process instances when filter changed', () => {
|
beforeEach(() => {
|
||||||
component.filter = new FilterRepresentationModel({});
|
spyOn(service, 'getProcessInstances').and.returnValue(Observable.of(fakeGlobalProcesses));
|
||||||
fixture.detectChanges();
|
component.data = new ObjectDataTableAdapter(
|
||||||
let getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(Observable.of([]));
|
[],
|
||||||
component.ngOnChanges({ filter: new SimpleChange(mockFilter, mockFilter) });
|
[
|
||||||
expect(getProcessInstancesSpy).toHaveBeenCalled();
|
{type: 'text', key: 'fake-id', title: 'Name'}
|
||||||
|
]
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT fetch new process instances when properties apart from filter changed', () => {
|
it('should NOT reload the process list when no parameters changed', () => {
|
||||||
component.filter = mockFilter;
|
expect(component.isListEmpty()).toBeTruthy();
|
||||||
fixture.detectChanges();
|
|
||||||
let getProcessInstancesSpy = spyOn(service, 'getProcessInstances').and.returnValue(Observable.of([]));
|
|
||||||
component.ngOnChanges({});
|
component.ngOnChanges({});
|
||||||
expect(getProcessInstancesSpy).not.toHaveBeenCalled();
|
expect(component.isListEmpty()).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
it('should reload the list when the appId parameter changes', (done) => {
|
||||||
|
const appId = '1';
|
||||||
|
let change = new SimpleChange(null, appId);
|
||||||
|
|
||||||
|
component.onSuccess.subscribe((res) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(component.data).toBeDefined();
|
||||||
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
|
expect(component.data.getRows().length).toEqual(2);
|
||||||
|
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
|
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges({'appId': change});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload the list when the processDefinitionKey parameter changes', (done) => {
|
||||||
|
const processDefinitionKey = 'fakeprocess';
|
||||||
|
let change = new SimpleChange(null, processDefinitionKey);
|
||||||
|
|
||||||
|
component.onSuccess.subscribe((res) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(component.data).toBeDefined();
|
||||||
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
|
expect(component.data.getRows().length).toEqual(2);
|
||||||
|
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
|
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges({'processDefinitionKey': change});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload the list when the state parameter changes', (done) => {
|
||||||
|
const state = 'open';
|
||||||
|
let change = new SimpleChange(null, state);
|
||||||
|
|
||||||
|
component.onSuccess.subscribe((res) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(component.data).toBeDefined();
|
||||||
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
|
expect(component.data.getRows().length).toEqual(2);
|
||||||
|
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
|
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges({'state': change});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload the list when the sort parameter changes', (done) => {
|
||||||
|
const sort = 'desc';
|
||||||
|
let change = new SimpleChange(null, sort);
|
||||||
|
|
||||||
|
component.onSuccess.subscribe((res) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(component.data).toBeDefined();
|
||||||
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
|
expect(component.data.getRows().length).toEqual(2);
|
||||||
|
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
|
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges({'sort': change});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload the process list when the name parameter changes', (done) => {
|
||||||
|
const name = 'FakeTaskName';
|
||||||
|
let change = new SimpleChange(null, name);
|
||||||
|
|
||||||
|
component.onSuccess.subscribe((res) => {
|
||||||
|
expect(res).toBeDefined();
|
||||||
|
expect(component.data).toBeDefined();
|
||||||
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
|
expect(component.data.getRows().length).toEqual(2);
|
||||||
|
expect(component.data.getRows()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
|
expect(component.data.getRows()[1].getValue('name')).toEqual('No name');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges({'name': change});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,10 +15,10 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, OnInit, Input, Output, EventEmitter, OnChanges, SimpleChanges } from '@angular/core';
|
import { Component, Input, Output, EventEmitter, OnInit, OnChanges, SimpleChanges } from '@angular/core';
|
||||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||||
import { ObjectDataTableAdapter, DataRowEvent, DataTableAdapter, ObjectDataRow } from 'ng2-alfresco-datatable';
|
import { ObjectDataTableAdapter, DataTableAdapter, DataRowEvent, ObjectDataRow } from 'ng2-alfresco-datatable';
|
||||||
import { TaskQueryRequestRepresentationModel, FilterRepresentationModel } from 'ng2-activiti-tasklist';
|
import { TaskQueryRequestRepresentationModel } from 'ng2-activiti-tasklist';
|
||||||
import { ActivitiProcessService } from '../services/activiti-process.service';
|
import { ActivitiProcessService } from '../services/activiti-process.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@ -30,7 +30,21 @@ import { ActivitiProcessService } from '../services/activiti-process.service';
|
|||||||
export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
filter: FilterRepresentationModel;
|
appId: string;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
processDefinitionKey: string;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
state: string;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
sort: string;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
name: string;
|
||||||
|
|
||||||
|
requestNode: TaskQueryRequestRepresentationModel;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
data: DataTableAdapter;
|
data: DataTableAdapter;
|
||||||
@ -44,11 +58,10 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
|||||||
@Output()
|
@Output()
|
||||||
onError: EventEmitter<any> = new EventEmitter<any>();
|
onError: EventEmitter<any> = new EventEmitter<any>();
|
||||||
|
|
||||||
errorMessage: string;
|
currentInstanceId: string;
|
||||||
currentProcessInstanceId: string;
|
|
||||||
|
|
||||||
private defaultSchemaColumn: any[] = [
|
private defaultSchemaColumn: any[] = [
|
||||||
{type: 'text', key: 'id', title: 'Id', sortable: true},
|
{type: 'text', key: 'id', title: 'Id'},
|
||||||
{type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true},
|
{type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true},
|
||||||
{type: 'text', key: 'started', title: 'Started', sortable: true},
|
{type: 'text', key: 'started', title: 'Started', sortable: true},
|
||||||
{type: 'text', key: 'startedBy.email', title: 'Started By', sortable: true}
|
{type: 'text', key: 'startedBy.email', title: 'Started By', sortable: true}
|
||||||
@ -68,14 +81,39 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
let filter = changes['filter'];
|
if (this.isPropertyChanged(changes)) {
|
||||||
if (filter && filter.currentValue) {
|
this.reload();
|
||||||
let requestNode = this.convertProcessInstanceToTaskQuery(filter.currentValue);
|
|
||||||
this.load(requestNode);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isPropertyChanged(changes: SimpleChanges): boolean {
|
||||||
|
let changed: boolean = false;
|
||||||
|
|
||||||
|
let appId = changes['appId'];
|
||||||
|
let processDefinitionKey = changes['processDefinitionKey'];
|
||||||
|
let state = changes['state'];
|
||||||
|
let sort = changes['sort'];
|
||||||
|
let name = changes['name'];
|
||||||
|
|
||||||
|
if (appId && appId.currentValue) {
|
||||||
|
changed = true;
|
||||||
|
} else if (processDefinitionKey && processDefinitionKey.currentValue) {
|
||||||
|
changed = true;
|
||||||
|
} else if (state && state.currentValue) {
|
||||||
|
changed = true;
|
||||||
|
} else if (sort && sort.currentValue) {
|
||||||
|
changed = true;
|
||||||
|
} else if (name && name.currentValue) {
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public reload() {
|
||||||
|
this.requestNode = this.createRequestNode();
|
||||||
|
this.load(this.requestNode);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an initDefaultSchemaColumns instance with the default Schema Column
|
* Return an initDefaultSchemaColumns instance with the default Schema Column
|
||||||
* @returns {ObjectDataTableAdapter}
|
* @returns {ObjectDataTableAdapter}
|
||||||
@ -90,62 +128,61 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
|||||||
private load(requestNode: TaskQueryRequestRepresentationModel) {
|
private load(requestNode: TaskQueryRequestRepresentationModel) {
|
||||||
this.processService.getProcessInstances(requestNode)
|
this.processService.getProcessInstances(requestNode)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(processInstances) => {
|
(response) => {
|
||||||
let processRow = this.createDataRow(processInstances);
|
let instancesRow = this.createDataRow(response);
|
||||||
this.renderProcessInstances(processRow);
|
this.renderInstances(instancesRow);
|
||||||
this.selectFirstProcess();
|
this.selectFirst();
|
||||||
this.onSuccess.emit(processInstances);
|
this.onSuccess.emit(response);
|
||||||
},
|
},
|
||||||
error => {
|
error => {
|
||||||
this.errorMessage = <any>error;
|
|
||||||
this.onError.emit(error);
|
this.onError.emit(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an array of ObjectDataRow
|
* Create an array of ObjectDataRow
|
||||||
* @param processes
|
* @param instances
|
||||||
* @returns {ObjectDataRow[]}
|
* @returns {ObjectDataRow[]}
|
||||||
*/
|
*/
|
||||||
private createDataRow(processes: any[]): ObjectDataRow[] {
|
private createDataRow(instances: any[]): ObjectDataRow[] {
|
||||||
let processRows: ObjectDataRow[] = [];
|
let instancesRows: ObjectDataRow[] = [];
|
||||||
processes.forEach((row) => {
|
instances.forEach((row) => {
|
||||||
processRows.push(new ObjectDataRow({
|
instancesRows.push(new ObjectDataRow({
|
||||||
id: row.id,
|
id: row.id,
|
||||||
name: row.name,
|
name: row.name,
|
||||||
started: row.started
|
started: row.started
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
return processRows;
|
return instancesRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the process list
|
* Render the instances list
|
||||||
*
|
*
|
||||||
* @param processInstances
|
* @param instances
|
||||||
*/
|
*/
|
||||||
private renderProcessInstances(processInstances: any[]) {
|
private renderInstances(instances: any[]) {
|
||||||
processInstances = this.optimizeProcessNames(processInstances);
|
instances = this.optimizeNames(instances);
|
||||||
this.data.setRows(processInstances);
|
this.data.setRows(instances);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select the first process of a process list if present
|
* Select the first instance of a list if present
|
||||||
*/
|
*/
|
||||||
private selectFirstProcess() {
|
selectFirst() {
|
||||||
if (!this.isListEmpty()) {
|
if (!this.isListEmpty()) {
|
||||||
this.currentProcessInstanceId = this.data.getRows()[0].getValue('id');
|
this.currentInstanceId = this.data.getRows()[0].getValue('id');
|
||||||
} else {
|
} else {
|
||||||
this.currentProcessInstanceId = null;
|
this.currentInstanceId = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current process
|
* Return the current id
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
getCurrentProcessId(): string {
|
getCurrentId(): string {
|
||||||
return this.currentProcessInstanceId;
|
return this.currentInstanceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -163,40 +200,33 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
|||||||
*/
|
*/
|
||||||
onRowClick(event: DataRowEvent) {
|
onRowClick(event: DataRowEvent) {
|
||||||
let item = event;
|
let item = event;
|
||||||
this.currentProcessInstanceId = item.value.getValue('id');
|
this.currentInstanceId = item.value.getValue('id');
|
||||||
this.rowClick.emit(this.currentProcessInstanceId);
|
this.rowClick.emit(this.currentInstanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimize process name field
|
* Optimize name field
|
||||||
* @param tasks
|
* @param istances
|
||||||
* @returns {any[]}
|
* @returns {any[]}
|
||||||
*/
|
*/
|
||||||
private optimizeProcessNames(tasks: any[]) {
|
private optimizeNames(istances: any[]) {
|
||||||
tasks = tasks.map(t => {
|
istances = istances.map(t => {
|
||||||
t.obj.name = t.obj.name || 'No name';
|
t.obj.name = t.obj.name || 'No name';
|
||||||
if (t.obj.name.length > 50) {
|
if (t.obj.name.length > 50) {
|
||||||
t.obj.name = t.obj.name.substring(0, 50) + '...';
|
t.obj.name = t.obj.name.substring(0, 50) + '...';
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
});
|
});
|
||||||
return tasks;
|
return istances;
|
||||||
}
|
}
|
||||||
|
|
||||||
public reload() {
|
private createRequestNode() {
|
||||||
if (this.filter) {
|
|
||||||
let requestNode = this.convertProcessInstanceToTaskQuery(this.filter);
|
|
||||||
this.load(requestNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private convertProcessInstanceToTaskQuery(processFilter: FilterRepresentationModel) {
|
|
||||||
let requestNode = {
|
let requestNode = {
|
||||||
appDefinitionId: processFilter.appId,
|
appDefinitionId: this.appId,
|
||||||
processDefinitionKey: processFilter.filter.processDefinitionKey,
|
processDefinitionKey: this.processDefinitionKey,
|
||||||
text: processFilter.filter.name,
|
text: this.name,
|
||||||
state: processFilter.filter.state,
|
state: this.state,
|
||||||
sort: processFilter.filter.sort
|
sort: this.sort
|
||||||
};
|
};
|
||||||
return new TaskQueryRequestRepresentationModel(requestNode);
|
return new TaskQueryRequestRepresentationModel(requestNode);
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
export class ProcessFilterRequestRepresentation {
|
export class ProcessFilterRequestRepresentation {
|
||||||
processDefinitionId: string;
|
processDefinitionId: string;
|
||||||
|
processDefinitionKey: string;
|
||||||
appDefinitionId: string;
|
appDefinitionId: string;
|
||||||
state: string;
|
state: string;
|
||||||
sort: string;
|
sort: string;
|
||||||
@ -25,6 +26,7 @@ export class ProcessFilterRequestRepresentation {
|
|||||||
|
|
||||||
constructor(obj?: any) {
|
constructor(obj?: any) {
|
||||||
this.processDefinitionId = obj && obj.processDefinitionId || null;
|
this.processDefinitionId = obj && obj.processDefinitionId || null;
|
||||||
|
this.processDefinitionKey = obj && obj.processDefinitionKey || null;
|
||||||
this.appDefinitionId = obj && obj.appDefinitionId || null;
|
this.appDefinitionId = obj && obj.appDefinitionId || null;
|
||||||
this.state = obj && obj.state || null;
|
this.state = obj && obj.state || null;
|
||||||
this.sort = obj && obj.sort || null;
|
this.sort = obj && obj.sort || null;
|
||||||
|
@ -61,6 +61,14 @@ describe('ActivitiProcessService', () => {
|
|||||||
|
|
||||||
let getProcessInstances: jasmine.Spy;
|
let getProcessInstances: jasmine.Spy;
|
||||||
|
|
||||||
|
let filter: ProcessFilterRequestRepresentation = new ProcessFilterRequestRepresentation({
|
||||||
|
processDefinitionId: '1',
|
||||||
|
appDefinitionId: '1',
|
||||||
|
page: 1,
|
||||||
|
sort: 'created-asc',
|
||||||
|
state: 'completed'
|
||||||
|
});
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
getProcessInstances = spyOn(alfrescoApi.activiti.processApi, 'getProcessInstances')
|
getProcessInstances = spyOn(alfrescoApi.activiti.processApi, 'getProcessInstances')
|
||||||
.and
|
.and
|
||||||
@ -68,13 +76,13 @@ describe('ActivitiProcessService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should return the correct number of instances', async(() => {
|
it('should return the correct number of instances', async(() => {
|
||||||
service.getProcessInstances(null).subscribe((instances) => {
|
service.getProcessInstances(filter).subscribe((instances) => {
|
||||||
expect(instances.length).toBe(1);
|
expect(instances.length).toBe(1);
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should return the correct instance data', async(() => {
|
it('should return the correct instance data', async(() => {
|
||||||
service.getProcessInstances(null).subscribe((instances) => {
|
service.getProcessInstances(filter).subscribe((instances) => {
|
||||||
let instance = instances[0];
|
let instance = instances[0];
|
||||||
expect(instance.id).toBe(exampleProcess.id);
|
expect(instance.id).toBe(exampleProcess.id);
|
||||||
expect(instance.name).toBe(exampleProcess.name);
|
expect(instance.name).toBe(exampleProcess.name);
|
||||||
@ -83,27 +91,11 @@ describe('ActivitiProcessService', () => {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('should call service to fetch process instances', () => {
|
it('should call service to fetch process instances', () => {
|
||||||
service.getProcessInstances(null);
|
service.getProcessInstances(filter);
|
||||||
expect(getProcessInstances).toHaveBeenCalled();
|
expect(getProcessInstances).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should call service with default parameters if no filter specified', () => {
|
|
||||||
service.getProcessInstances(null);
|
|
||||||
expect(getProcessInstances).toHaveBeenCalledWith(new ProcessFilterRequestRepresentation({
|
|
||||||
page: 0,
|
|
||||||
sort: 'created-desc',
|
|
||||||
state: 'all'
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should call service with supplied parameters', () => {
|
it('should call service with supplied parameters', () => {
|
||||||
let filter: ProcessFilterRequestRepresentation = new ProcessFilterRequestRepresentation({
|
|
||||||
processDefinitionId: '1',
|
|
||||||
appDefinitionId: '1',
|
|
||||||
page: 1,
|
|
||||||
sort: 'created-asc',
|
|
||||||
state: 'completed'
|
|
||||||
});
|
|
||||||
service.getProcessInstances(filter);
|
service.getProcessInstances(filter);
|
||||||
expect(getProcessInstances).toHaveBeenCalledWith(filter);
|
expect(getProcessInstances).toHaveBeenCalledWith(filter);
|
||||||
});
|
});
|
||||||
|
@ -46,15 +46,15 @@ export class ActivitiProcessService {
|
|||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
getProcessInstances(requestNode?: ProcessFilterRequestRepresentation): Observable<ProcessInstance[]> {
|
getProcessInstances(requestNode: ProcessFilterRequestRepresentation): Observable<ProcessInstance[]> {
|
||||||
requestNode = requestNode || new ProcessFilterRequestRepresentation({
|
|
||||||
page: 0,
|
|
||||||
sort: 'created-desc',
|
|
||||||
state: 'all'
|
|
||||||
});
|
|
||||||
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.processApi.getProcessInstances(requestNode))
|
return Observable.fromPromise(this.authService.getAlfrescoApi().activiti.processApi.getProcessInstances(requestNode))
|
||||||
.map(this.extractData)
|
.map((res: any) => {
|
||||||
.catch(this.handleError);
|
if (requestNode.processDefinitionKey) {
|
||||||
|
return res.data.filter(p => p.processDefinitionKey === requestNode.processDefinitionKey);
|
||||||
|
} else {
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
}).catch(this.handleError);
|
||||||
}
|
}
|
||||||
|
|
||||||
getProcessFilters(appId: number): Observable<FilterRepresentationModel[]> {
|
getProcessFilters(appId: number): Observable<FilterRepresentationModel[]> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user