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