Skip to content
Snippets Groups Projects
Verified Commit 9f16bb22 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

Merge branch 'f-add-query' of gitlab.indiscale.com:caosdb/src/caosdb-webui into f-add-query

parents 3d0942a9 6fc09520
No related branches found
No related tags found
2 merge requests!47Release v0.4.0,!44ENH: Add all query results to bookmarks
Pipeline #15090 passed
...@@ -225,15 +225,28 @@ ...@@ -225,15 +225,28 @@
<xsl:value-of select="$field-name"/> <xsl:value-of select="$field-name"/>
</xsl:attribute> </xsl:attribute>
<div class="caosdb-f-property-value caosdb-v-property-value"> <div class="caosdb-f-property-value caosdb-v-property-value">
<xsl:apply-templates select="/Response/*[@id=$entity-id and Version/@id=$version-id]" mode="walk-select-segments"> <xsl:choose>
<!--<xsl:apply-templates select="/Response/*[@id=$entity-id]" mode="walk-select-segments">--> <xsl:when test="$version-id!=''">
<xsl:with-param name="first-segment"> <xsl:apply-templates select="/Response/*[@id=$entity-id and Version/@id=$version-id]" mode="walk-select-segments">
<xsl:value-of select="substring-before(concat($field-name, '.'), '.')"/> <xsl:with-param name="first-segment">
</xsl:with-param> <xsl:value-of select="substring-before(concat($field-name, '.'), '.')"/>
<xsl:with-param name="next-segments"> </xsl:with-param>
<xsl:value-of select="substring-after($field-name, '.')"/> <xsl:with-param name="next-segments">
</xsl:with-param> <xsl:value-of select="substring-after($field-name, '.')"/>
</xsl:apply-templates> </xsl:with-param>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="/Response/*[@id=$entity-id]" mode="walk-select-segments">
<xsl:with-param name="first-segment">
<xsl:value-of select="substring-before(concat($field-name, '.'), '.')"/>
</xsl:with-param>
<xsl:with-param name="next-segments">
<xsl:value-of select="substring-after($field-name, '.')"/>
</xsl:with-param>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</div> </div>
</td> </td>
</xsl:template> </xsl:template>
......
...@@ -317,7 +317,7 @@ function applyTemplates(xml, xsl, mode, select = "*") { ...@@ -317,7 +317,7 @@ function applyTemplates(xml, xsl, mode, select = "*") {
return xslt(xml, modXsl); return xslt(xml, modXsl);
} }
function callTemplate(xsl, template, params, wrap_call) { function callTemplate(xsl, template, params, wrap_call, root) {
let entryRuleStart = '<xsl:call-template name="' + template + '">'; let entryRuleStart = '<xsl:call-template name="' + template + '">';
let entryRuleEnd = '</xsl:call-template>'; let entryRuleEnd = '</xsl:call-template>';
var entryRule = entryRuleStart; var entryRule = entryRuleStart;
...@@ -331,5 +331,6 @@ function callTemplate(xsl, template, params, wrap_call) { ...@@ -331,5 +331,6 @@ function callTemplate(xsl, template, params, wrap_call) {
entryRule = '<xsl:template xmlns="http://www.w3.org/1999/xhtml" priority="9" match="/">' + entryRule = '<xsl:template xmlns="http://www.w3.org/1999/xhtml" priority="9" match="/">' +
entryRule + '</xsl:template>'; entryRule + '</xsl:template>';
let modXsl = injectTemplate(xsl, entryRule); let modXsl = injectTemplate(xsl, entryRule);
return xslt(str2xml('<root/>'), modXsl); root = root || '<root/>';
return xslt(str2xml(root), modXsl);
} }
...@@ -28,19 +28,25 @@ QUnit.module("query.xsl", { ...@@ -28,19 +28,25 @@ QUnit.module("query.xsl", {
// load query.xsl // load query.xsl
var done = assert.async(); var done = assert.async();
var qunit_obj = this; var qunit_obj = this;
$.ajax({ _retrieveQueryXSL().then(function(xsl) {
cache: true, qunit_obj.queryXSL = xsl;
dataType: 'xml',
url: "xsl/query.xsl",
}).done(function(data, textStatus, jdXHR) {
insertParam(data, "entitypath", "/entitypath/");
qunit_obj.queryXSL = data;
}).always(function() {
done(); done();
}); });
} }
}); });
async function _retrieveQueryXSL() {
var queryXsl = await transformation.retrieveXsltScript("query.xsl");
var entityXsl = await transformation.retrieveXsltScript("entity.xsl");
var commonXsl = await transformation.retrieveXsltScript("common.xsl");
var xsl = transformation.mergeXsltScripts(entityXsl, [commonXsl, queryXsl]);
insertParam(xsl, "entitypath", "/entitypath/");
insertParam(xsl, "filesystempath", "/filesystempath/");
insertParam(xsl, "lowercase", "abcdefghijklmnopqrstuvwxyz");
insertParam(xsl, "uppercase", "ABCDEFGHIJKLMNOPQRSTUVWXYZ");
return xsl;
}
/* TESTS */ /* TESTS */
QUnit.test("availability", function(assert) { QUnit.test("availability", function(assert) {
assert.ok(this.queryXSL); assert.ok(this.queryXSL);
...@@ -183,6 +189,35 @@ QUnit.test("template select-table-row ", function(assert){ ...@@ -183,6 +189,35 @@ QUnit.test("template select-table-row ", function(assert){
assert.equal(next.tagName, "A", "tagName = A"); assert.equal(next.tagName, "A", "tagName = A");
}); });
QUnit.test("template select-table-cell (with version) ", function(assert){
let cell = callTemplate(this.queryXSL, "select-table-cell", {"version-id": "vid-2345", "entity-id": "eid-1234", "field-name": "name"}, (x) => `<table><tbody><tr>${x}</tr></tbody></table>`,`<Response><Entity id="eid-1234" name="the-name"><Version id="vid-2345"/></Entity></Response>`);
var next = cell.firstElementChild;
assert.equal(next.tagName, "TABLE", "tagName = TABLE");
next = next.firstElementChild;
assert.equal(next.tagName, "TBODY", "tagName = TBODY");
next = next.firstElementChild;
assert.equal(next.tagName, "TR", "tagName = TR");
next = next.firstElementChild;
assert.equal(next.tagName, "TD", "tagName = TD");
next = next.textContent;
assert.equal(next, "the-name", "name = the-name");
});
QUnit.test("template select-table-cell (id only) ", function(assert){
let cell = callTemplate(this.queryXSL, "select-table-cell", {"entity-id": "eid-1234", "field-name": "id"}, (x) => `<table><tbody><tr>${x}</tr></tbody></table>`,`<Response><Entity id="eid-1234"/></Response>`);
var next = cell.firstElementChild;
assert.equal(next.tagName, "TABLE", "tagName = TABLE");
next = next.firstElementChild;
assert.equal(next.tagName, "TBODY", "tagName = TBODY");
next = next.firstElementChild;
assert.equal(next.tagName, "TR", "tagName = TR");
next = next.firstElementChild;
assert.equal(next.tagName, "TD", "tagName = TD");
next = next.textContent;
assert.equal(next, "eid-1234", "id = eid-1234");
});
/* MISC FUNCTIONS */ /* MISC FUNCTIONS */
function getQueryForm(queryXSL) { function getQueryForm(queryXSL) {
var html = callTemplate(queryXSL, "caosdb-query-panel", {}); var html = callTemplate(queryXSL, "caosdb-query-panel", {});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment