Skip to content

Commit f62e910

Browse files
authored
Restored ldh:ChildrenViewContructor (#214)
* Restored `ldh:ChildrenViewContructor` * Improved template match pattern * Inline chart save feature * Comment fix
1 parent 091a1c5 commit f62e910

6 files changed

Lines changed: 146 additions & 20 deletions

File tree

src/main/resources/com/atomgraph/linkeddatahub/ldh.ttl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,14 +576,29 @@ dh:Item spin:constructor :TitleConstructor, :DescriptionConstructor, :PrimaryTop
576576
WHERE {}""" ;
577577
rdfs:isDefinedBy : .
578578

579+
:ChildrenViewContructor a :Constructor ;
580+
rdfs:label "Container content constructor" ;
581+
sp:text """
582+
PREFIX ldh: <https://w3id.org/atomgraph/linkeddatahub#>
583+
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
584+
PREFIX spin: <http://spinrdf.org/spin#>
585+
586+
CONSTRUCT {
587+
$this rdf:_1 [
588+
a ldh:Object ;
589+
rdf:value ldh:ChildrenView ;
590+
] .
591+
}
592+
WHERE {}""" ;
593+
rdfs:isDefinedBy : .
594+
579595
:MissingContainer a :MissingPropertyValue ;
580596
rdfs:label "Missing container" ;
581597
rdfs:comment "Requires items to have a parent container" ;
582598
sp:arg1 sioc:has_container ;
583599
rdfs:isDefinedBy : .
584600

585-
dh:Container spin:constructor :TitleConstructor, :DescriptionConstructor, :PrimaryTopicConstructor ;
586-
:template :ChildrenView .
601+
dh:Container spin:constructor :TitleConstructor, :DescriptionConstructor, :PrimaryTopicConstructor, :ChildrenViewContructor .
587602

588603
:MissingParent a :MissingPropertyValue ;
589604
rdfs:label "Missing parent" ;
@@ -678,4 +693,4 @@ sd:Service spin:constructor :ServiceConstructor ;
678693
}
679694
WHERE {}""" ;
680695
rdfs:label "Service constructor" ;
681-
rdfs:isDefinedBy : .
696+
rdfs:isDefinedBy : .

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/block.xsl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ exclude-result-prefixes="#all"
115115

116116
<!-- TEMPLATES -->
117117

118+
<!-- identity transform -->
119+
120+
<xsl:template match="@* | node()" mode="ldh:Identity">
121+
<xsl:copy>
122+
<xsl:apply-templates select="@* | node()" mode="#current"/>
123+
</xsl:copy>
124+
</xsl:template>
125+
118126
<!-- render row -->
119127

120128
<xsl:template match="*" mode="ldh:RenderRow" as="(function(item()?) as map(*))?">

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/block/chart.xsl

Lines changed: 112 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,54 @@ exclude-result-prefixes="#all"
3939

4040
<!-- TEMPLATES -->
4141

42+
<!-- set chart properties -->
43+
44+
<xsl:template match="ldh:chartType | ldh:categoryVarName | ldh:categoryProperty | ldh:seriesVarName | ldh:seriesProperty" mode="ldh:Identity" priority="1"/>
45+
46+
<xsl:template match="*[rdf:type/@rdf:resource = '&ldh;ResultSetChart']" mode="ldh:Identity" priority="1">
47+
<xsl:param name="chart-type" as="xs:anyURI" tunnel="yes"/>
48+
<xsl:param name="category" as="xs:string?" tunnel="yes"/>
49+
<xsl:param name="series" as="xs:string*" tunnel="yes"/>
50+
51+
<xsl:copy>
52+
<xsl:apply-templates select="@* | node()" mode="#current"/>
53+
54+
<xsl:for-each select="$chart-type">
55+
<ldh:chartType rdf:resource="{.}"/>
56+
</xsl:for-each>
57+
<xsl:for-each select="$category">
58+
<ldh:categoryVarName>
59+
<xsl:value-of select="."/>
60+
</ldh:categoryVarName>
61+
</xsl:for-each>
62+
<xsl:for-each select="$series">
63+
<ldh:seriesVarName>
64+
<xsl:value-of select="."/>
65+
</ldh:seriesVarName>
66+
</xsl:for-each>
67+
</xsl:copy>
68+
</xsl:template>
69+
70+
<xsl:template match="*[rdf:type/@rdf:resource = '&ldh;GraphChart']" mode="ldh:Identity" priority="1">
71+
<xsl:param name="chart-type" as="xs:anyURI" tunnel="yes"/>
72+
<xsl:param name="category" as="xs:string?" tunnel="yes"/>
73+
<xsl:param name="series" as="xs:string*" tunnel="yes"/>
74+
75+
<xsl:copy>
76+
<xsl:apply-templates select="@* | node()" mode="#current"/>
77+
78+
<xsl:for-each select="$chart-type">
79+
<ldh:chartType rdf:resource="{.}"/>
80+
</xsl:for-each>
81+
<xsl:for-each select="$category">
82+
<ldh:categoryProperty rdf:resource="{.}"/>
83+
</xsl:for-each>
84+
<xsl:for-each select="$series">
85+
<ldh:seriesProperty rdf:resource="{.}"/>
86+
</xsl:for-each>
87+
</xsl:copy>
88+
</xsl:template>
89+
4290
<!-- TO-DO: make 'data-table' configurable -->
4391
<xsl:template name="ac:draw-chart">
4492
<xsl:param name="data-table"/>
@@ -216,9 +264,9 @@ exclude-result-prefixes="#all"
216264
<xsl:param name="button-class" select="'btn'" as="xs:string?"/>
217265
<xsl:param name="accept-charset" select="'UTF-8'" as="xs:string?"/>
218266
<xsl:param name="enctype" as="xs:string?"/>
219-
<xsl:param name="chart-type-id" select="'chart-type'" as="xs:string"/>
220-
<xsl:param name="category-id" select="'category'" as="xs:string"/>
221-
<xsl:param name="series-id" select="'series'" as="xs:string"/>
267+
<xsl:param name="chart-type-id" select="'chart-type-' || generate-id()" as="xs:string"/>
268+
<xsl:param name="category-id" select="'category-' || generate-id()" as="xs:string"/>
269+
<xsl:param name="series-id" select="'series-' || generate-id()" as="xs:string"/>
222270
<xsl:param name="form-actions" as="element()?">
223271
<div class="form-actions">
224272
<button class="btn btn-primary btn-save-chart" type="button">
@@ -627,6 +675,67 @@ exclude-result-prefixes="#all"
627675
<ixsl:set-style name="cursor" select="'default'" object="ixsl:page()//body"/>
628676
</xsl:template>
629677

678+
<!-- save chart onclick -->
679+
<!-- TO-DO: use @typeof in match so that we don't need a custom button.btn-save-chart class -->
680+
681+
<xsl:template match="div[@typeof]//button[contains-token(@class, 'btn-save-chart')]" mode="ixsl:onclick">
682+
<ixsl:set-style name="cursor" select="'progress'" object="ixsl:page()//body"/>
683+
<xsl:variable name="block" select="ancestor::div[contains-token(@class, 'block')][1]" as="element()"/>
684+
<xsl:variable name="container" select="ancestor::div[@typeof][1]" as="element()"/>
685+
<xsl:variable name="about" select="$block/@about" as="xs:anyURI"/>
686+
<xsl:variable name="query-uri" select="$container//descendant::*[@property = '&spin;query']/@resource" as="xs:anyURI"/>
687+
<xsl:variable name="chart-type" select="$container//form//select[contains-token(@class, 'chart-type')]/ixsl:get(., 'value')" as="xs:anyURI?"/>
688+
<xsl:variable name="category" select="$container//form//select[contains-token(@class, 'chart-category')]/ixsl:get(., 'value')" as="xs:string?"/>
689+
<xsl:variable name="series" as="xs:string*">
690+
<xsl:for-each select="$container//form//select[contains-token(@class, 'chart-series')]">
691+
<xsl:variable name="select" select="." as="element()"/>
692+
<xsl:for-each select="0 to xs:integer(ixsl:get(., 'selectedOptions.length')) - 1">
693+
<xsl:sequence select="ixsl:get(ixsl:call(ixsl:get($select, 'selectedOptions'), 'item', [ . ]), 'value')"/>
694+
</xsl:for-each>
695+
</xsl:for-each>
696+
</xsl:variable>
697+
<xsl:variable name="method" select="'PATCH'" as="xs:string"/>
698+
<xsl:variable name="action" select="ac:absolute-path(ldh:base-uri(.))" as="xs:anyURI"/>
699+
<xsl:variable name="accept" select="'application/rdf+xml'" as="xs:string"/>
700+
<xsl:variable name="etag" select="ixsl:get(ixsl:get(ixsl:get(ixsl:window(), 'LinkedDataHub.contents'), '`' || ac:absolute-path(ldh:base-uri(.)) || '`'), 'etag')" as="xs:string"/>
701+
<!-- not using ldh:base-uri(.) because it goes stale when DOM is replaced -->
702+
<xsl:variable name="doc" select="ixsl:get(ixsl:get(ixsl:get(ixsl:window(), 'LinkedDataHub.contents'), '`' || ac:absolute-path(xs:anyURI(ixsl:location())) || '`'), 'results')" as="document-node()"/>
703+
<xsl:variable name="chart" select="key('resources', $about, $doc)" as="element()"/>
704+
<!-- update the properties on the chart resource -->
705+
<xsl:variable name="chart" as="element()">
706+
<xsl:apply-templates select="$chart" mode="ldh:Identity">
707+
<xsl:with-param name="chart-type" select="$chart-type" tunnel="yes"/>
708+
<xsl:with-param name="series" select="$series" tunnel="yes"/>
709+
<xsl:with-param name="category" select="$category" tunnel="yes"/>
710+
</xsl:apply-templates>
711+
</xsl:variable>
712+
<xsl:variable name="triples" select="ldh:descriptions-to-triples($chart)" as="element()*"/>
713+
<xsl:variable name="update-string" select="ldh:insertdelete-update(ldh:triples-to-bgp(ldh:uri-po-pattern($about)), ldh:triples-to-bgp($triples), ldh:triples-to-bgp(ldh:uri-po-pattern($about)))" as="xs:string"/>
714+
<xsl:variable name="resources" as="document-node()">
715+
<xsl:document>
716+
<rdf:RDF>
717+
<xsl:sequence select="ldh:triples-to-descriptions($triples)"/>
718+
</rdf:RDF>
719+
</xsl:document>
720+
</xsl:variable>
721+
<xsl:variable name="request-uri" select="ldh:href($ldt:base, ac:absolute-path($ldh:requestUri), map{}, $action)" as="xs:anyURI"/>
722+
<!-- If-Match header checks preconditions, i.e. that the graph has not been modified in the meanwhile -->
723+
<xsl:variable name="request" select="map{ 'method': $method, 'href': $request-uri, 'media-type': 'application/sparql-update', 'body': $update-string, 'headers': map{ 'If-Match': $etag, 'Accept': 'application/rdf+xml', 'Cache-Control': 'no-cache' } }" as="map(*)"/>
724+
<xsl:variable name="context" as="map(*)" select="
725+
map{
726+
'request': $request,
727+
'doc-uri': ac:absolute-path(ldh:base-uri(.)),
728+
'block': $block,
729+
'resources': $resources
730+
}"/>
731+
<ixsl:promise select="
732+
ixsl:http-request($context('request')) (: Step 1: send initial request :)
733+
=> ixsl:then(ldh:rethread-response($context, ?)) (: Step 2: attach response to context :)
734+
=> ixsl:then(ldh:handle-response#1) (: Step 3: handle 429s, etc. :)
735+
=> ixsl:then(ldh:row-form-response#1)
736+
"/>
737+
</xsl:template>
738+
630739
<!-- CALLBACKS -->
631740

632741
<!-- chart query response -->

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/block/query.xsl

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,9 @@ exclude-result-prefixes="#all"
4343
<xsl:attribute name="class" select="concat($class, ' ', 'btn-run-query')"/>
4444
</xsl:template>
4545

46-
<!-- identity transform -->
47-
48-
<xsl:template match="@* | node()" mode="ldh:SetQueryString">
49-
<xsl:copy>
50-
<xsl:apply-templates select="@* | node()" mode="#current"/>
51-
</xsl:copy>
52-
</xsl:template>
53-
5446
<!-- set query string -->
5547

56-
<xsl:template match="sp:text/text()" mode="ldh:SetQueryString" priority="1">
48+
<xsl:template match="sp:text/text()" mode="ldh:Identity" priority="1">
5749
<xsl:param name="query-string" as="xs:string" tunnel="yes"/>
5850

5951
<xsl:sequence select="$query-string"/>
@@ -467,7 +459,7 @@ exclude-result-prefixes="#all"
467459

468460
<!-- replace the query string (sp:text value) on the query resource -->
469461
<xsl:variable name="query" as="element()">
470-
<xsl:apply-templates select="$query" mode="ldh:SetQueryString">
462+
<xsl:apply-templates select="$query" mode="ldh:Identity">
471463
<xsl:with-param name="query-string" select="$query-string" tunnel="yes"/>
472464
</xsl:apply-templates>
473465
</xsl:variable>

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/client/form.xsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ WHERE
107107
<xsl:template match="*[rdf:type/@rdf:resource = ('&spin;ConstraintViolation', '&sh;ValidationResult', '&sh;ValidationReport', '&http;Response')]" mode="bs2:Form" priority="3"/>
108108

109109
<!-- suppress the system properties of document resources (they are set automatically by LinkedDataHub) -->
110-
<xsl:template match="*[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/dct:created | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/dct:modified | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/sioc:has_container | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/sioc:has_parent | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/dct:creator | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/acl:owner | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/*[namespace-uri() = '&rdf;'][starts-with(local-name(), '_')]" mode="bs2:FormControl" priority="1"/>
110+
<xsl:template match="*[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/dct:created | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/dct:modified | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/sioc:has_container | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/sioc:has_parent | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/dct:creator | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container', '&dh;Item')]/acl:owner | *[rdf:type/@rdf:resource = ('&def;Root', '&dh;Container')]/*[namespace-uri() = '&rdf;'][starts-with(local-name(), '_')][@rdf:resource] | *[rdf:type/@rdf:resource = '&dh;Item']/*[namespace-uri() = '&rdf;'][starts-with(local-name(), '_')]" mode="bs2:FormControl" priority="1"/>
111111

112112
<!-- canonicalize XML in rdf:XMLLiterals -->
113113
<xsl:template match="json:string[@key = 'object'][ends-with(., '^^&rdf;XMLLiteral')]" mode="ldh:CanonicalizeXML" priority="1">

src/main/webapp/static/com/atomgraph/linkeddatahub/xsl/bootstrap/2.3.2/layout.xsl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -805,8 +805,10 @@ LIMIT 100
805805
<xsl:param name="typeof" select="key('resources', ac:absolute-path(ldh:base-uri(.)))/rdf:type/@rdf:resource/xs:anyURI(.)" as="xs:anyURI*"/>
806806
<xsl:param name="doc-types" select="key('resources', ac:absolute-path(ldh:base-uri(.)))/rdf:type/@rdf:resource[ . = ('&def;Root', '&dh;Container', '&dh;Item')]" as="xs:anyURI*"/>
807807
<!-- take care not to load unnecessary documents over HTTP when $doc-types is empty -->
808-
<xsl:param name="block-values" select="if (exists($doc-types)) then (if (doc-available(resolve-uri('ns?query=ASK%20%7B%7D', $ldt:base))) then (ldh:query-result(map{}, resolve-uri('ns', $ldt:base), $template-query || ' VALUES $Type { ' || string-join(for $type in $doc-types return '&lt;' || $type || '&gt;', ' ') || ' }')//srx:binding[@name = 'block']/srx:uri/xs:anyURI(.)) else ()) else ()" as="xs:anyURI*"/>
809-
<xsl:param name="has-content" select="key('resources', key('resources', ac:absolute-path(ldh:base-uri(.)))/rdf:*[starts-with(local-name(), '_')]/@rdf:resource) or exists($block-values)" as="xs:boolean"/>
808+
<xsl:param name="template-block-uris" select="if (exists($doc-types)) then (if (doc-available(resolve-uri('ns?query=ASK%20%7B%7D', $ldt:base))) then (ldh:query-result(map{}, resolve-uri('ns', $ldt:base), $template-query || ' VALUES $Type { ' || string-join(for $type in $doc-types return '&lt;' || $type || '&gt;', ' ') || ' }')//srx:binding[@name = 'block']/srx:uri/xs:anyURI(.)) else ()) else ()" as="xs:anyURI*"/>
809+
<xsl:param name="block-uris" select="key('resources', ac:absolute-path(ldh:base-uri(.)))/rdf:*[starts-with(local-name(), '_')]/@rdf:resource" as="xs:anyURI*"/>
810+
<!-- document has content when either explicitly declared document-level blocks exist or template-declared class-level blocks exist -->
811+
<xsl:param name="has-content" select="exists(for $block-uri in $block-uris return (if (doc-available(ac:document-uri($block-uri))) then key('resources', $block-uri, document(ac:document-uri($block-uri))) else ())) or exists($template-block-uris)" as="xs:boolean"/>
810812

811813
<div>
812814
<xsl:if test="$id">
@@ -838,7 +840,7 @@ LIMIT 100
838840
</xsl:when>
839841
<!-- check if the current document has content or its class has content -->
840842
<xsl:when test="(empty($ac:mode) and $has-content) or $ac:mode = '&ldh;ContentMode'">
841-
<xsl:for-each select="$block-values">
843+
<xsl:for-each select="$template-block-uris">
842844
<xsl:if test="doc-available(ac:document-uri(.))">
843845
<xsl:apply-templates select="key('resources', ., document(ac:document-uri(.)))" mode="bs2:Row"/>
844846
</xsl:if>

0 commit comments

Comments
 (0)