From 696a81fd1147e301dd69609558da387f17c57228 Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Tue, 10 Sep 2024 15:21:03 +0200 Subject: templates: add name and status to client list Add a client name column to the client list view accessed through the Dashboard. Add status column to the client list. Move client status leyend into a separate file. Show the client status leyend in client list. Fix the 0 link speed conditional. Reuse the data returned by get_scopes() to reduce the number of requests. --- ogcp/templates/client_list.html | 32 ++++++++++++++++++++++++- ogcp/templates/client_status_leyend.html | 15 ++++++++++++ ogcp/templates/macros.html | 18 +++----------- ogcp/views.py | 41 ++++++++++++++++++++++---------- 4 files changed, 77 insertions(+), 29 deletions(-) create mode 100644 ogcp/templates/client_status_leyend.html diff --git a/ogcp/templates/client_list.html b/ogcp/templates/client_list.html index 8a3fd5b..723dce9 100644 --- a/ogcp/templates/client_list.html +++ b/ogcp/templates/client_list.html @@ -8,6 +8,8 @@
+{% include 'client_status_leyend.html' %} + {% for server_id, server_data in servers_data.items() %}
@@ -22,8 +24,10 @@ + + @@ -31,9 +35,10 @@ {% for client_data in server_data.clients %} + + {% endfor %} diff --git a/ogcp/templates/client_status_leyend.html b/ogcp/templates/client_status_leyend.html new file mode 100644 index 0000000..f43050e --- /dev/null +++ b/ogcp/templates/client_status_leyend.html @@ -0,0 +1,15 @@ +
+
+ +
+
diff --git a/ogcp/templates/macros.html b/ogcp/templates/macros.html index 4f18265..7583c59 100644 --- a/ogcp/templates/macros.html +++ b/ogcp/templates/macros.html @@ -93,21 +93,9 @@ {% macro selected_clients() -%}

{{_('Selected clients')}}

-
-
- -
-
+ +{% include 'client_status_leyend.html' %} +
{% endmacro %} diff --git a/ogcp/views.py b/ogcp/views.py index c24cb73..9a0c8e2 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -222,10 +222,12 @@ def get_client_setup_json(): def get_clients(state_filter=None): responses = multi_request('get', '/clients') - clients_list = [] for r in responses: - clients_list = clients_list + r['json']['clients'] + req_clients = r['json']['clients'] + for client in req_clients: + client['server'] = r['server'] + clients_list = clients_list + req_clients clients = {} clients['clients'] = clients_list @@ -600,21 +602,34 @@ def get_client_mac(): return jsonify(pretty_mac) -@app.route('/client/list', methods=['GET']) -@login_required -def client_list(): - clients_response = multi_request('get', '/clients') +def get_server_data_from_scopes(scopes, clients): servers_data = {} - for i in clients_response: - server_id = i['server'].id + + ip_to_name = {ip: c['name'] for c in parse_scopes_from_tree(scopes, 'computer') for ip in c['ip']} + + for client in clients['clients']: + client['name'] = ip_to_name[client['addr']] + server_id = client['server'].id if server_id not in servers_data: - servers_data[server_id] = {} - servers_data[server_id]['clients'] = i['json']['clients'] - for server in servers: - if server.id == server_id: - servers_data[server_id]['name'] = server.name + servers_data[server_id] = {'clients': []} + for server in servers: + if server.id == server_id: + servers_data[server_id]['name'] = server.name + + servers_data[server_id]['clients'].append(client) + + for server_id in servers_data: + servers_data[server_id]['clients'].sort(key=lambda x: x['name']) + + return servers_data + +@app.route('/client/list', methods=['GET']) +@login_required +def client_list(): scopes, clients = get_scopes() + servers_data = get_server_data_from_scopes(scopes, clients) + selected_clients = list(get_selected_clients(scopes['scope']).items()) return render_template('client_list.html', servers_data=servers_data, -- cgit v1.2.3-18-g5258
{{ _('Name') }} {{ _('IP') }} {{ _('Link speed') }}{{ _('Status') }} {{ _('Details') }}
{{ client_data.name }} {{ client_data.addr }} - {% if client_data.speed is not none %} + {% if client_data.speed is not none and client_data.speed > 0 %} {% if client_data.speed >= 1000 %} {{ (client_data.speed / 1000) | int }} Gb/s {% else %} @@ -43,6 +48,31 @@ {{ _('Not available') }} {% endif %} + + {{ _('View details') }}