forked from genepi/cloudgene3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add auto scroll and refresh the job log
- Loading branch information
1 parent
221482a
commit ea3e69d
Showing
2 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
53 changes: 47 additions & 6 deletions
53
src/main/html/webapp/components/core/job/detail/logs/logs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters