mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
Merge pull request #720 from Alfresco/dev-denys--groups-widget
#636 fix group filter
This commit is contained in:
commit
390bedf1d6
@ -47,6 +47,23 @@ describe('FunctionalGroupWidget', () => {
|
|||||||
expect(widget.value).toBeUndefined();
|
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) => {
|
it('should flush value on blur', (done) => {
|
||||||
spyOn(widget, 'flushValue').and.stub();
|
spyOn(widget, 'flushValue').and.stub();
|
||||||
widget.onBlur();
|
widget.onBlur();
|
||||||
@ -132,7 +149,28 @@ describe('FunctionalGroupWidget', () => {
|
|||||||
widget.value = 'group';
|
widget.value = 'group';
|
||||||
widget.onKeyUp(null);
|
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.groups).toBe(groups);
|
||||||
expect(widget.popupVisible).toBeTruthy();
|
expect(widget.popupVisible).toBeTruthy();
|
||||||
});
|
});
|
||||||
@ -148,7 +186,7 @@ describe('FunctionalGroupWidget', () => {
|
|||||||
widget.value = 'group';
|
widget.value = 'group';
|
||||||
widget.onKeyUp(null);
|
widget.onKeyUp(null);
|
||||||
|
|
||||||
expect(formService.getWorkflowGroups).toHaveBeenCalledWith('group');
|
expect(formService.getWorkflowGroups).toHaveBeenCalledWith('group', undefined);
|
||||||
expect(widget.groups.length).toBe(0);
|
expect(widget.groups.length).toBe(0);
|
||||||
expect(widget.popupVisible).toBeFalsy();
|
expect(widget.popupVisible).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
@ -34,6 +34,7 @@ export class FunctionalGroupWidget extends WidgetComponent implements OnInit {
|
|||||||
popupVisible: boolean = false;
|
popupVisible: boolean = false;
|
||||||
groups: GroupModel[] = [];
|
groups: GroupModel[] = [];
|
||||||
minTermLength: number = 1;
|
minTermLength: number = 1;
|
||||||
|
groupId: string;
|
||||||
|
|
||||||
constructor(private formService: FormService) {
|
constructor(private formService: FormService) {
|
||||||
super();
|
super();
|
||||||
@ -42,15 +43,23 @@ export class FunctionalGroupWidget extends WidgetComponent implements OnInit {
|
|||||||
// TODO: investigate, called 2 times
|
// TODO: investigate, called 2 times
|
||||||
// https://github.com/angular/angular/issues/6782
|
// https://github.com/angular/angular/issues/6782
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
if (this.field) {
|
||||||
let group = this.field.value;
|
let group = this.field.value;
|
||||||
if (group) {
|
if (group) {
|
||||||
this.value = group.name;
|
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) {
|
onKeyUp(event: KeyboardEvent) {
|
||||||
if (this.value && this.value.length >= this.minTermLength) {
|
if (this.value && this.value.length >= this.minTermLength) {
|
||||||
this.formService.getWorkflowGroups(this.value)
|
this.formService.getWorkflowGroups(this.value, this.groupId)
|
||||||
.subscribe((result: GroupModel[]) => {
|
.subscribe((result: GroupModel[]) => {
|
||||||
this.groups = result || [];
|
this.groups = result || [];
|
||||||
this.popupVisible = this.groups.length > 0;
|
this.popupVisible = this.groups.length > 0;
|
||||||
|
@ -212,7 +212,7 @@ export class FormService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: uses private webApp api
|
// TODO: uses private webApp api
|
||||||
getWorkflowGroups(filter: string): Observable<GroupModel[]> {
|
getWorkflowGroups(filter: string, groupId?: string): Observable<GroupModel[]> {
|
||||||
return Observable.create(observer => {
|
return Observable.create(observer => {
|
||||||
|
|
||||||
let xhr: XMLHttpRequest = new XMLHttpRequest();
|
let xhr: XMLHttpRequest = new XMLHttpRequest();
|
||||||
@ -235,6 +235,9 @@ export class FormService {
|
|||||||
|
|
||||||
let host = this.apiService.getInstance().config.hostBpm;
|
let host = this.apiService.getInstance().config.hostBpm;
|
||||||
let url = `${host}/activiti-app/app/rest/workflow-groups?filter=${filter}`;
|
let url = `${host}/activiti-app/app/rest/workflow-groups?filter=${filter}`;
|
||||||
|
if (groupId) {
|
||||||
|
url += `&groupId=${groupId}`;
|
||||||
|
}
|
||||||
xhr.open('GET', url, true);
|
xhr.open('GET', url, true);
|
||||||
xhr.setRequestHeader('Authorization', this.apiService.getInstance().getTicketBpm());
|
xhr.setRequestHeader('Authorization', this.apiService.getInstance().getTicketBpm());
|
||||||
xhr.send();
|
xhr.send();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user