2015-08-11 05:11:27 +08:00
|
|
|
import debounce from 'discourse/lib/debounce';
|
2014-11-14 03:15:36 +08:00
|
|
|
import { renderSpinner } from 'discourse/helpers/loading-spinner';
|
2016-06-15 02:31:51 +08:00
|
|
|
import { escapeExpression } from 'discourse/lib/utilities';
|
2016-10-25 03:21:44 +08:00
|
|
|
import { bufferedRender } from 'discourse-common/lib/buffered-render';
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2016-10-25 03:21:44 +08:00
|
|
|
export default Ember.Component.extend(bufferedRender({
|
2014-02-13 12:35:46 +08:00
|
|
|
classNames: ["admin-backups-logs"],
|
|
|
|
|
2016-10-21 01:26:41 +08:00
|
|
|
init() {
|
|
|
|
this._super();
|
|
|
|
this._reset();
|
|
|
|
},
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2015-08-07 23:34:58 +08:00
|
|
|
_reset() {
|
2014-02-13 12:35:46 +08:00
|
|
|
this.setProperties({ formattedLogs: "", index: 0 });
|
|
|
|
},
|
|
|
|
|
2016-10-27 23:57:33 +08:00
|
|
|
_scrollDown() {
|
|
|
|
const $div = this.$()[0];
|
|
|
|
$div.scrollTop = $div.scrollHeight;
|
|
|
|
},
|
|
|
|
|
2015-08-11 05:11:27 +08:00
|
|
|
_updateFormattedLogs: debounce(function() {
|
2016-10-21 01:26:41 +08:00
|
|
|
const logs = this.get("logs");
|
2014-02-13 12:35:46 +08: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
|
2015-08-07 23:34:58 +08:00
|
|
|
let formattedLogs = this.get("formattedLogs");
|
|
|
|
for (let i = this.get("index"), length = logs.length; i < length; i++) {
|
|
|
|
const date = logs[i].get("timestamp"),
|
2016-06-15 02:31:51 +08:00
|
|
|
message = escapeExpression(logs[i].get("message"));
|
2014-02-13 12:35:46 +08:00
|
|
|
formattedLogs += "[" + date + "] " + message + "\n";
|
|
|
|
}
|
|
|
|
// update the formatted logs & cache index
|
|
|
|
this.setProperties({ formattedLogs: formattedLogs, index: logs.length });
|
|
|
|
// force rerender
|
2016-10-25 03:21:44 +08:00
|
|
|
this.rerenderBuffer();
|
2014-02-13 12:35:46 +08:00
|
|
|
}
|
2016-10-27 23:57:33 +08:00
|
|
|
Ember.run.scheduleOnce('afterRender', this, this._scrollDown);
|
2016-10-21 01:26:41 +08:00
|
|
|
}, 150).observes("logs.[]").on('init'),
|
2014-02-13 12:35:46 +08:00
|
|
|
|
2016-10-25 03:21:44 +08:00
|
|
|
buildBuffer(buffer) {
|
2015-08-07 23:34:58 +08:00
|
|
|
const formattedLogs = this.get("formattedLogs");
|
2014-02-13 12:35:46 +08: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
|
2016-10-21 01:26:41 +08:00
|
|
|
if (this.get("status.isOperationRunning")) {
|
2014-11-14 03:15:36 +08:00
|
|
|
buffer.push(renderSpinner('small'));
|
2014-02-13 12:35:46 +08:00
|
|
|
}
|
2016-10-27 23:57:33 +08:00
|
|
|
}
|
2016-10-25 03:21:44 +08:00
|
|
|
}));
|