mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
add custom columns support for process list (#1787)
This commit is contained in:
committed by
Mario Romano
parent
c3e38e87ab
commit
c316fcac18
@@ -62,9 +62,9 @@ describe('ActivitiProcessInstanceListComponent', () => {
|
||||
}));
|
||||
|
||||
it('should use the default schemaColumn as default', () => {
|
||||
component.ngOnInit();
|
||||
component.ngAfterContentInit();
|
||||
expect(component.data.getColumns()).toBeDefined();
|
||||
expect(component.data.getColumns().length).toEqual(4);
|
||||
expect(component.data.getColumns().length).toEqual(2);
|
||||
});
|
||||
|
||||
it('should use the schemaColumn passed in input', () => {
|
||||
@@ -75,13 +75,13 @@ describe('ActivitiProcessInstanceListComponent', () => {
|
||||
]
|
||||
);
|
||||
|
||||
component.ngOnInit();
|
||||
component.ngAfterContentInit();
|
||||
expect(component.data.getColumns()).toBeDefined();
|
||||
expect(component.data.getColumns().length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return an empty process list when no input parameters are passed', () => {
|
||||
component.ngOnInit();
|
||||
component.ngAfterContentInit();
|
||||
expect(component.data).toBeDefined();
|
||||
expect(component.isListEmpty()).toBeTruthy();
|
||||
});
|
||||
|
@@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { Component, Input, Output, EventEmitter, OnInit, OnChanges, SimpleChanges } from '@angular/core';
|
||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||
import { ObjectDataTableAdapter, DataTableAdapter, DataRowEvent, ObjectDataRow, DataSorting } from 'ng2-alfresco-datatable';
|
||||
import { Component, Input, Output, EventEmitter, OnChanges, SimpleChanges, ContentChild, AfterContentInit } from '@angular/core';
|
||||
import { AlfrescoTranslationService, DataColumnListComponent } from 'ng2-alfresco-core';
|
||||
import { ObjectDataTableAdapter, DataTableAdapter, DataRowEvent, ObjectDataRow, DataSorting, DataColumn } from 'ng2-alfresco-datatable';
|
||||
import { ProcessFilterRequestRepresentation } from '../models/process-instance-filter.model';
|
||||
import { ProcessInstance } from '../models/process-instance.model';
|
||||
import { ActivitiProcessService } from '../services/activiti-process.service';
|
||||
@@ -29,7 +29,9 @@ import { ActivitiProcessService } from '../services/activiti-process.service';
|
||||
styleUrls: ['./activiti-processlist.component.css'],
|
||||
templateUrl: './activiti-processlist.component.html'
|
||||
})
|
||||
export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
||||
export class ActivitiProcessInstanceListComponent implements OnChanges, AfterContentInit {
|
||||
|
||||
@ContentChild(DataColumnListComponent) columnList: DataColumnListComponent;
|
||||
|
||||
@Input()
|
||||
appId: string;
|
||||
@@ -62,11 +64,9 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
||||
|
||||
currentInstanceId: string;
|
||||
|
||||
private defaultSchemaColumn: any[] = [
|
||||
{type: 'text', key: 'id', title: 'Id'},
|
||||
{type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true},
|
||||
{type: 'text', key: 'started', title: 'Started', sortable: true},
|
||||
{type: 'text', key: 'startedBy.email', title: 'Started By', sortable: true}
|
||||
private defaultSchema: DataColumn[] = [
|
||||
{ type: 'text', key: 'name', title: 'Name', cssClass: 'full-width name-column', sortable: true },
|
||||
{ type: 'text', key: 'created', title: 'Created', cssClass: 'hidden', sortable: true }
|
||||
];
|
||||
|
||||
constructor(private processService: ActivitiProcessService,
|
||||
@@ -76,15 +76,36 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
if (!this.data) {
|
||||
this.data = this.initDefaultSchemaColumns();
|
||||
}
|
||||
ngAfterContentInit() {
|
||||
this.setupSchema();
|
||||
|
||||
if (this.appId) {
|
||||
this.reload();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup html-based (html definitions) or code behind (data adapter) schema.
|
||||
* If component is assigned with an empty data adater the default schema settings applied.
|
||||
*/
|
||||
setupSchema() {
|
||||
let schema: DataColumn[] = [];
|
||||
|
||||
if (this.columnList && this.columnList.columns && this.columnList.columns.length > 0) {
|
||||
schema = this.columnList.columns.map(c => <DataColumn> c);
|
||||
}
|
||||
|
||||
if (!this.data) {
|
||||
this.data = new ObjectDataTableAdapter([], schema.length > 0 ? schema : this.defaultSchema);
|
||||
} else {
|
||||
if (schema && schema.length > 0) {
|
||||
this.data.setColumns(schema);
|
||||
} else if (this.data.getColumns().length === 0) {
|
||||
this.data.setColumns(this.defaultSchema);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges) {
|
||||
if (this.isPropertyChanged(changes)) {
|
||||
this.reload();
|
||||
@@ -119,17 +140,6 @@ export class ActivitiProcessInstanceListComponent implements OnInit, OnChanges {
|
||||
this.load(this.requestNode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an initDefaultSchemaColumns instance with the default Schema Column
|
||||
* @returns {ObjectDataTableAdapter}
|
||||
*/
|
||||
initDefaultSchemaColumns(): ObjectDataTableAdapter {
|
||||
return new ObjectDataTableAdapter(
|
||||
[],
|
||||
this.defaultSchemaColumn
|
||||
);
|
||||
}
|
||||
|
||||
private load(requestNode: ProcessFilterRequestRepresentation) {
|
||||
this.processService.getProcessInstances(requestNode)
|
||||
.subscribe(
|
||||
|
Reference in New Issue
Block a user