2019-11-08 05:38:28 +08:00
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
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";
|
2019-11-08 05:38:28 +08:00
|
|
|
|
2018-12-19 21:44:43 +08:00
|
|
|
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,
|
|
|
|
|
2019-11-08 05:38:28 +08:00
|
|
|
@discourseComputed("model.[]", "filter")
|
2018-12-19 21:44:43 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
});
|