Afficher les derniers auteurs
1 {{velocity output="false"}}
2 #macro (displaySearchFacetValues_mediaType $facetValues)
3 #set ($discard = $xwiki.ssx.use('Main.SolrMediaTypeFacet'))
4 #set ($discard = $xwiki.jsx.use('Main.SolrMediaTypeFacet'))
5 #set ($categoryMap = $solrConfig.facet.mediaType.categories)
6 #groupMediaTypes($facetValues $categoryMap true)
7 ## We also need to group some technical media types inside a category.
8 #set ($subcategoryMap = $solrConfig.facet.mediaType.subcategories)
9 #foreach ($facetValue in $facetValues)
10 #set ($subcategories = $subcategoryMap.get($facetValue.id))
11 #if ($subcategories)
12 #groupMediaTypes($facetValue.mediaTypesWithCounts $subcategories)
13 ## Update the list of media types to be able to unselect all subcategories when a category is selected.
14 #set ($discard = $facetValue.mediaTypes.clear())
15 #foreach ($mediaType in $facetValue.mediaTypesWithCounts)
16 #set ($discard = $facetValue.mediaTypes.add($mediaType.name))
17 #end
18 #end
19 #end
20 #displayMediaTypesWithPagination($facetValues)
21 #end
22
23 #macro (groupMediaTypes $mediaTypes $groups $groupRemainingMediaTypes)
24 #set ($matchedGroups = [])
25 #set ($groupedMediaTypes = [])
26 #foreach ($entry in $groups.entrySet())
27 #set ($group = {
28 'id': $entry.key,
29 'count': 0,
30 'mediaTypes': [],
31 'mediaTypesWithCounts': []
32 })
33 #foreach ($mediaType in $mediaTypes)
34 ## See if this media type is included in this group.
35 #foreach ($pattern in $entry.value)
36 #if ($mediaType.name == $pattern || $mediaType.name.startsWith($pattern) || $mediaType.name.endsWith($pattern))
37 #set ($group.count = $group.count + $mediaType.count)
38 #set ($discard = $group.mediaTypes.add($mediaType.name))
39 #set ($discard = $group.mediaTypesWithCounts.add($mediaType))
40 #set ($discard = $groupedMediaTypes.add($mediaType))
41 #break
42 #end
43 #end
44 #end
45 #if ($group.count > 0)
46 ## Compute the filter value.
47 #joinMediaTypes($entry.value $escapedFilterValue)
48 #set ($discard = $group.put('name', $escapedFilterValue))
49 #set ($discard = $matchedGroups.add($group))
50 #end
51 #end
52 #set ($discard = $mediaTypes.removeAll($groupedMediaTypes))
53 #if ($groupRemainingMediaTypes && $mediaTypes && $mediaTypes.size() > 0)
54 #set ($other = {
55 'id': 'other',
56 'count': 0,
57 'mediaTypes': [],
58 'mediaTypesWithCounts': []
59 })
60 #set ($discard = $other.mediaTypesWithCounts.addAll($mediaTypes))
61 #foreach ($mediaType in $mediaTypes)
62 #set ($other.count = $other.count + $mediaType.count)
63 #set ($discard = $other.mediaTypes.add($mediaType.name))
64 #end
65 #joinMediaTypes($other.mediaTypes $escapedFilterValue)
66 #set ($discard = $other.put('name', $escapedFilterValue))
67 #set ($discard = $mediaTypes.clear())
68 #set ($discard = $mediaTypes.add($other))
69 #end
70 #set ($discard = $mediaTypes.addAll($matchedGroups))
71 ## Sort the media type groups based on the number of matches.
72 ## Note that the sort tool doesn't change the passed list.
73 #set ($sortedMediaTypes = $collectiontool.sort($mediaTypes, 'count:desc'))
74 #set ($discard = $mediaTypes.clear())
75 #set ($discard = $mediaTypes.addAll($sortedMediaTypes))
76 #end
77
78 #macro (joinMediaTypes $mediaTypes $return)
79 #set ($escapedMediaTypes = [])
80 #foreach ($mediaType in $mediaTypes)
81 ## Escape the characters that have special meaning in the filter query.
82 #set ($escapedMediaType = $mediaType.replaceAll('([/.+\-])', '\\$1'))
83 #if ($mediaType.indexOf('/') > 0)
84 ## Prefix.
85 #set ($escapedMediaType = "$escapedMediaType*")
86 #else
87 ## Suffix.
88 #set ($escapedMediaType = "*$escapedMediaType")
89 #end
90 #set ($discard = $escapedMediaTypes.add($escapedMediaType))
91 #end
92 #set ($return = $NULL)
93 #setVariable("$return" "($stringtool.join($escapedMediaTypes, ' '))")
94 #end
95
96 #macro (displayMediaTypesWithPagination $categories)
97 #set ($limitRequestParameter = "l_$facetField.name")
98 #set ($categoryLimit = $numbertool.toNumber($request.getParameter($limitRequestParameter)).intValue())
99 #if ("$!categoryLimit" == '')
100 #set ($categoryLimit = $solrConfig.facetPaginationStep)
101 #end
102 #set ($categoryLimit = $mathtool.max($mathtool.min($categoryLimit, $categories.size()), 0))
103 <ul class="mediaTypes">
104 #foreach ($category in $categories)
105 #if ($foreach.index < $categoryLimit)
106 <li>
107 ## Backup the selected values to be able to restore them afterwards.
108 #set ($facetRequestValuesBackup = $facetRequestValues)
109 ## When an entire category is selected we need to remove the values that were selected from that category.
110 #set ($facetRequestValues = [])
111 #if ($facetRequestValuesBackup)
112 #set ($discard = $facetRequestValues.addAll($facetRequestValuesBackup.subList(0,
113 $facetRequestValuesBackup.size())))
114 #set ($discard = $facetRequestValues.removeAll($category.mediaTypes))
115 #end
116 <div class="mediaTypeCategory">#displaySearchFacetValue($category {} 'displaySearchFacetValue_mediaType')</div>
117 ## When a media type is selected, it's category should be unselected.
118 #set ($facetRequestValues = [])
119 #if ($facetRequestValuesBackup)
120 #set ($discard = $facetRequestValues.addAll($facetRequestValuesBackup.subList(0,
121 $facetRequestValuesBackup.size())))
122 #set ($discard = $facetRequestValues.remove($category.name))
123 #end
124 <ul>#displaySearchFacetValuesLimited($category.mediaTypesWithCounts {} 'displaySearchFacetValue_mediaType')</ul>
125 ## Restore the selected values.
126 #set ($facetRequestValues = $facetRequestValuesBackup)
127 </li>
128 #else
129 #extendQueryString($url {$limitRequestParameter: [$mathtool.add($categoryLimit, $solrConfig.facetPaginationStep)]})
130 <li><a href="$url" class="more">&hellip; $escapetool.xml($services.localization.render(
131 'solr.facets.moreValues', [$mathtool.sub($categories.size(), $categoryLimit)]))</a></li>
132 #break
133 #end
134 #end
135 </ul>
136 #end
137
138 #macro (displaySearchFacetValue_mediaType $mediaType)
139 #if ($facetValue.id)
140 ## A media type category.
141 $services.localization.render("solr.filterBy.fileType.$facetValue.id")
142 #else
143 #set ($prettyName = $stringtool.substringAfter($mediaType, '/'))
144 ## Fonts have a dedicated category so we can remove the 'x-font-' prefix.
145 #set ($prettyName = $stringtool.removeStart($prettyName, 'x-font-'))
146 ## Non-standard media type, i.e. not registered with the Internet Assigned Numbers Authority (IANA).
147 #set ($prettyName = $stringtool.removeStart($prettyName, 'x-'))
148 ## Vendor specific media type.
149 #set ($prettyName = $stringtool.removeStart($prettyName, 'vnd.'))
150 ## Many media types end with '+xml' or something similar. Let's remove this part.
151 #set ($prettyName = $stringtool.substringBeforeLast($prettyName, '+'))
152 ## Attempt to translate the pretty name.
153 #set ($translationKey = "solr.facet.fileType.${category.id}.$prettyName")
154 #if ($services.localization.get($translationKey))
155 #set ($prettyName = $services.localization.render($translationKey))
156 #elseif ($prettyName.length() < 5)
157 ## Probably a file extension (or acronym).
158 #set ($prettyName = $prettyName.toUpperCase())
159 #end
160 <span title="$mediaType">$prettyName</span>
161 #end
162 #end
163 {{/velocity}}
164
165 {{velocity}}
166 #if ($facetValues)
167 {{html clean="false"}}#displaySearchFacetValues_mediaType($facetValues){{/html}}
168 #end
169 {{/velocity}}
#getBlogDocument($space $blogDoc)
XWiki Enterprise 14.6 - Documentation