Skip to content

Commit

Permalink
Update facets.
Browse files Browse the repository at this point in the history
  • Loading branch information
wsalesky committed Dec 4, 2019
1 parent 5e55029 commit 8b1f1a3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion modules/app.xql
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ declare function app:display-facets($node as node(), $model as map(*), $collecti
let $facet-config := global:facet-definition-file($collection)
return
if(not(empty($facet-config))) then
(facet:selected-facets-display($facet-config/descendant::facet:facets/facet:facet-definition), facet:output-html-facets($hits, $facet-config/descendant::facet:facets/facet:facet-definition))
(facet:output-html-facets($hits, $facet-config/descendant::facet:facets/facet:facet-definition))
else ()
};

Expand Down
2 changes: 1 addition & 1 deletion modules/lib/browse.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ declare function browse:show-hits($node as node(), $model as map(*), $collection
</div>
<div class="row">
{if(not(empty($facet-config))) then
<div class="col-md-4">{(facet:selected-facets-display($facet-config/descendant::facet:facets/facet:facet-definition), facet:output-html-facets($hits, $facet-config/descendant::facet:facets/facet:facet-definition))}</div>
<div class="col-md-4">{(facet:output-html-facets($hits, $facet-config/descendant::facet:facets/facet:facet-definition))}</div>
else ()}
<div class="{if($facet-config != '') then 'col-md-8' else 'col-md-12'}">
<h3>{(
Expand Down
23 changes: 15 additions & 8 deletions modules/lib/facet.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,21 @@ else ()
};

declare function facet:key($label, $value, $count, $facet-definition){
let $facet-query := replace(replace(concat(';fq-',string($facet-definition/@name),':',string($value)),';fq-;fq-;',';fq-'),';fq- ','')
let $new-fq :=
if($facet:fq) then concat('fq=',encode-for-uri($facet:fq),encode-for-uri($facet-query))
else concat('fq=',normalize-space($facet-query))
let $active := if(contains($facet:fq,concat(';fq-',string($facet-definition/@name),':',string($value)))) then 'active' else ()
let $facet-query := concat(string($facet-definition/@name),':',$value)
(:replace(replace(concat(';fq-',string($facet-definition/@name),':',string($value)),';fq-;fq-;',';fq-'),';fq- ',''):)
let $active := if(contains($facet:fq,concat(';fq-',string($facet-definition/@name),':',string($value)))) then 'active' else ()
let $new-fq :=
if($active) then
concat('fq=',
string-join(for $facet-param in tokenize($facet:fq,';fq-')
return
if($facet-param = '' or $facet-param = $facet-query) then ()
else concat(';fq-',$facet-param),''))
else if($facet:fq) then concat('fq=',encode-for-uri($facet:fq),encode-for-uri(concat(';fq-',$facet-query)))
else concat('fq=',encode-for-uri(concat(';fq-',$facet-query)))
return
if($count gt 0) then
<a href="?{$new-fq}{facet:url-params()}" class="facet-label btn btn-default {$active}">{global:get-label(string($label))} <span class="count"> ({string($count)})</span></a>
<a href="?{$new-fq}{facet:url-params()}" class="facet-label btn btn-default {$active}">{if($active) then <span class="glyphicon glyphicon-remove facet-remove"></span> else ()}{global:get-label(string($label))} <span class="count"> ({string($count)})</span> </a>
else ()
};

Expand Down Expand Up @@ -349,7 +356,7 @@ declare function facet:titles($results as item()*, $facet-definition as element(
if($sort/text() = 'value') then $f[1]
else count($f)
ascending
return facet:key(normalize-space(string-join($f[1]/ancestor-or-self::tei:title[1]//text())), $facet-grp, count($f), $facet-definition)
return facet:key(normalize-space(string-join($f[1]/ancestor-or-self::tei:title[1]/text())), $facet-grp, count($f), $facet-definition)
let $count := count($facets)
return facet:list-keys($facets, $count, $facet-definition)
else
Expand All @@ -360,7 +367,7 @@ declare function facet:titles($results as item()*, $facet-definition as element(
if($sort/text() = 'value') then $f[1]
else count($f)
descending
return facet:key(normalize-space(string-join($f[1]/ancestor-or-self::tei:title[1]//text())), $facet-grp, count($f), $facet-definition)
return facet:key(normalize-space(string-join($f[1]/ancestor-or-self::tei:title[1]/text())), $facet-grp, count($f), $facet-definition)
let $count := count($facets)
return facet:list-keys($facets, $count, $facet-definition)
};
1 change: 1 addition & 0 deletions resources/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ footer .poweredby img { width: 120px; }
white-space: normal;
}
.facet-label.remove {background-color:#eee; color:#666; font-weight:normal; margin:.25em; display:inline-block;}
.facet-remove {padding-right:6px; margin-right:6px; border-right:1px solid #666; font-weight:normal; color:#666;}

/* G */
.geo-home {margin-top:4em !important;}
Expand Down

0 comments on commit 8b1f1a3

Please sign in to comment.