From 85a22b9b8137a26869494c8b908c03321dc47846 Mon Sep 17 00:00:00 2001 From: Javier Hernandez Date: Thu, 1 Feb 2024 10:58:07 +0100 Subject: 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 --- ogcp/templates/actions/delete_center.html | 29 +++++++++++++++++++++ ogcp/templates/actions/delete_room.html | 30 +++++++++++++++++++++ ogcp/templates/actions/folder_delete.html | 33 +++++++++++++++++++----- ogcp/views.py | 43 +++++++++++++++++++++++++------ 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 %}

{{_('Delete center')}}

+{% if children %} +

The following items will be deleted

+ + + + + + + +{% for c in children %} + + + +{% endfor %} + +
+{% for x in ancestors %} + {{x}} + {% if not loop.last %} + > + {% endif %} +{% endfor %} +
+ {% if c['type'] == 'folder' %} + 📁 + {% endif %} + {{c['name']}} +
+{% 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 @@

{{_('Delete room')}}

+{% if children %} +

The following items will be deleted

+ + + + + + + +{% for c in children %} + + + +{% endfor %} + +
+{% for x in ancestors %} + {{x}} + {% if not loop.last %} + > + {% endif %} +{% endfor %} +
+ {% if c['type'] == 'folder' %} + 📁 + {% endif %} + {{c['name']}} +
+{% 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 @@

{{_('Delete folder')}}

- - - {% for content in folder_content %} +{% if children %} +

The following items will be deleted

+
+ + + + + + +{% for c in children %} - - + - {% endfor %} - +{% endfor %} +
+{% for x in ancestors %} + {{x}} + {% if not loop.last %} + > + {% endif %} +{% endfor %} +
{{ content['type'] }}{{ content['name'] }} + {% if c['type'] == 'folder' %} + 📁 + {% endif %} + {{c['name']}} +
+{% 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 -- cgit v1.2.3-18-g5258