mirror of
https://github.com/fluent/fluentd-ui.git
synced 2025-08-09 07:47:07 +02:00
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
(function(){
|
|
"use strict";
|
|
|
|
$(function(){
|
|
if($('#fluent-log').length === 0) return;
|
|
|
|
new Vue({
|
|
el: "#fluent-log",
|
|
paramAttributes: ["logUrl"],
|
|
data: {
|
|
"autoFetch": false,
|
|
"logs": [],
|
|
"limit": 30,
|
|
"processing": false
|
|
},
|
|
|
|
created: function(){
|
|
this.fetchLogs();
|
|
|
|
var self = this;
|
|
var timer;
|
|
this.$watch("autoFetch", function(newValue){
|
|
if(newValue === true) {
|
|
timer = setInterval(function(){
|
|
self.fetchLogs();
|
|
var $log = $(".log", self.$el);
|
|
$log.scrollTop($log[0].scrollHeight);
|
|
}, 1000);
|
|
} else {
|
|
clearInterval(timer);
|
|
}
|
|
});
|
|
},
|
|
|
|
methods: {
|
|
fetchLogs: function() {
|
|
if(this.processing) return;
|
|
this.processing = true;
|
|
var self = this;
|
|
new Promise(function(resolve, reject) {
|
|
$.getJSON(self.logUrl + "?limit=" + self.limit, resolve).fail(reject);
|
|
}).then(function(logs){
|
|
self.logs = logs;
|
|
setTimeout(function(){
|
|
self.processing = false;
|
|
}, 256); // delay to reduce flicking loading icon
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
})();
|
|
|