2021-02-24 08:43:35 +01:00
|
|
|
import { default as computed } from "discourse-common/utils/decorators";
|
|
|
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2020-04-15 02:46:44 +02:00
|
|
|
import { notEmpty } from "@ember/object/computed";
|
2021-02-24 08:43:35 +01:00
|
|
|
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: [],
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-04-15 02:46:44 +02:00
|
|
|
loadLogs() {
|
|
|
|
if (!this.canLoadMore) return;
|
|
|
|
|
|
|
|
this.set("refreshing", true);
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-04-15 04:10:39 +02:00
|
|
|
CustomWizardLogs.list()
|
2021-02-24 08:43:35 +01:00
|
|
|
.then((result) => {
|
2020-04-15 02:46:44 +02:00
|
|
|
if (!result || result.length === 0) {
|
2021-02-24 08:43:35 +01:00
|
|
|
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-02-24 08:43:35 +01:00
|
|
|
|
|
|
|
@computed("hasLogs", "refreshing")
|
2020-04-15 02:46:44 +02:00
|
|
|
noResults(hasLogs, refreshing) {
|
|
|
|
return !hasLogs && !refreshing;
|
|
|
|
},
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-04-15 02:46:44 +02:00
|
|
|
actions: {
|
|
|
|
loadMore() {
|
2021-02-24 08:43:35 +01:00
|
|
|
this.set("page", (this.page += 1));
|
2020-04-15 02:46:44 +02:00
|
|
|
this.loadLogs();
|
|
|
|
},
|
2021-02-24 08:43:35 +01:00
|
|
|
|
2020-04-15 02:46:44 +02:00
|
|
|
refresh() {
|
|
|
|
this.setProperties({
|
|
|
|
canLoadMore: true,
|
|
|
|
page: 0,
|
2021-02-24 08:43:35 +01:00
|
|
|
logs: [],
|
|
|
|
});
|
2020-04-15 02:46:44 +02:00
|
|
|
this.loadLogs();
|
2021-02-24 08:43:35 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|