Skip to content

Commit

Permalink
[Fixes #4105] [Remote Services] harvesting resources pagination does …
Browse files Browse the repository at this point in the history
…not keep memory of the selection if changing page
  • Loading branch information
afabiani committed Dec 5, 2018
1 parent 9773ba9 commit e5fce5c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
47 changes: 42 additions & 5 deletions geonode/services/templates/services/service_resources_harvest.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h3>{% trans "Import resources" %}<small> {{ service.name }}</small></h3>
<table class="table table table-hover">
<thead>
<tr>
<th>{% if not errored_state %}<input type="checkbox" checked="true" id="checkAll" />{% endif %}</th>
<th>{% if not errored_state %}<input type="checkbox" id="checkAll" />{% endif %}</th>
<th>{% trans "Id" %}</th>
<th>{% trans "Name" %}</th>
<th>{% trans "Description" %}</th>
Expand All @@ -32,7 +32,11 @@ <h3>{% trans "Import resources" %}<small> {{ service.name }}</small></h3>
<tbody>
{% for resource_meta in resources %}
<tr>
<td>{% if not errored_state %}<input type="checkbox" name="resource_list" id="option_{{resource_meta.id}}" value="{{ resource_meta.id }}" checked/>{% endif %}</td>
<td>
{% if not errored_state %}
<input {% if resource_meta.id in requested %}checked{% endif %} type="checkbox" name="resource_list" id="option_{{resource_meta.id}}" value="{{ resource_meta.id }}"/>
{% endif %}
</td>
<td>{{ resource_meta.id }}</td>
<td>{{ resource_meta.title }}</td>
<td>{{ resource_meta.abstract }}</td>
Expand All @@ -59,16 +63,14 @@ <h3>{% trans "Import resources" %}<small> {{ service.name }}</small></h3>
{% endif %}
<li class="active"><a href="#">{{ resources.number }}/{{ resources.paginator.num_pages }}</a></li>
{% if resources.has_next %}
<li><a aria-label="Next" href="?page={{ resources.next_page_number }}">next</a></li>
<li><a id="next" aria-label="Next" href="?page={{ resources.next_page_number }}">next</a></li>
{% else %}
<li class="disabled"><a aria-label="Next" href="#">next</a></li>
{% endif %}
</ul>
</nav>
</div>
{% endif %}


</div>
{% else %}
<p>{% trans "All resources have already been imported" %}</p>
Expand Down Expand Up @@ -136,11 +138,46 @@ <h3>{% trans "Import resources" %}<small> {{ service.name }}</small></h3>
$("#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;
});
}
</script>
{% endblock extra_script %}
4 changes: 4 additions & 0 deletions geonode/services/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit e5fce5c

Please sign in to comment.