Skip to content

Commit

Permalink
sync with current UBO version
Browse files Browse the repository at this point in the history
  • Loading branch information
kkrebs committed Nov 21, 2023
1 parent 8525834 commit 679f129
Show file tree
Hide file tree
Showing 3 changed files with 372 additions and 22 deletions.
289 changes: 289 additions & 0 deletions src/main/resources/xsl/response-facets.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,289 @@
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
xmlns:i18n="xalan://org.mycore.services.i18n.MCRTranslation"
xmlns:encoder="xalan://java.net.URLEncoder"
xmlns:str="xalan://java.lang.String"
xmlns:mcrxml="xalan://org.mycore.common.xml.MCRXMLFunctions"
exclude-result-prefixes="xsl xalan i18n encoder mcrxml str">

<xsl:param name="RequestURL" />
<xsl:param name="ServletsBaseURL" />

<xsl:variable name="maxFacetValuesDisplayed">5</xsl:variable>
<xsl:variable name="quotes">"</xsl:variable>
<xsl:variable name="fq_not">-</xsl:variable>

<xsl:template match="lst[@name='facet_counts']">
<xsl:apply-templates select="../lst[@name='responseHeader']/lst[@name='params']" mode="fq" />
<xsl:apply-templates select="lst[@name='facet_fields']/lst[int]" />
</xsl:template>

<!-- List currently active filter queries -->
<xsl:template match="lst[@name='responseHeader']/lst[@name='params']" mode="fq">
<xsl:variable name="hasActiveFilters" select="boolean(*[@name='fq'])" />
<article class="card mb-3">
<div class="card-body">
<hgroup>
<h3>
<xsl:value-of select="i18n:translate(concat('facets.filters.',$hasActiveFilters))" />
</h3>
</hgroup>
<xsl:if test="$hasActiveFilters">
<ul class="list-group">
<xsl:for-each select="*[@name='fq']/descendant-or-self::str">

<xsl:variable name="fq" select="text()" />

<xsl:variable name="removeURL">
<xsl:text>select?</xsl:text>
<xsl:for-each select="/response/lst[@name='responseHeader']/lst[@name='params']/*">
<xsl:variable name="param_name" select="@name" />
<xsl:for-each select="descendant-or-self::str"> <!-- may be an array: arr/str or ./str -->
<xsl:choose>
<xsl:when test="$param_name='start'" />
<xsl:when test="($param_name='fq') and (text()=$fq)" /> <!-- remove this -->
<xsl:otherwise>
<xsl:value-of select="$param_name" />
<xsl:text>=</xsl:text>
<xsl:value-of select="encoder:encode(text(),'UTF-8')" />
<xsl:text>&amp;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
<xsl:text>start=0</xsl:text>
</xsl:variable>

<xsl:variable name="fq_without_quotes" select="str:replaceAll(str:new($fq),$quotes,'')" />

<li class="mycore-list-item">
<a class="mycore-facet-remove" href="{$removeURL}">
<span class="far fa-times-circle" aria-hidden="true" />
</a>
<span class="mycore-facet-filter">
<xsl:choose>
<xsl:when test="starts-with($fq_without_quotes,$fq_not)">
<xsl:variable name="fq_without_not" select="substring-after($fq_without_quotes,'-')" />
<xsl:call-template name="output.facet.value">
<xsl:with-param name="prefix" select="concat(i18n:translate('facets.filters.not'),' ')" />
<xsl:with-param name="type" select="substring-before($fq_without_not,':')" />
<xsl:with-param name="value" select="substring-after($fq_without_not,':')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="output.facet.value">
<xsl:with-param name="type" select="substring-before($fq_without_quotes,':')" />
<xsl:with-param name="value" select="substring-after($fq_without_quotes,':')" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</span>
</li>
</xsl:for-each>
</ul>
</xsl:if>
</div>
</article>
</xsl:template>

<xsl:variable name="permission.admin" xmlns:check="xalan://org.mycore.ubo.AccessControl" select="check:currentUserIsAdmin()" />

