summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorDaniel García Moreno <danigm@soleta.eu>2021-06-08 11:33:30 +0200
committerDaniel García Moreno <danigm@soleta.eu>2021-06-08 11:46:40 +0200
commit22dcea19ff74871b7200bfc7f976836f436c5342 (patch)
tree7c8808fafb9ac27db8e06491da5cb4d352d7e121 /ogcp/views.py
parentdb29b306aaeebcc385d9a0874f4386010a5c6a98 (diff)
Add sidebar and command bar to base template
Modify the base template to add the sidebar and command bar, implemented just in the scopes view. This patch also modifies the "actions/mode.html" template to be shown in the scopes page. Any other action that should be inside the scopes should do the same, add the scopes and clients to the template context and use the "scopes.html" as base in those actions. The notification has been also changed to use a toast notification instead of the usual alert to avoid changing the layout on error.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py48
1 files changed, 27 insertions, 21 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 9865e0f..5496daf 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -105,6 +105,30 @@ 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):
+ if 'ip' in scope:
+ filtered_client = filter(lambda x: x['addr']==scope['ip'], clients)
+ client = next(filtered_client, False)
+ if client:
+ scope['state'] = client['state']
+ else:
+ scope['state'] = 'OFF'
+ scope['ip'] = [scope['ip']]
+ else:
+ scope['ip'] = []
+ for child in scope['scope']:
+ scope['ip'] += add_state_and_ips(child, clients)
+ return scope['ip']
+
+def get_scopes():
+ r = g.server.get('/scopes')
+ scopes = r.json()
+ r = g.server.get('/clients')
+ clients = r.json()
+ add_state_and_ips(scopes, clients['clients'])
+
+ return scopes, clients
+
@login_manager.user_loader
def load_user(user_id):
if user_id == 1:
@@ -167,26 +191,7 @@ def logout():
@app.route('/scopes/')
@login_required
def scopes():
- def add_state_and_ips(scope, clients):
- if 'ip' in scope:
- filtered_client = filter(lambda x: x['addr']==scope['ip'], clients)
- client = next(filtered_client, False)
- if client:
- scope['state'] = client['state']
- else:
- scope['state'] = 'OFF'
- scope['ip'] = [scope['ip']]
- else:
- scope['ip'] = []
- for child in scope['scope']:
- scope['ip'] += add_state_and_ips(child, clients)
- return scope['ip']
-
- r = g.server.get('/scopes')
- scopes = r.json()
- r = g.server.get('/clients')
- clients = r.json()
- add_state_and_ips(scopes, clients['clients'])
+ scopes, clients = get_scopes()
return render_template('scopes.html', scopes=scopes, clients=clients)
@app.route('/action/poweroff', methods=['POST'])
@@ -585,7 +590,8 @@ def action_mode():
return redirect(url_for("scopes"))
form.ok.render_kw = { 'formaction': url_for('action_mode') }
- return render_template('actions/mode.html', form=form)
+ scopes, clients = get_scopes()
+ return render_template('actions/mode.html', form=form, scopes=scopes, clients=clients)
@app.route('/action/image/create', methods=['GET', 'POST'])