diff --git a/misc/map_test_data.py b/misc/map_test_data.py index addc0e8c7f52cc60d228e079e5b76f5893be74d4..657a01f254b6d7ea2a24a54035d167f621c0c3c5 100755 --- a/misc/map_test_data.py +++ b/misc/map_test_data.py @@ -8,6 +8,7 @@ import caosdb import random caosdb.get_connection()._login() +caosdb.execute_query("FIND ENTITY WITH ID > 99").delete() # data model datamodel = caosdb.Container() @@ -18,6 +19,9 @@ datamodel.extend([ "MapObject" ).add_property("longitude", importance=caosdb.OBLIGATORY ).add_property("latitude", importance=caosdb.OBLIGATORY), + caosdb.RecordType( + "PathObject" + ).add_property("MapObject", datatype=caosdb.LIST("MapObject")), ]) datamodel.insert() @@ -25,19 +29,23 @@ datamodel.insert() # test data +testdata = caosdb.Container() +path = caosdb.Record() +path.add_parent("PathObject") +path.add_property("MapObject", datatype=caosdb.LIST("MapObject"), value=[]) +testdata.append(path) +for i in range(100): + loc = caosdb.Record( + "Object-{}".format(i) + ).add_parent("MapObject" + ).add_property("longitude", random.gauss(-42.0, 5) + ).add_property("latitude", random.gauss(77.0, 5)) + testdata.append(loc) + path.get_property("MapObject").value.append(loc) -testdata = caosdb.Container() -for i in range(100): - testdata.append( - caosdb.Record( - "Object-{}".format(i) - ).add_parent("MapObject" - ).add_property("longitude", random.gauss(-42.0, 5) - ).add_property("latitude", random.gauss(77.0, 5)) - ) testdata.insert(); diff --git a/src/core/js/caosdb.js b/src/core/js/caosdb.js index a2c1f55ce49e409b0153c888197002868b90a637..0df57dd4095cb3efb325d68821007cae8c55f13b 100644 --- a/src/core/js/caosdb.js +++ b/src/core/js/caosdb.js @@ -604,6 +604,7 @@ function getPropertyFromElement(propertyelement, names = undefined) { if (valel && valel.textContent.length > 0) { value_string = valel.textContent; } else if (valel && valel.value && valel.value.length > 0) { + // this is the case when the valel is an input coming from edit_mode. value_string = valel.value; } @@ -642,7 +643,6 @@ function getPropertyFromElement(propertyelement, names = undefined) { } } - return property; } @@ -762,9 +762,20 @@ var getPropertyValues = function (entities, selectors) { while (current_entity) { const row = []; for (let expr of xpaths) { - const property = entities.evaluate(expr, current_entity).iterateNext(); - if (typeof property != "undefined" && property != null) { - row.push(property.textContent.trim()); + const property_iter = entities.evaluate(expr, current_entity); + var property = property_iter.iterateNext(); + if (typeof property !== "undefined" && property !== null) { + // handle lists and single values + var values = []; + while (property !== null) { + values.push(property.textContent.trim()); + property = property_iter.iterateNext(); + } + if(values.length < 2) { + // wasn't a list + values = values[0]; + } + row.push(values); } else { row.push(undefined) } diff --git a/src/core/js/ext_map.js b/src/core/js/ext_map.js index b08c7968f10069cb9446dc0537907741e1a6d316..f0283cddc4940dc5ac56594a0a1b2fda7f9ea047 100644 --- a/src/core/js/ext_map.js +++ b/src/core/js/ext_map.js @@ -400,7 +400,7 @@ var caosdb_map = new function () { this._get_with_POV = function (props) { var pov = "" for (let p of props) { - pov = pov + ` WITH ${p} `; + pov = pov + ` WITH "${p}" `; } return pov; } @@ -444,12 +444,12 @@ var caosdb_map = new function () { var pov = undefined; if (typeof ids === "undefined") { pov = (caosdb_map._get_with_POV(props) + - ` WITH ${datamodel.lat} AND ${datamodel.lng}`); + ` WITH ( "${datamodel.lat}" AND "${datamodel.lng}" )`); } else { pov = caosdb_map._get_id_POV(ids); } - return `SELECT parent,${selector}${datamodel.lat},${selector}${datamodel.lng} FROM ENTITY ${recordtype} ${pov} `; + return `SELECT parent,${selector}${datamodel.lat},${selector}${datamodel.lng} FROM ENTITY "${recordtype}" ${pov} `; } @@ -544,9 +544,21 @@ var caosdb_map = new function () { var latlong = caosdb_map._get_leaf_prop(entities, depth, datamodel); for (let rec_id in latlong) { + const is_list_lat = Array.isArray(latlong[rec_id][0]); + const is_list_lng = Array.isArray(latlong[rec_id][0]); + var lat, lng; + if (is_list_lat) { + var lat_val = `<Value>${latlong[rec_id][0].join("</Value><Value>")}</Value>`; + lat = `<Property name="${datamodel.lat}" datatype="LIST<lat>">${lat_val}</Property>`; + var lng_val = `<Value>${latlong[rec_id][1].join("</Value><Value>")}</Value>`; + lng = `<Property name="${datamodel.lng}" datatype="LIST<lng>">${lng_val}</Property>`; + } else { + lat = `<Property name="${datamodel.lat}">${latlong[rec_id][0]}</Property>`; + lng = `<Property name="${datamodel.lng}">${latlong[rec_id][1]}</Property>`; + } let tmp_rec = caosdb_map._get_toplvl_rec_with_id(entities, rec_id); - tmp_rec.append(str2xml(`<Property name="${datamodel.lat}">${latlong[rec_id][0]}</Property>`).firstElementChild); - tmp_rec.append(str2xml(`<Property name="${datamodel.lng}">${latlong[rec_id][1]}</Property>`).firstElementChild); + tmp_rec.append(str2xml(lat).firstElementChild); + tmp_rec.append(str2xml(lng).firstElementChild); } } @@ -569,7 +581,7 @@ var caosdb_map = new function () { results = await transformation.transformEntities(entities); } else { results = await caosdb_map.query( - `FIND ENTITY WITH ${datamodel.lat} AND ${datamodel.lng}`); + `FIND ENTITY WITH ( "${datamodel.lat}" AND "${datamodel.lng}" )`); } const container = $('<div>').append(results)[0]; @@ -588,9 +600,7 @@ var caosdb_map = new function () { * used for the coordinates. * @returns {HTMLElement} a popup element. */ - this._make_map_popup = function (entity, datamodel) { - const lat = getProperty(entity, datamodel.lat); - const lng = getProperty(entity, datamodel.lng); + this._make_map_popup = function (entity, datamodel, lat, lng) { const role_label = $(entity).find( ".label.caosdb-f-entity-role").first().clone(); const parent_list = caosdb_map.make_parent_labels(entity); @@ -603,8 +613,7 @@ var caosdb_map = new function () { extra_loc_hint = `<div>Location of related ${path[path.length-1]}<div>`; } const loc = $(`<div class="small text-muted">${extra_loc_hint} - Lat: ${dms_lat} Lng: ${dms_lng} - </div>`); + Lat: ${dms_lat} Lng: ${dms_lng}</div>`); const ret = $('<div/>') .append(role_label) .append(parent_list) @@ -1518,6 +1527,33 @@ var caosdb_map = new function () { */ this.query = query; + /* + * Create a single map marker for the given entity. + * + * @param {HTMLElement} map_entity - the entity. + * @param {DataModelConfig} datamodel - specifies the properties for + * coordinates. + * @param {number} lat - latitude + * @param {number} lng - longitude + * @param {DivIcon_options} icon_options + * @param {number} zIndexOffset - zIndexOffset of the marker. + * @param {mapEntityPopupGenerator} [make_popup] - creates popup content. + * @returns {L.Marker} the marker for the map. + */ + var _create_single_entity_marker = function(map_entity, datamodel, lat, + lng, icon_options, zIndexOffset, make_popup) { + var marker = L.marker([lat, lng], { + icon: L.divIcon(icon_options) + }); + + if (zIndexOffset) { + marker.setZIndexOffset(zIndexOffset); + } + if (make_popup) { + marker.bindPopup(make_popup(map_entity, datamodel, lat, lng)); + } + return marker; + } /** * Create markers for the map for an array of entities. @@ -1531,32 +1567,75 @@ var caosdb_map = new function () { * @param {DivIcon_options} icon_options * @returns {L.Marker[]} an array of markers for the map. */ - this.create_entity_markers = function (entities, datamodel, make_popup, zIndexOffset, icon_options) { - logger.trace("enter create_entity_markers", entities, datamodel, zIndexOffset, icon_options); + this.create_entity_markers = function (entities, datamodel, make_popup, + zIndexOffset, icon_options) { + logger.trace("enter create_entity_markers", entities, datamodel, + zIndexOffset, icon_options); var ret = [] for (const map_entity of entities) { - var lat = getProperty(map_entity, datamodel.lat); - var lng = getProperty(map_entity, datamodel.lng); + var lat_vals = getProperty(map_entity, datamodel.lat); + var lng_vals = getProperty(map_entity, datamodel.lng); - if (lat && lng) { - logger.debug(`create entity marker at [${lat}, ${lng}] for`, + var is_list_lat = true; + if (!Array.isArray(lat_vals)) { + lat_vals = [lat_vals]; + is_list_lat = false; + } + var is_list_lng = true; + if (!Array.isArray(lng_vals)) { + lng_vals = [lng_vals]; + is_list_lng = false; + } + if (!lng_vals || !lng_vals) { + logger.debug("undefined latitude or longitude", + map_entity, lat_vals, lng_vals); + continue; + } else if (is_list_lng !== is_list_lat + || (is_list_lat && is_list_lng + && lat_vals.length !== lng_vals.length)) { + logger.error("Cannot show this entity on the map. " + + "Its lat/long properties have different lenghts: ", map_entity); - var marker = L.marker([lat, lng], { - icon: L.divIcon(icon_options) - }); + continue; + } - if (zIndexOffset) { - marker.setZIndexOffset(zIndexOffset); - } - if (make_popup) { - marker.bindPopup(make_popup(map_entity, datamodel)); - } + + // zip both arrays + // [lat1, lat2, ... latN] + // [lng1, lng2, ... lngN] + // into one + // [[lat1,lng1],[lat2,lng2],... [latN,lngN]] + var latlngs = lat_vals.map(function(e, i) { + return [e, lng_vals[i]]; + }); + logger.debug(`create point marker(s) at ${latlngs} for`, + map_entity); + for (let latlng of latlngs) { + var marker = _create_single_entity_marker(map_entity, + datamodel, latlng[0], latlng[1], + icon_options, zIndexOffset, make_popup); ret.push(marker); - } else { - logger.debug("undefined latitude or longitude", - map_entity, lat, lng); } + + /* Code for showing a PATH on the map. + * Maybe we re-use it later + * + logger.debug(`create path line at ${latlngs} for`, + map_entity); + + var opts = {color:'red', smoothFactor: 10.0, weight: 1.5, opacity: 0.5}; + var opts_2 = {color:'green', smoothFactor: 10.0, weight: 3, opacity: 0.5}; + var path = L.polyline(latlngs, opts); + if (make_popup) { + path.bindPopup(make_popup(map_entity, datamodel, lat, lng)); + } + path.on("mouseover",()=>path.setStyle(opts_2)); + path.on("mouseout",()=>path.setStyle(opts)); + ret.push(path); + * + * + */ } return ret; } diff --git a/test/core/js/modules/caosdb.js.js b/test/core/js/modules/caosdb.js.js index 49b26b61d3448cbc0c9b8dd50b536e282d134dec..b9925f28aa8eee3a828b17ea2f0dcd6b050f2711 100644 --- a/test/core/js/modules/caosdb.js.js +++ b/test/core/js/modules/caosdb.js.js @@ -491,59 +491,37 @@ QUnit.test("_constructXpaths", function (assert) { QUnit.test("getPropertyValues", function (assert) { const test_response = str2xml(` -<Response srid="851d063d-121b-4b67-98d4-6e5ad4d31e72" timestamp="1606214042274" baseuri="https://localhost:10443" count="8"> - <Query string="select Campaign.responsible.firstname from icecore" results="8"> - <ParseTree>(cq select (prop_sel (prop_subsel (selector_txt C a m p a i g n) . (prop_subsel (selector_txt r e s p o n s i b l e) . (prop_subsel (selector_txt f i r s t n a m e ))))) from (entity icecore) <EOF>)</ParseTree> - <Role/> - <Entity>icecore</Entity> - <Selection> - <Selector name="Campaign.responsible.firstname"/> - </Selection> - </Query> +<Response> <Record id="6525" name="Test_IceCore_1"> - <Permissions/> <Property datatype="Campaign" id="6430" name="Campaign"> <Record id="6516" name="Test-2020_Camp1"> - <Permissions/> <Property datatype="REFERENCE" id="168" name="responsible"> <Record id="6515" name="Test_Scientist"> - <Permissions/> <Property datatype="DOUBLE" id="151" name="latitude" importance="FIX"> 1.34 - <Permissions/> </Property> <Property datatype="DOUBLE" id="151" name="longitude" importance="FIX"> 2 - <Permissions/> </Property> </Record> - <Permissions/> </Property> </Record> - <Permissions/> </Property> </Record> <Record id="6526" name="Test_IceCore_2"> - <Permissions/> <Property datatype="Campaign" id="6430" name="Campaign"> <Record id="6516" name="Test-2020_Camp1"> - <Permissions/> <Property datatype="REFERENCE" id="168" name="responsible"> <Record id="6515" name="Test_Scientist"> - <Permissions/> <Property datatype="DOUBLE" id="151" name="latitude" importance="FIX"> 3 - <Permissions/> </Property> <Property datatype="DOUBLE" id="151" name="longitude" importance="FIX"> 4.8345 - <Permissions/> </Property> </Record> - <Permissions/> </Property> </Record> - <Permissions/> </Property> </Record> </Response>`); @@ -553,6 +531,57 @@ QUnit.test("getPropertyValues", function (assert) { [["6525" ,"1.34", "2"], ["6526", "3", "4.8345"]]); }); +QUnit.test("getPropertyValues - with list of references", function (assert) { + const test_response = str2xml(` +<Response> + <Record id="7393"> + <Version id="7f04ebc3a09d43f8711371a1d62905e5fc6af80f" head="true" /> + <Parent id="7392" name="PathObject" /> + <Property datatype="LIST<MapObject>" id="7391" name="MapObject"> + <Value> + <Record id="7394" name="Object-0"> + <Version id="4c3b4a7ef4abc4d3b6045968f3b5f028d82baab2" head="true" /> + <Property datatype="DOUBLE" id="7389" name="longitude" importance="FIX" unit="°"> + -44.840238182501864 + </Property> + <Property datatype="DOUBLE" id="7390" name="latitude" importance="FIX" unit="°"> + 83.98152416509532 + </Property> + </Record> + </Value> + <Value> + <Record id="7395" name="Object-1"> + <Version id="42fbe0c9be68c356f81f590cddbdd3d5fc17cba4" head="true" /> + <Property datatype="DOUBLE" id="7389" name="longitude" importance="FIX" unit="°"> + -35.60247552143245 + </Property> + <Property datatype="DOUBLE" id="7390" name="latitude" importance="FIX" unit="°"> + 73.86388403927366 + </Property> + </Record> + </Value> + <Value> + <Record id="7396" name="Object-2"> + <Version id="45b71028261061e94ae198eaaa66af0612004173" head="true" /> + <Property datatype="DOUBLE" id="7389" name="longitude" importance="FIX" unit="°"> + -42.429495631197724 + </Property> + <Property datatype="DOUBLE" id="7390" name="latitude" importance="FIX" unit="°"> + 74.95382063506622 + </Property> + </Record> + </Value> + </Property> + </Record> +</Response>`); + + assert.propEqual( + getPropertyValues(test_response, [["id"], ["", "latitude"],["", + "longitude"]]), [["7393", ["83.98152416509532", "73.86388403927366", + "74.95382063506622"], ["-44.840238182501864", "-35.60247552143245", + "-42.429495631197724"]]]); +}); + // Test for bug 103 // If role is File when creating XML for entities, checksum, path and size must be given. QUnit.test("unset_file_attributes", function(assert) { diff --git a/test/core/js/modules/ext_map.js.js b/test/core/js/modules/ext_map.js.js index 4425b2e79076d92819cc31e2f5852ed1305bff54..3e55506b9abc8742ae59bf958febd9f63f968ba9 100644 --- a/test/core/js/modules/ext_map.js.js +++ b/test/core/js/modules/ext_map.js.js @@ -43,6 +43,31 @@ QUnit.module("ext_map.js", { lng + `</div> <div class="caosdb-f-property-value">5.23</div> </div> +</div>`; + // This one has lists of lat/lng. + this.test_map_entity_2 = ` +<div class="caosdb-entity-panel caosdb-properties"> + <div class="caosdb-id">1234</div> + <div class="list-group-item caosdb-f-entity-property"> + <div class="caosdb-property-datatype">LIST</div> + <div class="caosdb-property-name">` + + lat + `</div> + <div class="caosdb-f-property-value"> + <div class="caosdb-value-list"><div + class="caosdb-f-property-single-raw-value">1.231</div> + <div class="caosdb-f-property-single-raw-value">1.232</div></div> + </div> + </div> + <div class="list-group-item caosdb-f-entity-property"> + <div class="caosdb-property-datatype">LIST</div> + <div class="caosdb-property-name">` + + lng + `</div> + <div class="caosdb-f-property-value"> + <div class="caosdb-value-list"><div + class="caosdb-f-property-single-raw-value">5.231</div> + <div class="caosdb-f-property-single-raw-value">5.232</div></div> + </div> + </div> </div>`; }, beforeEach: function (assert) { @@ -177,7 +202,6 @@ QUnit.test("create_map_view", function (assert) { map = caosdb_map.create_map_view(map_panel[0], view_config); - console.log(map_panel[0]); assert.ok(map instanceof L.Map, "map instance created"); assert.equal($(map_panel).find(".leaflet-container").length, 1, "map_panel has .leaflet-container child"); assert.ok(map._crs instanceof L.Proj.CRS, "map has special crs"); @@ -208,8 +232,24 @@ QUnit.test("create_entity_markers", function (assert) { assert.notOk(markers[0].getPopup(), "no popup"); // with popup - var markers = caosdb_map.create_entity_markers(entities, datamodel, () => "popup"); + markers = caosdb_map.create_entity_markers(entities, datamodel, () => "popup"); assert.ok(markers[0].getPopup(), "has popup"); + + + // test with list of lat/lng + entities = $(this.test_map_entity_2).toArray(); + markers = caosdb_map.create_entity_markers(entities, datamodel); + assert.equal(markers.length, 2, "has two marker"); + assert.ok(markers[0] instanceof L.Marker, "is marker"); + assert.ok(markers[1] instanceof L.Marker, "is marker"); + + latlng = markers[0]._latlng; + assert.equal(latlng.lat, "1.231", "latitude set"); + assert.equal(latlng.lng, "5.231", "longitude set"); + + latlng = markers[1]._latlng; + assert.equal(latlng.lat, "1.232", "latitude set"); + assert.equal(latlng.lng, "5.232", "longitude set"); }); @@ -263,9 +303,9 @@ QUnit.test("_get_with_POV ", function (assert) { assert.equal(caosdb_map._get_with_POV( []), "", "no POV"); assert.equal(caosdb_map._get_with_POV( - ["lol"]), " WITH lol ", "single POV"); + ["lol"]), " WITH \"lol\" ", "single POV"); assert.equal(caosdb_map._get_with_POV( - ["lol", "hi"]), " WITH lol WITH hi ", "with two POV"); + ["lol", "hi"]), " WITH \"lol\" WITH \"hi\" ", "with two POV"); }); @@ -274,71 +314,49 @@ QUnit.test("_get_select_with_path ", function (assert) { assert.throws(() => caosdb_map._get_select_with_path(this.datamodel, []), /Supply at least a RecordType./, "missing value"); assert.equal(caosdb_map._get_select_with_path( this.datamodel, - ["RealRT"]), "SELECT parent,latitude,longitude FROM ENTITY RealRT WITH latitude AND longitude ", "RT only"); + ["RealRT"]), "SELECT parent,latitude,longitude FROM ENTITY \"RealRT\" WITH ( \"latitude\" AND \"longitude\" ) ", "RT only"); assert.equal(caosdb_map._get_select_with_path( this.datamodel, - ["RealRT", "prop1"]), "SELECT parent,prop1.latitude,prop1.longitude FROM ENTITY RealRT WITH prop1 WITH latitude AND longitude ", "RT with one prop"); + ["RealRT", "prop1"]), "SELECT parent,prop1.latitude,prop1.longitude FROM ENTITY \"RealRT\" WITH \"prop1\" WITH ( \"latitude\" AND \"longitude\" ) ", "RT with one prop"); assert.equal(caosdb_map._get_select_with_path( this.datamodel, - ["RealRT", "prop1", "prop2"]), "SELECT parent,prop1.prop2.latitude,prop1.prop2.longitude FROM ENTITY RealRT WITH prop1 WITH prop2 WITH latitude AND longitude ", "RT with two props"); + ["RealRT", "prop1", "prop2"]), "SELECT parent,prop1.prop2.latitude,prop1.prop2.longitude FROM ENTITY \"RealRT\" WITH \"prop1\" WITH \"prop2\" WITH ( \"latitude\" AND \"longitude\" ) ", "RT with two props"); }); QUnit.test("_get_leaf_prop", async function (assert) { const test_response = str2xml(` -<Response srid="851d063d-121b-4b67-98d4-6e5ad4d31e72" timestamp="1606214042274" baseuri="https://localhost:10443" count="8"> - <Query string="select Campaign.responsible.firstname from icecore" results="8"> - <ParseTree>(cq select (prop_sel (prop_subsel (selector_txt C a m p a i g n) . (prop_subsel (selector_txt r e s p o n s i b l e) . (prop_subsel (selector_txt f i r s t n a m e ))))) from (entity icecore) <EOF>)</ParseTree> - <Role/> - <Entity>icecore</Entity> - <Selection> - <Selector name="Campaign.responsible.firstname"/> - </Selection> - </Query> +<Response> <Record id="6525" name="Test_IceCore_1"> - <Permissions/> <Property datatype="Campaign" id="6430" name="Campaign"> <Record id="6516" name="Test-2020_Camp1"> - <Permissions/> <Property datatype="REFERENCE" id="168" name="responsible"> <Record id="6515" name="Test_Scientist"> - <Permissions/> <Property datatype="DOUBLE" id="151" name="latitude" importance="FIX"> 1.34 - <Permissions/> </Property> <Property datatype="DOUBLE" id="151" name="longitude" importance="FIX"> 2 - <Permissions/> </Property> </Record> - <Permissions/> </Property> </Record> - <Permissions/> </Property> </Record> <Record id="6526" name="Test_IceCore_2"> - <Permissions/> <Property datatype="Campaign" id="6430" name="Campaign"> <Record id="6516" name="Test-2020_Camp1"> - <Permissions/> <Property datatype="REFERENCE" id="168" name="responsible"> <Record id="6515" name="Test_Scientist"> - <Permissions/> <Property datatype="DOUBLE" id="151" name="latitude" importance="FIX"> 3 - <Permissions/> </Property> <Property datatype="DOUBLE" id="151" name="longitude" importance="FIX"> 4.8345 - <Permissions/> </Property> </Record> - <Permissions/> </Property> </Record> - <Permissions/> </Property> </Record> </Response>`); @@ -373,6 +391,85 @@ QUnit.test("_get_leaf_prop", async function (assert) { }); + +QUnit.test("_get_leaf_prop - list of referenced map entities", async function (assert) { + const test_response = str2xml(` +<Response> + <Record id="7393"> + <Version id="7f04ebc3a09d43f8711371a1d62905e5fc6af80f" head="true" /> + <Parent id="7392" name="PathObject" /> + <Property datatype="LIST<MapObject>" id="7391" name="MapObject"> + <Value> + <Record id="7394" name="Object-0"> + <Version id="4c3b4a7ef4abc4d3b6045968f3b5f028d82baab2" head="true" /> + <Property datatype="DOUBLE" id="7389" name="longitude" importance="FIX" unit="°"> + -44.840238182501864 + </Property> + <Property datatype="DOUBLE" id="7390" name="latitude" importance="FIX" unit="°"> + 83.98152416509532 + </Property> + </Record> + </Value> + <Value> + <Record id="7395" name="Object-1"> + <Version id="42fbe0c9be68c356f81f590cddbdd3d5fc17cba4" head="true" /> + <Property datatype="DOUBLE" id="7389" name="longitude" importance="FIX" unit="°"> + -35.60247552143245 + </Property> + <Property datatype="DOUBLE" id="7390" name="latitude" importance="FIX" unit="°"> + 73.86388403927366 + </Property> + </Record> + </Value> + <Value> + <Record id="7396" name="Object-2"> + <Version id="45b71028261061e94ae198eaaa66af0612004173" head="true" /> + <Property datatype="DOUBLE" id="7389" name="longitude" importance="FIX" unit="°"> + -42.429495631197724 + </Property> + <Property datatype="DOUBLE" id="7390" name="latitude" importance="FIX" unit="°"> + 74.95382063506622 + </Property> + </Record> + </Value> + </Property> + </Record> +</Response> +`); + var leaves = caosdb_map._get_leaf_prop(test_response, 1, this.datamodel) + + assert.equal(Object.keys(leaves).length, 1, "number of records"); + var leave = leaves["7393"]; + assert.ok(leave, "has entity"); + assert.deepEqual(leave, [["83.98152416509532", + "73.86388403927366", "74.95382063506622"], [ "-44.840238182501864", + "-35.60247552143245", "-42.429495631197724" ]]); + + assert.equal( + caosdb_map._get_toplvl_rec_with_id(test_response, "7393")["id"], + "7393", + "number of records"); + + caosdb_map._set_subprops_at_top( + test_response, 1, this.datamodel, { + "7393": [["83.98152416509532", "73.86388403927366", + "74.95382063506622"], [ "-44.840238182501864", + "-35.60247552143245", "-42.429495631197724" ]] }) + assert.equal($(test_response).find(`[name='longitude']`).length, + 4, + "number lng props"); + assert.equal($(test_response).find(`[name='latitude']`).length, + 4, + "number lat props"); + // after transforming, the long/lat props should be accessible + var html_ents = await transformation.transformEntities(test_response); + assert.deepEqual( + getProperty(html_ents[0], "longitude"), [ "-44.840238182501864", + "-35.60247552143245", "-42.429495631197724" ], + "longitude of first rec"); + +}); + QUnit.test("_get_id_POV", function (assert) { assert.equal(caosdb_map._get_id_POV([]), "WITH ", "no POV"); assert.equal(caosdb_map._get_id_POV([5]), "WITH id=5", "one id"); diff --git a/test/core/js/modules/form_panel.js.js b/test/core/js/modules/form_panel.js.js index bc8343d4a65233e025039e7476861fb998c2abbc..be4c4ad8e66402adedf8c386ff086be4d7cb7955 100644 --- a/test/core/js/modules/form_panel.js.js +++ b/test/core/js/modules/form_panel.js.js @@ -55,7 +55,7 @@ QUnit.test("create_show_form_callback ", function (assert) { help: help_text, }, ], }; - cb = form_panel.create_show_form_callback( panel_id, title, csv_form_config); + const cb = form_panel.create_show_form_callback( panel_id, title, csv_form_config); assert.equal(typeof cb, "function", "function created"); cb() });