<!-- List a facet -->
<xsl:template match="lst[@name='facet_fields']/lst[int]">
<xsl:choose>
<xsl:when test="(@name='status') and not($permission.admin)" /> <!-- do not show status facet if not admin -->
<xsl:when test="(@name='importID') and not($permission.admin)" /> <!-- do not show importID facet if not admin -->
<xsl:otherwise>
<xsl:call-template name="display.facet" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="display.facet">
<xsl:variable name="max">
<xsl:for-each select="int">
<xsl:sort select="text()" data-type="number" order="descending"/>
<xsl:if test="position() = 1"><xsl:value-of select="string-length(text())"/></xsl:if>
</xsl:for-each>
</xsl:variable>
<article class="card mb-3">
<div class="card-body">
<hgroup>
<h3><xsl:value-of select="i18n:translate(concat('facets.facet.',str:replaceAll(str:new(@name),'facet_','')))" /></h3>
</hgroup>
<ul id="{generate-id(.)}" class="list-group counter-length-{$max}">
<xsl:choose>
<xsl:when test="@name='year'"> <!-- sort year facets by year, descending -->
<xsl:apply-templates select="int" mode="facets">
<xsl:sort select="@name" data-type="number" order="descending" />
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise> <!-- sort other facets by facet count, descending -->
<xsl:apply-templates select="int" mode="facets">
<xsl:sort select="text()" data-type="number" order="descending" />
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</ul>
<xsl:variable name="numMore" select="count(int) - number($maxFacetValuesDisplayed)" />
<xsl:if test="$numMore &gt; 0">
<div class="float-right mycore-slidetoggle">
<a class="mycore-facets-toggle" id="tg{generate-id(.)}" onclick="$('ul#{generate-id(.)} li:gt({$maxFacetValuesDisplayed - 1})').slideToggle(); $('a#tg{generate-id(.)} span').toggle();">
<span><xsl:value-of select="concat($numMore,' ',i18n:translate('facets.toggle.more'))" /></span>
<span style="display:none;"><xsl:value-of select="i18n:translate('facets.toggle.less')" /></span>
<xsl:text>...</xsl:text>
</a>
</div>
</xsl:if>
</div>
</article>
</xsl:template>

<!-- URL to build links to add a facet filter query -->
<xsl:variable name="baseURL">
<xsl:text>select?</xsl:text>
<xsl:for-each select="/response/lst[@name='responseHeader']/lst[@name='params']/*">
<xsl:variable name="name" select="@name" />
<xsl:for-each select="descendant-or-self::str"> <!-- may be an array: arr/str or ./str -->
<xsl:choose>
<xsl:when test="$name='start'" />
<xsl:otherwise>
<xsl:value-of select="$name" />
<xsl:text>=</xsl:text>
<xsl:value-of select="encoder:encode(text(),'UTF-8')" />
<xsl:text>&amp;</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:for-each>
<xsl:text>start=0&amp;fq=</xsl:text>
</xsl:variable>

<!-- Output single facet value -->
<xsl:template match="lst[@name='facet_fields']/lst/int" mode="facets">
<li class="mycore-list-item">
<xsl:if test="position() &gt; number($maxFacetValuesDisplayed)">
<xsl:attribute name="style">display:none;</xsl:attribute>
</xsl:if>
<span class="mycore-facet-count">
<xsl:value-of select="text()" />
</span>
<xsl:variable name="fq" select="encoder:encode(concat(../@name,':',$quotes,@name,$quotes),'UTF-8')" />
<xsl:choose>
<xsl:when test="number(text()) &lt; number($numFound)"> <!-- When count = 100%, filtering makes no sense -->
<a class="mycore-facet-exclude" href="{$baseURL}{encoder:encode($fq_not)}{$fq}"> <!-- Link to exclude this facet value -->
<span class="far fa-times-circle" aria-hidden="true" />
</a>
<a class="mycore-facet-add" href="{$baseURL}{$fq}">
<span class="mycore-facet-value">
<xsl:call-template name="output.facet.value">
<xsl:with-param name="type" select="../@name" />
<xsl:with-param name="value" select="@name"/>
</xsl:call-template>
</span>
</a>
</xsl:when>
<xsl:otherwise>
<span class="mycore-facet-exclude" />
<span class="mycore-facet-value">
<xsl:call-template name="output.facet.value">
<xsl:with-param name="type" select="../@name" />
<xsl:with-param name="value" select="@name"/>
</xsl:call-template>
</span>
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:template>

