summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorQuentinAndre <quentin.andre@imt-atlantique.net>2021-08-07 01:23:16 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-09-01 12:36:46 +0200
commiteaee32ea5763a10b31f2e6daf59b3bed9a55cba9 (patch)
treedc821f50994ea4ae807c1e509155fd56a32d356a /ishtar_common
parentdccb0b5be17050731b352e8a7e422f31426cf884 (diff)
downloadIshtar-eaee32ea5763a10b31f2e6daf59b3bed9a55cba9.tar.bz2
Ishtar-eaee32ea5763a10b31f2e6daf59b3bed9a55cba9.zip
PR for peer review
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/static/js/ishtar-map.js143
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_geo_items.html7
-rw-r--r--ishtar_common/templates/ishtar/blocks/sheet_simple_map.html4
-rw-r--r--ishtar_common/tests.py112
4 files changed, 255 insertions, 11 deletions
diff --git a/ishtar_common/static/js/ishtar-map.js b/ishtar_common/static/js/ishtar-map.js
index c78da1098..d4eb7285d 100644
--- a/ishtar_common/static/js/ishtar-map.js
+++ b/ishtar_common/static/js/ishtar-map.js
@@ -550,6 +550,17 @@ var vector_source = {};
var vector_layer = {};
var vector_features = {};
+// for test
+var geo_items_features = null;
+var current_test = false;
+var initialize_test_map = function () {
+ geo_items_features = {};
+ current_test = true;
+ if ($("#http-geo-items-ready").length === 0) {
+ $("#display-geo-items").after('<div id="http-geo-items-ready">Ready!</div>');
+ }
+ $("#http-geo-items-ready").hide();
+}
var initialize_base_map = function(map_id, layers){
center = wkt_format.readGeometry(map_default_center).getCoordinates();
@@ -603,20 +614,31 @@ var display_map = function(map_id, points, lines_and_polys, layers){
link_template[map_id] = lines_and_polys['link_template'];
}
if (map[map_id]){
+
redraw_map(map_id, layers);
} else {
initialize_base_map(map_id, layers);
}
+ console.log('map init')
+ console.log(map[map_id]);
display_points(map_id, points);
display_lines_and_polys(map_id, lines_and_polys);
+ console.log('map after points');
+ console.log(map[map_id]);
init_popup(map_id);
map[map_id].on('click', manage_click_on_map(map_id));
map[map_id].on('pointermove', manage_hover(map_id));
+
+ if (current_test) {
+ geo_items_features[map_id] = []; // for test
+ }
};
var display_points = function(map_id, points){
+ console.log('points');
+ console.log(points);
if (!points) return;
point_features[map_id] = geojson_format.readFeatures(points);
enable_clustering(map_id);
@@ -662,19 +684,32 @@ var disp_geo_items = function(map_id, base_url, slug, pk,
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
geo_items = to_geo_items(JSON.parse(httpRequest.responseText), slug, display_both)
+ if (current_test) {
+ geo_items_features[map_id] = [];
+ }
+ var feat = null;
for (geo_item of geo_items['base-finds']) {
if (get_poly) {
- display_associated_polys(map_id, geo_item, 'basefind');
+ feat = display_associated_polys(map_id, geo_item, 'basefind');
} else {
- display_associated_points(map_id, geo_item, 'basefind');
+ feat = display_associated_points(map_id, geo_item, 'basefind');
+ }
+ if (current_test) {
+ geo_items_features[map_id].push(feat);
}
}
for (geo_item of geo_items['context-records']) {
if (get_poly) {
- display_associated_polys(map_id, geo_item, 'contextrecord');
+ feat = display_associated_polys(map_id, geo_item, 'contextrecord');
} else {
- display_associated_points(map_id, geo_item, 'contextrecord');
+ feat = display_associated_points(map_id, geo_item, 'contextrecord');
}
+ if (current_test) {
+ geo_items_features[map_id].push(feat);
+ }
+ }
+ if (current_test) {
+ $("#http-geo-items-ready").show();
}
} else { return; }
}
@@ -714,6 +749,7 @@ var display_associated_polys = function (map_id, polys, slug) {
style: style
});
map[map_id].addLayer(_vector_layer);
+ return _vector_features
}
var get_associated_base_find_style = function (feature) {
@@ -742,17 +778,18 @@ var get_associated_context_record_style = function (feature) {
};
var display_associated_points = function (map_id, points, slug) {
+ console.log('geo items points')
console.log(points);
- _point_features = geojson_format.readFeatures(points);
- console.log(_point_features[0].getGeometry().getType())
+ /*_point_features = geojson_format.readFeatures(points);
_cluster_source = new ol.source.Cluster({
distance: 40,
source: new ol.source.Vector()
});
_cluster_source.getSource().addFeatures(_point_features);
- style = get_associated_base_find_style;
+ // TODO: create own style
+ style = cluster_get_style;
if (slug === 'contextrecord') {
- style = get_associated_context_record_style;
+ style = style;
}
_cluster_layer = new ol.layer.Vector({
name: 'Cluster',
@@ -760,5 +797,95 @@ var display_associated_points = function (map_id, points, slug) {
style: style
});
map[map_id].addLayer(_cluster_layer);
+ return _point_features;*/
+}
+
+// for test purpose
+// to insert in sheet_simple_map.html when working with maps
+// wait_for_map("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}");
+var wait_for_map = function(map_id) {
+ map[map_id].on('rendercomplete', function(event) {
+ console.log("map fully loaded");
+ })
+ if (map_id in cluster_layer) {
+ console.log('cluster layer');
+ cluster_layer[map_id].on('change', function(event) {
+ if (cluster_layer.getState === "ready") {
+ console.log("cluster fully loaded");
+ }
+ })
+ }
+ if (map_id in vector_layer) {
+ console.log('vector layer');
+ vector_layer[map_id].on('change', function(event) {
+ if (vector_layer.getState === "ready") {
+ console.log("vector fully loaded");
+ }
+ })
+ }
+ if (map_id in cluster_source) {
+ console.log('cluster source');
+ cluster_source[map_id].on('change', function(event) {
+ if (cluster_source.getState === "ready") {
+ console.log("cluster source fully loaded");
+ }
+ })
+ }
+ if (map_id in vector_source) {
+ console.log('vector source');
+ vector_source[map_id].on('change', function(event) {
+ if (vector_source.getState === "ready") {
+ console.log("vector source fully loaded");
+ }
+ })
+ }
+}
+
+var get_map_by_id_test = function (id) {
+// problem here: async function because map and layers are not fully loaded directly
+ map[id].getLayers().getArray()[0].getSource().on(
+ 'change', function (evt) {
+ console.log('change')
+ var source = evt.target;
+ if (source.getState() === "ready") {
+ console.log('ready');
+ console.log(map_layers[id][0].getSource().getKeys())
+ }
+ }
+ )
+ map[id].on(
+ 'change', function (evt) {
+ console.log('change')
+ var map = evt.target;
+ if (map.getState() === "ready") {
+ console.log('ready');
+ console.log(map_layers[id][0].getSource().getKeys())
+ }
+ }
+ )
+ console.log("vector_features")
+ console.log(vector_features[id])
+ console.log("layers")
+ console.log(map_layers[id])
+ console.log("source")
+ console.log(map_layers[id][0].getSource())
+}
+
+var get_map_by_id = function (id) {
+ if (vector_features[id] == null) {
+ var base_features = geojson_format.writeFeaturesObject(point_features[id], {decimals: 3});
+ } else {
+ var base_features = geojson_format.writeFeaturesObject(vector_features[id], {decimals: 3});
+ }
+ var geo_items_feats = [];
+ if (geo_items_features && id in geo_items_features) {
+ for (var features of geo_items_features[id]) {
+ geo_items_feats.push(geojson_format.writeFeaturesObject(features, {decimals: 3}));
+ }
+ }
+ return [base_features, geo_items_feats];
+}
+var print = function (id) {
+ return "vector " + typeof vector_features[id] + ", cluster " + typeof point_features[id] ;
} \ No newline at end of file
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html b/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html
index 36fbabfcf..99fc7b866 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_geo_items.html
@@ -24,9 +24,9 @@
</dl>
<script>
var hide_get_polygons = function() {
- const disp = $("#display-geo-items");
- const get_poly = $("#get-polygons");
- const label = $("#label-get-polygons");
+ var disp = $("#display-geo-items");
+ var get_poly = $("#get-polygons");
+ var label = $("#label-get-polygons");
get_poly.hide();
label.hide();
disp.change( function () {
@@ -38,6 +38,7 @@ var hide_get_polygons = function() {
})
}
hide_get_polygons();
+
</script>
{% endif %}
{% endif %} \ No newline at end of file
diff --git a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
index b4e669a70..e8a33ae68 100644
--- a/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
+++ b/ishtar_common/templates/ishtar/blocks/sheet_simple_map.html
@@ -53,6 +53,10 @@ get_polygons.change( function () {
disp_map();
display_geo_items(disp.val(), get_polygons.val());
})
+console.log('points with base points');
+display_associated_points("map-{{window_id}}-{{geo_item.SLUG}}-{{geo_item.pk}}",
+ {{geo_item.point_2d_geojson|safe}}, "{{geo_item.SLUG}}");
+
{% endif %}
</script>
{% endif %}
diff --git a/ishtar_common/tests.py b/ishtar_common/tests.py
index e535eda4b..73e3dda88 100644
--- a/ishtar_common/tests.py
+++ b/ishtar_common/tests.py
@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# See the file COPYING for details.
+import re
from bs4 import BeautifulSoup as Soup
import csv
@@ -3127,3 +3128,114 @@ class TemplateGenerationTest(TestCase):
filtr = doc.get_filter(template, filter_re)
for key in expected_keys:
self.assertIn(key, filtr)
+
+from django.contrib.staticfiles.testing import StaticLiveServerTestCase
+from selenium.webdriver.firefox.webdriver import WebDriver
+
+class SeleniumTests(StaticLiveServerTestCase):
+ from selenium.webdriver.support.wait import WebDriverWait
+ from selenium.webdriver.common.by import By
+ from selenium.webdriver.support import expected_conditions as EC
+ from archaeological_operations.models import Operation
+
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ cls.selenium = WebDriver()
+ cls.selenium.implicitly_wait(20)
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.selenium.quit()
+ super().tearDownClass()
+
+ def setUp(self):
+ # profile
+ profile = models.get_current_profile()
+ profile.mapping = True
+ profile.files = True
+ profile.context_record = True
+ profile.find = True
+ profile.warehouse = True
+ profile.save()
+
+ # login
+ self.username, self.password, self.user = create_superuser()
+ self.selenium.get('%s%s' % (self.live_server_url, '/accounts/login/'))
+ self.WebDriverWait(self.selenium, 2).until(
+ lambda driver: driver.find_element_by_name("username"))
+ username_input = self.selenium.find_element_by_name("username")
+ username_input.send_keys(self.username)
+ password_input = self.selenium.find_element_by_name("password")
+ password_input.send_keys(self.password)
+ self.selenium.find_element_by_xpath('//button[@type="submit"][@class="btn btn-primary"]').click()
+
+ def setUpDefaultGeoItems(self):
+ from django.contrib.gis.geos import GEOSGeometry
+ from ishtar_common.models_common import SpatialReferenceSystem
+ from archaeological_finds.tests import GeomaticTest
+ from archaeological_operations.tests import create_operation
+
+ ope1 = create_operation(self.user)
+ ope2 = create_operation(self.user)
+
+ wgs84 = SpatialReferenceSystem.objects.get(srid=4326)
+ limit = (
+ "MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2)),"
+ "((6 3,9 2,9 4,6 3)))"
+ )
+ geom = GEOSGeometry("POINT({} {} {})".format(2, 43, 1), srid=4326)
+ geom_2d = GEOSGeometry("POINT({} {})".format(2, 43), srid=4326)
+ xy = 2, 43
+ geom_params = [limit, geom, geom_2d, xy, wgs84]
+
+ ope1 = self.Operation.objects.get(pk=ope1.pk)
+ ope1.multi_polygon = limit
+ ope1.save()
+ ope1 = self.Operation.objects.get(pk=ope1.pk)
+ ope1.point = geom
+ ope1.x, ope2.y = xy
+ ope1.point_source = "P"
+ ope1.spatial_reference_system = wgs84
+ ope1.point_source_item = "Operation"
+ ope1.save()
+ ope1 = self.Operation.objects.get(pk=ope1.pk)
+ ope2.multi_polygon = limit
+ ope2.save()
+
+ cr_pt1, (bf_poly_pt1, bf_pt_pt1) = GeomaticTest.create_cr_with_bfs(ope1, "Point", ["Polygon", "Point"],
+ "CR Pt Poly Pt", geom_params)
+ cr_poly1, (bf_poly_poly1, bf_pt_poly1) = GeomaticTest.create_cr_with_bfs(ope1, "Polygon", ["Polygon", "Point"],
+ "CR Poly Poly Pt", geom_params)
+ cr_pt2, (bf_poly_pt2, bf_pt_pt2) = GeomaticTest.create_cr_with_bfs(ope2, "Point", ["Polygon", "Point"],
+ "CR Pt Poly Pt", geom_params)
+ cr_poly2, (bf_poly_poly2, bf_pt_poly2) = GeomaticTest.create_cr_with_bfs(ope2, "Polygon", ["Polygon", "Point"],
+ "CR Poly Poly Pt", geom_params)
+ def scroll(self, element):
+ self.selenium.execute_script(
+ "var viewPortHeight = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);"
+ + "var elementTop = arguments[0].getBoundingClientRect().top;"
+ + "window.scrollBy(0, elementTop-(viewPortHeight/2));",
+ element)
+
+ def assertMap(self, dic_base, features_collecs=None):
+ mapdiv = self.selenium.find_element_by_class_name("window-map")
+ mapid = mapdiv.get_attribute("id")
+ id = int(re.search(r'\d+$', mapid).group())
+ # TODO: use the map and not the map_features in the js function
+ if features_collecs:
+ self.WebDriverWait(self.selenium, 2).until(
+ self.EC.visibility_of_element_located((self.By.ID, "http-geo-items-ready"))
+ )
+ print(id)
+ print(self.selenium.execute_script('return print(arguments[0])', mapid))
+ base_features, geo_items_feats = self.selenium.execute_script('return get_map_by_id(arguments[0])', mapid)
+ base_features['features'][0]['properties'].pop('name')
+ dic_base['features'][0]['properties']['id'] = id
+ print('feat : ', base_features)
+ print('dic : ', dic_base)
+ self.assertEqual(base_features, dic_base)
+ if features_collecs:
+ print('feat : ', geo_items_feats)
+ print('dic : ', features_collecs)
+ self.assertEqual(geo_items_feats, features_collecs)