Skip to content

Commit

Permalink
MIR-1241: split the response-mir.xsl file, dynamic facets were split …
Browse files Browse the repository at this point in the history
…into a separate facets.xsl file; improved usability and customized the code in the mir_results.scss file; added some facets to the solr-config.json file and corresponding messages to messages_*.properties files.
  • Loading branch information
Oleksiy 'Alex' Levshyn committed Sep 26, 2023
1 parent 7e2889d commit 78befcd
Show file tree
Hide file tree
Showing 8 changed files with 713 additions and 588 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,12 @@ mir.response.openAccess.facet.true = Dateien frei zug\u00E4nglich
mir.response.openAccess.false = Keine frei verf\u00FCgbare Datei angehangen.
mir.response.openAccess.true = Frei verf\u00FCgbare Datei angehangen.
mir.response.relevance = Relevanz des Treffers in Bezug auf alle Treffer dieser Suche
mir.response.facet.mods.genre.title = Typ
mir.response.facet.derivates.title = Derivate
mir.response.facet.state.title = Status
mir.response.facet.createdby.title = Erstellt von
mir.response.facet.modifiedby.title = Angepasst von
mir.response.facet.mods.author.title = Autor*in
mir.results.hitDoesNotExist = Dieser Treffer kann nicht angezeigt werden oder wurde gerade gel\u00F6scht.
mir.rights = Lizenz
mir.rightsHolder = Rechteinhaber:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ mir.response.openAccess.facet.true = Files freely accessible
mir.response.openAccess.false = No free available file attached.
mir.response.openAccess.true = Free available file attached.
mir.response.relevance = Relevance of this hit in relation to all hits of current search
mir.response.facet.mods.genre.title = Type
mir.response.facet.derivates.title = Derivates
mir.response.facet.state.title = State
mir.response.facet.createdby.title = Created by
mir.response.facet.modifiedby.title = Modified by
mir.response.facet.mods.author.title = Author
mir.results.hitDoesNotExist = This result can not be displayed or was recently deleted.
mir.rights = License
mir.rightsHolder = License Holder:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,11 @@ mir.response.button.filter = Filtri
mir.response.openAccess.facet.false = file no o protetti
mir.response.openAccess.facet.title = Disponibilit\u00E0
mir.response.openAccess.facet.true = File liberamente accessibili
mir.response.facet.mods.genre.title = Tipo
mir.response.facet.derivates.title = Derivati
mir.response.facet.state.title = Stato
mir.response.facet.createdby.title = Creato da
mir.response.facet.modifiedby.title = Modificato da
mir.response.facet.mods.author.title = Autore

user.profile.id.orcid = Your ORCID iD
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,16 @@
},
"appends": {
"facet": "true",
"facet.field": "mods.genre",
"facet.field": [
"mods.genre",
"derivates",
"state",
"createdby",
"modifiedby",
"mods.author"
],
"facet.mincount": "1"
}
}
}
]
]
181 changes: 181 additions & 0 deletions mir-module/src/main/resources/xsl/facets.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:encoder="xalan://java.net.URLEncoder"
xmlns:i18n="xalan://org.mycore.services.i18n.MCRTranslation"
xmlns:mcrxsl="xalan://org.mycore.common.xml.MCRXMLFunctions"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
exclude-result-prefixes="i18n mcrxsl encoder fn"
>
<xsl:template name="facets">
<xsl:if test="/response/lst[@name='facet_counts']/lst[@name='facet_fields'] !=''">
<xsl:for-each select="/response/lst[@name='facet_counts']/lst[@name='facet_fields']/*">
<xsl:variable name="facet_name" select="self::node()/@name"/>
<!-- TODO: remove conditions for facets 'worldReadableComplete' and 'mods.genre' after code refactoring -->
<xsl:if test="self::node()[@name=$facet_name]/int">
<div class="card {$facet_name}">
<div class="card-header" data-toggle="collapse-next">
<h3 class="card-title">
<!-- Checking facet name for compatibility with old code, facets named -->
<!-- 'worldReadableComplete' and 'mods.genre' from old code -->
<xsl:choose>
<!-- facet 'worldReadableComplete' -->
<xsl:when test="$facet_name='worldReadableComplete'">
<xsl:value-of select="i18n:translate('mir.response.openAccess.facet.title')"/>
</xsl:when>

<!-- facet 'mods.genre' -->
<xsl:when test="$facet_name='mods.genre'">
<xsl:value-of select="i18n:translate('editor.search.mir.genre')"/>
</xsl:when>

<!-- all other facets -->
<xsl:otherwise>
<!-- If there is no value in the messages_*.properties files, then we take the facet name as the title of the card -->
<xsl:choose>
<xsl:when
test="fn:matches(i18n:translate(concat('mir.response.facet.', $facet_name, '.title')),'^\?\?\?(.*?)\?\?\?$')">
<xsl:value-of select="$facet_name"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="i18n:translate(concat('mir.response.facet.', $facet_name, '.title'))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</h3>
</div>

