Added basic search to members list

This commit is contained in:
Kevin Ansfield 2019-02-23 17:14:00 +07:00
parent bb2c5426bc
commit 49942f5604
2 changed files with 27 additions and 2 deletions

View File

@ -1,4 +1,5 @@
import Controller from '@ember/controller';
import {computed} from '@ember/object';
import {inject as service} from '@ember/service';
import {task} from 'ember-concurrency';
@ -8,12 +9,30 @@ export default Controller.extend({
meta: null,
members: null,
searchText: '',
init() {
this._super(...arguments);
this.set('members', this.store.peekAll('member'));
},
filteredMembers: computed('members.@each.{name,email}', 'searchText', function () {
let {members, searchText} = this;
searchText = searchText.toLowerCase();
let filtered = members.filter((member) => {
if (!searchText) {
return true;
}
let {name, email} = member;
return name.toLowerCase().indexOf(searchText) >= 0
|| email.toLowerCase().indexOf(searchText) >= 0;
});
return filtered;
}),
fetchMembers: task(function* () {
let newFetchDate = new Date();
let results;

View File

@ -13,13 +13,19 @@
(Loading...)
{{/if}}
</h2>
<div>
<GhTextInput
placeholder="Search..."
@value={{this.searchText}}
@input={{action (mut this.searchText) value="target.value"}} />
</div>
</div>
{{#if this.members}}
{{#if this.filteredMembers}}
{{!-- members list, styles taken from .apps-grid --}}
<div class="flex flex-row flex-wrap items-start ba br3 b--whitegrey mt2 mb10">
<VerticalCollection
@items={{this.members}}
@items={{this.filteredMembers}}
@key="id"
@containerSelector=".gh-main"
@estimateHeight=76