discourse/app/assets/javascripts/admin/addon/controllers/admin-email-logs.js
Kris f0069a4fab
REFACTOR: modernize email logs, fix filtering (#34015)
Started off attempting to fix filters, but was frustrated working with
the old patterns and template duplication so I've updated everything and
tried to consolidate into a `email-logs-list.gjs` component.

The primary issue was that the filters only worked once, and if you
needed to change them or remove them... you couldn't and had to refresh
the page.


Before: 


https://github.com/user-attachments/assets/9cfa0328-41d4-4178-ab87-ba2ff495d932



After:


https://github.com/user-attachments/assets/febcff8f-3dfa-4b86-9be1-f333e6502648
2025-08-27 13:43:12 -04:00

62 lines
1.4 KiB
JavaScript
Vendored

import { tracked } from "@glimmer/tracking";
import Controller from "@ember/controller";
import { action } from "@ember/object";
import EmailLog from "admin/models/email-log";
export default class AdminEmailLogsController extends Controller {
@tracked loading = false;
@tracked status = "";
filters = []; // populated by child controllers
loadLogs(sourceModel, loadMore) {
if (
(loadMore && this.loading) ||
(loadMore && this.get("model.allLoaded"))
) {
return;
}
this.set("loading", true);
if (!loadMore && this.model) {
this.model.set("allLoaded", false);
}
sourceModel = sourceModel || EmailLog;
let filterArgs = this.getFilterArgs();
return sourceModel
.findAll(filterArgs, loadMore ? this.get("model.length") : null)
.then((logs) => {
if (this.model && loadMore && logs.length < 50) {
this.model.set("allLoaded", true);
}
if (this.model && loadMore) {
this.model.addObjects(logs);
} else {
this.set("model", logs);
}
})
.finally(() => this.set("loading", false));
}
getFilterArgs() {
const args = { status: this.status };
this.filters.forEach(({ property, name }) => {
const value = this[property];
if (value) {
args[name] = value;
}
});
return args;
}
@action
loadMore() {
this.loadLogs(EmailLog, true);
}
}