From 152337b6bdb8ad95c516ec818d9f625cb9dff54d Mon Sep 17 00:00:00 2001 From: Javier Hernandez Date: Tue, 5 Dec 2023 09:58:43 +0100 Subject: views: add action to delete repo allow the user to delete a repo by selecting one and pressing the delete button. Previous to deletion, show the user a confirmation page (a form) with the details of the repo to delete the confirmation form is constructed with the fields of Repoform. RepoForm is also used in template used to create a repo. To make both templates work with RepoForm, RepoForm's field 'create' has been renamed to 'submit' ogcp.js: add a function to make that, when the user selects a repository, the server in which it is contained is automatically checked. We need it checked so that action_repo_delete can know the server to which it has to send the delete request. Use data-server in repos_details.html to make this work Validate, in action_delete_repo, that user has only selected one repo to delete. In order to do that, action_delete_repo view needs to be able to get a list of all selected repos. This is only possible if elements that are associated with repos info contain a different name attribute per repo. In this case, template repos.html has been modified to use name={repo name}-{repo_id}. After this, parse_elements() will work and parse a set containing all selected repos. modify html input associated to repos server in order to follow same convention as in other templates. For example, images uses image-server; scopes, scope-server. --- ogcp/forms/action_forms.py | 3 +- ogcp/static/js/ogcp.js | 17 ++++++++++++ ogcp/templates/actions/repos_details.html | 3 +- ogcp/templates/repos.html | 10 +++++-- ogcp/views.py | 46 ++++++++++++++++++++++++++++--- 5 files changed, 70 insertions(+), 9 deletions(-) (limited to 'ogcp') diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index 0a9bd32..c15d254 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -100,9 +100,10 @@ class ImageRestoreForm(FlaskForm): class RepoForm(FlaskForm): server = HiddenField() + repo_id = HiddenField() name = StringField(label=_l('Name')) ip = StringField(label=_l('IP')) - create = SubmitField(label=_l('Create')) + submit = SubmitField(label=_l('Submit')) class ClientDetailsForm(FlaskForm): server = HiddenField() diff --git a/ogcp/static/js/ogcp.js b/ogcp/static/js/ogcp.js index 5028993..0ac67fe 100644 --- a/ogcp/static/js/ogcp.js +++ b/ogcp/static/js/ogcp.js @@ -329,6 +329,23 @@ function checkImageServer() { }); } +function checkRepoServer() { + const repos = $('input:checkbox[form|="reposForm"][name!="repos-server"]') + repos.on('change', function() { + const selectedServer = $('#' + $.escapeSelector(this.dataset.server)); + const serversSelector = 'input:checkbox[name|="repos-server"]'; + const nonSelectedServers = $(serversSelector).not(selectedServer); + + selectedServer.prop('checked', true); + + nonSelectedServers.each(function() { + $(this).prop('checked', false); + const checkboxes = $('input:checkbox[data-server|="' + this.id + '"]'); + checkboxes.prop('checked', false); + }); + }); +} + function limitCheckboxes() { const checkboxes = $('input:checkbox[form|="scopesForm"]'); diff --git a/ogcp/templates/actions/repos_details.html b/ogcp/templates/actions/repos_details.html index 32b96bf..2768492 100644 --- a/ogcp/templates/actions/repos_details.html +++ b/ogcp/templates/actions/repos_details.html @@ -10,7 +10,8 @@

{{_('Repo details')}}

{{ wtf.quick_form(form, + action=url_for('repo_add_post'), method='post', - button_map={'create': 'primary'}, + button_map={'submit': 'primary'}, extra_classes="mx-5") }} {% endblock %} diff --git a/ogcp/templates/repos.html b/ogcp/templates/repos.html index 881057b..8477d29 100644 --- a/ogcp/templates/repos.html +++ b/ogcp/templates/repos.html @@ -17,8 +17,8 @@ {% set server_ip_port = repos["server"].ip ~ ":" ~ repos["server"].port %} {% set repos_list = repos["json"]["repositories"] %} {% endfor %} @@ -42,6 +43,7 @@ document.addEventListener('readystatechange', () => { if (document.readyState === 'complete') { keepReposTreeState() + checkRepoServer() } }); @@ -50,6 +52,8 @@ {% block commands %} + {% if btn_back %}