Search user in admin panel

This commit is contained in:
guillaume 2019-04-19 14:57:52 +02:00
parent 9c3a976250
commit 308417852c
3 changed files with 43 additions and 3 deletions

View file

@ -8,6 +8,7 @@ BlazeComponent.extendComponent({
this.error = new ReactiveVar('');
this.loading = new ReactiveVar(false);
this.people = new ReactiveVar(true);
this.findUsersOptions = new ReactiveVar({});
this.page = new ReactiveVar(1);
this.loadNextPageLocked = false;
@ -26,6 +27,25 @@ BlazeComponent.extendComponent({
});
});
},
events() {
return [{
'click #searchButton'(event) {
const value = $('#searchInput').first().val();
if (value === '') {
this.findUsersOptions.set({});
} else {
const regex = new RegExp(value, 'i');
this.findUsersOptions.set({
$or: [
{ username: regex },
{ 'profile.fullname': regex },
{ 'emails.address': regex },
]
});
}
}
}];
},
loadNextPage() {
if (this.loadNextPageLocked === false) {
this.page.set(this.page.get() + 1);
@ -49,7 +69,8 @@ BlazeComponent.extendComponent({
this.loading.set(w);
},
peopleList() {
return Users.find({}, {
// get users in front to cache them
return Users.find(this.findUsersOptions.get(), {
fields: {_id: true},
});
},