summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne@peacefrogs.net>2019-02-07 18:20:11 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2019-04-24 19:38:56 +0200
commita39df7b6088527faf4108e9a50040e8165ab6a3d (patch)
tree92b1e3e2650434e5ee40a49b5249f32405b0f699
parent1b0d2c7558b5cf64a65d05eeba0be8f5c2388bf8 (diff)
downloadIshtar-a39df7b6088527faf4108e9a50040e8165ab6a3d.tar.bz2
Ishtar-a39df7b6088527faf4108e9a50040e8165ab6a3d.zip
Map: manage show detail for simple map
-rw-r--r--archaeological_finds/templates/ishtar/sheet_basefind.html14
-rw-r--r--archaeological_finds/urls.py2
-rw-r--r--archaeological_finds/views.py10
-rw-r--r--ishtar_common/models.py42
-rw-r--r--ishtar_common/static/js/ishtar-map.js24
-rw-r--r--ishtar_common/static/js/ishtar.js5
-rw-r--r--ishtar_common/templates/blocks/DataTables.html7
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_simple_map.html11
-rw-r--r--ishtar_common/templatetags/link_to_window.py4
9 files changed, 82 insertions, 37 deletions
diff --git a/archaeological_finds/templates/ishtar/sheet_basefind.html b/archaeological_finds/templates/ishtar/sheet_basefind.html
index 74a2b527e..fa96ddf0e 100644
--- a/archaeological_finds/templates/ishtar/sheet_basefind.html
+++ b/archaeological_finds/templates/ishtar/sheet_basefind.html
@@ -66,15 +66,14 @@
</div>
{% endif %}
<h3>{% trans "Map"%}</h3>
- {% with geo_item=base_find %}
- {% include "ishtar/blocks/sheet_simple_map.html"%}
- {% endwith %}
- {% if base_find.x or base_find.y or base_find.topographic_localisation %}
<div class='row'>
+ {% with geo_item=base_find %}
+ {% include "ishtar/blocks/sheet_simple_map.html"%}
+ {% endwith %}
{% field_flex "Point of topographic reference" base_find.topographic_localisation %}
- <dl class="col-12 d-flex flex-wrap row">
- <dt class="col-2">{% trans "Coordinates" %}</dt>
- <dd class="col-10">
+ <dl class="col-12 col-lg-6 d-flex flex-wrap row">
+ <dt class="col-4">{% trans "Coordinates" %}</dt>
+ <dd class="col-8">
{% trans "X:"%} {{base_find.x|default_if_none:"-"}}
{% if base_find.estimated_error_x %} ({% trans "error:" %} {{base_find.estimated_error_x}}){% endif %},
{% trans "Y:"%} {{base_find.y|default_if_none:"-"}},
@@ -89,6 +88,5 @@
</dl>
</div>
{% endif %}
- {% endif %}
</div>
diff --git a/archaeological_finds/urls.py b/archaeological_finds/urls.py
index fe7b2acd2..7e8b52ddf 100644
--- a/archaeological_finds/urls.py
+++ b/archaeological_finds/urls.py
@@ -250,6 +250,8 @@ urlpatterns = [
url(r'^show-find/basket-(?:(?P<pk>.+)/(?P<type>.+)?)?$',
views.show_findbasket,
name='show-findbasket'),
+ url(r'^show-basefind/(?:(?P<pk>.+)/(?P<type>.+)?)?$',
+ views.show_basefind, name='show-basefind'),
url(r'^display-find/basket-(?P<pk>.+)/$', views.display_findbasket,
name='display-findbasket'),
url(r'^show-historized-find/(?P<pk>.+)?/(?P<date>.+)?$',
diff --git a/archaeological_finds/views.py b/archaeological_finds/views.py
index e4f8ab66d..72d02305c 100644
--- a/archaeological_finds/views.py
+++ b/archaeological_finds/views.py
@@ -118,6 +118,15 @@ def autocomplete_treatmentfile(request):
return HttpResponse(data, content_type='text/plain')
+def show_basefind(request, pk, **dct):
+ q = models.Find.objects.filter(base_finds__pk=pk,
+ downstream_treatment__isnull=True)
+ if not q.count():
+ return Http404()
+ find_pk = q.order_by('-pk')[0]
+ return show_item(models.Find, 'find')(request, find_pk, **dct)
+
+
def show_find_extra(request, find):
if not request.user or not request.user.ishtaruser:
return {}
@@ -156,6 +165,7 @@ def autocomplete_findbasket(request, current_right=None):
)
return HttpResponse(data, content_type='text/plain')
+
get_find_basket = get_item(
models.FindBasket, 'get_findbasket', 'findbasket',
model_for_perms=models.Find
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index bd6c38ff1..962fc93a1 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -25,6 +25,7 @@ import datetime
import inspect
from importlib import import_module
from jinja2 import TemplateSyntaxError
+import json
import logging
import os
import re
@@ -71,6 +72,7 @@ from ishtar_common.models_imports import ImporterModel, ImporterType, \
ImporterDefault, ImporterDefaultValues, ImporterColumn, \
ImporterDuplicateField, Regexp, ImportTarget, TargetKey, FormaterType, \
Import, TargetKeyGroup
+from ishtar_common.templatetags.link_to_window import simple_link_to_window
from ishtar_common.utils import get_cache, disable_for_loaddata, create_slug, \
get_all_field_names, merge_tsvectors, cached_label_changed, \
generate_relation_graph, max_size_help
@@ -1598,8 +1600,8 @@ class DocumentItem(object):
if can_add_doc:
actions = [
(
- reverse("create-document") + "?{}={}".format(self.SLUG,
- self.pk),
+ reverse("create-document") + "?{}={}".format(
+ self.SLUG, self.pk),
_(u"Add document/image"),
"fa fa-plus",
_(u"doc./image"),
@@ -1611,21 +1613,37 @@ class DocumentItem(object):
class GeoItem(object):
+ def _geojson_serialize(self, geom_attr):
+ if not hasattr(self, geom_attr):
+ return ""
+ cached_label_key = 'cached_label'
+ if getattr(self, "CACHED_LABELS", None):
+ cached_label_key = self.CACHED_LABELS[-1]
+ geojson = serialize(
+ 'geojson',
+ self.__class__.objects.filter(pk=self.pk),
+ geometry_field=geom_attr, fields=(cached_label_key,))
+ geojson_dct = json.loads(geojson)
+ features = geojson_dct.pop('features')
+ for idx in range(len(features)):
+ feature = features[idx]
+ lbl = feature['properties'].pop(cached_label_key)
+ feature['properties']['name'] = lbl
+ feature['properties']['id'] = self.pk
+ geojson_dct['features'] = features
+ geojson_dct['link_template'] = simple_link_to_window(self).replace(
+ '999999', '<pk>'
+ )
+ geojson = json.dumps(geojson_dct)
+ return geojson
+
@property
def point_2d_geojson(self):
- if not hasattr(self, 'point_2d'):
- return ""
- return serialize('geojson', self.__class__.objects.filter(pk=self.pk),
- geometry_field='point_2d',
- fields=('cache_complete_id',))
+ return self._geojson_serialize('point_2d')
@property
def multi_polygon_geojson(self):
- if not hasattr(self, 'multi_polygon'):
- return ""
- return serialize('geojson', self.__class__.objects.filter(pk=self.pk),
- geometry_field='multi_polygon',
- fields=('cache_complete_id',))
+ return self._geojson_serialize('multi_polygon')
class BaseHistorizedItem(DocumentItem, FullSearch, Imported, JsonData, GeoItem,
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index 0613ec285..c1bed2554 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -169,7 +169,11 @@ var manage_click_on_map = function(map_id){
};
};
+var current_event;
+
var click_on_feature = function(map_id, feature, e){
+ // console.log("click_on_feature");
+ current_event = e;
if (!$(e.target).is($(popup_item[map_id]))
&& !$.contains($(popup_item[map_id])[0], e.target) ) {
@@ -183,11 +187,11 @@ var click_on_feature = function(map_id, feature, e){
current_feature = feature;
if (!feature) return;
- var timeout = 200;
+ var timeout = 10;
setTimeout(function(){
// zoom on aggregated
var key = feature.get('key');
- if (key && key.length > 6 && key.substring(0, 7) == 'cluster'){
+ if (feature.get('name') || feature.get('key')){
feature = click_on_cluster(map_id, feature);
}
}, timeout);
@@ -197,6 +201,7 @@ var auto_zoom = false;
var click_on_cluster = function(map_id, feature, zoom_level, duration, nb_zoom,
current_nb_items){
+ // console.log("click_on_cluster");
if (!duration){
// zoom animation must be slower
duration = animation_duration * 2;
@@ -271,9 +276,13 @@ var click_on_cluster = function(map_id, feature, zoom_level, duration, nb_zoom,
var display_cluster_detail = function(map_id, cluster){
// console.log("display_cluster_detail");
var features = cluster.getProperties()['features']
+
var offset_x = 0;
var offset_y = -21;
- if (features.length == 1){
+ if (!features){
+ features = [cluster];
+ offset_y = -7;
+ } else if (features.length == 1){
offset_y = -54;
}
display_items(map_id, features, offset_x, offset_y);
@@ -319,7 +328,12 @@ var _display_items = function(map_id, features, offset_x, offset_y){
$("#ishtar-map-window-" + map_id + " .modal-body").html(window_content);
$(popup_item[map_id]).html(popup_content);
$("." + ul_class + " .map-list-detail").click(open_map_window(map_id));
- popup[map_id].setPosition(geom.getCoordinates());
+
+ if (geom.getType() == "Point"){
+ popup[map_id].setPosition(geom.getCoordinates());
+ } else {
+ popup[map_id].setPosition(current_event.coordinate);
+ }
popup[map_id].setOffset([offset_x, offset_y]);
$(popup_item[map_id]).css({opacity: 0});
$(popup_item[map_id]).show(0, function(){
@@ -417,7 +431,7 @@ var display_map = function(map_id, points, lines_and_polys, layers){
if (points){
link_template[map_id] = points['link_template'];
} else {
- /// link_template = lines_and_polys['link_template'];
+ link_template[map_id] = lines_and_polys['link_template'];
}
if (map[map_id]){
redraw_map(map_id, layers);
diff --git a/ishtar_common/static/js/ishtar.js b/ishtar_common/static/js/ishtar.js
index 6600181e7..e7ec6850c 100644
--- a/ishtar_common/static/js/ishtar.js
+++ b/ishtar_common/static/js/ishtar.js
@@ -1250,13 +1250,12 @@ var render_map_list_modal = function(map_id){
return html;
};
-var render_map = function(data_table, table_name, nb_select, map_id){
- //var html = render_paginate_select(table_name, 'map', nb_select);
+var render_map = function(map_id){
var html = "";
html += "<div class='ishtar-table-map' id='" + map_id + "'></div>";
html += "<div class='ishtar-map-popup' id='ishtar-map-popup-" + map_id + "'></div>";
html += render_map_list_modal(map_id);
- return {"points": data_table, "html": html};
+ return html;
};
var register_map = function(map_id, points){
diff --git a/ishtar_common/templates/blocks/DataTables.html b/ishtar_common/templates/blocks/DataTables.html
index 3e0faffd0..cf33a8cfa 100644
--- a/ishtar_common/templates/blocks/DataTables.html
+++ b/ishtar_common/templates/blocks/DataTables.html
@@ -114,14 +114,15 @@ map_submit_search = function(){
var timestamp = Math.floor(Date.now() / 1000);
var map_id = "map-" + timestamp;
$('.modal-progress .modal-header').html("{% trans 'Render map...' %}");
- var result = render_map(data, "{{name}}", nb_select, map_id);
- $("#tab-content-map-{{name}}").html(result["html"]);
+
+ var html = render_map(map_id);
+ $("#tab-content-map-{{name}}").html(html);
$("#id_{{name}}-length_map").change(map_submit_search);
if ($('.modal-progress').length > 0){
$('.modal-progress').modal('hide');
$('.modal-progress .modal-header').html(modal_base_text);
}
- register_map(map_id, result["points"]);
+ register_map(map_id, data);
});
return false;
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
index bf25db653..d0ec50b5f 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
@@ -1,8 +1,12 @@
{% if geo_item.point_2d or geo_item.multi_polygon %}
-<div class="window-map"
- id="map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}"></div>
-
+<div class="col-12 col-lg-6 flex-wrap">
+<div class="window-map" id="map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}">
+</div>
+<div id="map-content-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}"></div>
+</div>
<script type="text/javascript">
+var html = render_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}");
+$("#map-content-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}").html(html);
{% if geo_item.point_source == 'P' or not geo_item.multi_polygon %}
var {{geo_item.SLUG}}{{geo_item.pk}} = {{geo_item.point_2d_geojson|safe}};
display_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", {{geo_item.SLUG}}{{geo_item.pk}});
@@ -11,5 +15,4 @@ var {{geo_item.SLUG}}{{geo_item.pk}} = {{geo_item.multi_polygon_geojson|safe}};
display_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}", null, {{geo_item.SLUG}}{{geo_item.pk}});
{% endif %}
</script>
-
{% endif %}
diff --git a/ishtar_common/templatetags/link_to_window.py b/ishtar_common/templatetags/link_to_window.py
index 439602665..4c1c79727 100644
--- a/ishtar_common/templatetags/link_to_window.py
+++ b/ishtar_common/templatetags/link_to_window.py
@@ -10,13 +10,13 @@ register = Library()
@register.filter
def simple_link_to_window(item):
- if not hasattr(item, 'SHOW_URL'):
+ if not hasattr(item, 'SLUG'):
return ""
return mark_safe(
u' <a class="display_details" href="#" '
u'onclick="load_window(\'{}\')">'
u'<i class="fa fa-info-circle" aria-hidden="true"></i></a>'.format(
- reverse(item.SHOW_URL, args=[item.pk, ''])))
+ reverse("show-" + item.SLUG, args=[item.pk, ''])))
@register.filter