|
|
|
@ -30,7 +30,7 @@ import {Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild} f |
|
|
|
|
import {DynamicBootstrapper} from "core-app/globals/dynamic-bootstrapper"; |
|
|
|
|
import {HalResourceService} from "core-app/modules/hal/services/hal-resource.service"; |
|
|
|
|
import {PathHelperService} from "core-app/modules/common/path-helper/path-helper.service"; |
|
|
|
|
import {ApiV3FilterBuilder} from "core-components/api/api-v3/api-v3-filter-builder"; |
|
|
|
|
import {ApiV3FilterBuilder, FilterOperator} from "core-components/api/api-v3/api-v3-filter-builder"; |
|
|
|
|
import {NgSelectComponent} from "@ng-select/ng-select/dist"; |
|
|
|
|
import {I18nService} from "core-app/modules/common/i18n/i18n.service"; |
|
|
|
|
|
|
|
|
@ -70,6 +70,7 @@ export class UserAutocompleterComponent implements OnInit { |
|
|
|
|
private updateInputField:HTMLInputElement|undefined; |
|
|
|
|
|
|
|
|
|
public options:any[]; |
|
|
|
|
public filters:ApiV3FilterBuilder = new ApiV3FilterBuilder(); |
|
|
|
|
|
|
|
|
|
constructor(protected elementRef:ElementRef, |
|
|
|
|
protected halResourceService:HalResourceService, |
|
|
|
@ -80,6 +81,7 @@ export class UserAutocompleterComponent implements OnInit { |
|
|
|
|
ngOnInit() { |
|
|
|
|
const input = this.elementRef.nativeElement.dataset['updateInput']; |
|
|
|
|
const allowEmpty = this.elementRef.nativeElement.dataset['allowEmpty']; |
|
|
|
|
|
|
|
|
|
if (input) { |
|
|
|
|
this.updateInputField = document.getElementsByName(input)[0] as HTMLInputElement|undefined; |
|
|
|
|
this.setInitialSelection(); |
|
|
|
@ -89,13 +91,21 @@ export class UserAutocompleterComponent implements OnInit { |
|
|
|
|
this.allowEmpty = true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setAvailableUsers(this.url, ''); |
|
|
|
|
|
|
|
|
|
let filterInput = this.elementRef.nativeElement.dataset['additionalFilter']; |
|
|
|
|
if (filterInput) { |
|
|
|
|
JSON.parse(filterInput).forEach((filter:{selector:string; operator:FilterOperator, values:string[]}) => { |
|
|
|
|
this.filters.add(filter['selector'], filter['operator'], filter['values']); |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setAvailableUsers(this.url, this.filters); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public onModelChange(user:any) { |
|
|
|
|
if (user) { |
|
|
|
|
this.onChange.emit(user); |
|
|
|
|
this.setAvailableUsers(this.url, ''); |
|
|
|
|
this.setAvailableUsers(this.url, this.filters); |
|
|
|
|
|
|
|
|
|
if (this.clearAfterSelection) { |
|
|
|
|
this.ngSelectComponent.clearItem(user); |
|
|
|
@ -108,24 +118,26 @@ export class UserAutocompleterComponent implements OnInit { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public onSearch($event:any) { |
|
|
|
|
let urlQuery:any; |
|
|
|
|
let newFilters = this.filters; |
|
|
|
|
if($event) { |
|
|
|
|
let filters = new ApiV3FilterBuilder(); |
|
|
|
|
filters.add('name', '~', [$event]); |
|
|
|
|
urlQuery = { filters: filters.toJson() }; |
|
|
|
|
newFilters.add('name', '~', [$event]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.setAvailableUsers(this.url, urlQuery); |
|
|
|
|
this.setAvailableUsers(this.url, newFilters); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public onFocus(){ |
|
|
|
|
// For dynamic changes of the available users
|
|
|
|
|
// we have to reload them on focus (e.g. watchers)
|
|
|
|
|
this.setAvailableUsers(this.url, ''); |
|
|
|
|
this.setAvailableUsers(this.url, this.filters); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private setAvailableUsers(url:string, filters:any) { |
|
|
|
|
this.halResourceService.get(url, filters) |
|
|
|
|
private setAvailableUsers(url:string, filters:ApiV3FilterBuilder) { |
|
|
|
|
let params = { |
|
|
|
|
filters: filters.toJson() |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
this.halResourceService.get(url, params) |
|
|
|
|
.subscribe(res => { |
|
|
|
|
this.options = res.elements.map((el:any) => { |
|
|
|
|
return {name: el.name, id: el.id, href: el.href, avatar: el.avatar}; |
|
|
|
|