Commit 20ea0387 authored by Daniel's avatar Daniel
Browse files

Merge remote-tracking branch 'origin/dev' into js-client-extensions

parents d8e00464 e7776874
......@@ -3,9 +3,47 @@
* Alexander Schlemmer, 11/2018
*/
/*!
* Check if an element is out of the viewport
* (c) 2018 Chris Ferdinandi, MIT License, https://gomakethings.com
* @param {Node} elem The element to check
* @return {Object} A set of booleans for each side of the element
*/
// Source address: https://gomakethings.com/how-to-check-if-any-part-of-an-element-is-out-of-the-viewport-with-vanilla-js/
var isOutOfViewport = function (elem) {
// Get element's bounding
var bounding = elem.getBoundingClientRect();
// Check if it's out of the viewport on each side
var out = {};
out.top = bounding.top < 0;
out.left = bounding.left < 0;
out.bottom = bounding.bottom > (window.innerHeight || document.documentElement.clientHeight);
out.right = bounding.right > (window.innerWidth || document.documentElement.clientWidth);
out.any = out.top || out.left || out.bottom || out.right;
out.all = out.top && out.left && out.bottom && out.right;
return out;
};
// Variation that checks whether an element is inside of the viewport.
var isInViewport = function (elem) {
var bounding = elem.getBoundingClientRect();
var out = {};
out.top = bounding.bottom < 0;
out.left = bounding.left < 0;
out.bottom = bounding.top > (window.innerHeight || document.documentElement.clientHeight);
out.right = bounding.left > (window.innerWidth || document.documentElement.clientWidth);
return !(out.top || out.left || out.bottom || out.right);
}
var resolve_references = new function() {
this.init = function() {
this.references();
// this.references();
this.update_visible_references();
}
this.get_person_str = function(el) {
......@@ -13,10 +51,17 @@ var resolve_references = new function() {
if (valpr == undefined) {
return;
}
return valpr.filter(valprel => valprel.name == "firstName")[0].value +
" " + valpr.filter(valprel => valprel.name == "lastName")[0].value;
return valpr.filter(valprel => valprel.name.toLowerCase() == "firstname")[0].value +
" " + valpr.filter(valprel => valprel.name.toLowerCase() == "lastname")[0].value;
}
/*
* Function that retrieves meaningful information for a single element.
*
* This function needs to be customized for specific implementations.
*
* rs: Element having the class caosdb-resolvable-reference and including a caosdb-resolve-reference target.
*/
this.update_single_resolvable_reference = async function(rs) {
var rseditable = rs.getElementsByClassName("caosdb-resolve-reference-target")[0];
var el = await retrieve(getIDfromHREF(rs));
......@@ -43,6 +88,20 @@ var resolve_references = new function() {
}
}
/*
* This function updates all references that are inside of the current viewport.
*
*/
this.update_visible_references = async function() {
var rs = document.getElementsByClassName("caosdb-resolvable-reference");
for (var i = 0; i < rs.length; i++) {
if (isInViewport(rs[i])) {
this.update_single_resolvable_reference(rs[i]);
}
}
}
this.references = async function() {
var rs = document.getElementsByClassName("caosdb-resolvable-reference");
......@@ -55,4 +114,13 @@ var resolve_references = new function() {
$(document).ready(function() {
resolve_references.init();
var scrollTimeout = undefined;
$(window).scroll(()=> {
if (scrollTimeout) {
clearTimeout(scrollTimeout);
}
scrollTimeout = setTimeout(function() {
resolve_references.update_visible_references();
}, 500);
});
});
......@@ -76,7 +76,9 @@
</xsl:if>
<xsl:apply-templates mode="query-results" select="./ParseTree"/>
</div>
<xsl:apply-templates mode="select-table" select="./Selection"/>
<xsl:if test="@results!=0">
<xsl:apply-templates mode="select-table" select="./Selection"/>
</xsl:if>
</xsl:template>
<xsl:template match="Selection" mode="select-table">
<div class="panel panel-default caosdb-select-table">
......
......@@ -55,6 +55,67 @@ QUnit.test("basic properties of select-table feature", function(assert) {
assert.equal(html.firstElementChild.className, "panel panel-default caosdb-select-table", "first child has class caosdb-select-table.");
});
/* Test table of empty result sets of queries */
QUnit.test("empty results in SELECT create no table", function(assert) {
var testresult = '\
<?xml version="1.0" encoding="UTF-8"?>\
<Response count="0">\
<Query string="select test from bla" results="0">\
<ParseTree>(cq select (prop_sel (prop_subsel (selector_txt t e s t ))) from (entity bla) &lt;EOF&gt;)</ParseTree>\
<Role />\
<Entity>bla</Entity>\
<Selection>\
<Selector name="test" />\
</Selection>\
</Query>\
</Response>\
';
var xml = str2xml(testresult);
var html = applyTemplates(xml, this.queryXSL, "query-results");
assert.equal(html.children.length, 1);
// For select queries actually containing results, this would be 2.
});
// This uses results from the demo server.
QUnit.test("one result in SELECT create table", function(assert) {
var testresult = '\
<?xml version="1.0" encoding="UTF-8"?>\
<Response count="12">\
<Query string="SELECT Width, Result, Success FROM MySimulation" results="1">\
<ParseTree>(cq SELECT (prop_sel (prop_subsel (selector_txt W i d t h)) , (prop_subsel (selector_txt R e s u l t)) , (prop_subsel (selector_txt S u c c e s s ))) FROM (entity MySimulation) &lt;EOF&gt;)</ParseTree>\
<Role />\
<Entity>MySimulation</Entity>\
<Selection>\
<Selector name="Width" />\
<Selector name="Result" />\
<Selector name="Success" />\
</Selection>\
</Query>\
<Record id="243">\
<Permissions />\
<Property id="235" name="Width" datatype="INTEGER" importance="FIX" unit="px">\
200\
<Permissions />\
</Property>\
<Property id="237" name="Result" datatype="DOUBLE" importance="FIX">\
1.25\
<Permissions />\
</Property>\
<Property id="238" name="Success" datatype="BOOLEAN" importance="FIX">\
TRUE\
<Permissions />\
</Property>\
</Record>\
</Response>';
var xml = str2xml(testresult);
var html = applyTemplates(xml, this.queryXSL, "query-results");
assert.equal(html.children.length, 2);
});
/* -- -- */
QUnit.test("Query tag is transformed via xslt", function(assert) {
assert.equal(this.queryXSL.getElementsByClassName("caosdb-query-response")[0].tagName, "div", "xsl sheet defines a caosdb-query response div");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment