Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor / Configuration / Add condition on element and session for all. #6355

Merged
merged 1 commit into from Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions schemas/config-editor.xsd
Expand Up @@ -1007,6 +1007,7 @@ the mandatory section with no name and then the inner elements.
<xs:attribute ref="or"/>
<xs:attribute ref="in"/>
<xs:attribute ref="displayIfRecord"/>
<xs:attribute ref="displayIfServiceInfo"/>
josegar74 marked this conversation as resolved.
Show resolved Hide resolved
</xs:complexType>
<xs:unique name="avoidDuplicateFieldWithSameXPath">
<xs:annotation>
Expand Down Expand Up @@ -1043,6 +1044,7 @@ the mandatory section with no name and then the inner elements.
<xs:element ref="field"/>
</xs:sequence>
<xs:attribute name="name" use="required" type="xs:string"/>
<xs:attribute ref="displayIfServiceInfo"/>
</xs:complexType>
</xs:element>

Expand Down Expand Up @@ -1118,6 +1120,7 @@ Activate the "flat" mode at the tab level to make the form display only existing
<xs:element ref="template" minOccurs="0" maxOccurs="1"/>
<xs:element ref="directiveAttributes" minOccurs="0" maxOccurs="1"/>
</xs:sequence>
<xs:attribute ref="displayIfServiceInfo"/>
<xs:attribute name="if">
<xs:annotation>
<xs:documentation><![CDATA[
Expand Down Expand Up @@ -1353,6 +1356,7 @@ An XPath expression to evaluate. If true, the text is displayed.
]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute ref="displayIfServiceInfo"/>
</xs:complexType>
</xs:element>

Expand Down Expand Up @@ -1613,6 +1617,7 @@ with the metadata identifier.
]]></xs:documentation>
</xs:annotation>
</xs:attribute>
<xs:attribute ref="displayIfServiceInfo"/>
<xs:attribute name="class" type="xs:string">
<xs:annotation>
<xs:documentation>Optional CSS class to add to the parent div element. eg. gn-required to show a *.</xs:documentation>
Expand Down Expand Up @@ -2195,6 +2200,8 @@ Include any custom directive with required attributes.
]]></xs:documentation>
</xs:annotation>
<xs:complexType>
<xs:attribute ref="displayIfServiceInfo"/>
<xs:attribute ref="displayIfRecord"/>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>
Expand Down
Expand Up @@ -4,6 +4,7 @@
xmlns:gn-fn-core="http://geonetwork-opensource.org/xsl/functions/core"
xmlns:tr="java:org.fao.geonet.api.records.formatters.SchemaLocalizations"
xmlns:utils="java:org.fao.geonet.util.XslUtil"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:saxon="http://saxon.sf.net/"
extension-element-prefixes="saxon"
exclude-result-prefixes="#all"
Expand Down Expand Up @@ -391,35 +392,48 @@
-->
<xsl:template mode="render-view"
match="section[@xpath]">
<div id="gn-view-{generate-id()}" class="gn-tab-content">
<xsl:apply-templates mode="render-view" select="@xpath"/>
<xsl:comment select="'icon'"/>
</div>
<xsl:variable name="isDisplayed"
as="xs:boolean"
select="gn-fn-metadata:check-elementandsession-visibility(
$schema, $metadata, $serviceInfo, @displayIfRecord, @displayIfServiceInfo)"/>

<xsl:if test="$isDisplayed">
<div id="gn-view-{generate-id()}" class="gn-tab-content">
<xsl:apply-templates mode="render-view" select="@xpath"/>
<xsl:comment select="'icon'"/>
</div>
</xsl:if>
</xsl:template>


<xsl:template mode="render-view"
match="section[not(@xpath)]">
<xsl:variable name="isDisplayed"
as="xs:boolean"
select="gn-fn-metadata:check-elementandsession-visibility(
$schema, $metadata, $serviceInfo, @displayIfRecord, @displayIfServiceInfo)"/>

<xsl:if test="$isDisplayed">
<xsl:variable name="content">
<xsl:apply-templates mode="render-view"
select="section|field|xsl"/>&#160;
</xsl:variable>

<xsl:variable name="content">
<xsl:apply-templates mode="render-view"
select="section|field|xsl"/>&#160;
</xsl:variable>

