mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
#1107 Improve TaskList - The load method is called twice
This commit is contained in:
committed by
Mario Romano
parent
d905aaa0cf
commit
44137ecbbe
@@ -1,12 +1,12 @@
|
|||||||
<div *ngIf="!requestNode">{{ 'TASK_FILTERS.MESSAGES.NONE' | translate }}</div>
|
<div *ngIf="!requestNode">{{ 'TASK_FILTERS.MESSAGES.NONE' | translate }}</div>
|
||||||
<div *ngIf="requestNode">
|
<div *ngIf="requestNode">
|
||||||
<div *ngIf="!isTaskListEmpty()">
|
<div *ngIf="!isListEmpty()">
|
||||||
<alfresco-datatable
|
<alfresco-datatable
|
||||||
[data]="data"
|
[data]="data"
|
||||||
(rowClick)="onRowClick($event)">
|
(rowClick)="onRowClick($event)">
|
||||||
</alfresco-datatable>
|
</alfresco-datatable>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="isTaskListEmpty()">
|
<div *ngIf="isListEmpty()">
|
||||||
{{ 'TASK_LIST.MESSAGES.NONE' | translate }}
|
{{ 'TASK_LIST.MESSAGES.NONE' | translate }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { SimpleChange } from '@angular/core';
|
||||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||||
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';
|
||||||
@@ -108,7 +109,7 @@ describe('ActivitiTaskList', () => {
|
|||||||
it('should return an empty task list when no input parameters are passed', () => {
|
it('should return an empty task list when no input parameters are passed', () => {
|
||||||
component.ngOnInit();
|
component.ngOnInit();
|
||||||
expect(component.data).toBeDefined();
|
expect(component.data).toBeDefined();
|
||||||
expect(component.isTaskListEmpty()).toBeTruthy();
|
expect(component.isListEmpty()).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return the filtered task list when the input parameters are passed', (done) => {
|
it('should return the filtered task list when the input parameters are passed', (done) => {
|
||||||
@@ -120,7 +121,7 @@ describe('ActivitiTaskList', () => {
|
|||||||
component.onSuccess.subscribe( (res) => {
|
component.onSuccess.subscribe( (res) => {
|
||||||
expect(res).toBeDefined();
|
expect(res).toBeDefined();
|
||||||
expect(component.data).toBeDefined();
|
expect(component.data).toBeDefined();
|
||||||
expect(component.isTaskListEmpty()).not.toBeTruthy();
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
expect(component.data.getRows().length).toEqual(2);
|
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()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
expect(component.data.getRows()[1].getValue('name')).toEqual('Nameless task');
|
expect(component.data.getRows()[1].getValue('name')).toEqual('Nameless task');
|
||||||
@@ -138,7 +139,7 @@ describe('ActivitiTaskList', () => {
|
|||||||
component.onSuccess.subscribe( (res) => {
|
component.onSuccess.subscribe( (res) => {
|
||||||
expect(res).toBeDefined();
|
expect(res).toBeDefined();
|
||||||
expect(component.data).toBeDefined();
|
expect(component.data).toBeDefined();
|
||||||
expect(component.isTaskListEmpty()).not.toBeTruthy();
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
expect(component.data.getRows().length).toEqual(2);
|
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()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
expect(component.data.getRows()[1].getValue('name')).toEqual('Nameless task');
|
expect(component.data.getRows()[1].getValue('name')).toEqual('Nameless task');
|
||||||
@@ -174,7 +175,7 @@ describe('ActivitiTaskList', () => {
|
|||||||
component.onSuccess.subscribe( (res) => {
|
component.onSuccess.subscribe( (res) => {
|
||||||
expect(res).toBeDefined();
|
expect(res).toBeDefined();
|
||||||
expect(component.data).toBeDefined();
|
expect(component.data).toBeDefined();
|
||||||
expect(component.isTaskListEmpty()).not.toBeTruthy();
|
expect(component.isListEmpty()).not.toBeTruthy();
|
||||||
expect(component.data.getRows().length).toEqual(2);
|
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()[0].getValue('name')).toEqual('fake-long-name-fake-long-name-fake-long-name-fak50...');
|
||||||
expect(component.data.getRows()[1].getValue('name')).toEqual('Nameless task');
|
expect(component.data.getRows()[1].getValue('name')).toEqual('Nameless task');
|
||||||
@@ -198,29 +199,126 @@ describe('ActivitiTaskList', () => {
|
|||||||
component.onRowClick(rowEvent);
|
component.onRowClick(rowEvent);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reload the task list when the input parameters changes', (done) => {
|
describe('component changes', () => {
|
||||||
spyOn(component.activiti, 'getTotalTasks').and.returnValue(Observable.of(fakeGlobalTotalTasks));
|
|
||||||
spyOn(component.activiti, 'getTasks').and.returnValue(Observable.of(fakeGlobalTask));
|
|
||||||
|
|
||||||
component.data = new ObjectDataTableAdapter(
|
beforeEach(() => {
|
||||||
[],
|
spyOn(component.activiti, 'getTotalTasks').and.returnValue(Observable.of(fakeGlobalTotalTasks));
|
||||||
[
|
spyOn(component.activiti, 'getTasks').and.returnValue(Observable.of(fakeGlobalTask));
|
||||||
{type: 'text', key: 'fake-id', title: 'Name'}
|
|
||||||
]
|
component.data = new ObjectDataTableAdapter(
|
||||||
);
|
[],
|
||||||
component.state = 'open';
|
[
|
||||||
component.assignment = 'fake-assignee';
|
{type: 'text', key: 'fake-id', title: 'Name'}
|
||||||
component.onSuccess.subscribe( (res) => {
|
]
|
||||||
expect(res).toBeDefined();
|
);
|
||||||
expect(component.data).toBeDefined();
|
|
||||||
expect(component.isTaskListEmpty()).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('Nameless task');
|
|
||||||
done();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
component.ngOnChanges({});
|
it('should NOT reload the process list when no parameters changed', () => {
|
||||||
});
|
expect(component.isListEmpty()).toBeTruthy();
|
||||||
|
component.ngOnChanges({});
|
||||||
|
expect(component.isListEmpty()).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload the process 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('Nameless task');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges({'appId': change});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload the process 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('Nameless task');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges({'processDefinitionKey': change});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload the process 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('Nameless task');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges({'state': change});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload the process 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('Nameless task');
|
||||||
|
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('Nameless task');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges({'name': change});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should reload the process list when the assignment parameter changes', (done) => {
|
||||||
|
const assignment = 'assignee';
|
||||||
|
let change = new SimpleChange(null, assignment);
|
||||||
|
|
||||||
|
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('Nameless task');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
component.ngOnChanges({'assignment': change});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -87,7 +87,35 @@ export class ActivitiTaskList implements OnInit, OnChanges {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnChanges(changes: SimpleChanges) {
|
ngOnChanges(changes: SimpleChanges) {
|
||||||
this.reload();
|
if (this.isPropertyChanged(changes)) {
|
||||||
|
this.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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'];
|
||||||
|
let assignment = changes['assignment'];
|
||||||
|
|
||||||
|
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;
|
||||||
|
} else if (assignment && assignment.currentValue) {
|
||||||
|
changed = true;
|
||||||
|
}
|
||||||
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public reload() {
|
public reload() {
|
||||||
@@ -156,7 +184,7 @@ export class ActivitiTaskList implements OnInit, OnChanges {
|
|||||||
* Select the first task of a tasklist if present
|
* Select the first task of a tasklist if present
|
||||||
*/
|
*/
|
||||||
selectFirstTask() {
|
selectFirstTask() {
|
||||||
if (!this.isTaskListEmpty()) {
|
if (!this.isListEmpty()) {
|
||||||
this.currentTaskId = this.data.getRows()[0].getValue('id');
|
this.currentTaskId = this.data.getRows()[0].getValue('id');
|
||||||
} else {
|
} else {
|
||||||
this.currentTaskId = null;
|
this.currentTaskId = null;
|
||||||
@@ -175,7 +203,7 @@ export class ActivitiTaskList implements OnInit, OnChanges {
|
|||||||
* Check if the tasks list is empty
|
* Check if the tasks list is empty
|
||||||
* @returns {ObjectDataTableAdapter|boolean}
|
* @returns {ObjectDataTableAdapter|boolean}
|
||||||
*/
|
*/
|
||||||
isTaskListEmpty(): boolean {
|
isListEmpty(): boolean {
|
||||||
return this.data === undefined || (this.data && this.data.getRows() && this.data.getRows().length === 0);
|
return this.data === undefined || (this.data && this.data.getRows() && this.data.getRows().length === 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user