From c13c1ab36561182d2df3e0eb3d4bcbee8064ba99 Mon Sep 17 00:00:00 2001 From: LukasDoesDev Date: Mon, 14 Dec 2020 17:59:59 +0200 Subject: [PATCH 1/4] #8 --- .../templates/panel/parts/details_stats.html | 64 +++++++++++++++++-- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/app/frontend/templates/panel/parts/details_stats.html b/app/frontend/templates/panel/parts/details_stats.html index d7074cca..475ed5ef 100644 --- a/app/frontend/templates/panel/parts/details_stats.html +++ b/app/frontend/templates/panel/parts/details_stats.html @@ -4,13 +4,14 @@
- Server Status: {% if data['server_stats'][0]['running'] %} - Online
- Server Started: {{ data['server_stats'][0]['started'] }} + Server Status: Online
+ Server Started: {{ data['server_stats'][0]['started'] }}
+ Server Uptime: Not calculated yet {% else %} - Offline
- Server Started: Not Started + Server Status: Offline
+ Server Started: Offline
+ Server Uptime: Offline {% end %}
@@ -40,4 +41,55 @@
- \ No newline at end of file + + + + + \ No newline at end of file From 4c9f947aa1bb5f41f6539292aa38f4a321eb030f Mon Sep 17 00:00:00 2001 From: LukasDoesDev Date: Mon, 14 Dec 2020 23:52:46 +0200 Subject: [PATCH 2/4] Rework #8 --- app/classes/web/panel_handler.py | 8 +- .../templates/panel/parts/details_stats.html | 79 ++++++++++--------- 2 files changed, 49 insertions(+), 38 deletions(-) diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index fa602545..821fb32b 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -3,6 +3,8 @@ import logging import tornado.web import tornado.escape import bleach +import time +import datetime from app.classes.shared.console import console from app.classes.shared.models import Users, installer @@ -23,6 +25,9 @@ class PanelHandler(BaseHandler): 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() page_data = { @@ -38,7 +43,8 @@ class PanelHandler(BaseHandler): 'menu_servers': defined_servers, 'hosts_data': db_helper.get_latest_hosts_stats(), '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 diff --git a/app/frontend/templates/panel/parts/details_stats.html b/app/frontend/templates/panel/parts/details_stats.html index 475ed5ef..ee562ccc 100644 --- a/app/frontend/templates/panel/parts/details_stats.html +++ b/app/frontend/templates/panel/parts/details_stats.html @@ -6,7 +6,7 @@
{% if data['server_stats'][0]['running'] %} Server Status: Online
- Server Started: {{ data['server_stats'][0]['started'] }}
+ Server Started: {{ data['server_stats'][0]['started'] }} (Server Time)
Server Uptime: Not calculated yet {% else %} Server Status: Offline
@@ -47,49 +47,54 @@ \ No newline at end of file From 359a2e1c42f9e1ebdf44fa241656be216ff2ab81 Mon Sep 17 00:00:00 2001 From: LukasDoesDev Date: Wed, 16 Dec 2020 01:17:41 +0200 Subject: [PATCH 3/4] Now server started shows browser time, not server time. --- app/classes/web/panel_handler.py | 4 +++- .../templates/panel/parts/details_stats.html | 17 ++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/classes/web/panel_handler.py b/app/classes/web/panel_handler.py index 821fb32b..dd2779b0 100644 --- a/app/classes/web/panel_handler.py +++ b/app/classes/web/panel_handler.py @@ -125,7 +125,9 @@ class PanelHandler(BaseHandler): self.render( template, - data=page_data + data=page_data, + time=time, + utc_offset=(time.timezone * -1 / 60 / 60), ) @tornado.web.authenticated diff --git a/app/frontend/templates/panel/parts/details_stats.html b/app/frontend/templates/panel/parts/details_stats.html index ee562ccc..46d79afa 100644 --- a/app/frontend/templates/panel/parts/details_stats.html +++ b/app/frontend/templates/panel/parts/details_stats.html @@ -78,12 +78,27 @@ return output; } - document.addEventListener('load', () => { + 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'] }}'; From 2523e2e1988cc03aec56e241d2103ab95bcc2cfa Mon Sep 17 00:00:00 2001 From: LukasDoesDev Date: Thu, 31 Dec 2020 19:41:02 +0200 Subject: [PATCH 4/4] 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. --- .../templates/panel/parts/details_stats.html | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/app/frontend/templates/panel/parts/details_stats.html b/app/frontend/templates/panel/parts/details_stats.html index 46d79afa..4d44c117 100644 --- a/app/frontend/templates/panel/parts/details_stats.html +++ b/app/frontend/templates/panel/parts/details_stats.html @@ -7,7 +7,7 @@ {% if data['server_stats'][0]['running'] %} Server Status: Online
Server Started: {{ data['server_stats'][0]['started'] }} (Server Time)
- Server Uptime: Not calculated yet + Server Uptime: Error Calculating {% else %} Server Status: Offline
Server Started: Offline
@@ -63,9 +63,8 @@ .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) + if (num == -1 || num == 1) returnData = returnData.slice(0, -1) return returnData; }) @@ -83,20 +82,26 @@ console.log('calculateTime'); let uptime = document.querySelector('#uptime'); let started = document.querySelector('#started'); + let startedUTC; + let startedLocal; 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); 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'); + startedLocal = startedUTC.utcOffset(browserUTCOffset); + 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'] }}'; @@ -109,6 +114,17 @@ var diff = moment.duration(msdiff); 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) + } } });