Merge pull request #720 from Alfresco/dev-denys--groups-widget

#636 fix group filter
This commit is contained in:
Mario Romano 2016-09-08 15:04:59 +01:00 committed by GitHub
commit 390bedf1d6
3 changed files with 57 additions and 7 deletions

View File

@ -47,6 +47,23 @@ describe('FunctionalGroupWidget', () => {
expect(widget.value).toBeUndefined();
});
it('should require form field to setup values on init', () => {
widget.field = null;
widget.ngOnInit();
expect(widget.value).toBeUndefined();
expect(widget.groupId).toBeUndefined();
});
it('should setup group restriction', () => {
widget.ngOnInit();
expect(widget.groupId).toBeUndefined();
widget.field.params = { restrictWithGroup: { id: '<id>' } };
widget.ngOnInit();
expect(widget.groupId).toBe('<id>');
});
it('should flush value on blur', (done) => {
spyOn(widget, 'flushValue').and.stub();
widget.onBlur();
@ -132,7 +149,28 @@ describe('FunctionalGroupWidget', () => {
widget.value = 'group';
widget.onKeyUp(null);
expect(formService.getWorkflowGroups).toHaveBeenCalledWith('group');
expect(formService.getWorkflowGroups).toHaveBeenCalledWith('group', undefined);
expect(widget.groups).toBe(groups);
expect(widget.popupVisible).toBeTruthy();
});
it('should fetch groups with a group filter', () => {
let groups: GroupModel[] = [
new GroupModel(),
new GroupModel()
];
spyOn(formService, 'getWorkflowGroups').and.returnValue(
Observable.create(observer => {
observer.next(groups);
observer.complete();
})
);
widget.groupId = 'parentGroup';
widget.value = 'group';
widget.onKeyUp(null);
expect(formService.getWorkflowGroups).toHaveBeenCalledWith('group', 'parentGroup');
expect(widget.groups).toBe(groups);
expect(widget.popupVisible).toBeTruthy();
});
@ -148,7 +186,7 @@ describe('FunctionalGroupWidget', () => {
widget.value = 'group';
widget.onKeyUp(null);
expect(formService.getWorkflowGroups).toHaveBeenCalledWith('group');
expect(formService.getWorkflowGroups).toHaveBeenCalledWith('group', undefined);
expect(widget.groups.length).toBe(0);
expect(widget.popupVisible).toBeFalsy();
});

View File

@ -34,6 +34,7 @@ export class FunctionalGroupWidget extends WidgetComponent implements OnInit {
popupVisible: boolean = false;
groups: GroupModel[] = [];
minTermLength: number = 1;
groupId: string;
constructor(private formService: FormService) {
super();
@ -42,15 +43,23 @@ export class FunctionalGroupWidget extends WidgetComponent implements OnInit {
// TODO: investigate, called 2 times
// https://github.com/angular/angular/issues/6782
ngOnInit() {
let group = this.field.value;
if (group) {
this.value = group.name;
if (this.field) {
let group = this.field.value;
if (group) {
this.value = group.name;
}
let params = this.field.params;
if (params && params['restrictWithGroup']) {
let restrictWithGroup = <GroupModel> params['restrictWithGroup'];
this.groupId = restrictWithGroup.id;
}
}
}
onKeyUp(event: KeyboardEvent) {
if (this.value && this.value.length >= this.minTermLength) {
this.formService.getWorkflowGroups(this.value)
this.formService.getWorkflowGroups(this.value, this.groupId)
.subscribe((result: GroupModel[]) => {
this.groups = result || [];
this.popupVisible = this.groups.length > 0;

View File

@ -212,7 +212,7 @@ export class FormService {
}
// TODO: uses private webApp api
getWorkflowGroups(filter: string): Observable<GroupModel[]> {
getWorkflowGroups(filter: string, groupId?: string): Observable<GroupModel[]> {
return Observable.create(observer => {
let xhr: XMLHttpRequest = new XMLHttpRequest();
@ -235,6 +235,9 @@ export class FormService {
let host = this.apiService.getInstance().config.hostBpm;
let url = `${host}/activiti-app/app/rest/workflow-groups?filter=${filter}`;
if (groupId) {
url += `&groupId=${groupId}`;
}
xhr.open('GET', url, true);
xhr.setRequestHeader('Authorization', this.apiService.getInstance().getTicketBpm());
xhr.send();