diff options
author | Javier Hernandez <jhernandez@soleta.eu> | 2024-02-01 10:58:07 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-02-01 11:20:04 +0100 |
commit | 85a22b9b8137a26869494c8b908c03321dc47846 (patch) | |
tree | 06906dd76485b5bf117f8d64db9055b199920036 /ogcp/views.py | |
parent | 556e06cc3d159c9b1b207a55d3f35f7d0ba048c6 (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/views.py')
-rw-r--r-- | ogcp/views.py | 43 |
1 files changed, 35 insertions, 8 deletions
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 |