<xsl:if test="count($content/*) > 0">
<div id="gn-section-{generate-id()}" class="gn-tab-content">
<xsl:if test="@name">
<xsl:variable name="title"
select="
if (contains( @name, ':'))
then gn-fn-render:get-schema-labels($schemaLabels, @name)
else gn-fn-render:get-schema-strings($schemaStrings, @name) "/>
<xsl:element name="h{1 + count(ancestor-or-self::*[name(.) = 'section'])}">
<xsl:value-of select="$title"/>
</xsl:element>
</xsl:if>
<xsl:copy-of select="$content"/>
</div>
<xsl:if test="count($content/*) > 0">
<div id="gn-section-{generate-id()}" class="gn-tab-content">
<xsl:if test="@name">
<xsl:variable name="title"
select="
if (contains( @name, ':'))
then gn-fn-render:get-schema-labels($schemaLabels, @name)
else gn-fn-render:get-schema-strings($schemaStrings, @name) "/>
<xsl:element name="h{1 + count(ancestor-or-self::*[name(.) = 'section'])}">
<xsl:value-of select="$title"/>
</xsl:element>
</xsl:if>
<xsl:copy-of select="$content"/>
</div>
</xsl:if>
</xsl:if>
</xsl:template>

Expand Down
120 changes: 43 additions & 77 deletions web/src/main/webapp/xslt/ui-metadata/form-configurator.xsl
Expand Up @@ -34,9 +34,17 @@
-->

<xsl:template mode="form-builder" match="directive">
<div>
<xsl:copy-of select="@*"/>
</div>

<xsl:variable name="isDisplayed"
as="xs:boolean"
select="gn-fn-metadata:check-elementandsession-visibility(
$schema, $metadata, $serviceInfo, @displayIfRecord, @displayIfServiceInfo)"/>

<xsl:if test="$isDisplayed">
<div>
<xsl:copy-of select="@*"/>
</div>
</xsl:if>
</xsl:template>


Expand All @@ -46,21 +54,12 @@
<xsl:template mode="form-builder" match="section[@name]|fieldset">
<xsl:param name="base" as="node()"/>

<xsl:variable name="match">
<xsl:choose>
<xsl:when test="@displayIfRecord">
<saxon:call-template name="{concat('evaluate-', $schema, '-boolean')}">
<xsl:with-param name="base" select="$metadata"/>
<xsl:with-param name="in" select="concat('/../', @displayIfRecord)"/>
</saxon:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="true()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="isDisplayed"
as="xs:boolean"
select="gn-fn-metadata:check-elementandsession-visibility(
$schema, $metadata, $serviceInfo, @displayIfRecord, @displayIfServiceInfo)"/>

<xsl:if test="$match = true()">
<xsl:if test="$isDisplayed">
<xsl:variable name="sectionName" select="@name"/>

<xsl:choose>
Expand Down Expand Up @@ -96,41 +95,24 @@
<xsl:variable name="id" select="@ref"/>
<xsl:variable name="text" select="$strings/*[name() = $id]"/>

<xsl:variable name="match">
<xsl:choose>
<xsl:when test="@if">
<saxon:call-template name="{concat('evaluate-', $schema, '-boolean')}">
<xsl:with-param name="base" select="$metadata"/>
<xsl:with-param name="in" select="concat('/../', @if)"/>
</saxon:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="true()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$match = true()">
<xsl:if test="$text">
<xsl:copy-of select="$text/*" copy-namespaces="no"/>
</xsl:if>
<xsl:variable name="isDisplayed"
as="xs:boolean"
select="gn-fn-metadata:check-elementandsession-visibility(
$schema, $metadata, $serviceInfo, @if, @displayIfServiceInfo)"/>

<xsl:if test="$isDisplayed and $text">
<xsl:copy-of select="$text/*" copy-namespaces="no"/>
</xsl:if>
</xsl:template>

<xsl:template mode="form-builder" match="action">
<xsl:variable name="match">
<xsl:choose>
<xsl:when test="@if">
<saxon:call-template name="{concat('evaluate-', $schema, '-boolean')}">
<xsl:with-param name="base" select="$metadata"/>
<xsl:with-param name="in" select="concat('/../', @if)"/>
</saxon:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="true()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="$match = true()">

<xsl:variable name="isDisplayed"
as="xs:boolean"
select="gn-fn-metadata:check-elementandsession-visibility(
$schema, $metadata, $serviceInfo, @if, @displayIfServiceInfo)"/>

<xsl:if test="$isDisplayed">
<xsl:choose>
<xsl:when test="@type = 'process' and @process">
<xsl:call-template name="render-batch-process-button">
Expand Down Expand Up @@ -237,19 +219,10 @@
<!-- Check if this field is controlled by a condition
(eg. display that field for service metadata record only).
If @if expression return false, the field is not displayed. -->
<xsl:variable name="isDisplayed">
<xsl:choose>
<xsl:when test="@if">
<saxon:call-template name="{concat('evaluate-', $schema, '-boolean')}">
<xsl:with-param name="base" select="$base"/>
<xsl:with-param name="in" select="concat('/../', @if)"/>
</saxon:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="true()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="isDisplayed"
as="xs:boolean"
select="gn-fn-metadata:check-elementandsession-visibility(
$schema, $base, $serviceInfo, @if, @displayIfServiceInfo)"/>

<!--
<xsl:message> Field: <xsl:value-of select="@name"/></xsl:message>
Expand All @@ -271,7 +244,7 @@
In that case, a geonet:child element should exist in the document.
-->
<xsl:choose>
<xsl:when test="$isDisplayed = 'true' and not(@templateModeOnly)">
<xsl:when test="$isDisplayed and not(@templateModeOnly)">
<xsl:variable name="configName" select="@name"/>


Expand Down Expand Up @@ -369,7 +342,7 @@
</xsl:if>

</xsl:when>
<xsl:when test="$isDisplayed = 'true' and (@templateModeOnly or template)">
<xsl:when test="$isDisplayed and (@templateModeOnly or template)">
<!--
templateModeOnly

Expand Down Expand Up @@ -639,6 +612,8 @@

<xsl:template mode="form-builder" match="action[@type='add']">
<xsl:param name="base" as="node()"/>


<!-- Match any gn:child nodes from the metadocument which
correspond to non existing node but available in the schema. -->
<xsl:variable name="nonExistingChildParent">
Expand All @@ -664,26 +639,17 @@
<!-- Check if this field is controlled by a condition (eg. display that field for
service metadata record only).
If @if expression return false, the field is not displayed. -->
<xsl:variable name="isDisplayed">
<xsl:choose>
<xsl:when test="@if">
<saxon:call-template name="{concat('evaluate-', $schema, '-boolean')}">
<xsl:with-param name="base" select="$base"/>
<xsl:with-param name="in" select="concat('/../', @if)"/>
</saxon:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="true()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="isDisplayed"
as="xs:boolean"
select="gn-fn-metadata:check-elementandsession-visibility(
$schema, $base, $serviceInfo, @if, @displayIfServiceInfo)"/>

<!--<xsl:message>## Add action</xsl:message>
<xsl:message><xsl:copy-of select="."/></xsl:message>
<xsl:message>Is displayed: <xsl:copy-of select="$isDisplayed"/> because no if provided or if attribute XPath '<xsl:value-of select="@if"/>' expression found a match.</xsl:message>
<xsl:message> = Display action <xsl:value-of select="$nonExistingChildParent/* and $isDisplayed = 'true'"/></xsl:message>-->

<xsl:if test="$nonExistingChildParent/* and $isDisplayed = 'true'">
<xsl:if test="$nonExistingChildParent/* and $isDisplayed">
<xsl:variable name="childName" select="@or"/>

<!-- Get label from action or from gn:child -->
Expand Down
4 changes: 2 additions & 2 deletions web/src/main/webapp/xslt/ui-metadata/menu-builder.xsl
Expand Up @@ -80,7 +80,7 @@

<xsl:variable name="isViewDisplayed"
as="xs:boolean"
select="gn-fn-metadata:check-viewtab-visibility(
select="gn-fn-metadata:check-elementandsession-visibility(
$schema, $metadata, $serviceInfo,
@displayIfRecord,
@displayIfServiceInfo)"/>
Expand Down Expand Up @@ -168,7 +168,7 @@
<xsl:template mode="menu-builder" match="tab">
<xsl:variable name="isTabDisplayed"
as="xs:boolean"
select="gn-fn-metadata:check-viewtab-visibility(
select="gn-fn-metadata:check-elementandsession-visibility(
$schema, $metadata, $serviceInfo,
@displayIfRecord,
@displayIfServiceInfo)"/>
Expand Down