diff --git a/demo-shell/src/app/components/process-list-demo/process-list-demo.component.html b/demo-shell/src/app/components/process-list-demo/process-list-demo.component.html
index 4aa5fc5579..4eca87fa11 100644
--- a/demo-shell/src/app/components/process-list-demo/process-list-demo.component.html
+++ b/demo-shell/src/app/components/process-list-demo/process-list-demo.component.html
@@ -18,6 +18,15 @@
+
+ ProcessInstanceId
+
+ SimpleProcess:1:2
+
+
ProcessDefinitionId
{
expect(dataRow[0]['id']).toEqual('999');
});
- it('should throw an exception when the response is wrong', fakeAsync(() => {
- let emitSpy: jasmine.Spy = spyOn(component.error, 'emit');
+ it('should return an empty list when the response is wrong', fakeAsync(() => {
let mockError = 'Fake server error';
getProcessInstancesSpy.and.returnValue(throwError(mockError));
component.appId = 1;
component.state = 'open';
fixture.detectChanges();
tick();
- expect(emitSpy).toHaveBeenCalledWith(mockError);
+ expect(component.isListEmpty()).toBeTruthy();
}));
it('should emit onSuccess event when reload() called', fakeAsync(() => {
diff --git a/lib/process-services/process-list/components/process-list.component.ts b/lib/process-services/process-list/components/process-list.component.ts
index d7506f57e1..bb3c020256 100644
--- a/lib/process-services/process-list/components/process-list.component.ts
+++ b/lib/process-services/process-list/components/process-list.component.ts
@@ -44,6 +44,7 @@ import { processPresetsDefaultModel } from '../models/process-preset.model';
import { ProcessService } from '../services/process.service';
import { BehaviorSubject } from 'rxjs';
import { ProcessListModel } from '../models/process-list.model';
+import moment from 'moment-es6';
@Component({
selector: 'adf-process-instance-list',
@@ -53,6 +54,7 @@ import { ProcessListModel } from '../models/process-list.model';
export class ProcessInstanceListComponent extends DataTableSchema implements OnChanges, AfterContentInit, PaginatedComponent {
static PRESET_KEY = 'adf-process-list.presets';
+ public FORMAT_DATE: string = 'll';
@ContentChild(EmptyCustomContentDirective) emptyCustomContent: EmptyCustomContentDirective;
@@ -208,10 +210,10 @@ export class ProcessInstanceListComponent extends DataTableSchema implements On
private load(requestNode: ProcessFilterParamRepresentationModel) {
this.isLoading = true;
- this.processService.getProcessInstances(requestNode, this.processDefinitionKey)
+ this.processService.getProcesses(requestNode, this.processDefinitionKey)
.subscribe(
(response) => {
- this.rows = this.optimizeNames(response.data);
+ this.rows = this.optimizeProcessDetails(response.data);
this.selectFirst();
this.success.emit(response);
this.isLoading = false;
@@ -283,9 +285,12 @@ export class ProcessInstanceListComponent extends DataTableSchema implements On
* Optimize name field
* @param instances
*/
- private optimizeNames(instances: any[]): any[] {
+ private optimizeProcessDetails(instances: any[]): any[] {
instances = instances.map(instance => {
instance.name = this.getProcessNameOrDescription(instance, 'medium');
+ if (instance.started) {
+ instance.started = moment(instance.started).format(this.FORMAT_DATE);
+ }
return instance;
});
return instances;
diff --git a/lib/process-services/process-list/models/process-list.model.ts b/lib/process-services/process-list/models/process-list.model.ts
index 1ebf081621..12831b099f 100644
--- a/lib/process-services/process-list/models/process-list.model.ts
+++ b/lib/process-services/process-list/models/process-list.model.ts
@@ -17,11 +17,21 @@
import { ProcessInstance } from './process-instance.model';
-export interface ProcessListModel {
+export class ProcessListModel {
size: number;
total: number;
start: number;
length: number;
data: ProcessInstance [];
+ constructor(obj?: any) {
+ if (obj) {
+ this.size = obj.size || null;
+ this.total = obj.total || null;
+ this.start = obj.start || null;
+ this.length = obj.length || null;
+ this.data = obj.data || [];
+ }
+ }
+
}
diff --git a/lib/process-services/process-list/services/process.service.ts b/lib/process-services/process-list/services/process.service.ts
index a1af905f33..5c652349a8 100644
--- a/lib/process-services/process-list/services/process.service.ts
+++ b/lib/process-services/process-list/services/process.service.ts
@@ -17,7 +17,7 @@
import { AlfrescoApiService, FormValues } from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
-import { Observable, from, throwError } from 'rxjs';
+import { Observable, from, throwError, of } from 'rxjs';
import { TaskDetailsModel } from '../../task-list';
import { ProcessFilterParamRepresentationModel } from '../models/filter-process.model';
import { ProcessDefinitionRepresentation } from '../models/process-definition.model';
@@ -58,6 +58,13 @@ export class ProcessService {
);
}
+ getProcesses(requestNode: ProcessFilterParamRepresentationModel, processDefinitionKey?: string): Observable {
+ return this.getProcessInstances(requestNode, processDefinitionKey || null)
+ .pipe(catchError(() => {
+ return of(new ProcessListModel({}));
+ }));
+ }
+
/**
* Fetches the Process Audit information as a PDF.
* @param processId ID of the target process
@@ -102,9 +109,9 @@ export class ProcessService {
*/
getProcessTasks(processInstanceId: string, state?: string): Observable {
let taskOpts = state ? {
- processInstanceId: processInstanceId,
- state: state
- } : {
+ processInstanceId: processInstanceId,
+ state: state
+ } : {
processInstanceId: processInstanceId
};
return from(this.alfrescoApiService.getInstance().activiti.taskApi.listTasks(taskOpts))
@@ -125,19 +132,19 @@ export class ProcessService {
*/
getProcessDefinitions(appId?: number): Observable {
let opts = appId ? {
- latest: true,
- appDefinitionId: appId
- } : {
+ latest: true,
+ appDefinitionId: appId
+ } : {
latest: true
};
return from(
this.alfrescoApiService.getInstance().activiti.processApi.getProcessDefinitions(opts)
)
- .pipe(
- map(this.extractData),
- map(processDefs => processDefs.map((pd) => new ProcessDefinitionRepresentation(pd))),
- catchError(err => this.handleProcessError(err))
- );
+ .pipe(
+ map(this.extractData),
+ map(processDefs => processDefs.map((pd) => new ProcessDefinitionRepresentation(pd))),
+ catchError(err => this.handleProcessError(err))
+ );
}
/**
@@ -166,10 +173,10 @@ export class ProcessService {
return from(
this.alfrescoApiService.getInstance().activiti.processApi.startNewProcessInstance(startRequest)
)
- .pipe(
- map((pd) => new ProcessInstance(pd)),
- catchError(err => this.handleProcessError(err))
- );
+ .pipe(
+ map((pd) => new ProcessInstance(pd)),
+ catchError(err => this.handleProcessError(err))
+ );
}
/**
@@ -181,9 +188,9 @@ export class ProcessService {
return from(
this.alfrescoApiService.getInstance().activiti.processApi.deleteProcessInstance(processInstanceId)
)
- .pipe(
- catchError(err => this.handleProcessError(err))
- );
+ .pipe(
+ catchError(err => this.handleProcessError(err))
+ );
}
/**
@@ -195,10 +202,10 @@ export class ProcessService {
return from(
this.alfrescoApiService.getInstance().activiti.processInstanceVariablesApi.getProcessInstanceVariables(processInstanceId)
)
- .pipe(
- map((processVars: any[]) => processVars.map((pd) => new ProcessInstanceVariable(pd))),
- catchError(err => this.handleProcessError(err))
- );
+ .pipe(
+ map((processVars: any[]) => processVars.map((pd) => new ProcessInstanceVariable(pd))),
+ catchError(err => this.handleProcessError(err))
+ );
}
/**
@@ -211,9 +218,9 @@ export class ProcessService {
return from(
this.alfrescoApiService.getInstance().activiti.processInstanceVariablesApi.createOrUpdateProcessInstanceVariables(processInstanceId, variables)
)
- .pipe(
- catchError(err => this.handleProcessError(err))
- );
+ .pipe(
+ catchError(err => this.handleProcessError(err))
+ );
}
/**
@@ -226,9 +233,9 @@ export class ProcessService {
return from(
this.alfrescoApiService.getInstance().activiti.processInstanceVariablesApi.deleteProcessInstanceVariable(processInstanceId, variableName)
)
- .pipe(
- catchError(err => this.handleProcessError(err))
- );
+ .pipe(
+ catchError(err => this.handleProcessError(err))
+ );
}
private extractData(res: any) {
diff --git a/lib/process-services/task-list/components/start-task.component.spec.ts b/lib/process-services/task-list/components/start-task.component.spec.ts
index f8ab89e8b1..e4db077450 100644
--- a/lib/process-services/task-list/components/start-task.component.spec.ts
+++ b/lib/process-services/task-list/components/start-task.component.spec.ts
@@ -155,7 +155,7 @@ describe('StartTaskComponent', () => {
let successSpy = spyOn(component.success, 'emit');
component.appId = 42;
component.startTaskModel = new StartTaskModel(startTaskMock);
- component.formKey = 1204;
+ component.formKey = '1204';
fixture.detectChanges();
let createTaskButton = element.querySelector('#button-start');
createTaskButton.click();
@@ -216,7 +216,7 @@ describe('StartTaskComponent', () => {
let successSpy = spyOn(component.success, 'emit');
component.appId = 42;
component.startTaskModel = new StartTaskModel(startTaskMock);
- component.formKey = 1204;
+ component.formKey = '1204';
component.assigneeId = testUser.id;
fixture.detectChanges();
let createTaskButton = element.querySelector('#button-start');
@@ -232,7 +232,7 @@ describe('StartTaskComponent', () => {
it('should not assign task when no assignee is selected', () => {
let successSpy = spyOn(component.success, 'emit');
component.appId = 42;
- component.formKey = 1204;
+ component.formKey = '1204';
component.assigneeId = null;
component.startTaskModel = new StartTaskModel(startTaskMock);
fixture.detectChanges();
@@ -250,7 +250,7 @@ describe('StartTaskComponent', () => {
let successSpy = spyOn(component.success, 'emit');
component.appId = 42;
component.startTaskModel = new StartTaskModel(startTaskMock);
- component.formKey = 1204;
+ component.formKey = '1204';
component.getAssigneeId(testUser.id);
fixture.detectChanges();
let createTaskButton = element.querySelector('#button-start');
diff --git a/lib/process-services/task-list/components/start-task.component.ts b/lib/process-services/task-list/components/start-task.component.ts
index 19f121e9a0..be220f019f 100644
--- a/lib/process-services/task-list/components/start-task.component.ts
+++ b/lib/process-services/task-list/components/start-task.component.ts
@@ -63,7 +63,7 @@ export class StartTaskComponent implements OnInit {
assigneeId: number;
- formKey: number;
+ formKey: string;
taskId: string;
@@ -124,10 +124,10 @@ export class StartTaskComponent implements OnInit {
this.assigneeId = userId;
}
- private attachForm(taskId: string, formKey: number): Observable {
+ private attachForm(taskId: string, formKey: string): Observable {
let response = of();
if (taskId && formKey) {
- response = this.taskService.attachFormToATask(taskId, formKey);
+ response = this.taskService.attachFormToATask(taskId, parseInt(formKey, 10));
}
return response;
}