<!-- Output facet value: some must be translated to a label, e.g. subject, genre -->
<xsl:template name="output.facet.value">
<xsl:param name="prefix"/>
<xsl:param name="type"/>
<xsl:param name="value"/>

<xsl:variable name="label">
<xsl:value-of select="$prefix"/>
<xsl:choose>
<xsl:when test="$type='subject'">
<xsl:variable name="url">classification:metadata:0:children:fachreferate:<xsl:value-of
select="encoder:encode($value,'UTF-8')"/>
</xsl:variable>
<xsl:value-of select="document($url)/mycoreclass/categories/category[1]/label[@xml:lang=$CurrentLang]/@text"/>
</xsl:when>
<xsl:when test="$type='oa'">
<xsl:value-of select="$oa//category[@ID=$value]/label[lang($CurrentLang)]/@text"/>
</xsl:when>
<xsl:when test="$type='genre'">
<xsl:value-of select="$genres//category[@ID=$value]/label[lang($CurrentLang)]/@text"/>
</xsl:when>
<xsl:when test="$type='origin_exact'">
<xsl:value-of select="$origin//category[@ID=$value]/label[lang($CurrentLang)]/@text"/>
</xsl:when>
<xsl:when test="$type='status'">
<xsl:value-of select="i18n:translate(concat('search.dozbib.status.',$value))"/>
</xsl:when>
<xsl:when test="$type='partOf'">
<xsl:value-of select="i18n:translate(concat('search.dozbib.partOf.', $value))"/>
</xsl:when>
<xsl:when test="$type='project'">
<xsl:value-of select="mcrxml:getDisplayName('project', $value)"/>
</xsl:when>
<xsl:when test="$type='fundingType'">
<xsl:value-of select="mcrxml:getDisplayName('fundingType', $value)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="fallback-label">
<xsl:if test="string-length($label) = 0">
<xsl:value-of select="$prefix"/>
<xsl:choose>
<xsl:when test="$type='subject'">
<xsl:variable name="url">classification:metadata:0:children:fachreferate:<xsl:value-of
select="encoder:encode($value,'UTF-8')"/>
</xsl:variable>
<xsl:value-of select="document($url)/mycoreclass/categories/category[1]/label[@xml:lang=$DefaultLang]/@text"/>
</xsl:when>
<xsl:when test="$type='oa'">
<xsl:value-of select="$oa//category[@ID=$value]/label[lang($DefaultLang)]/@text"/>
</xsl:when>
<xsl:when test="$type='genre'">
<xsl:value-of select="$genres//category[@ID=$value]/label[lang($DefaultLang)]/@text"/>
</xsl:when>
<xsl:when test="$type='peerreviewed'">
<xsl:value-of select="$peerreviewed//category[@ID=$value]/label[lang($DefaultLang)]/@text"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$value"/>
</xsl:otherwise>
</xsl:choose>
</xsl:if>
</xsl:variable>

<span>
<xsl:choose>
<xsl:when test="string-length($label) ">
<xsl:if test="string-length($label) &gt; 20">
<xsl:attribute name="class">scroll-on-hover</xsl:attribute>
</xsl:if>
<xsl:value-of select="$label"/>
</xsl:when>
<xsl:when test="$label">
<xsl:if test="string-length($fallback-label) &gt; 20">
<xsl:attribute name="class">scroll-on-hover</xsl:attribute>
</xsl:if>
<xsl:value-of select="$fallback-label"/>
</xsl:when>
</xsl:choose>
</span>
</xsl:template>

</xsl:stylesheet>
31 changes: 20 additions & 11 deletions src/main/resources/xsl/response.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@
xmlns:i18n="xalan://org.mycore.services.i18n.MCRTranslation"
xmlns:mods="http://www.loc.gov/mods/v3"
xmlns:mcr="http://www.mycore.org/"
xmlns:mcrxml="xalan://org.mycore.common.xml.MCRXMLFunctions"
xmlns:encoder="xalan://java.net.URLEncoder"
xmlns:str="xalan://java.lang.String"
xmlns:basket="xalan://org.mycore.ubo.basket.BasketUtils"
exclude-result-prefixes="xsl xalan i18n mods mcr encoder str basket"
>
exclude-result-prefixes="xsl xalan i18n mods mcr mcrxml encoder str basket">

