2019-10-30 21:48:24 +08:00
|
|
|
import { observes, on } from "discourse-common/utils/decorators";
|
2019-10-24 00:30:52 +08:00
|
|
|
import Component from "@ember/component";
|
2020-05-14 04:23:41 +08:00
|
|
|
import I18n from "I18n";
|
2020-12-18 21:18:52 +08:00
|
|
|
import discourseDebounce from "discourse-common/lib/debounce";
|
2019-11-08 05:38:28 +08:00
|
|
|
import { scheduleOnce } from "@ember/runloop";
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2019-12-10 05:42:08 +08:00
|
|
|
export default Component.extend({
|
|
|
|
classNames: ["admin-backups-logs"],
|
|
|
|
showLoadingSpinner: false,
|
|
|
|
hasFormattedLogs: false,
|
|
|
|
noLogsMessage: I18n.t("admin.backups.logs.none"),
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2019-12-10 05:42:08 +08:00
|
|
|
init() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this._reset();
|
|
|
|
},
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2019-12-10 05:42:08 +08:00
|
|
|
_reset() {
|
|
|
|
this.setProperties({ formattedLogs: "", index: 0 });
|
|
|
|
},
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2019-12-10 05:42:08 +08:00
|
|
|
_scrollDown() {
|
|
|
|
const div = this.element;
|
|
|
|
div.scrollTop = div.scrollHeight;
|
|
|
|
},
|
2016-10-27 23:57:33 +08:00
|
|
|
|
2019-12-10 05:42:08 +08:00
|
|
|
@on("init")
|
|
|
|
@observes("logs.[]")
|
|
|
|
_resetFormattedLogs() {
|
|
|
|
if (this.logs.length === 0) {
|
|
|
|
this._reset(); // reset the cached logs whenever the model is reset
|
|
|
|
this.renderLogs();
|
|
|
|
}
|
|
|
|
},
|
2018-09-20 02:00:03 +08:00
|
|
|
|
2020-12-18 21:18:52 +08:00
|
|
|
_updateFormattedLogsFunc: function () {
|
2019-12-10 05:42:08 +08:00
|
|
|
const logs = this.logs;
|
2020-09-22 22:28:28 +08:00
|
|
|
if (logs.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2018-09-20 02:00:03 +08:00
|
|
|
|
2019-12-10 05:42:08 +08:00
|
|
|
// do the log formatting only once for HELLish performance
|
|
|
|
let formattedLogs = this.formattedLogs;
|
|
|
|
for (let i = this.index, length = logs.length; i < length; i++) {
|
|
|
|
const date = logs[i].get("timestamp"),
|
|
|
|
message = logs[i].get("message");
|
|
|
|
formattedLogs += "[" + date + "] " + message + "\n";
|
|
|
|
}
|
|
|
|
// update the formatted logs & cache index
|
|
|
|
this.setProperties({
|
|
|
|
formattedLogs: formattedLogs,
|
|
|
|
index: logs.length,
|
|
|
|
});
|
|
|
|
// force rerender
|
|
|
|
this.renderLogs();
|
2018-09-20 02:00:03 +08:00
|
|
|
|
2019-12-10 05:42:08 +08:00
|
|
|
scheduleOnce("afterRender", this, this._scrollDown);
|
2020-12-18 21:18:52 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
@on("init")
|
|
|
|
@observes("logs.[]")
|
|
|
|
_updateFormattedLogs() {
|
|
|
|
discourseDebounce(this, this._updateFormattedLogsFunc, 150);
|
|
|
|
},
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2019-12-10 05:42:08 +08:00
|
|
|
renderLogs() {
|
|
|
|
const formattedLogs = this.formattedLogs;
|
|
|
|
if (formattedLogs && formattedLogs.length > 0) {
|
|
|
|
this.set("hasFormattedLogs", true);
|
|
|
|
} else {
|
|
|
|
this.set("hasFormattedLogs", false);
|
|
|
|
}
|
|
|
|
// add a loading indicator
|
|
|
|
if (this.get("status.isOperationRunning")) {
|
|
|
|
this.set("showLoadingSpinner", true);
|
|
|
|
} else {
|
|
|
|
this.set("showLoadingSpinner", false);
|
2014-02-13 12:35:46 +08:00
|
|
|
}
|
2019-12-10 05:42:08 +08:00
|
|
|
},
|
|
|
|
});
|