Fix server reordering

This commit is contained in:
amcmanu3 2022-03-03 22:25:30 -05:00
parent bbd4335d79
commit 0a08324963

View File

@ -208,17 +208,14 @@ class PanelHandler(BaseHandler):
user_order = user_order['server_order'].split(',') user_order = user_order['server_order'].split(',')
page_servers = [] page_servers = []
server_ids = [] server_ids = []
un_used_servers = defined_servers
for server_id in user_order: for server_id in user_order:
for server in un_used_servers: for server in defined_servers:
if str(server['server_id']) == str(server_id): if str(server['server_id']) == str(server_id):
page_servers.append(server) page_servers.append(server)
un_used_servers.remove(server)
user_order.remove(server_id)
for server in un_used_servers: for server in defined_servers:
server_ids.append(str(server['server_id'])) server_ids.append(str(server['server_id']))
if server not in page_servers: if server not in page_servers:
page_servers.append(server) page_servers.append(server)
@ -340,30 +337,18 @@ class PanelHandler(BaseHandler):
un_used_servers = page_data['servers'] un_used_servers = page_data['servers']
flag = 0 flag = 0
for server_id in user_order: user_order = self.controller.users.get_user_by_id(exec_user['user_id'])
for server in un_used_servers: user_order = user_order['server_order'].split(',')
if flag == 0: page_servers = []
server['stats']['downloading'] = self.controller.servers.get_download_status( server_ids = []
str(server['stats']['server_id']['server_id']))
server['stats']['crashed'] = self.controller.servers.is_crashed(
str(server['stats']['server_id']['server_id']))
try:
server['stats']['waiting_start'] = self.controller.servers.get_waiting_start(
str(server['stats']['server_id']['server_id']))
except Exception as e:
logger.error(f"Failed to get server waiting to start: {e}")
server['stats']['waiting_start'] = False
for server_id in user_order:
for server in page_data['servers']:
if str(server['server_data']['server_id']) == str(server_id): if str(server['server_data']['server_id']) == str(server_id):
page_servers.append(server) page_servers.append(server)
un_used_servers.remove(server)
user_order.remove(server_id)
#we only want to set these server stats values once. We need to update the flag so it only hits that if once.
flag += 1
for server in page_data['servers']:
for server in un_used_servers:
server_ids.append(str(server['server_data']['server_id'])) server_ids.append(str(server['server_data']['server_id']))
if server not in page_servers: if server not in page_servers:
page_servers.append(server) page_servers.append(server)
@ -374,6 +359,17 @@ class PanelHandler(BaseHandler):
page_data['servers'] = page_servers page_data['servers'] = page_servers
for data in page_data['servers']:
data['stats']['crashed'] = self.controller.servers.is_crashed(
str(data['stats']['server_id']['server_id']))
try:
data['stats']['waiting_start'] = self.controller.servers.get_waiting_start(
str(data['stats']['server_id']['server_id']))
except Exception as e:
logger.error(f"Failed to get server waiting to start: {e}")
data['stats']['waiting_start'] = False
for data in page_data['servers']: for data in page_data['servers']:
data['stats']['crashed'] = self.controller.servers.is_crashed( data['stats']['crashed'] = self.controller.servers.is_crashed(
str(data['stats']['server_id']['server_id'])) str(data['stats']['server_id']['server_id']))