Änderungen von Dokument RecentlyUpdated
Zuletzt geändert von xwikiadmin am 2025/12/11 06:32
Von Version 4.1
bearbeitet von xwikiadmin
am 2023/10/26 09:48
am 2023/10/26 09:48
Änderungskommentar:
Install extension [com.xwiki.pro:xwiki-pro-macros/1.12]
Auf Version 1.1
bearbeitet von xwikiadmin
am 2023/03/07 16:26
am 2023/03/07 16:26
Änderungskommentar:
Install extension [com.xwiki.pro:xwiki-pro-macros/1.7]
Zusammenfassung
-
Objekte (3 geändert, 0 hinzugefügt, 0 gelöscht)
Details
- XWiki.JavaScriptExtension[0]
-
- Code
-
... ... @@ -4,71 +4,67 @@ 4 4 #[[ 5 5 6 6 require(['jquery'], $ => { 7 - const MACRO_SERVICE_URL = new XWiki.Document( 8 - XWiki.Model.resolve('Confluence.Macros.RecentlyUpdatedService', XWiki.EntityType.DOCUMENT) 9 - ).getURL('get'); 7 + $(() => { 8 + const MACRO_SERVICE_URL = new XWiki.Document( 9 + XWiki.Model.resolve('Confluence.Macros.RecentlyUpdatedService', XWiki.EntityType.DOCUMENT) 10 + ).getURL('get'); 10 10 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; 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 + }); 19 19 } 20 20 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); 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>') 56 56 } 53 + $dataElement.remove(); 57 57 } 58 - dataElement.remove(); 59 - } 60 - } 55 + }; 61 61 62 - function init() { 63 - for (const macro of document.querySelectorAll('.recently-updated-macro')) { 64 - handleMetadata(macro); 65 - } 66 - } 57 + // Init 58 + $macros.each(function (i, macro) { 59 + handleMetadata($(macro)); 60 + }); 67 67 68 - $(() => { 69 - $(document).on('xwiki:dom:updated', init); 70 - init(); 71 - }); 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 + }) 72 72 }); 73 73 74 74 ]]#
- 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 { 33 + .result-last-author-avatar img.avatar { 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 { 61 + .result-last-author-avatar img.avatar { 62 62 display: none; 63 63 } 64 64
- XWiki.WikiMacroClass[0]
-
- Makro-Code
-
... ... @@ -18,10 +18,7 @@ 18 18 ## (adds extra quotes / spaces at the beginning and end of the string) 19 19 #set ($searchRegex = '(?:^|$|,)\s*([-+]?)') 20 20 #set ($replacement = '" $1"') 21 - #if (!$serializedList) 22 - #set($serializedList = "") 23 - #end 24 - #set ($formatted = $serializedList.replace($searchRegex, $replacement)) 21 + #set ($formatted = $!stringtool.replaceAll($serializedList, $searchRegex, $replacement)) 25 25 ## Remove extra quotes / spaces at the beginning and end of the string 26 26 #set ($formatted = $!stringtool.substring($formatted, 2, -2)) 27 27 ## Return ... ... @@ -173,47 +173,32 @@ 173 173 #set ($return = $NULL) 174 174 #setVariable("$return" $options) 175 175 #end 176 - 177 -#macro (executeMacro) 178 - ## ----------------------------------------------------------------- 179 - ## ----------------------------------------------------------------- 180 - ## ----------------------------------------------------------------- 181 - ## Fetch results 182 - ## ----------------------------------------------------------------- 183 - $xwiki.ssx.use('xwiki:Confluence.Macros.RecentlyUpdated') 184 - $xwiki.jsx.use('xwiki:Confluence.Macros.RecentlyUpdated') 185 - {{html clean="false"}} 186 - #initOptionsFromParameters($options) 187 - #fetchResults($options, $results) 188 - #set ($confluenceWidth = $escapetool.xml($wikimacro.parameters.width)) 189 - #set ($widthStyle = "style='--width: $confluenceWidth'") 190 - <section class="recently-updated-macro" $widthStyle> 191 - #if ("$wikimacro.parameters.hideHeading" != "true") 192 - <h2>$escapetool.xml($services.localization.render('recentlyUpdatedMacro.title'))</h2> 193 - #end 194 - <ul class="results theme-${options.theme}"> 195 - #displayResults($results $options) 196 - </ul> 197 - <button class="btn btn-link show-more"> 198 - Show more 199 - </button> 200 - </section> 201 - {{/html}} 202 -#end 203 203 {{/velocity}} 204 204 205 -{{include reference="Licenses.Code.VelocityMacros"/}} 206 - 207 207 {{velocity}} 208 -## We need to check if there is a valid license because the macro is registered even if the user doesn't have view right 209 -## on the macro definition page. See XWIKI-14828: Rendering macros defined in wiki pages are available to users that 210 -## don't have view right on those pages. 211 -#if ($services.licensing.licensor.hasLicensureForEntity($xcontext.macro.doc.documentReference)) 212 - #executeMacro 213 -#else 214 - {{error}} 215 - #getMissingLicenseMessage('proMacros.extension.name') 216 - {{/error}} 217 -#end 176 +## ----------------------------------------------------------------- 177 +## ----------------------------------------------------------------- 178 +## ----------------------------------------------------------------- 179 +## Fetch results 180 +## ----------------------------------------------------------------- 181 +$xwiki.ssx.use('xwiki:Confluence.Macros.RecentlyUpdated') 182 +$xwiki.jsx.use('xwiki:Confluence.Macros.RecentlyUpdated') 183 +{{html clean="false"}} 184 + #initOptionsFromParameters($options) 185 + #fetchResults($options, $results) 186 + #set ($confluenceWidth = $escapetool.xml($wikimacro.parameters.width)) 187 + #set ($widthStyle = "style='--width: $confluenceWidth'") 188 + <section class="recently-updated-macro" $widthStyle> 189 + #if ("$wikimacro.parameters.hideHeading" != "true") 190 + <h2>$escapetool.xml($services.localization.render('recentlyUpdatedMacro.title'))</h2> 191 + #end 192 + <ul class="results theme-${options.theme}"> 193 + #displayResults($results $options) 194 + </ul> 195 + <button class="btn btn-link show-more"> 196 + Show more 197 + </button> 198 + </section> 199 +{{/html}} 218 218 {{/velocity}} 219 219