<div class="card-body collapse show">
<ul class="filter">
<!-- Checking facet name for compatibility with old code, facets named -->
<!-- 'worldReadableComplete' and 'mods.genre' from old code -->
<xsl:choose>
<!-- facet 'worldReadableComplete' -->
<xsl:when test="$facet_name='worldReadableComplete'">
<xsl:apply-templates
select="/response/lst[@name='facet_counts']/lst[@name='facet_fields']">
<xsl:with-param name="facet_name" select="$facet_name"/>
<xsl:with-param name="i18nPrefix"
select="'mir.response.openAccess.facet.'"/>
</xsl:apply-templates>
</xsl:when>

<!-- facet 'mods.genre' -->
<xsl:when test="$facet_name='mods.genre'">
<xsl:apply-templates
select="/response/lst[@name='facet_counts']/lst[@name='facet_fields']">
<xsl:with-param name="facet_name" select="$facet_name"/>
<xsl:with-param name="classId" select="'mir_genres'"/>
</xsl:apply-templates>
</xsl:when>

<!-- all other facets -->
<xsl:otherwise>
<xsl:apply-templates
select="/response/lst[@name='facet_counts']/lst[@name='facet_fields']">
<xsl:with-param name="facet_name" select="$facet_name"/>
<xsl:with-param name="classId" select="$facet_name"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</ul>
</div>
</div>
</xsl:if>
</xsl:for-each>
</xsl:if>

</xsl:template>

<xsl:template match="/response/lst[@name='facet_counts']/lst[@name='facet_fields']">
<xsl:param name="facet_name"/>
<xsl:param name="classId"/>
<xsl:param name="i18nPrefix"/>

<xsl:for-each select="lst[@name=$facet_name]/int">
<xsl:variable name="fqValue" select="concat($facet_name,':',@name)"/>
<xsl:variable name="fqFragment" select="concat('fq=',$fqValue)"/>
<xsl:variable name="fqFragmentEncoded" select="concat('fq=',encoder:encode($fqValue, 'UTF-8'))"/>
<xsl:variable name="queryWithoutStart"
select="mcrxsl:regexp($RequestURL, '(&amp;|%26)(start=)[0-9]*', '')"/>
<xsl:variable name="queryURL">
<xsl:choose>
<xsl:when test="contains($queryWithoutStart, $fqFragment)">
<xsl:choose>
<xsl:when test="not(substring-after($queryWithoutStart, $fqFragment))">
<!-- last parameter -->
<xsl:value-of
select="substring($queryWithoutStart, 1, string-length($queryWithoutStart) - string-length($fqFragment) - 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="concat(substring-before($queryWithoutStart, $fqFragment), substring-after($queryWithoutStart, concat($fqFragment,'&amp;')))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="contains($queryWithoutStart, $fqFragmentEncoded)">
<xsl:choose>
<xsl:when test="not(substring-after($queryWithoutStart, $fqFragmentEncoded))">
<!-- last parameter -->
<xsl:value-of
select="substring($queryWithoutStart, 1, string-length($queryWithoutStart) - string-length($fqFragmentEncoded) - 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of
select="concat(substring-before($queryWithoutStart, $fqFragmentEncoded), substring-after($queryWithoutStart, concat($fqFragmentEncoded,'&amp;')))"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="not(contains($queryWithoutStart, '?'))">
<xsl:value-of select="concat($queryWithoutStart, '?', $fqFragment)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($queryWithoutStart, '&amp;', $fqFragment)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<li data-fq="{$fqValue}">
<div class="custom-control custom-checkbox" onclick="location.href='{$queryURL}';">
<input type="checkbox" class="custom-control-input">
<xsl:if test="
/response/lst[@name='responseHeader']/lst[@name='params']/str[@name='fq' and text() = $fqValue] |
/response/lst[@name='responseHeader']/lst[@name='params']/arr[@name='fq']/str[text() = $fqValue]">
<xsl:attribute name="checked">true</xsl:attribute>
</xsl:if>
</input>
<label class="custom-control-label">
<span class="title">
<xsl:choose>
<xsl:when test="string-length($classId) &gt; 0">
<xsl:variable name="displayName" select="mcrxsl:getDisplayName($classId, @name)"/>
<xsl:choose>
<xsl:when test="displayName">
<xsl:value-of select="$displayName"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="string-length($i18nPrefix) &gt; 0">
<xsl:value-of select="i18n:translate(concat($i18nPrefix,@name))"
disable-output-escaping="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="@name"/>
</xsl:otherwise>
</xsl:choose>
</span>
<span class="hits">
<xsl:value-of select="."/>
</span>
</label>
</div>
</li>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>
2 changes: 1 addition & 1 deletion mir-module/src/main/resources/xsl/response-mir-utils.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,4 @@
<xsl:value-of select="concat($href, '&amp;start=',(($page -1) * $numPerPage), '&amp;rows=', $numPerPage)" />
</xsl:template>

</xsl:stylesheet>
</xsl:stylesheet>
Loading

0 comments on commit 78befcd

Please sign in to comment.