();
constructor(protected alfrescoApiService: AlfrescoApiService) {}
@@ -98,7 +102,7 @@ export class DataTableCellComponent implements OnInit, OnDestroy {
protected updateValue() {
if (this.column && this.column.key && this.row && this.data) {
- const value = this.data.getValue(this.row, this.column);
+ const value = this.data.getValue(this.row, this.column, this.resolverFn);
this.value$.next(value);
diff --git a/lib/core/datatable/components/datatable/datatable.component.html b/lib/core/datatable/components/datatable/datatable.component.html
index 6d8ebdad09..657980cf44 100644
--- a/lib/core/datatable/components/datatable/datatable.component.html
+++ b/lib/core/datatable/components/datatable/datatable.component.html
@@ -141,6 +141,7 @@
[data]="data"
[column]="col"
[row]="row"
+ [resolverFn]="resolverFn"
[tooltip]="getCellTooltip(row, col)">
@@ -150,6 +151,7 @@
[data]="data"
[column]="col"
[row]="row"
+ [resolverFn]="resolverFn"
[tooltip]="getCellTooltip(row, col)">
@@ -159,6 +161,7 @@
[data]="data"
[column]="col"
[row]="row"
+ [resolverFn]="resolverFn"
[tooltip]="getCellTooltip(row, col)">
@@ -169,6 +172,7 @@
[data]="data"
[column]="col"
[row]="row"
+ [resolverFn]="resolverFn"
[tooltip]="getCellTooltip(row, col)">
@@ -177,6 +181,7 @@
[editable]="col.editable"
[data]="data"
[column]="col"
+ [resolverFn]="resolverFn"
[row]="row">
@@ -189,7 +194,7 @@
+ [ngTemplateOutletContext]="{ $implicit: { data: data, row: row, col: col }, value: data.getValue(row, col, resolverFn) }">
diff --git a/lib/core/datatable/components/datatable/datatable.component.ts b/lib/core/datatable/components/datatable/datatable.component.ts
index d863dea578..cbb7ffff13 100644
--- a/lib/core/datatable/components/datatable/datatable.component.ts
+++ b/lib/core/datatable/components/datatable/datatable.component.ts
@@ -161,6 +161,13 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
@Input()
rowMenuCacheEnabled = true;
+ /**
+ * Custom resolver function which is used to parse dynamic column objects
+ * see the docs to learn how to configure a resolverFn.
+ */
+ @Input()
+ resolverFn: (row: DataRow, col: DataColumn) => any = null;
+
noContentTemplate: TemplateRef;
noPermissionTemplate: TemplateRef;
loadingTemplate: TemplateRef;
diff --git a/lib/core/datatable/components/datatable/json-cell.component.ts b/lib/core/datatable/components/datatable/json-cell.component.ts
index 785823fd95..f6faf7093f 100644
--- a/lib/core/datatable/components/datatable/json-cell.component.ts
+++ b/lib/core/datatable/components/datatable/json-cell.component.ts
@@ -52,12 +52,12 @@ export class JsonCellComponent extends DataTableCellComponent implements OnInit
ngOnInit() {
if (this.column && this.column.key && this.row && this.data) {
- this.value$.next(this.data.getValue(this.row, this.column));
+ this.value$.next(this.data.getValue(this.row, this.column, this.resolverFn));
}
}
view() {
- const rawValue: string | object = this.data.getValue(this.row, this.column);
+ const rawValue: string | object = this.data.getValue(this.row, this.column, this.resolverFn);
const value = typeof rawValue === 'object'
? JSON.stringify(rawValue || {}, null, 2)
: rawValue;
diff --git a/lib/core/datatable/components/datatable/location-cell.component.ts b/lib/core/datatable/components/datatable/location-cell.component.ts
index bd37d216ee..4105344618 100644
--- a/lib/core/datatable/components/datatable/location-cell.component.ts
+++ b/lib/core/datatable/components/datatable/location-cell.component.ts
@@ -52,7 +52,8 @@ export class LocationCellComponent extends DataTableCellComponent implements OnI
if (this.column && this.column.key && this.row && this.data) {
const path: PathInfoEntity = this.data.getValue(
this.row,
- this.column
+ this.column,
+ this.resolverFn
);
if (path && path.name && path.elements) {
diff --git a/lib/core/datatable/data/datatable-adapter.ts b/lib/core/datatable/data/datatable-adapter.ts
index 698f31160d..b1719baac7 100644
--- a/lib/core/datatable/data/datatable-adapter.ts
+++ b/lib/core/datatable/data/datatable-adapter.ts
@@ -28,7 +28,7 @@ export interface DataTableAdapter {
setRows(rows: Array): void;
getColumns(): Array;
setColumns(columns: Array): void;
- getValue(row: DataRow, col: DataColumn): any;
+ getValue(row: DataRow, col: DataColumn, resolverFn?: (row: DataRow, col: DataColumn) => any): any;
getSorting(): DataSorting;
setSorting(sorting: DataSorting): void;
sort(key?: string, direction?: string): void;
diff --git a/lib/core/datatable/data/object-datatable-adapter.ts b/lib/core/datatable/data/object-datatable-adapter.ts
index a34042a045..7c0e036d80 100644
--- a/lib/core/datatable/data/object-datatable-adapter.ts
+++ b/lib/core/datatable/data/object-datatable-adapter.ts
@@ -99,7 +99,7 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
this._columns = columns || [];
}
- getValue(row: DataRow, col: DataColumn): any {
+ getValue(row: DataRow, col: DataColumn, resolver?: (row: DataRow, col: DataColumn) => any ): any {
if (!row) {
throw new Error('Row not found');
}
@@ -107,6 +107,10 @@ export class ObjectDataTableAdapter implements DataTableAdapter {
throw new Error('Column not found');
}
+ if (resolver) {
+ return resolver(row, col);
+ }
+
const value = row.getValue(col.key);
if (col.type === 'icon') {
diff --git a/lib/process-services/src/lib/mock/process/process-instances-list.mock.ts b/lib/process-services/src/lib/mock/process/process-instances-list.mock.ts
index 6032f8fe99..d409197cee 100644
--- a/lib/process-services/src/lib/mock/process/process-instances-list.mock.ts
+++ b/lib/process-services/src/lib/mock/process/process-instances-list.mock.ts
@@ -45,7 +45,12 @@ export let fakeProcessInstance = {
graphicalNotationDefined: true,
startFormDefined: false,
suspended: false,
- variables: []
+ variables: [
+ {
+ name: 'initiator',
+ value: 'fake-user-1'
+ }
+ ]
},
{
id: '2',
@@ -70,7 +75,12 @@ export let fakeProcessInstance = {
graphicalNotationDefined: true,
startFormDefined: false,
suspended: false,
- variables: []
+ variables: [
+ {
+ name: 'initiator',
+ value: 'fake-user-2'
+ }
+ ]
}
]
};
diff --git a/lib/process-services/src/lib/process-list/components/process-list.component.html b/lib/process-services/src/lib/process-list/components/process-list.component.html
index 92542adc9c..a5240f6ecb 100644
--- a/lib/process-services/src/lib/process-list/components/process-list.component.html
+++ b/lib/process-services/src/lib/process-list/components/process-list.component.html
@@ -6,6 +6,7 @@
[loading]="isLoading"
[selectionMode]="selectionMode"
[multiselect]="multiselect"
+ [resolverFn]="resolverFn"
(rowClick)="onRowClick($event)"
(row-keyup)="onRowKeyUp($event)">
diff --git a/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts b/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts
index 026d60771e..64141937d3 100644
--- a/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts
+++ b/lib/process-services/src/lib/process-list/components/process-list.component.spec.ts
@@ -22,7 +22,7 @@ import { By } from '@angular/platform-browser';
import { ProcessInstanceListComponent } from './process-list.component';
-import { AppConfigService, setupTestBed, CoreModule, DataTableModule } from '@alfresco/adf-core';
+import { AppConfigService, setupTestBed, CoreModule, DataTableModule, DataRow, DataColumn } from '@alfresco/adf-core';
import { DataRowEvent, ObjectDataRow, ObjectDataTableAdapter } from '@alfresco/adf-core';
import { fakeProcessInstance, fakeProcessInstancesWithNoName, fakeProcessInstancesEmpty } from '../../mock';
@@ -38,6 +38,13 @@ describe('ProcessInstanceListComponent', () => {
let service: ProcessService;
let getProcessInstancesSpy: jasmine.Spy;
let appConfig: AppConfigService;
+ const resolverfn = (row: DataRow, col: DataColumn) => {
+ const value = row.getValue(col.key);
+ if (col.key === 'variables') {
+ return (value || []).map((processVar) => `${processVar.name} - ${processVar.value}`).toString();
+ }
+ return value;
+ };
setupTestBed({
imports: [
@@ -271,6 +278,30 @@ describe('ProcessInstanceListComponent', () => {
});
}));
+ it('should show custom resolved value in the column', async(() => {
+ appConfig.config['adf-process-list'] = {
+ 'presets': {
+ 'fakeProcessCustomSchema': [
+ {
+ 'key': 'variables',
+ 'type': 'text',
+ 'title': 'Variables'
+ }
+ ]
+ }
+ };
+ component.presetColumn = 'fakeProcessCustomSchema';
+ component.resolverFn = resolverfn;
+ component.reload();
+
+ fixture.whenStable().then(() => {
+ fixture.detectChanges();
+ const customColumn = fixture.debugElement.queryAll(By.css('[title="Variables"] adf-datatable-cell'));
+ expect(customColumn[0].nativeElement.innerText).toEqual('initiator - fake-user-1');
+ expect(customColumn[1].nativeElement.innerText).toEqual('initiator - fake-user-2');
+ });
+ }));
+
describe('component changes', () => {
beforeEach(() => {
diff --git a/lib/process-services/src/lib/process-list/components/process-list.component.ts b/lib/process-services/src/lib/process-list/components/process-list.component.ts
index fc5b1ccb6d..5f075bd000 100644
--- a/lib/process-services/src/lib/process-list/components/process-list.component.ts
+++ b/lib/process-services/src/lib/process-list/components/process-list.component.ts
@@ -20,7 +20,9 @@ import {
DataRowEvent,
DataTableAdapter,
CustomEmptyContentTemplateDirective,
- CustomLoadingContentTemplateDirective
+ CustomLoadingContentTemplateDirective,
+ DataRow,
+ DataColumn
} from '@alfresco/adf-core';
import {
AppConfigService,
@@ -112,6 +114,13 @@ export class ProcessInstanceListComponent extends DataTableSchema implements On
@Input()
selectFirstRow: boolean = true;
+ /**
+ * Resolver function is used to show dynamic complex column objects
+ * see the docs to learn how to configure a resolverFn.
+ */
+ @Input()
+ resolverFn: (row: DataRow, col: DataColumn) => any = null;
+
/** Emitted when a row in the process list is clicked. */
@Output()
rowClick: EventEmitter = new EventEmitter();