<xsl:include href="mods-display.xsl" />
<xsl:include href="response-facets.xsl" />
<xsl:include href="ubo-dialog.xsl" />
<xsl:include href="coreFunctions.xsl" />
<xsl:include href="csl-export-gui.xsl" />

<xsl:param name="RequestURL" />
<xsl:param name="MCR.ORCID.OAuth.ClientSecret" select="''" />
<xsl:param name="MCR.ORCID.OAuth.Scopes" select="''" />
<xsl:param name="CurrentUser" />
<xsl:param name="MCR.Users.Guestuser.UserName" />
<xsl:param name="MCR.ORCID2.OAuth.ClientSecret" select="''" />
<xsl:param name="MCR.ORCID2.OAuth.Scope" select="''" />

<!-- ==================== Trefferliste Metadaten ==================== -->

Expand Down Expand Up @@ -110,8 +109,18 @@
<html id="dozbib.search">
<head>
<xsl:call-template name="page.title" />
<xsl:if test="string-length($MCR.ORCID.OAuth.ClientSecret) &gt; 0 and contains($MCR.ORCID.OAuth.Scopes,'update')">
<script src="{$WebApplicationBaseURL}js/mycore2orcid.js" />
<xsl:if test="not(mcrxml:isCurrentUserGuestUser()) and string-length($MCR.ORCID2.OAuth.ClientSecret) &gt; 0 and contains($MCR.ORCID2.OAuth.Scope,'update')">

<xsl:call-template name="notification-dialog">
<xsl:with-param name="id" select="'success'"/>
<xsl:with-param name="title" select="'⚠'"/>
<xsl:with-param name="message" select="i18n:translate('orcid.publication.action.confirmation')"/>
</xsl:call-template>
<xsl:call-template name="notification-dialog">
<xsl:with-param name="id" select="'fail'"/>
<xsl:with-param name="title" select="'⚠'"/>
<xsl:with-param name="message" select="i18n:translate('upload.failed')"/>
</xsl:call-template>
</xsl:if>
</head>
<body>
Expand Down Expand Up @@ -216,7 +225,7 @@
</nav>
</div>

<xsl:if test="$CurrentUser != $MCR.Users.Guestuser.UserName">
<xsl:if test="not(mcrxml:isCurrentUserGuestUser())">
<div class="col-2 text-right">
<span class="pageLink">
<a class="btn btn-sm btn-secondary" href="statistics?{$exportParams}&amp;XSL.Style=statistics"><xsl:value-of select="i18n:translate('button.statistics')" /></a>
Expand Down Expand Up @@ -275,7 +284,7 @@
<xsl:call-template name="label-year" />
<xsl:call-template name="pubtype" />
<xsl:call-template name="label-oa" />
<xsl:if test="string-length($MCR.ORCID.OAuth.ClientSecret) &gt; 0 and contains($MCR.ORCID.OAuth.Scopes,'update')">
<xsl:if test="string-length($MCR.ORCID2.OAuth.ClientSecret) &gt; 0 and contains($MCR.ORCID2.OAuth.Scope,'update')">
<xsl:call-template name="orcid-status" />
</xsl:if>
</div>
Expand All @@ -290,7 +299,7 @@
<xsl:call-template name="bibentry.add.to.basket" />
</xsl:if>
<xsl:call-template name="bibentry.subselect.return" />
<xsl:if test="string-length($MCR.ORCID.OAuth.ClientSecret) &gt; 0 and contains($MCR.ORCID.OAuth.Scopes,'update')">
<xsl:if test="string-length($MCR.ORCID2.OAuth.ClientSecret) &gt; 0 and contains($MCR.ORCID2.OAuth.Scope,'update')">
<xsl:call-template name="orcid-publish" />
</xsl:if>
<span class="float-right"># <xsl:value-of select="$hitNo"/></span>
Expand Down
Loading

0 comments on commit 679f129

Please sign in to comment.