Skip to content

Commit 09a4a90

Browse files
committed
Refactored chart rendering using "suspended promise tree" approach
1 parent 1090b6d commit 09a4a90

6 files changed

Lines changed: 196 additions & 39 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ exclude-result-prefixes="#all"
120120
<xsl:template match="*" mode="ldh:RenderRow">
121121
<xsl:apply-templates mode="#current"/>
122122
</xsl:template>
123+
124+
<xsl:template match="text()" mode="ldh:RenderRow"/>
123125

124126
<!-- hide type control -->
125127
<xsl:template match="*[rdf:type/@rdf:resource = '&ldh;XHTML']" mode="bs2:TypeControl" priority="1">

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ exclude-result-prefixes="#all"
203203
</xsl:template>
204204

205205
<!-- render chart block -->
206-
<xsl:template match="*[@typeof = ('&ldh;ResultSetChart', '&ldh;GraphChart')][descendant::*[@property = '&spin;query'][@resource]][descendant::*[@property = '&ldh;chartType'][@resource]]" mode="ldh:RenderRow" priority="2"> <!-- prioritize above block.xsl -->
206+
<!-- <xsl:template match="*[@typeof = ('&ldh;ResultSetChart', '&ldh;GraphChart')][descendant::*[@property = '&spin;query'][@resource]][descendant::*[@property = '&ldh;chartType'][@resource]]" mode="ldh:RenderRow" priority="2"> prioritize above block.xsl
207207
<xsl:param name="block" select="ancestor-or-self::div[contains-token(@class, 'block')][1]" as="element()"/>
208208
<xsl:param name="about" select="$block/@about" as="xs:anyURI"/>
209209
<xsl:param name="container" select="." as="element()"/>
@@ -262,7 +262,7 @@ exclude-result-prefixes="#all"
262262
<xsl:apply-templates select="key('resources', '&ldh;chartType', document(ac:document-uri('&ldh;')))" mode="ac:label"/>
263263
</xsl:value-of>
264264
</label>
265-
<!-- TO-DO: replace with xsl:apply-templates on ac:Chart subclasses as in imports/ldh.xsl -->
265+
TO-DO: replace with xsl:apply-templates on ac:Chart subclasses as in imports/ldh.xsl
266266
<select id="{$chart-type-id}" name="ou" class="input-medium chart-type">
267267
<option value="&ac;Table">
268268
<xsl:if test="$chart-type = '&ac;Table'">
@@ -346,7 +346,7 @@ exclude-result-prefixes="#all"
346346
ixsl:then(ldh:handle-response#1) =>
347347
ixsl:then(ldh:chart-query-response#1)"
348348
on-failure="ldh:promise-failure#1"/>
349-
</xsl:template>
349+
</xsl:template>-->
350350

351351
<!-- EVENT LISTENERS -->
352352

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

Lines changed: 78 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ exclude-result-prefixes="#all"
6565

6666
<!-- object block (RDF resource) -->
6767

68-
<xsl:template match="*[@typeof = '&ldh;Object'][descendant::*[@property = '&rdf;value'][@resource]]" mode="ldh:RenderRow" priority="2"> <!-- prioritize above block.xsl -->
68+
<xsl:template match="*[@typeof = '&ldh;Object'][descendant::*[@property = '&rdf;value'][@resource]]" mode="ldh:RenderRow" as="item()" priority="2"> <!-- prioritize above block.xsl -->
6969
<xsl:param name="block" select="ancestor::div[contains-token(@class, 'block')][1]" as="element()"/>
7070
<xsl:param name="about" select="$block/@about" as="xs:anyURI"/>
7171
<xsl:param name="block-uri" select="$about" as="xs:anyURI"/>
@@ -81,6 +81,10 @@ exclude-result-prefixes="#all"
8181
<ixsl:set-style name="width" select="'50%'" object="."/>
8282
</xsl:for-each>
8383

84+
<xsl:variable name="child-promise" as="item()?">
85+
<xsl:apply-templates mode="#current"/>
86+
</xsl:variable>
87+
8488
<!-- don't use ldh:base-uri(.) because its value comes from the last HTML document load -->
8589
<xsl:variable name="request-uri" select="ldh:href($ldt:base, if (starts-with($graph, $ldt:base)) then $graph else ac:absolute-path(xs:anyURI(ixsl:location())), map{}, ac:document-uri($resource-uri), $graph, ())" as="xs:anyURI"/>
8690
<xsl:variable name="request" select="map{ 'method': 'GET', 'href': $request-uri, 'headers': map{ 'Accept': 'application/rdf+xml' } }" as="map(*)"/>
@@ -94,14 +98,19 @@ exclude-result-prefixes="#all"
9498
'mode': $mode,
9599
'show-edit-button': $show-edit-button
96100
}"/>
97-
<ixsl:promise select="ixsl:http-request($context('request')) =>
101+
<xsl:variable name="self-promise" as="item()" select="ixsl:http-request($context('request')) =>
98102
ixsl:then(ldh:rethread-response($context, ?)) =>
99103
ixsl:then(ldh:handle-response#1) =>
100-
ixsl:then(ldh:block-object-value-response#1)"
101-
on-failure="ldh:promise-failure#1"/>
104+
ixsl:then(ldh:block-object-value-response#1)"/>
105+
106+
<xsl:sequence select="
107+
ixsl:all-settled(
108+
array{ $self-promise, $child-promise }
109+
) => ixsl:then(ldh:hide-block-progress-bar($container, ?))
110+
"/>
102111
</xsl:template>
103112

104-
<xsl:function name="ldh:block-object-value-response" ixsl:updating="yes">
113+
<xsl:function name="ldh:block-object-value-response" as="item()" ixsl:updating="yes">
105114
<xsl:param name="context" as="map(*)"/>
106115
<xsl:variable name="response" select="$context('response')" as="map(*)"/>
107116
<xsl:variable name="block" select="$context('block')" as="element()"/>
@@ -111,6 +120,8 @@ exclude-result-prefixes="#all"
111120
<xsl:variable name="mode" select="$context('mode')" as="xs:anyURI?"/>
112121
<xsl:variable name="show-edit-button" select="$context('show-edit-button')" as="xs:boolean?"/>
113122

123+
<xsl:message>ldh:block-object-value-response</xsl:message>
124+
114125
<xsl:for-each select="$response">
115126
<xsl:choose>
116127
<xsl:when test="?status = 200 and ?media-type = 'application/rdf+xml'">
@@ -138,11 +149,23 @@ exclude-result-prefixes="#all"
138149
'mode': $mode,
139150
'show-edit-button': $show-edit-button
140151
}"/>
141-
<ixsl:promise select="ixsl:http-request($context('request')) =>
152+
<!--
153+
<ixsl:promise select="
154+
ixsl:http-request($context('request')) =>
142155
ixsl:then(ldh:rethread-response($context, ?)) =>
143156
ixsl:then(ldh:handle-response#1) =>
144-
ixsl:then(ldh:block-object-metadata-response#1)"
157+
ixsl:then(ldh:block-object-metadata-response#1) =>
158+
ixsl:then(ldh:block-object-apply#1)
159+
"
145160
on-failure="ldh:promise-failure#1"/>
161+
-->
162+
<xsl:sequence select="
163+
ixsl:http-request($context('request')) =>
164+
ixsl:then(ldh:rethread-response($context, ?)) =>
165+
ixsl:then(ldh:handle-response#1) =>
166+
ixsl:then(ldh:block-object-metadata-response#1) =>
167+
ixsl:then(ldh:block-object-apply#1)
168+
"/>
146169
</xsl:when>
147170
<xsl:otherwise>
148171
<xsl:for-each select="$container">
@@ -190,11 +213,13 @@ exclude-result-prefixes="#all"
190213
</xsl:otherwise>
191214
</xsl:choose>
192215
</xsl:for-each>
216+
217+
<xsl:sequence select="$context"/>
193218
</xsl:function>
194219

195220
<!-- replaces the block with a row -->
196221

197-
<xsl:function name="ldh:block-object-metadata-response" ixsl:updating="yes">
222+
<xsl:function name="ldh:block-object-metadata-response" as="map(*)" ixsl:updating="yes">
198223
<xsl:param name="context" as="map(*)"/>
199224
<xsl:variable name="response" select="$context('response')" as="map(*)"/>
200225
<xsl:variable name="block" select="$context('block')" as="element()"/>
@@ -220,24 +245,65 @@ exclude-result-prefixes="#all"
220245
</xsl:apply-templates>
221246
</xsl:variable>
222247

248+
<xsl:variable name="obj-value-id" select="'obj-value-' || generate-id($block)" as="xs:string"/>
223249
<xsl:for-each select="$container">
224250
<xsl:result-document href="?." method="ixsl:replace-content">
225251
<!-- wrap the row -->
226-
<div class="span12">
252+
<div id="{$obj-value-id}" class="span12">
227253
<xsl:copy-of select="$row"/>
228254
</div>
229255
</xsl:result-document>
256+
</xsl:for-each>
257+
258+
<xsl:sequence select="map:put($context, 'obj-value-id', $obj-value-id)"/>
259+
260+
<!-- <xsl:apply-templates mode="ldh:RenderRow"/> --> <!-- recurse down the block hierarchy -->
261+
262+
<!-- <xsl:variable name="promises" as="item()*">
263+
<xsl:apply-templates mode="ldh:RenderRow"/> recurse down the block hierarchy
264+
</xsl:variable>
265+
<xsl:variable name="promise-array" select="array{ $promises }" as="array(item())"/>
266+
267+
<xsl:message>
268+
$promise-array: <xsl:value-of select="serialize($promise-array, map{ 'method': 'adaptive' })"/>
269+
array:size($promise-array): <xsl:value-of select="array:size($promise-array)"/>
270+
</xsl:message>
271+
<xsl:message>generate-id($container): <xsl:value-of select="generate-id($container)"/></xsl:message>
230272
231-
<xsl:apply-templates mode="ldh:RenderRow"/> <!-- recurse down the block hierarchy -->
273+
cannot hide the progress bar here as the blocks might continue loading
232274
233-
<!-- cannot hide the progress bar here as the blocks might continue loading -->
234-
</xsl:for-each>
275+
<ixsl:promise select="ixsl:all-settled($promise-array)
276+
=> ixsl:then(ldh:hide-block-progress-bar($container, ?))"/>-->
235277
</xsl:when>
236278
<xsl:otherwise>
237279
<xsl:value-of select="ixsl:call(ixsl:window(), 'alert', [ ?message ])[current-date() lt xs:date('2000-01-01')]"/>
238280
</xsl:otherwise>
239281
</xsl:choose>
240282
</xsl:for-each>
283+
284+
<xsl:sequence select="$context"/>
241285
</xsl:function>
242286

287+
<xsl:function name="ldh:block-object-apply" as="item()" ixsl:updating="yes">
288+
<xsl:param name="context" as="map(*)"/>
289+
<xsl:variable name="obj-value-id" select="$context('obj-value-id')" as="xs:string"/>
290+
291+
<xsl:for-each select="id($obj-value-id, ixsl:page())">
292+
<xsl:apply-templates mode="ldh:RenderRow"/>
293+
</xsl:for-each>
294+
</xsl:function>
295+
296+
<xsl:function name="ldh:hide-block-progress-bar" ixsl:updating="yes">
297+
<xsl:param name="container" as="element()"/>
298+
<xsl:param name="results" as="array(*)"/>
299+
<xsl:message>ldh:hide-block-progress-bar</xsl:message>
300+
301+
<!-- hide the progress bar -->
302+
<xsl:for-each select="$container/ancestor::div[contains-token(@class, 'span12')][contains-token(@class, 'progress')][contains-token(@class, 'active')]">
303+
<xsl:sequence select="ixsl:call(ixsl:get(., 'classList'), 'toggle', [ 'progress', false() ])[current-date() lt xs:date('2000-01-01')]"/>
304+
<xsl:sequence select="ixsl:call(ixsl:get(., 'classList'), 'toggle', [ 'progress-striped', false() ])[current-date() lt xs:date('2000-01-01')]"/>
305+
<xsl:sequence select="ixsl:call(ixsl:get(., 'classList'), 'toggle', [ 'active', false() ])[current-date() lt xs:date('2000-01-01')]"/>
306+
</xsl:for-each>
307+
</xsl:function>
308+
243309
</xsl:stylesheet>

0 commit comments

Comments
 (0)