2019-10-23 13:06:54 -04:00
|
|
|
import Controller from "@ember/controller";
|
2016-01-18 18:57:55 -05:00
|
|
|
import EmailLog from "admin/models/email-log";
|
2023-03-15 05:42:12 -04:00
|
|
|
import EmberObject, { action } from "@ember/object";
|
2016-01-18 18:57:55 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
export default class AdminEmailLogsController extends Controller {
|
|
|
|
loading = false;
|
|
|
|
filter = EmberObject.create();
|
2016-03-25 11:37:26 -04:00
|
|
|
|
2019-02-26 11:53:52 -05:00
|
|
|
loadLogs(sourceModel, loadMore) {
|
2019-05-27 04:15:39 -04:00
|
|
|
if ((loadMore && this.loading) || this.get("model.allLoaded")) {
|
2019-02-26 11:53:52 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.set("loading", true);
|
|
|
|
|
|
|
|
sourceModel = sourceModel || EmailLog;
|
2016-03-25 11:37:26 -04:00
|
|
|
|
2020-10-09 14:53:40 -04:00
|
|
|
let args = {};
|
|
|
|
Object.keys(this.filter).forEach((k) => {
|
|
|
|
if (this.filter[k]) {
|
|
|
|
args[k] = this.filter[k];
|
|
|
|
}
|
|
|
|
});
|
2019-02-26 11:53:52 -05:00
|
|
|
return sourceModel
|
2020-10-09 14:53:40 -04:00
|
|
|
.findAll(args, loadMore ? this.get("model.length") : null)
|
2019-02-26 11:53:52 -05:00
|
|
|
.then((logs) => {
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.model && loadMore && logs.length < 50) {
|
|
|
|
this.model.set("allLoaded", true);
|
2019-02-26 11:53:52 -05:00
|
|
|
}
|
|
|
|
|
2019-05-27 04:15:39 -04:00
|
|
|
if (this.model && loadMore) {
|
|
|
|
this.model.addObjects(logs);
|
2019-02-26 11:53:52 -05:00
|
|
|
} else {
|
|
|
|
this.set("model", logs);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.finally(() => this.set("loading", false));
|
2023-03-15 05:42:12 -04:00
|
|
|
}
|
2019-02-26 11:53:52 -05:00
|
|
|
|
2023-03-15 05:42:12 -04:00
|
|
|
@action
|
|
|
|
loadMore() {
|
|
|
|
this.loadLogs(EmailLog, true);
|
|
|
|
}
|
|
|
|
}
|