-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add UI for logs
- Loading branch information
Showing
6 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
{% extends "base/base.html" %} | ||
|
||
{% load bootstrap5 mathfilters symbols %} | ||
|
||
{% block title %} | ||
Botzinhos (小bots) | ||
{% endblock title %} | ||
|
||
{% block content %} | ||
<div class="container"> | ||
<h6 class="text-center"> | ||
<span id="date"></span> | | ||
<strong id="clock" class="text-primary"></strong> | ||
<strong>UTC</strong> - Time Interval: <span class="text-primary fw-bolder">| {{ time_interval }}m |</span> | ||
</h6> | ||
|
||
{% groups_breadcrumbs request.user %} | ||
|
||
<div id="bots-list" class="list-group pt-2"> | ||
{% bot_render_html_snippet bot=bot %} | ||
</div> | ||
|
||
{% include "base/logs_section.html" with summary=summary logs=logs page_obj=page_obj %} | ||
|
||
{% endblock content %} | ||
|
||
{% block bootstrap5_extra_script %} | ||
<script> | ||
if (location.protocol === "http:") { | ||
ws_protocol = "ws:" | ||
} else { | ||
ws_protocol = "wss:" | ||
} | ||
|
||
const botsSocket = new WebSocket( | ||
ws_protocol + '//' | ||
+ window.location.host | ||
+ '/ws/bots/html' | ||
); | ||
|
||
botsSocket.onmessage = function(e) { | ||
const data = JSON.parse(e.data); | ||
// console.log(data) | ||
if (data.type === "bot_update") { | ||
bot_element = document.getElementById(data.bot) | ||
if (bot_element) { | ||
bot_element.outerHTML = data.text; | ||
} | ||
} | ||
}; | ||
|
||
botsSocket.onclose = function(e) { | ||
console.error('Bots socket closed unexpectedly'); | ||
}; | ||
|
||
function currentTime() { | ||
let date = new Date(); | ||
let hh = date.getUTCHours(); | ||
let mm = date.getUTCMinutes(); | ||
let ss = date.getUTCSeconds(); | ||
|
||
hh = (hh < 10) ? "0" + hh : hh; | ||
mm = (mm < 10) ? "0" + mm : mm; | ||
ss = (ss < 10) ? "0" + ss : ss; | ||
|
||
let time = hh + ":" + mm + ":" + ss; | ||
|
||
document.getElementById("clock").innerText = time; | ||
document.getElementById("date").innerText = date.toLocaleDateString("en-US", {year: 'numeric', month: 'long', day: 'numeric' }); | ||
let t = setTimeout(function(){ currentTime() }, 1000); | ||
} | ||
|
||
currentTime(); | ||
</script> | ||
{% endblock %} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<div class="container"> | ||
|
||
<h4>Logs</h4> | ||
|
||
<div id="logs-list" class="list-group"> | ||
{% for log in page_obj %} | ||
{{ log.timestamp|date:"r" }}| {{ log.message }} <br> | ||
{% endfor %} | ||
</div> | ||
|
||
<div class="container"> | ||
{% include "base/_paginator.html" with page_obj=page_obj %} | ||
</div> | ||
|
||
</div> |
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
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
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