2019-10-30 21:48:24 +08:00
|
|
|
import { debounce } from "@ember/runloop";
|
2019-10-24 01:06:54 +08:00
|
|
|
import Controller from "@ember/controller";
|
2018-12-19 21:44:43 +08:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
const { get } = Ember;
|
|
|
|
|
2019-10-24 01:06:54 +08:00
|
|
|
export default Controller.extend({
|
2018-12-19 21:44:43 +08:00
|
|
|
filter: null,
|
|
|
|
|
|
|
|
@computed("model.[]", "filter")
|
|
|
|
filterReports(reports, filter) {
|
|
|
|
if (filter) {
|
|
|
|
filter = filter.toLowerCase();
|
|
|
|
return reports.filter(report => {
|
|
|
|
return (
|
|
|
|
(get(report, "title") || "").toLowerCase().indexOf(filter) > -1 ||
|
|
|
|
(get(report, "description") || "").toLowerCase().indexOf(filter) > -1
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return reports;
|
|
|
|
},
|
|
|
|
|
|
|
|
actions: {
|
|
|
|
filterReports(filter) {
|
2019-10-30 21:48:24 +08:00
|
|
|
debounce(this, this._performFiltering, filter, 250);
|
2018-12-19 21:44:43 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_performFiltering(filter) {
|
|
|
|
this.set("filter", filter);
|
|
|
|
}
|
|
|
|
});
|