Skip to content
Snippets Groups Projects
Verified Commit 56ef103b authored by Alex ORLUC's avatar Alex ORLUC
Browse files

FIX #8101 change autocomplete in ajax mode

parent 3f51f59a
No related branches found
No related tags found
No related merge requests found
...@@ -44,17 +44,21 @@ export class AutoCompletePlugin { ...@@ -44,17 +44,21 @@ export class AutoCompletePlugin {
} }
if (target.indexOf('adminUsers') != -1) { if (target.indexOf('adminUsers') != -1) {
this.userCtrl = new FormControl(); this.userCtrl = new FormControl();
this.http.get(this.coreUrl + 'rest/autocomplete/users/administration') this.userCtrl.valueChanges.pipe(
.subscribe((data: any) => { debounceTime(300),
this.userList = data; filter(value => value.length > 2),
this.filteredUsers = this.userCtrl.valueChanges distinctUntilChanged(),
.pipe( switchMap(data => this.http.get(this.coreUrl + 'rest/autocomplete/users/administration', { params: { "search": data } }))
startWith(''), ).subscribe((response: any) => {
map(user => user ? this.autocompleteFilterUser(user) : this.userList.slice()) if (response.length == 0) {
); this.userCtrl.setErrors({'noResult': true})
}, () => { }
location.href = "index.php"; this.filteredUsers = this.userCtrl.valueChanges
}); .pipe(
startWith(''),
map(user => user ? this.autocompleteFilterUser(user) : response.slice())
);
});
} }
if (target.indexOf('statuses') != -1) { if (target.indexOf('statuses') != -1) {
...@@ -75,55 +79,68 @@ export class AutoCompletePlugin { ...@@ -75,55 +79,68 @@ export class AutoCompletePlugin {
this.elementCtrl = new FormControl(); this.elementCtrl = new FormControl();
this.elemList = []; this.elemList = [];
this.http.get(this.coreUrl + 'rest/autocomplete/users') this.elementCtrl.valueChanges.pipe(
.subscribe((data: any) => { debounceTime(300),
this.elemList = data; filter(value => value.length > 2),
distinctUntilChanged(),
this.http.get(this.coreUrl + 'rest/autocomplete/entities') switchMap(data => this.http.get(this.coreUrl + 'rest/autocomplete/users', { params: { "search": data } }))
.subscribe((data: any) => { ).subscribe((response: any) => {
this.elemList = this.elemList.concat(data); this.elemList = response;
this.filteredElements = this.elementCtrl.valueChanges });
.pipe(
startWith(''),
map(elem => elem ? this.autocompleteFilterElements(elem) : this.elemList.slice())
);
}, () => {
location.href = "index.php";
});
}, () => {
location.href = "index.php";
});
this.elementCtrl.valueChanges.pipe(
debounceTime(300),
filter(value => value.length > 2),
distinctUntilChanged(),
switchMap(data => this.http.get(this.coreUrl + 'rest/autocomplete/entities', { params: { "search": data } }))
).subscribe((response: any) => {
this.elemList = this.elemList.concat(response);
if (this.elemList.length == 0) {
this.elementCtrl.setErrors({'noResult': true})
}
this.filteredElements = this.elementCtrl.valueChanges
.pipe(
startWith(''),
map(elem => elem ? this.autocompleteFilterUser(elem) : this.elemList.slice())
);
});
} }
if (target.indexOf('entities') != -1) { if (target.indexOf('entities') != -1) {
this.elementCtrl = new FormControl(); this.elementCtrl = new FormControl();
this.elemList = []; this.elementCtrl.valueChanges.pipe(
this.http.get(this.coreUrl + 'rest/autocomplete/entities') debounceTime(300),
.subscribe((data: any) => { filter(value => value.length > 2),
this.elemList = data; distinctUntilChanged(),
this.filteredElements = this.elementCtrl.valueChanges switchMap(data => this.http.get(this.coreUrl + 'rest/autocomplete/entities', { params: { "search": data } }))
.pipe( ).subscribe((response: any) => {
startWith(''), if (response.length == 0) {
map(elem => elem ? this.autocompleteFilterElements(elem) : this.elemList.slice()) this.elementCtrl.setErrors({'noResult': true})
); }
}, () => { this.filteredElements = this.elementCtrl.valueChanges
location.href = "index.php"; .pipe(
}); startWith(''),
map(elem => elem ? this.autocompleteFilterUser(elem) : response.slice())
);
});
} else if (target.indexOf('visaUsers') != -1) { } else if (target.indexOf('visaUsers') != -1) {
this.visaUserCtrl = new FormControl(); this.visaUserCtrl = new FormControl();
this.http.get(this.coreUrl + 'rest/autocomplete/users/visa') this.visaUserCtrl.valueChanges.pipe(
.subscribe((data: any) => { debounceTime(300),
this.visaUserList = data; filter(value => value.length > 2),
this.filteredVisaUsers = this.visaUserCtrl.valueChanges distinctUntilChanged(),
.pipe( switchMap(data => this.http.get(this.coreUrl + 'rest/autocomplete/users/visa', { params: { "search": data } }))
startWith(''), ).subscribe((response: any) => {
map(user => user ? this.autocompleteFilterUser(user) : this.visaUserList.slice()) if (response.length == 0) {
); this.visaUserCtrl.setErrors({'noResult': true})
}, () => { }
location.href = "index.php"; this.filteredVisaUsers = this.visaUserCtrl.valueChanges
}); .pipe(
startWith(''),
map(user => user ? this.autocompleteFilterUser(user) : response.slice())
);
});
} else { } else {
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment