Created
May 30, 2021 08:17
-
-
Save hoangsetup/f7d579174c6bf2bfe88f9d4c7dbdc15d to your computer and use it in GitHub Desktop.
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
diff --git a/public/js/main.js b/public/js/main.js | |
index 1274c8a..a2e19e7 100644 | |
--- a/public/js/main.js | |
+++ b/public/js/main.js | |
@@ -1,5 +1,7 @@ | |
(function ($, window, document) { | |
$(async function () { | |
+ const socket = io(); | |
+ | |
function getStatusBadge(status) { | |
switch (status) { | |
case "stopped": | |
@@ -17,6 +19,9 @@ | |
<button type="button" class="btn btn-outline-danger" data-action="stop" title="stop"> | |
<i class="bi bi-pause-circle"></i> | |
</button> | |
+ <button type="button" class="btn btn-outline-warning" data-action="tail-log" title="show log"> | |
+ <i class="bi bi-terminal"></i> | |
+ </button> | |
`; | |
} | |
return ` | |
@@ -59,6 +64,17 @@ | |
$('#tbl-miners tbody').html(trs.join('')); | |
} | |
+ function showStdLog(process) { | |
+ const $console = $('#console'); | |
+ $console.empty(); | |
+ socket.removeAllListeners(); | |
+ | |
+ socket.on(`${process}:out_log`, (procLog) => { | |
+ $console.append(`<p id="console-text">${procLog.data}</p>`); | |
+ $('#console-background').animate({ scrollTop: $console[0].scrollHeight + 1000 }, 500); | |
+ }); | |
+ } | |
+ | |
updateMinersStatus(); | |
setInterval(() => { | |
@@ -70,6 +86,10 @@ | |
const action = self.data('action'); | |
const process = self.parents('tr').attr('id'); | |
+ if (!action) { | |
+ return; | |
+ } | |
+ | |
if (action && process && ['start', 'stop', 'restart'].indexOf(action) >= 0) { | |
try { | |
const response = await fetch(`/miners/${process}/${action}`, { method: 'PUT' }); | |
@@ -82,6 +102,10 @@ | |
alert(error.message); | |
} | |
} | |
+ | |
+ if (action === 'tail-log') { | |
+ showStdLog(process); | |
+ } | |
}); | |
}); | |
}(window.jQuery, window, document)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment