Skip to content

Commit

Permalink
Re-render the whole form after 422 response by applying the `bs2:RowF…
Browse files Browse the repository at this point in the history
…orm` mode
  • Loading branch information
namedgraph committed Oct 18, 2024
1 parent 8e1e114 commit 146af95
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -770,56 +770,16 @@ WHERE
</xsl:when>
<!-- POST or PUT constraint violation response is 422 Unprocessable Entity, bad RDF syntax is 400 Bad Request -->
<xsl:when test="?status = (400, 422) and starts-with(?media-type, 'application/rdf+xml')"> <!-- allow 'application/rdf+xml;charset=UTF-8' as well -->
<xsl:variable name="row-form" as="element()">
<xsl:apply-template select="?body" mode="bs2:RowForm"/>
</xsl:variable>

<xsl:variable name="body" select="?body" as="document-node()"/>
<!-- iterate each form fieldset as resource -->
<xsl:for-each select="$form/fieldset">
<!-- guard against multiple subject URI/bnode values as there can be nested fieldsets -->
<xsl:variable name="resource-uri" select="(.//input[@name = 'su'])[1]/ixsl:get(., 'value')" as="xs:anyURI?"/>
<xsl:variable name="resource-bnode" select="(.//input[@name = 'sb'])[1]/ixsl:get(., 'value')" as="xs:string?"/>
<xsl:message>
$resource-uri: <xsl:value-of select="$resource-uri"/>
$resource-bnode: <xsl:value-of select="$resource-bnode"/>
</xsl:message>
<!-- select violations specific to this resource -->
<!-- TO-DO: key('violations-by-value', $resources//*/@rdf:resource, ?body) -->
<xsl:variable name="violations" select="key('violations-by-root', ($resource-uri, $resource-bnode), $body) | key('violations-by-focus-node', ($resource-uri, $resource-bnode), $body)" as="element()*"/>
<xsl:message>$violations: <xsl:value-of select="serialize($violations)"/></xsl:message>

<!-- iterate control groups as properties -->
<xsl:for-each select="./div[contains-token(@class, 'control-group')][input[@name = 'pu']]">
<xsl:variable name="predicate" select="input[@name = 'pu']/ixsl:get(., 'value')" as="xs:anyURI"/>

<xsl:choose>
<!-- if there are SPIN or SHACL violations specific to the predicate of this control group, set error class on the group -->
<!-- TO-DO: @rdf:resource = $violations/ldh:violationValue -->
<xsl:when test="$violations[spin:violationPath/@rdf:resource = $predicate or sh:resultPath/@rdf:resource = $predicate]">
<xsl:sequence select="ixsl:call(ixsl:get(., 'classList'), 'toggle', [ 'error', true() ])[current-date() lt xs:date('2000-01-01')]"/>
</xsl:when>
<!-- otherwise, remove the error class -->
<xsl:otherwise>
<xsl:sequence select="ixsl:call(ixsl:get(., 'classList'), 'toggle', [ 'error', false() ])[current-date() lt xs:date('2000-01-01')]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>

<xsl:for-each select="./div[contains-token(@class, 'violations')]">
<xsl:choose>
<!-- render violations if they exist for this resource -->
<xsl:when test="exists($violations)">
<xsl:result-document href="?." method="ixsl:replace-content">
<xsl:apply-templates select="$violations" mode="bs2:Violation"/>
</xsl:result-document>
<ixsl:set-style name="display" select="'block'"/>
</xsl:when>
<!-- hide any previous violations if this resource now has none -->
<xsl:otherwise>
<ixsl:set-style name="display" select="'none'"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<xsl:for-each select="$block">
<xsl:result-document href="?." method="ixsl:replace-content">
<xsl:copy-of select="$row-form/*"/>
</xsl:result-document>
</xsl:for-each>

<ixsl:set-style name="cursor" select="'default'" object="ixsl:page()//body"/>
</xsl:when>
<!-- error response -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ extension-element-prefixes="ixsl"
</xsl:if>
</xsl:template>

<!-- BLOCK -->
<!-- ROW -->

<xsl:template match="rdf:RDF" mode="bs2:Row">
<xsl:param name="create-resource" select="true()" as="xs:boolean"/>
Expand Down

0 comments on commit 146af95

Please sign in to comment.