@@ -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 -->
0 commit comments