summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-08-12 10:38:04 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-08-31 15:57:51 +0200
commitbf0459a837f955b82da9eb65805f0c424449d921 (patch)
treeeceaffb4305f5806c6e9d84c39aac13c72b4d583
parent8726ade25ae3c8ef34ad2c1cd53b3b0c469f4634 (diff)
Add a client to a room using the scopes tree
With this commit users can select a room from the scopes tree, and then add a client to that room.
-rw-r--r--ogcp/templates/macros.html8
-rw-r--r--ogcp/views.py12
2 files changed, 17 insertions, 3 deletions
diff --git a/ogcp/templates/macros.html b/ogcp/templates/macros.html
index 4da76d6..28c4f5a 100644
--- a/ogcp/templates/macros.html
+++ b/ogcp/templates/macros.html
@@ -23,7 +23,13 @@
{% macro scopes_tree_collapse_level(scopes, parent_id, state) -%}
{% for scope in scopes %}
<li id="{{ scope["name"]|replace(".", "_")|replace(" ", "_") }}_{{ scope["id"] }}" class="nav-item">
- {% if " ".join(scope["ip"]) %}
+ {% if scope["type"] == "room" %}
+ <input class="form-check-input" type="checkbox" form="scopesForm"
+ value="{{ scope["id"] }}"
+ {% if state %}style="filter: grayscale(100%);" onclick="return false;"{% endif %}
+ {% if scope.get("selected", False) %}checked{% endif %}
+ name="scope-room" />
+ {% elif " ".join(scope["ip"]) %}
<input class="form-check-input" type="checkbox" form="scopesForm"
value="{{ " ".join(scope["ip"]) }}"
{% if state %}style="filter: grayscale(100%);" onclick="return false;"{% endif %}
diff --git a/ogcp/views.py b/ogcp/views.py
index 00a680a..eb3ed12 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -96,9 +96,10 @@ def validate_elements(elements, min_len=1, max_len=float('inf')):
return valid
def parse_elements(checkboxes_dict):
+ unwanted_elements = ['csrf_token', 'scope-room']
elements = set()
for key, elements_list in checkboxes_dict.items():
- if key != 'csrf_token':
+ if key not in unwanted_elements:
elements.update(elements_list.split(' '))
return elements
@@ -846,13 +847,20 @@ def action_client_add():
return redirect(url_for("scopes"))
else:
r = g.server.get('/mode')
+ params = request.args.to_dict()
+ if not params.get('scope-room'):
+ flash(_('Please, select one room'), category='error')
+ return redirect(url_for('scopes'))
available_modes = [(mode, mode) for mode in r.json()['modes']]
form.boot.choices = list(available_modes)
r = g.server.get('/scopes')
+ room_id = params['scope-room']
rooms = parse_scopes_from_tree(r.json(), 'room')
- rooms = [(room['id'], room['name']) for room in rooms]
+ rooms = [(room['id'], room['name']) for room in rooms
+ if room['id'] == int(room_id)]
form.room.choices = list(rooms)
+ form.room.render_kw = {'readonly': True}
form.create.render_kw = {"formaction": url_for('action_client_add')}
scopes, clients = get_scopes()