From e5fce5c6677e5038100732a3c5d5e668a52d3d9a Mon Sep 17 00:00:00 2001 From: afabiani Date: Wed, 5 Dec 2018 09:30:50 +0100 Subject: [PATCH] [Fixes #4105] [Remote Services] harvesting resources pagination does not keep memory of the selection if changing page --- .../services/service_resources_harvest.html | 47 +++++++++++++++++-- geonode/services/views.py | 4 ++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/geonode/services/templates/services/service_resources_harvest.html b/geonode/services/templates/services/service_resources_harvest.html index 2b67397574d..e62d8fdb7cc 100644 --- a/geonode/services/templates/services/service_resources_harvest.html +++ b/geonode/services/templates/services/service_resources_harvest.html @@ -23,7 +23,7 @@

{% trans "Import resources" %} {{ service.name }}

- + @@ -32,7 +32,11 @@

{% trans "Import resources" %} {{ service.name }}

{% for resource_meta in resources %} - + @@ -59,7 +63,7 @@

{% trans "Import resources" %} {{ service.name }}

{% endif %}
  • {{ resources.number }}/{{ resources.paginator.num_pages }}
  • {% if resources.has_next %} -
  • next
  • +
  • {% else %}
  • next
  • {% endif %} @@ -67,8 +71,6 @@

    {% trans "Import resources" %} {{ service.name }}

    {% endif %} - - {% else %}

    {% trans "All resources have already been imported" %}

    @@ -136,11 +138,46 @@

    {% trans "Import resources" %} {{ service.name }}

    $("#rescanService").on('click', function () { $("#progressModal").modal("show"); }); + $("#next").on('click', function () { + appendResourcesToTheUrl(this); + }); + $("#previous").on('click', function () { + appendResourcesToTheUrl(this); + }); {% if is_sync %} $("input[type = submit]").on('click', function () { $("#harvestingResourceSync").modal("show"); }); {% endif %} }); + + function appendResourcesToTheUrl(element) { + $(element).attr('href', function() { + var resource_list = ""; + $(window.location.href.slice(window.location.href.indexOf('?') + 1).split('&')).each( + function() + { + var param = this; + var uncehcked_resource = false; + $('input[name=resource_list]').each(function () { + var sThisVal = (this.checked ? $(this).val() : ""); + if (sThisVal && !resource_list.includes(sThisVal)) { + resource_list += "&resource_list="+sThisVal; + } else if ($(this).val() == param.split("=")[1]) { + uncehcked_resource = true; + } + }); + + if (!uncehcked_resource && + param.split("=")[0] == "resource_list" && + !resource_list.includes(param.split("=")[1])) { + resource_list += "&resource_list="+param.split("=")[1]; + } + } + ); + + return element.href + resource_list; + }); + } {% endblock extra_script %} diff --git a/geonode/services/views.py b/geonode/services/views.py index d43cd37c3d0..109de7482d2 100644 --- a/geonode/services/views.py +++ b/geonode/services/views.py @@ -165,12 +165,16 @@ def harvest_resources(request, service_id): "service": service, "importable": not_yet_harvested, "resources": harvestable_resources, + "requested": request.GET.getlist("resource_list"), "is_sync": is_sync, "errored_state": errored_state, } ) elif request.method == "POST": requested = request.POST.getlist("resource_list") + requested.extend(request.GET.getlist("resource_list")) + # Let's remove duplicates + requested = list(set(requested)) resources_to_harvest = [] for id in _gen_harvestable_ids(requested, available_resources): logger.debug("id: {}".format(id))
    {% if not errored_state %}{% endif %}{% if not errored_state %}{% endif %} {% trans "Id" %} {% trans "Name" %} {% trans "Description" %}
    {% if not errored_state %}{% endif %} + {% if not errored_state %} + + {% endif %} + {{ resource_meta.id }} {{ resource_meta.title }} {{ resource_meta.abstract }}