discourse/app/assets/javascripts/admin/views/admin-backups-logs.js.es6

54 lines
1.8 KiB
Text
Raw Permalink Normal View History

2015-08-10 17:11:27 -04:00
import debounce from 'discourse/lib/debounce';
2014-11-13 14:15:36 -05:00
import { renderSpinner } from 'discourse/helpers/loading-spinner';
import { escapeExpression } from 'discourse/lib/utilities';
2014-02-12 23:35:46 -05:00
export default Ember.View.extend({
2014-02-12 23:35:46 -05:00
classNames: ["admin-backups-logs"],
_initialize: function() { this._reset(); }.on("init"),
_reset() {
2014-02-12 23:35:46 -05:00
this.setProperties({ formattedLogs: "", index: 0 });
},
2015-08-10 17:11:27 -04:00
_updateFormattedLogs: debounce(function() {
const logs = this.get("controller.model");
2014-02-12 23:35:46 -05:00
if (logs.length === 0) {
this._reset(); // reset the cached logs whenever the model is reset
} else {
// do the log formatting only once for HELLish performance
let formattedLogs = this.get("formattedLogs");
for (let i = this.get("index"), length = logs.length; i < length; i++) {
const date = logs[i].get("timestamp"),
message = escapeExpression(logs[i].get("message"));
2014-02-12 23:35:46 -05:00
formattedLogs += "[" + date + "] " + message + "\n";
}
// update the formatted logs & cache index
this.setProperties({ formattedLogs: formattedLogs, index: logs.length });
// force rerender
this.rerender();
}
}, 150).observes("controller.model.[]"),
2014-02-12 23:35:46 -05:00
render(buffer) {
const formattedLogs = this.get("formattedLogs");
2014-02-12 23:35:46 -05:00
if (formattedLogs && formattedLogs.length > 0) {
buffer.push("<pre>");
buffer.push(formattedLogs);
buffer.push("</pre>");
} else {
buffer.push("<p>" + I18n.t("admin.backups.logs.none") + "</p>");
}
// add a loading indicator
if (this.get("controller.status.model.isOperationRunning")) {
2014-11-13 14:15:36 -05:00
buffer.push(renderSpinner('small'));
2014-02-12 23:35:46 -05:00
}
},
_forceScrollToBottom: function() {
const $div = this.$()[0];
2014-02-12 23:35:46 -05:00
$div.scrollTop = $div.scrollHeight;
}.on("didInsertElement")
});