summaryrefslogtreecommitdiffstats
path: root/ogcp
diff options
context:
space:
mode:
authorJavier Hernandez <jhernandez@soleta.eu>2024-02-01 10:58:07 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2024-02-01 11:20:04 +0100
commit85a22b9b8137a26869494c8b908c03321dc47846 (patch)
tree06906dd76485b5bf117f8d64db9055b199920036 /ogcp
parent556e06cc3d159c9b1b207a55d3f35f7d0ba048c6 (diff)
improve delete confirmation page
In delete-center, delete-room and delete-folder confirmation pages, show the ancestors of the items about to delete. Likewise, show the items it contains. For example, if user is about to delete a room, confirmation page will display in which center it is contained and the clients and folder it has inside
Diffstat (limited to 'ogcp')
-rw-r--r--ogcp/templates/actions/delete_center.html29
-rw-r--r--ogcp/templates/actions/delete_room.html30
-rw-r--r--ogcp/templates/actions/folder_delete.html33
-rw-r--r--ogcp/views.py43
4 files changed, 120 insertions, 15 deletions
diff --git a/ogcp/templates/actions/delete_center.html b/ogcp/templates/actions/delete_center.html
index 6fef1f6..af89364 100644
--- a/ogcp/templates/actions/delete_center.html
+++ b/ogcp/templates/actions/delete_center.html
@@ -9,6 +9,35 @@
{% block content %}
<h1 class="m-5">{{_('Delete center')}}</h1>
+{% if children %}
+<p class="text-left mx-5">The following items will be deleted</p>
+<table class="table table-hover mx-5">
+<thead class="thead-light">
+<tr>
+<th>
+{% for x in ancestors %}
+ {{x}}
+ {% if not loop.last %}
+ >
+ {% endif %}
+{% endfor %}
+</th>
+</tr>
+</thead>
+<tbody class="text-left">
+{% for c in children %}
+ <tr>
+ <td>
+ {% if c['type'] == 'folder' %}
+ &#x1F4C1;
+ {% endif %}
+ {{c['name']}}
+ </td>
+ </tr>
+{% endfor %}
+</tbody>
+</table>
+{% endif %}
{{ wtf.quick_form(form,
action=url_for('action_center_delete'),
diff --git a/ogcp/templates/actions/delete_room.html b/ogcp/templates/actions/delete_room.html
index aa57368..3fa24cf 100644
--- a/ogcp/templates/actions/delete_room.html
+++ b/ogcp/templates/actions/delete_room.html
@@ -10,6 +10,36 @@
<h1 class="m-5">{{_('Delete room')}}</h1>
+{% if children %}
+<p class="text-left mx-5">The following items will be deleted</p>
+<table class="table table-hover mx-5">
+<thead class="thead-light">
+<tr>
+<th>
+{% for x in ancestors %}
+ {{x}}
+ {% if not loop.last %}
+ >
+ {% endif %}
+{% endfor %}
+</th>
+</tr>
+</thead>
+<tbody class="text-left">
+{% for c in children %}
+ <tr>
+ <td>
+ {% if c['type'] == 'folder' %}
+ &#x1F4C1;
+ {% endif %}
+ {{c['name']}}
+ </td>
+ </tr>
+{% endfor %}
+</tbody>
+</table>
+{% endif %}
+
{{ wtf.quick_form(form,
action=url_for('action_room_delete'),
method='post',
diff --git a/ogcp/templates/actions/folder_delete.html b/ogcp/templates/actions/folder_delete.html
index 78fc136..8d497e8 100644
--- a/ogcp/templates/actions/folder_delete.html
+++ b/ogcp/templates/actions/folder_delete.html
@@ -10,16 +10,35 @@
<h1 class="m-5">{{_('Delete folder')}}</h1>
-<table class="table">
- <tbody>
- {% for content in folder_content %}
+{% if children %}
+<p class="text-left mx-5">The following items will be deleted</p>
+<table class="table table-hover mx-5">
+<thead class="thead-light">
+<tr>
+<th>
+{% for x in ancestors %}
+ {{x}}
+ {% if not loop.last %}
+ >
+ {% endif %}
+{% endfor %}
+</th>
+</tr>
+</thead>
+<tbody class="text-left">
+{% for c in children %}
<tr>
- <th scope="row">{{ content['type'] }}</th>
- <td>{{ content['name'] }}</td>
+ <td>
+ {% if c['type'] == 'folder' %}
+ &#x1F4C1;
+ {% endif %}
+ {{c['name']}}
+ </td>
</tr>
- {% endfor %}
- </tbody>
+{% endfor %}
+</tbody>
</table>
+{% endif %}
{{ wtf.quick_form(form,
method='post',
diff --git a/ogcp/views.py b/ogcp/views.py
index fa6ebc2..dd16e79 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -1242,14 +1242,13 @@ def action_folder_delete():
form.submit.render_kw = {"formaction": url_for('action_folder_delete')}
scopes, unused = get_scopes()
- folder = find_folder(int(folder_id), scopes)
- if not folder:
- flash(_('Folder was not found'), category='info')
- return redirect(url_for("scopes"))
- form.name.data = folder['name']
form.name.render_kw = {'readonly': True}
+
+ ancestors, children = get_scope_context(int(folder_id), 'folder', scopes)
+ form.name.data = ancestors[len(ancestors)-1]
+
return render_template('actions/folder_delete.html', form=form,
- parent="scopes.html", scopes=scopes, folder_content=folder['scope'])
+ parent="scopes.html", scopes=scopes, ancestors=ancestors, children=children)
@app.route('/action/folder/add', methods=['GET'])
@login_required
@@ -1885,6 +1884,32 @@ def action_center_add():
return render_template('actions/add_center.html', form=form,
scopes=scopes)
+def get_scope_context_rec(elem_id, elem_type, scopes, ancestors):
+ if not scopes:
+ return ([], None)
+ res = None
+ for s in scopes:
+ if s['type'] == elem_type and int(s['id']) == elem_id:
+ ancestors.append(s['name'])
+ return (ancestors, s)
+ ancestors_tmp = list(ancestors)
+ ancestors_tmp.append(s['name'])
+ ancestors_tmp, elem = get_scope_context_rec(elem_id, elem_type, s['scope'], ancestors_tmp)
+ if elem:
+ res = (ancestors_tmp, elem)
+ break
+ if res:
+ return res
+ else:
+ return ([], None)
+
+def get_scope_context(elem_id, elem_type, scopes):
+ ancestors, elem = get_scope_context_rec(elem_id, elem_type, scopes['scope'], [])
+ children = []
+ for c in elem['scope']:
+ children.append({'name':c['name'], 'type':c['type']})
+ return (ancestors, children)
+
@app.route('/action/center/delete', methods=['GET', 'POST'])
@login_required
def action_center_delete():
@@ -1919,8 +1944,9 @@ def action_center_delete():
form.center.render_kw = {'readonly': True}
form.server.data = params['scope-server']
scopes, clients = get_scopes()
+ ancestors, children = get_scope_context(int(selected_center_id), 'center', scopes)
return render_template('actions/delete_center.html', form=form,
- scopes=scopes)
+ scopes=scopes, ancestors=ancestors, children=children)
@app.route('/action/room/add', methods=['GET', 'POST'])
@login_required
@@ -2002,8 +2028,9 @@ def action_room_delete():
form.room.render_kw = {'readonly': True}
form.server.data = params['scope-server']
scopes, clients = get_scopes()
+ ancestors, children = get_scope_context(int(selected_room_id), 'room', scopes)
return render_template('actions/delete_room.html', form=form,
- scopes=scopes)
+ scopes=scopes, ancestors=ancestors, children=children)
@app.route('/commands/', methods=['GET'])
@login_required