mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-21 07:55:00 +00:00
backups: Add option to select/deselect all apps for backup or restore
This is less tiresome for users and also improves the speed of functional tests. Signed-off-by: Joseph Nuthalapati <njoseph@thoughtworks.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
c84769d800
commit
061c308e35
@ -40,7 +40,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
def _get_app_choices(apps):
|
||||
"""Return a list of check box multiple choices from list of apps."""
|
||||
choices = []
|
||||
choices = [('select_all', _("Include all apps"))]
|
||||
for app in apps:
|
||||
name = app.app.name
|
||||
if not app.has_data:
|
||||
|
||||
50
plinth/modules/backups/static/select_all.js
Normal file
50
plinth/modules/backups/static/select_all.js
Normal file
@ -0,0 +1,50 @@
|
||||
/*
|
||||
This file is part of FreedomBox.
|
||||
|
||||
@licstart The following is the entire license notice for the
|
||||
JavaScript code in this page.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
@licend The above is the entire license notice
|
||||
for the JavaScript code in this page.
|
||||
*/
|
||||
|
||||
|
||||
// jQuery selector for the "select all" checkbox
|
||||
var select_all = "#id_backups-selected_apps_0";
|
||||
|
||||
// Initialize the "select all" checkbox to checked
|
||||
$(select_all).prop('checked', true);
|
||||
|
||||
/*
|
||||
* When there is a change on the "select all" checkbox,set the
|
||||
* checked property of all the checkboxes to the value of the
|
||||
* "select all" checkbox
|
||||
*/
|
||||
$(select_all).change(function() {
|
||||
$(":checkbox").prop('checked', $(this).prop("checked"));
|
||||
});
|
||||
|
||||
|
||||
$(':checkbox').change(function() {
|
||||
// If the rest of the checkbox items are checked check the "select all" checkbox as well
|
||||
if ($(':checkbox:checked').length == ($(':checkbox').length-1)) {
|
||||
$(select_all).prop('checked', true);
|
||||
}
|
||||
// Uncheck "select all" if one of the listed checkbox item is unchecked
|
||||
if (false == $(this).prop("checked")) {
|
||||
$(select_all).prop('checked', false);
|
||||
}
|
||||
});
|
||||
@ -20,16 +20,21 @@
|
||||
|
||||
{% load bootstrap %}
|
||||
{% load i18n %}
|
||||
{% load static %}
|
||||
|
||||
{% block configuration %}
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% csrf_token %}
|
||||
|
||||
{{ form|bootstrap }}
|
||||
{{ form|bootstrap }}
|
||||
|
||||
<input type="submit" class="btn btn-primary"
|
||||
value="{% trans "Submit" %}"/>
|
||||
<input type="submit" class="btn btn-primary"
|
||||
value="{% trans "Submit" %}"/>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block page_js %}
|
||||
<script type="text/javascript" src="{% static 'backups/select_all.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
@ -59,4 +59,5 @@
|
||||
{% block page_js %}
|
||||
<script type="text/javascript"
|
||||
src="{% static 'backups/loading_button.js' %}"></script>
|
||||
<script type="text/javascript" src="{% static 'backups/select_all.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
@ -103,7 +103,8 @@ class CreateArchiveView(SuccessMessageMixin, FormView):
|
||||
repository.mount()
|
||||
|
||||
name = datetime.now().strftime('%Y-%m-%d:%H:%M')
|
||||
repository.create_archive(name, form.cleaned_data['selected_apps'])
|
||||
selected_apps = form.cleaned_data['selected_apps'][1:]
|
||||
repository.create_archive(name, selected_apps)
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
@ -224,7 +225,8 @@ class RestoreFromUploadView(BaseRestoreView):
|
||||
def form_valid(self, form):
|
||||
"""Restore files from the archive on valid form submission."""
|
||||
path = self.request.session.get(SESSION_PATH_VARIABLE)
|
||||
backups.restore_from_upload(path, form.cleaned_data['selected_apps'])
|
||||
selected_apps = form.cleaned_data['selected_apps'][1:]
|
||||
backups.restore_from_upload(path, selected_apps)
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
@ -241,8 +243,8 @@ class RestoreArchiveView(BaseRestoreView):
|
||||
def form_valid(self, form):
|
||||
"""Restore files from the archive on valid form submission."""
|
||||
repository = get_repository(self.kwargs['uuid'])
|
||||
repository.restore_archive(self.kwargs['name'],
|
||||
form.cleaned_data['selected_apps'])
|
||||
selected_apps = form.cleaned_data['selected_apps'][1:]
|
||||
repository.restore_archive(self.kwargs['name'], selected_apps)
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user