summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorDaniel GarcĂ­a Moreno <danigm@soleta.eu>2021-06-17 14:13:16 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-06-17 16:42:50 +0200
commitf121d591e5fb0b53f4e25099ca4f11afa005a1c9 (patch)
tree3d54d1ef1d6796fca8cfa2c4818ca41fbf3bf3e8 /ogcp/views.py
parentf8e27fb149daea8b3151b91c175d051589f8f6ed (diff)
Keep the selection in the sidebar for mode & setup
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py18
1 files changed, 12 insertions, 6 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 3e7c4e4..c4b8afe 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -105,7 +105,8 @@ def parse_scopes_from_tree(tree, scope_type):
scopes += parse_scopes_from_tree(scope, scope_type)
return scopes
-def add_state_and_ips(scope, clients):
+def add_state_and_ips(scope, clients, ips):
+ scope['selected'] = False
if 'ip' in scope:
filtered_client = filter(lambda x: x['addr']==scope['ip'], clients)
client = next(filtered_client, False)
@@ -114,18 +115,20 @@ def add_state_and_ips(scope, clients):
else:
scope['state'] = 'OFF'
scope['ip'] = [scope['ip']]
+ scope['selected'] = set(scope['ip']).issubset(ips)
else:
scope['ip'] = []
for child in scope['scope']:
- scope['ip'] += add_state_and_ips(child, clients)
+ scope['ip'] += add_state_and_ips(child, clients, ips)
+ scope['selected'] = set(scope['ip']).issubset(ips)
return scope['ip']
-def get_scopes():
+def get_scopes(ips=set()):
r = g.server.get('/scopes')
scopes = r.json()
r = g.server.get('/clients')
clients = r.json()
- add_state_and_ips(scopes, clients['clients'])
+ add_state_and_ips(scopes, clients['clients'], ips)
return scopes, clients
@@ -243,7 +246,10 @@ def action_setup_show():
form.size.data = db_part['size']
form.modify.render_kw = {"formaction": url_for('action_setup_modify')}
form.delete.render_kw = {"formaction": url_for('action_setup_delete')}
- return render_template('actions/setup.html', forms=forms)
+ scopes, _clients = get_scopes(ips)
+ return render_template('actions/setup.html',
+ forms=forms,
+ scopes=scopes)
@app.route('/action/setup/modify', methods=['POST'])
@login_required
@@ -590,7 +596,7 @@ def action_mode():
return redirect(url_for("scopes"))
form.ok.render_kw = { 'formaction': url_for('action_mode') }
- scopes, clients = get_scopes()
+ scopes, clients = get_scopes(set(ips))
return render_template('actions/mode.html', form=form, scopes=scopes, clients=clients)