mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
115 lines
4.2 KiB
HTML
115 lines
4.2 KiB
HTML
<div class="row">
|
|
<div class="col-sm-12 grid-margin">
|
|
<div class="card">
|
|
<div class="card-body pt-3 pb-3">
|
|
<div class="row">
|
|
<div class="col-sm-3 mr-2">
|
|
{% if data['server_stats'][0]['running'] %}
|
|
<b>Server Status:</b> <span class="text-success">Online</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>
|
|
{% else %}
|
|
<b>Server Status:</b> <span class="text-danger">Offline</span><br />
|
|
<b>Server Started:</b> <span class="text-danger">Offline</span><br />
|
|
<b>Server Uptime:</b> <span class="text-danger">Offline</span>
|
|
{% end %}
|
|
</div>
|
|
|
|
<div class="col-sm-3 mr-2">
|
|
<b>CPU:</b> {{ data['server_stats'][0]['cpu'] }}% <br />
|
|
<b>Mem:</b> {{ data['server_stats'][0]['mem'] }} <br />
|
|
{% if data['server_stats'][0]['int_ping_results'] %}
|
|
<b>Players:</b> {{ data['server_stats'][0]['online'] }} / {{ data['server_stats'][0]['max'] }}<br />
|
|
{% else %}
|
|
<b>Players:</b> 0/0<br />
|
|
{% end %}
|
|
</div>
|
|
|
|
<div class="col-sm-3 mr-2">
|
|
{% if data['server_stats'][0]['version'] != 'False' %}
|
|
<b>Server:</b> {{ data['server_stats'][0]['version'] }} <br />
|
|
<b>Desc:</b> {{ data['server_stats'][0]['desc'] }} <br />
|
|
{% else %}
|
|
<b>Server:</b> Unable To Connect <br />
|
|
<b>Desc:</b> Unable To Connect <br />
|
|
{% end %}
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<script src="/static/assets/vendors/moment/moment.min.js" type="text/javascript" charset="utf-8"></script>
|
|
|
|
<script>
|
|
|
|
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;
|
|
|
|
let obj = {
|
|
hours: Math.round(duration._data.hours),
|
|
minutes: duration._data.minutes,
|
|
seconds: duration._data.seconds
|
|
}
|
|
|
|
output = Object.entries(obj)
|
|
.map(([type, num]) => {
|
|
// make them strings
|
|
returnData = num + ' ' + type;
|
|
console.log(returnData);
|
|
// remove the s in the end if the data is -1 or 1
|
|
if (returnData == -1 || returnData == 1)
|
|
returnData = returnData.slice(0, -1)
|
|
return returnData;
|
|
})
|
|
.map((v, i, a) => // example input: [1,2,3], output: "1, 2 and 3"
|
|
v + (i !== a.length - 1
|
|
? i !== a.length - 2
|
|
? ', '
|
|
: ' and '
|
|
: '')).join('');
|
|
return output;
|
|
}
|
|
|
|
document.body.onload = (() => {
|
|
|
|
console.log('calculateTime');
|
|
let uptime = document.querySelector('#uptime');
|
|
let started = document.querySelector('#started');
|
|
|
|
if (started != null) {
|
|
let startedUTC = '{{ (datetime.datetime.strptime(data['server_stats'][0]['started'], '%Y-%m-%d %H:%M:%S') - datetime.timedelta(seconds=-time.timezone)).strftime('%Y-%m-%d %H:%M:%S') }}';
|
|
console.log('utc', startedUTC);
|
|
startedUTC = moment.utc(startedUTC, 'YYYY-MM-DD HH:mm:ss');
|
|
|
|
let browserUTCOffset = moment().utcOffset(); // This is in minutes
|
|
|
|
let startedLocal = startedUTC.utcOffset(browserUTCOffset);
|
|
startedLocal = startedLocal.format('YYYY-MM-DD HH:mm:ss');
|
|
|
|
console.log('local', startedLocal);
|
|
|
|
started.textContent = startedLocal
|
|
}
|
|
|
|
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> |