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