0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-11-23 18:00:29 +01:00
discourse-custom-wizard/assets/javascripts/discourse/controllers/admin-wizards-logs.js.es6

51 Zeilen
1,1 KiB
Text

2021-04-12 07:44:47 +02:00
import discourseComputed from "discourse-common/utils/decorators";
2020-04-15 02:46:44 +02:00
import { notEmpty } from "@ember/object/computed";
import CustomWizardLogs from "../models/custom-wizard-logs";
2020-05-28 03:26:39 +02:00
import Controller from "@ember/controller";
2020-04-15 02:46:44 +02:00
2020-05-28 03:26:39 +02:00
export default Controller.extend({
2020-04-15 02:46:44 +02:00
refreshing: false,
hasLogs: notEmpty("logs"),
page: 0,
canLoadMore: true,
logs: [],
2020-04-15 02:46:44 +02:00
loadLogs() {
2021-04-12 08:12:20 +02:00
if (!this.canLoadMore) {
return;
}
2020-04-15 02:46:44 +02:00
this.set("refreshing", true);
2020-04-15 04:10:39 +02:00
CustomWizardLogs.list()
.then((result) => {
2020-04-15 02:46:44 +02:00
if (!result || result.length === 0) {
this.set("canLoadMore", false);
2020-04-15 02:46:44 +02:00
}
this.set("logs", this.logs.concat(result));
})
.finally(() => this.set("refreshing", false));
},
2021-04-12 07:44:47 +02:00
@discourseComputed("hasLogs", "refreshing")
2020-04-15 02:46:44 +02:00
noResults(hasLogs, refreshing) {
return !hasLogs && !refreshing;
},
2020-04-15 02:46:44 +02:00
actions: {
loadMore() {
this.set("page", (this.page += 1));
2020-04-15 02:46:44 +02:00
this.loadLogs();
},
2020-04-15 02:46:44 +02:00
refresh() {
this.setProperties({
canLoadMore: true,
page: 0,
logs: [],
});
2020-04-15 02:46:44 +02:00
this.loadLogs();
},
},
});