summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.md1
-rw-r--r--archaeological_finds/views.py6
-rw-r--r--archaeological_operations/tests.py15
-rw-r--r--ishtar_common/static/js/ishtar.js30
-rw-r--r--ishtar_common/templates/blocks/DataTables-content.html4
-rw-r--r--ishtar_common/templates/blocks/DataTables.html52
-rw-r--r--ishtar_common/views_item.py8
-rw-r--r--scss/custom.scss9
8 files changed, 119 insertions, 6 deletions
diff --git a/CHANGES.md b/CHANGES.md
index d7e8f9635..c51fef4c4 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -7,6 +7,7 @@ Ishtar changelog
================
### Features/improvements ###
+- Search result - export: export only selected
- Commands: manage update search vector with maintenance script
- utils: adapt to v4 OSM relations importer
- syndication ui: better color for external sources
diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py
index 2cd83c566..bf8d0dfcb 100644
--- a/archaeological_finds/views.py
+++ b/archaeological_finds/views.py
@@ -1331,14 +1331,16 @@ def get_geo_items(request, current_right=None):
operation_pk = request.GET.get("operation_id")
context_record_pk = request.GET.get("context_record_id")
pk = request.GET.get("pk")
- if "external_" in operation_pk or "external_" in context_record_pk:
- return HttpResponse("{}")
if operation_pk:
+ if "external_" in operation_pk:
+ return HttpResponse("{}")
try:
item = Operation.objects.get(pk=operation_pk)
except Operation.DoesNotExist:
raise Http404()
elif context_record_pk:
+ if "external_" in context_record_pk:
+ return HttpResponse("{}")
try:
item = ContextRecord.objects.get(pk=context_record_pk)
except ContextRecord.DoesNotExist:
diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py
index 7bc51539d..25a561b6f 100644
--- a/archaeological_operations/tests.py
+++ b/archaeological_operations/tests.py
@@ -2875,6 +2875,21 @@ class OperationSearchTest(TestCase, OperationInitTest, SearchText):
result = json.loads(response.content.decode())
self.assertEqual(result["recordsTotal"], 3)
+ def test_search_selected(self):
+ c = Client()
+ ope1 = self.operations[0]
+ ope2 = self.operations[1]
+ response = c.get(reverse("get-operation"), {"selected_ids": ope1.pk})
+ # no result when no authentication
+ self.assertTrue(not json.loads(response.content.decode()))
+ c.login(username=self.username, password=self.password)
+ response = c.get(reverse("get-operation"), {"selected_ids": ope1.pk})
+ result = json.loads(response.content.decode())
+ self.assertEqual(result["recordsTotal"], 1)
+ response = c.get(reverse("get-operation"), {"selected_ids": f"{ope1.pk}-{ope2.pk}"})
+ result = json.loads(response.content.decode())
+ self.assertEqual(result["recordsTotal"], 2)
+
def test_base_search_vector(self):
c = Client()
response = c.get(reverse("get-operation"), {"search_vector": "chaTEAU"})
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js
index 03d62bac3..3b4aa7156 100644
--- a/ishtar_common/static/js/ishtar.js
+++ b/ishtar_common/static/js/ishtar.js
@@ -1127,6 +1127,36 @@ var qa_action_register = function(url, slug) {
});
};
+
+var update_export_urls = function(dt, sname, source, source_full, extra_sources, extra_tpl){
+ let rows = dt.rows( { selected: true } ).data();
+ let data = "selected_ids=";
+ for (k in rows){
+ if (!rows[k]['id']) continue;
+ if (k > 0) data += "-";
+ data += rows[k]['id'];
+ }
+ let csv_url = source + "csv?submited=1&" + data;
+ $("." + sname + "-csv").attr("href", csv_url);
+ let csv_full_url = source_full + "csv?submited=1&" + data;
+ $("." + sname + "-csv-full").attr("href", csv_full_url);
+
+ for (k in extra_sources){
+ let src = extra_sources[k];
+ let slug = src[0];
+ let name = src[1];
+ let extra_source = src[2];
+ $("." + slug + "-csv-full").attr("href", extra_source + "csv?submited=1&" + data);
+ }
+ for (k in extra_tpl){
+ let tpl = extra_tpl[k];
+ let slug = tpl[0];
+ let lnk = tpl[1];
+ $("." + slug + "-labels").attr("href", lnk + "?submited=1&" + data);
+ }
+ return false;
+};
+
var dt_single_enable_disable_submit_button = function(e, dt, type, indexes){
var rows = dt.rows( { selected: true } ).count();
if (rows == 1) {
diff --git a/ishtar_common/templates/blocks/DataTables-content.html b/ishtar_common/templates/blocks/DataTables-content.html
index 9de143cd4..832b60d22 100644
--- a/ishtar_common/templates/blocks/DataTables-content.html
+++ b/ishtar_common/templates/blocks/DataTables-content.html
@@ -54,6 +54,10 @@
{% endfor %}
</div>
</div>{% endif %}
+ <span class="selected-lines">
+ <span class="sl-whole">{% trans "whole table" %}</span>
+ <span class="sl-selected"><span class="sl-number"></span>&nbsp;{% trans "selected item(s)" %}</span>
+ </span>
</div>
</div>
diff --git a/ishtar_common/templates/blocks/DataTables.html b/ishtar_common/templates/blocks/DataTables.html
index 9f0ab04ca..95ebbbc6b 100644
--- a/ishtar_common/templates/blocks/DataTables.html
+++ b/ishtar_common/templates/blocks/DataTables.html
@@ -167,6 +167,26 @@ update_submit_args = function(){
return false;
};
+update_select_args = function(dt){
+ let nb_row = dt.rows( { selected: true } ).count();
+ $(".sl-number").html(nb_row);
+ if (nb_row == 0){
+ $(".selected-lines .sl-whole").show();
+ $(".selected-lines .sl-selected").hide();
+ update_submit_args();
+ return;
+ }
+ $(".selected-lines .sl-selected").show();
+ $(".selected-lines .sl-whole").hide();
+ let extra_sources = [{% for slug, name, extra_source in extra_sources %}
+ ["{{slug}}", "{{name}}", "{{extra_source}}"]{% if not forloop.last %},{% endif %}
+ {% endfor %}];
+ let extra_tpl = [{% for template in current_model.label_templates %}
+ ["{{template.slug}}", "{{template.get_baselink_for_labels}}"]{% if not forloop.last %},{% endif %}
+ {% endfor %}];
+ update_export_urls(dt, "{{sname}}", "{{source}}", "{{source_full}}", extra_sources, extra_tpl);
+}
+
var current_source = "default";
jQuery(document).ready(function(){
@@ -284,11 +304,35 @@ jQuery(document).ready(function(){
datatable_{{sname}} = jQuery("#grid_{{name}}").DataTable(datatable_options);
{% if not multiple_select %}
- datatable_{{sname}}.on('select', dt_single_enable_disable_submit_button);
- datatable_{{sname}}.on('deselect', dt_single_enable_disable_submit_button);
+ datatable_{{sname}}.on(
+ 'select',
+ function(e, dt, type, indexes){
+ update_select_args(dt);
+ dt_single_enable_disable_submit_button(e, dt, type, indexes);
+ }
+ );
+ datatable_{{sname}}.on(
+ 'deselect',
+ function(e, dt, type, indexes){
+ update_select_args(dt);
+ dt_single_enable_disable_submit_button(e, dt, type, indexes);
+ }
+ );
{% else %}
- datatable_{{sname}}.on('select', dt_multi_enable_disable_submit_button);
- datatable_{{sname}}.on('deselect', dt_multi_enable_disable_submit_button);
+ datatable_{{sname}}.on(
+ 'select',
+ function(e, dt, type, indexes){
+ update_select_args(dt);
+ dt_multi_enable_disable_submit_button(e, dt, type, indexes);
+ }
+ );
+ datatable_{{sname}}.on(
+ 'deselect',
+ function(e, dt, type, indexes){
+ update_select_args(dt);
+ dt_multi_enable_disable_submit_button(e, dt, type, indexes);
+ }
+ );
{% endif %}
{% if external_sources %}{% for source_id, source_label, source_url in external_sources %}
diff --git a/ishtar_common/views_item.py b/ishtar_common/views_item.py
index 9853e5410..ebe9ca07d 100644
--- a/ishtar_common/views_item.py
+++ b/ishtar_common/views_item.py
@@ -1864,10 +1864,18 @@ def get_item(
except ValueError:
return HttpResponse("[]", content_type="text/plain")
+ selected_ids = request_items.get("selected_ids", None)
+ if selected_ids:
+ if "-" in selected_ids:
+ q = Q(pk__in=selected_ids.split("-"))
+ else:
+ q = Q(pk=selected_ids)
+ and_reqs.append(q)
for k in request_keys:
val = request_items.get(k)
if not val:
continue
+
req_keys = request_keys[k]
target = dct
if k in query_parameters:
diff --git a/scss/custom.scss b/scss/custom.scss
index 9fbd3b816..00bbd5f12 100644
--- a/scss/custom.scss
+++ b/scss/custom.scss
@@ -311,6 +311,15 @@ pre {
/* datatable - start */
+.selected-lines{
+ margin: 0 1em;
+ font-size: 0.8em;
+ .sl-selected{
+ display: none;
+ }
+}
+
+
table.dataTable {
font-size: 0.8em;
}