summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ogcp/templates/actions/mode.html2
-rw-r--r--ogcp/templates/actions/setup.html2
-rw-r--r--ogcp/templates/macros.html1
-rw-r--r--ogcp/views.py18
4 files changed, 15 insertions, 8 deletions
diff --git a/ogcp/templates/actions/mode.html b/ogcp/templates/actions/mode.html
index 3adce8f..e2e9bcf 100644
--- a/ogcp/templates/actions/mode.html
+++ b/ogcp/templates/actions/mode.html
@@ -1,4 +1,4 @@
-{% extends 'scopes.html' %}
+{% extends 'commands.html' %}
{% import "bootstrap/wtf.html" as wtf %}
{% block content %}
diff --git a/ogcp/templates/actions/setup.html b/ogcp/templates/actions/setup.html
index f105dd2..0dcd4c7 100644
--- a/ogcp/templates/actions/setup.html
+++ b/ogcp/templates/actions/setup.html
@@ -1,4 +1,4 @@
-{% extends 'base.html' %}
+{% extends 'commands.html' %}
{% import "bootstrap/wtf.html" as wtf %}
{% block content %}
diff --git a/ogcp/templates/macros.html b/ogcp/templates/macros.html
index d9d2997..3bde877 100644
--- a/ogcp/templates/macros.html
+++ b/ogcp/templates/macros.html
@@ -5,6 +5,7 @@
<li class="list-group-item state--{{ scope['state'] | lower }}">
<input class="form-check-input" type="checkbox" form="scopesForm"
value="{{ " ".join(scope["ip"]) }}"
+ {% if scope.get("selected", False) %}checked{% endif %}
name="{{ scope["name"] }}_{{ scope["id"] }}">
{{ scope["name"] }}
{% if "state" in scope %}
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)