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
master
Javier Hernandez 2024-02-01 10:58:07 +01:00 committed by OpenGnSys Support Team
parent 556e06cc3d
commit 85a22b9b81
4 changed files with 120 additions and 15 deletions

View File

@ -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'),

View File

@ -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',

View File

@ -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',

View File

@ -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