Skip to content

Commit

Permalink
add auto scroll and refresh the job log
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhleviet committed Nov 19, 2024
1 parent 221482a commit ea3e69d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
53 changes: 47 additions & 6 deletions src/main/html/webapp/components/core/job/detail/logs/logs.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,59 @@
import $ from 'jquery';
import Control from 'can-control';

import template from './logs.stache';


export default Control.extend({
init: function(element, options) {
this.element = element;
this.options = options;
this.loadLogs();

// Start refresh if job is in running state (state 1, 2, or 3)
if ([1, 2, 3].includes(options.job.attr('state'))) {
this.startRefresh();
}

"init": function(element, options) {
// Listen for state changes
this.options.job.bind('state', (ev, newState) => {
if ([1, 2, 3].includes(newState)) {
this.startRefresh();
} else {
this.stopRefresh();
}
});
},

$.get('logs/' + options.job.attr('id'),function(data) {
$(element).html(template({
loadLogs: function() {
$.get('logs/' + this.options.job.attr('id'), (data) => {
$(this.element).html(template({
content: data,
job: options.job
job: this.options.job
}));

// Auto scroll to bottom after content loads
const preElement = $(this.element).find('pre');
preElement.scrollTop(preElement[0].scrollHeight);
});
},

startRefresh: function() {
if (!this.refreshInterval) {
this.refreshInterval = setInterval(() => {
this.loadLogs();
}, 5000);
}
},

stopRefresh: function() {
if (this.refreshInterval) {
clearInterval(this.refreshInterval);
this.refreshInterval = null;
}
},

destroy: function() {
this.stopRefresh();
this.options.job.unbind('state');
Control.prototype.destroy.call(this);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</div>

<div class="list-group-item flex-column align-items-start" style="padding: 0px;">
<pre class="tomorrow-night-eighties-ansi-theme">{{{ansiToHtml(content)}}}</pre>
<pre class="tomorrow-night-eighties-ansi-theme" style="max-height: 500px; overflow-y: auto; margin-bottom: 0;">{{{ansiToHtml(content)}}}</pre>
</div>
</div>
<br>

0 comments on commit ea3e69d

Please sign in to comment.