mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Rework #8
This commit is contained in:
parent
c13c1ab365
commit
4c9f947aa1
@ -3,6 +3,8 @@ import logging
|
|||||||
import tornado.web
|
import tornado.web
|
||||||
import tornado.escape
|
import tornado.escape
|
||||||
import bleach
|
import bleach
|
||||||
|
import time
|
||||||
|
import datetime
|
||||||
|
|
||||||
from app.classes.shared.console import console
|
from app.classes.shared.console import console
|
||||||
from app.classes.shared.models import Users, installer
|
from app.classes.shared.models import Users, installer
|
||||||
@ -23,6 +25,9 @@ class PanelHandler(BaseHandler):
|
|||||||
|
|
||||||
template = "panel/denied.html"
|
template = "panel/denied.html"
|
||||||
|
|
||||||
|
now = time.time()
|
||||||
|
formatted_time = str(datetime.datetime.fromtimestamp(now).strftime('%Y-%m-%d %H:%M:%S'))
|
||||||
|
|
||||||
defined_servers = controller.list_defined_servers()
|
defined_servers = controller.list_defined_servers()
|
||||||
|
|
||||||
page_data = {
|
page_data = {
|
||||||
@ -38,7 +43,8 @@ class PanelHandler(BaseHandler):
|
|||||||
'menu_servers': defined_servers,
|
'menu_servers': defined_servers,
|
||||||
'hosts_data': db_helper.get_latest_hosts_stats(),
|
'hosts_data': db_helper.get_latest_hosts_stats(),
|
||||||
'show_contribute': helper.get_setting("show_contribute_link", True),
|
'show_contribute': helper.get_setting("show_contribute_link", True),
|
||||||
'error': error
|
'error': error,
|
||||||
|
'time': formatted_time
|
||||||
}
|
}
|
||||||
|
|
||||||
# if no servers defined, let's go to the build server area
|
# if no servers defined, let's go to the build server area
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<div class="col-sm-3 mr-2">
|
<div class="col-sm-3 mr-2">
|
||||||
{% if data['server_stats'][0]['running'] %}
|
{% if data['server_stats'][0]['running'] %}
|
||||||
<b>Server Status:</b> <span class="text-success">Online</span><br />
|
<b>Server Status:</b> <span class="text-success">Online</span><br />
|
||||||
<b>Server Started:</b> <span id="started">{{ data['server_stats'][0]['started'] }}</span><br />
|
<b>Server Started:</b> <span id="started">{{ data['server_stats'][0]['started'] }} (Server Time)</span><br />
|
||||||
<b>Server Uptime:</b> <span id="uptime">Not calculated yet</span>
|
<b>Server Uptime:</b> <span id="uptime">Not calculated yet</span>
|
||||||
{% else %}
|
{% else %}
|
||||||
<b>Server Status:</b> <span class="text-danger">Offline</span><br />
|
<b>Server Status:</b> <span class="text-danger">Offline</span><br />
|
||||||
@ -47,49 +47,54 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
document.addEventListener('load', () => console.log('loadedghfghfghk'));
|
function durationToHumanizedString (duration) {
|
||||||
|
duration._data.months += duration._data.years * 12;
|
||||||
|
// 30.45833333333 = average month length, calculate with (31+28.5+31+30+31+30+31+31+30+31+30+31) / 12
|
||||||
|
duration._data.days += duration._data.months * 30.45833333333;
|
||||||
|
duration._data.hours += duration._data.days * 24;
|
||||||
|
|
||||||
console.log('calculateTime');
|
let obj = {
|
||||||
let uptime = document.querySelector('#uptime');
|
hours: Math.round(duration._data.hours),
|
||||||
let started = document.querySelector('#started');
|
minutes: duration._data.minutes,
|
||||||
|
seconds: duration._data.seconds
|
||||||
|
}
|
||||||
|
|
||||||
if (uptime != null && started != null) {
|
output = Object.entries(obj)
|
||||||
|
.map(([type, num]) => {
|
||||||
var msdiff = moment(started.textContent,"YYYY-MM-DD HH:mm:ss").diff(moment());
|
// make them strings
|
||||||
var diff = moment(msdiff);
|
returnData = num + ' ' + type;
|
||||||
var s = diff
|
console.log(returnData);
|
||||||
.format("YYYY-MM-DD HH:mm:ss")
|
// remove the s in the end if the data is -1 or 1
|
||||||
.split(' ')
|
if (returnData == -1 || returnData == 1)
|
||||||
.map(x=>x.split('-'))
|
returnData = returnData.slice(0, -1)
|
||||||
.flat()
|
return returnData;
|
||||||
.map(x=>x.split(':'))
|
})
|
||||||
.flat()
|
|
||||||
.map(str => str.replace(',', ''))
|
|
||||||
.map(str => +str) // Convert to number(s)
|
|
||||||
.reverse()
|
|
||||||
.map((n, i) =>
|
|
||||||
n === 0
|
|
||||||
? n
|
|
||||||
: `${n} ` +
|
|
||||||
[
|
|
||||||
'year',
|
|
||||||
'month',
|
|
||||||
'day',
|
|
||||||
'hour',
|
|
||||||
'minute',
|
|
||||||
'second'
|
|
||||||
].reverse()[i] + (n != 1 && n != -1 ? 's' : '')
|
|
||||||
)
|
|
||||||
.reverse()
|
|
||||||
.filter(num => num !== 0) // filter out 0s
|
|
||||||
.map((v, i, a) => // example input: [1,2,3], output: "1, 2 and 3"
|
.map((v, i, a) => // example input: [1,2,3], output: "1, 2 and 3"
|
||||||
v + (i !== a.length - 1
|
v + (i !== a.length - 1
|
||||||
? i !== a.length - 2
|
? i !== a.length - 2
|
||||||
? ', '
|
? ', '
|
||||||
: ' and '
|
: ' and '
|
||||||
: '')).join('');
|
: '')).join('');
|
||||||
|
return output;
|
||||||
uptime.textContent = s;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.addEventListener('load', () => {
|
||||||
|
|
||||||
|
console.log('calculateTime');
|
||||||
|
let uptime = document.querySelector('#uptime');
|
||||||
|
let started = document.querySelector('#started');
|
||||||
|
|
||||||
|
let nowServerTime = '{{ data['time'] }}';
|
||||||
|
let startedServerTime = '{{ data['server_stats'][0]['started'] }}';
|
||||||
|
|
||||||
|
if (uptime != null && started != null) {
|
||||||
|
|
||||||
|
var msdiff = moment(nowServerTime,"YYYY-MM-DD hh:mm:ss")
|
||||||
|
.diff(moment(startedServerTime,"YYYY-MM-DD hh:mm:ss"));
|
||||||
|
var diff = moment.duration(msdiff);
|
||||||
|
|
||||||
|
uptime.textContent = durationToHumanizedString(diff);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue
Block a user