Änderungen von Dokument RecentlyUpdated

Zuletzt geändert von xwikiadmin am 2024/06/24 14:35

Von Version 1.1
bearbeitet von xwikiadmin
am 2023/04/25 10:54
Änderungskommentar: Install extension [com.xwiki.pro:xwiki-pro-macros/1.7.1]
Auf Version 4.1
bearbeitet von xwikiadmin
am 2024/06/24 14:35
Änderungskommentar: Install extension [com.xwiki.pro:xwiki-pro-macros-ui/1.19.4]

Zusammenfassung

Details

XWiki.JavaScriptExtension[0]
Code
... ... @@ -4,67 +4,71 @@
4 4  #[[
5 5  
6 6  require(['jquery'], $ => {
7 - $(() => {
8 - const MACRO_SERVICE_URL = new XWiki.Document(
9 - XWiki.Model.resolve('Confluence.Macros.RecentlyUpdatedService', XWiki.EntityType.DOCUMENT)
10 - ).getURL('get');
7 + const MACRO_SERVICE_URL = new XWiki.Document(
8 + XWiki.Model.resolve('Confluence.Macros.RecentlyUpdatedService', XWiki.EntityType.DOCUMENT)
9 + ).getURL('get');
11 11  
12 - const $macros = $('.recently-updated-macro');
13 -
14 - /*
15 - * Query new results and append them to the page
16 - */
17 - const fetchMoreResultsHTML = function ($macro) {
18 - const urlParams = [
19 - 'xpage=plain',
20 - 'outputSyntax=plain',
21 - 'macroOptions=' + encodeURIComponent($macro.data('options')),
22 - ].join('&');
23 - const url = MACRO_SERVICE_URL + '?' + urlParams;
24 - fetch(url)
25 - .then(function (response) {
26 - if (!response.ok) {
27 - throw new Error('An error occured fetching new results.');
28 - }
29 - return response.text();
30 - })
31 - .then(function (html) {
32 - // Append html results directly to the page
33 - $macro.find('ul.results').append(html);
34 - handleMetadata($macro);
35 - });
11 + /*
12 + * Query new results and append them to the page
13 + */
14 + function showMore(event) {
15 + const macro = event.target.closest('.recently-updated-macro');
16 + if (!macro) {
17 + console.log("Failed to show more");
18 + return;
36 36   }
37 37  
38 - /*
39 - * Store fetched metadata for next result fetch
40 - * Update fetch button according to whether there are more results to fetch
41 - */
42 - const handleMetadata = function ($macro) {
43 - const $dataElement = $macro.find('.recently-updated-options');
44 - if ($dataElement.length === 0) {
45 - console.warn('No options were found when fetching new results')
46 - } else {
47 - $macro.data('options', $dataElement.attr('data-options'))
48 - const hasNext = JSON.parse($dataElement.attr('data-has-next'));
49 - if (!hasNext) {
50 - $macro.find('button.show-more')
51 - .replaceWith('<div class="no-more-results">' + l10n['noMoreResults'] + '</div>')
21 + const urlParams = [
22 + 'xpage=plain',
23 + 'outputSyntax=plain',
24 + 'fromAjax=true',
25 + 'macroOptions=' + encodeURIComponent(macro.dataset.options),
26 + ].join('&');
27 + const url = MACRO_SERVICE_URL + '?' + urlParams;
28 + fetch(url)
29 + .then(function (response) {
30 + if (!response.ok) {
31 + throw new Error('An error occured fetching new results.');
32 + }
33 + return response.text();
34 + })
35 + .then(function (html) {
36 + // Append html results directly to the page
37 + $(macro.querySelector('ul.results')).append(html);
38 + handleMetadata(macro);
39 + });
40 + }
41 +
42 + /*
43 + * Store fetched metadata for next result fetch
44 + * Update fetch button according to whether there are more results to fetch
45 + */
46 + function handleMetadata(macro) {
47 + const dataElement = macro.querySelector('.recently-updated-options');
48 + if (dataElement) {
49 + macro.dataset.options = dataElement.dataset.options;
50 + const btn = macro.querySelector('button.show-more');
51 + if (btn) {
52 + if (dataElement.dataset.hasNext !== "true") {
53 + $(btn).replaceWith('<div class="no-more-results">' + l10n['noMoreResults'] + '</div>');
54 + } else {
55 + btn.addEventListener('click', showMore);
52 52   }
53 - $dataElement.remove();
54 54   }
55 - };
58 + dataElement.remove();
59 + }
60 + }
56 56  
57 - // Init
58 - $macros.each(function (i, macro) {
59 - handleMetadata($(macro));
60 - });
62 + function init() {
63 + for (const macro of document.querySelectorAll('.recently-updated-macro')) {
64 + handleMetadata(macro);
65 + }
66 + }
61 61  
62 - // Fetch new results
63 - $macros.find('button.show-more').click(function (event) {
64 - const $macro = $(event.target).closest('.recently-updated-macro');
65 - fetchMoreResultsHTML($macro);
66 - })
67 - })
68 + $(() => {
69 + $(document).on('xwiki:dom:updated', init);
70 + init();
71 + });
68 68  });
69 69  
70 70  ]]#
XWiki.StyleSheetExtension[0]
Code
... ... @@ -30,7 +30,7 @@
30 30   grid-area: metadata;
31 31   .text-muted-smaller();
32 32  
33 - .result-last-author-avatar img.avatar {
33 + .result-last-author-avatar img {
34 34   display: inline-block;
35 35   width: 1em;
36 36   height: 1em;
... ... @@ -58,7 +58,7 @@
58 58   column-gap: 0.6rem;
59 59  
60 60   &.collapsed {
61 - .result-last-author-avatar img.avatar {
61 + .result-last-author-avatar img {
62 62   display: none;
63 63   }
64 64  
XWiki.WikiMacroClass[0]
Makro-Code
... ... @@ -8,49 +8,6 @@
8 8  ## Parameter formatting macros
9 9  ## -----------------------------------------------------------------
10 10  
11 -## Format serialized comma-separated list coming from macro parameters
12 -## so that it can be used inside a solr filter query parameter
13 -## * Escape spaces inside values by wrapping them inside quotes,
14 -## making sure "+" and "-" filter modifiers stay outside the quotes
15 -## * Remove commas so that values are separated only by spaces
16 -#macro (formatSerializedList $serializedList $return)
17 - ## Wrap each value around quotes and replace commas by spaces
18 - ## (adds extra quotes / spaces at the beginning and end of the string)
19 - #set ($searchRegex = '(?:^|$|,)\s*([-+]?)')
20 - #set ($replacement = '" $1"')
21 - #set ($formatted = $!stringtool.replaceAll($serializedList, $searchRegex, $replacement))
22 - ## Remove extra quotes / spaces at the beginning and end of the string
23 - #set ($formatted = $!stringtool.substring($formatted, 2, -2))
24 - ## Return
25 - #set ($return = $NULL)
26 - #setVariable("$return" $formatted)
27 -#end
28 -
29 -## Format serialized comma-separated author list coming from macro parameters
30 -## Author format is different between comments and document metadata
31 -## ("xwiki:" wiki prefix is missing from comments author metadata),
32 -## so add both versions in the formatted serialized list
33 -#macro (formatSerializedAuthorList $serializedAuthorList $return)
34 - #set ($authorsList = [])
35 - #set ($splittedAuthorList = $!stringtool.split($serializedAuthorList, ','))
36 - #foreach ($author in $splittedAuthorList)
37 - #set ($author = $!stringtool.strip($author))
38 - #set ($modifier = '')
39 - #if ($author.startsWith('-'))
40 - #set ($modifier = '-')
41 - #set ($author = $author.substring(1))
42 - #end
43 - #set ($resolvedAuthor = $services.model.resolveDocument($author))
44 - #set ($discard = $authorsList.add("${modifier}${author}"))
45 - #set ($discard = $authorsList.add("${modifier}${services.model.serialize($resolvedAuthor, 'default')}"))
46 - #end
47 - #set ($authors = $!stringtool.join($authorsList, ','))
48 - #formatSerializedList($authors, $authors)
49 - ## Return
50 - #set ($return = $NULL)
51 - #setVariable("$return" $authors)
52 -#end
53 -
54 54  ## Format serialized comma-separated types list coming from macro parameters
55 55  ## Return a list containing all the types of results that need to be displayed
56 56  #macro (parseTypes $serializedTypeList $return)
... ... @@ -97,9 +97,7 @@
97 97   #end
98 98  
99 99   ## Authors
100 - #set ($confluenceAuthorsString = "$!stringtool.strip($!wikimacro.parameters.author)")
101 - #formatSerializedAuthorList($confluenceAuthorsString, $authors)
102 - #set ($options.authors = $authors)
57 + #set ($options.authors = "$!stringtool.strip($!wikimacro.parameters.author)")
103 103  
104 104   ## Wiki & Spaces
105 105   #set ($confluenceSpacesString = "$!stringtool.strip($!wikimacro.parameters.spaces)")
... ... @@ -110,6 +110,7 @@
110 110   || $confluenceSpacesString.equals('@self')
111 111   )
112 112   ## Search in current space
68 + ## Newly migrated content don't have @self, see https://jira.xwiki.org/projects/CONFLUENCE/issues/CONFLUENCE-236
113 113   #set ($options.spaces = $doc.space)
114 114   #elseif (
115 115   $confluenceSpacesString.equals('@global')
... ... @@ -129,14 +129,11 @@
129 129   #set ($options.wiki = $NULL)
130 130   #else
131 131   ## Search in specified spaces
132 - #formatSerializedList($confluenceSpacesString, $spaces)
133 - #set ($options.spaces = $spaces)
88 + #set ($options.spaces = $confluenceSpacesString)
134 134   #end
135 135  
136 136   ## Tags
137 - #set ($confluenceLabelString = "$!stringtool.strip($!wikimacro.parameters.labels)")
138 - #formatSerializedList($confluenceLabelString, $tags)
139 - #set ($options.tags = $tags)
92 + #set ($options.tags = "$!stringtool.strip($!wikimacro.parameters.labels)")
140 140  
141 141   ## Types
142 142   #set ($confluenceTypesString = "$!stringtool.strip($!wikimacro.parameters.types)")
... ... @@ -199,18 +199,14 @@
199 199  #end
200 200  {{/velocity}}
201 201  
202 -{{include reference="Licenses.Code.VelocityMacros"/}}
203 -
204 204  {{velocity}}
205 205  ## We need to check if there is a valid license because the macro is registered even if the user doesn't have view right
206 206  ## on the macro definition page. See XWIKI-14828: Rendering macros defined in wiki pages are available to users that
207 207  ## don't have view right on those pages.
208 -#if ($services.licensing.licensor.hasLicensureForEntity($xcontext.macro.doc.documentReference))
159 +#if ($services.promacrolicensing.hasLicensureForEntity($xcontext.macro.doc.documentReference))
209 209   #executeMacro
210 210  #else
211 - {{error}}
212 - #getMissingLicenseMessage('proMacros.extension.name')
213 - {{/error}}
162 + {{missingLicenseMessage extensionName="proMacros.extension.name"/}}
214 214  #end
215 215  {{/velocity}}
216 216  
Standardkategorie
... ... @@ -1,1 +1,0 @@
1 -confluence
XWiki.WikiMacroParameterClass[2]
Parameter-Beschreibung
... ... @@ -1,1 +1,1 @@
1 -Filter the results by label. The macro will display only the pages etc which are tagged with the label(s) you specify here. You can specify one or more label values, separated by a comma or a space. To exclude content which matches a given label, put a minus sign (-) immediately in front of that label value. For example: If you specify a label value of -badpage you will get only content which is not labeled with 'badpage'. To indicate that the results** **must match a given label value, put a plus sign (+) immediately in front of that label value. For example: If you specify a label value of +superpage,+goodpage you will get only content which has at least two labels, being 'superpage' and 'goodpage'. The labels parameter only applies to the page and blog content types.
1 +Filter the results by label. The macro will display only the pages etc which are tagged with the label(s) you specify here. You can specify one or more label values, separated by a comma or a space. To exclude content which matches a given label, put a minus sign (-) immediately in front of that label value. For example: If you specify a label value of -badpage you will get only content which is not labeled with 'badpage'. To indicate that the results** **must match a given label value, put a plus sign (+) immediately in front of that label value. For example: If you specify a label value of +superpage,+goodpage you will get only content which has at least two labels, being 'superpage' and 'goodpage'. The labels parameter only applies to the page and blog content types.