mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Fix error when server is offline, change "Not calculated yet" to "Error Calculating", remove unnecessary logging, make a loop, and fix durationToHumanizedString output number types having s's even though the number is 1 or -1.
This commit is contained in:
parent
359a2e1c42
commit
2523e2e198
@ -7,7 +7,7 @@
|
|||||||
{% 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'] }} (Server Time)</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">Error Calculating</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 />
|
||||||
<b>Server Started:</b> <span class="text-danger">Offline</span><br />
|
<b>Server Started:</b> <span class="text-danger">Offline</span><br />
|
||||||
@ -63,9 +63,8 @@
|
|||||||
.map(([type, num]) => {
|
.map(([type, num]) => {
|
||||||
// make them strings
|
// make them strings
|
||||||
returnData = num + ' ' + type;
|
returnData = num + ' ' + type;
|
||||||
console.log(returnData);
|
|
||||||
// remove the s in the end if the data is -1 or 1
|
// remove the s in the end if the data is -1 or 1
|
||||||
if (returnData == -1 || returnData == 1)
|
if (num == -1 || num == 1)
|
||||||
returnData = returnData.slice(0, -1)
|
returnData = returnData.slice(0, -1)
|
||||||
return returnData;
|
return returnData;
|
||||||
})
|
})
|
||||||
@ -83,20 +82,26 @@
|
|||||||
console.log('calculateTime');
|
console.log('calculateTime');
|
||||||
let uptime = document.querySelector('#uptime');
|
let uptime = document.querySelector('#uptime');
|
||||||
let started = document.querySelector('#started');
|
let started = document.querySelector('#started');
|
||||||
|
let startedUTC;
|
||||||
|
let startedLocal;
|
||||||
|
|
||||||
if (started != null) {
|
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('88', '{{ data['server_stats'][0]['started'] }}');
|
||||||
|
{% if data['server_stats'][0]['started'] != 'False' %}
|
||||||
|
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') }}';
|
||||||
|
{% end %}
|
||||||
console.log('utc', startedUTC);
|
console.log('utc', startedUTC);
|
||||||
startedUTC = moment.utc(startedUTC, 'YYYY-MM-DD HH:mm:ss');
|
startedUTC = moment.utc(startedUTC, 'YYYY-MM-DD HH:mm:ss');
|
||||||
|
|
||||||
let browserUTCOffset = moment().utcOffset(); // This is in minutes
|
let browserUTCOffset = moment().utcOffset(); // This is in minutes
|
||||||
|
|
||||||
let startedLocal = startedUTC.utcOffset(browserUTCOffset);
|
startedLocal = startedUTC.utcOffset(browserUTCOffset);
|
||||||
startedLocal = startedLocal.format('YYYY-MM-DD HH:mm:ss');
|
startedLocalFormatted = startedLocal.format('YYYY-MM-DD HH:mm:ss');
|
||||||
|
|
||||||
console.log('local', startedLocal);
|
console.log('startedLocal', startedLocal);
|
||||||
|
console.log('startedLocalFormatted', startedLocalFormatted);
|
||||||
|
|
||||||
started.textContent = startedLocal
|
started.textContent = startedLocalFormatted
|
||||||
}
|
}
|
||||||
|
|
||||||
let nowServerTime = '{{ data['time'] }}';
|
let nowServerTime = '{{ data['time'] }}';
|
||||||
@ -109,6 +114,17 @@
|
|||||||
var diff = moment.duration(msdiff);
|
var diff = moment.duration(msdiff);
|
||||||
|
|
||||||
uptime.textContent = durationToHumanizedString(diff);
|
uptime.textContent = durationToHumanizedString(diff);
|
||||||
|
|
||||||
|
console.log('startedLocal', startedLocal)
|
||||||
|
if (startedLocal) {
|
||||||
|
var uptimeLoop = setInterval(() => {
|
||||||
|
var msdiff = moment()
|
||||||
|
.diff(startedLocal);
|
||||||
|
var diff = moment.duration(msdiff);
|
||||||
|
|
||||||
|
uptime.textContent = durationToHumanizedString(diff);
|
||||||
|
}, 1000)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user