Changes for page Attachments Macro


on 2021-03-01 08:43


on 2021-09-20 03:35
Summary
Details
- Page properties
-
- Content
-
... ... @@ -1,7 +1,4 @@ 1 1 {{velocity output="false"}} 2 -#if ("$!request.xpage" == 'plain') 3 - $response.setContentType('application/json') 4 -#end 5 5 ## 6 6 ## Offset = item # at which to start displaying data 7 7 ## ------------------------------- ... ... @@ -21,7 +21,7 @@ 21 21 #set ($limit = '10') 22 22 #end 23 23 #set ($limit = $mathtool.max($numbertool.integer($limit), 1)) 24 -## 21 +## 25 25 ## Document parameter 26 26 ## ------------------------------- 27 27 #set ($aDocFullName = "$!request.document") ... ... @@ -28,7 +28,7 @@ 28 28 #if ($aDocFullName != '' && $xwiki.exists($aDocFullName)) 29 29 #set ($aDoc = $xwiki.getDocument($aDocFullName)) 30 30 #end 31 -## 28 +## 32 32 ## Sort parameter 33 33 ## ------------------------------- 34 34 #set ($sortColumn = "$!request.sort.toLowerCase()") ... ... @@ -41,7 +41,7 @@ 41 41 #set ($filterByName = true) 42 42 #set ($namePattern = "$!request.name.toLowerCase()") 43 43 #end 44 -## 41 +## 45 45 ## Macros 46 46 ## ------------------------------- 47 47 #macro (getOrderedAttachmentNameList) ... ... @@ -54,7 +54,7 @@ 54 54 #if ($sortColumn == 'date') 55 55 #set ($prefix = $datetool.format('yyyyMMddHHmmss', $attach.date)) 56 56 #elseif ($sortColumn == 'size') 57 - #set ($fileSize = "$!attach. filesize")54 + #set ($fileSize = "$!attach.longSize") 58 58 #set ($maxFileSize = "100000000000") 59 59 #set ($index = $maxFileSize.length() - $fileSize.length()) 60 60 #set ($prefix = $maxFileSize.substring(0, $index) + $fileSize) ... ... @@ -63,7 +63,7 @@ 63 63 #set ($discard = $attachmentComposedNameList.add($attachComposedName)) 64 64 #end 65 65 #end 66 - #set ($orderedAttachmentComposedNameList = $ sorttool.sort($attachmentComposedNameList))63 + #set ($orderedAttachmentComposedNameList = $collectiontool.sort($attachmentComposedNameList)) 67 67 #foreach ($attachComposedName in $orderedAttachmentComposedNameList) 68 68 #set ($authorLastIndex = $attachComposedName.indexOf('|') + 1) 69 69 #set ($attachName = $attachComposedName.substring($authorLastIndex)) ... ... @@ -82,7 +82,7 @@ 82 82 #set ($discard = $orderedAttachmentNameList.add($attach.filename)) 83 83 #end 84 84 #end 85 - #set ($orderedAttachmentNameList = $ sorttool.sort($orderedAttachmentNameList))82 + #set ($orderedAttachmentNameList = $collectiontool.sort($orderedAttachmentNameList)) 86 86 #elseif ($sortColumn == 'type') 87 87 #set ($attachmentReversedNameList = []) 88 88 #set ($orderedAttachmentReversedNameList = []) ... ... @@ -97,7 +97,7 @@ 97 97 #set ($discard = $attachmentReversedNameList.add($attachReversedName)) 98 98 #end 99 99 #end 100 - #set ($orderedAttachmentReversedNameList = $ sorttool.sort($attachmentReversedNameList))97 + #set ($orderedAttachmentReversedNameList = $collectiontool.sort($attachmentReversedNameList)) 101 101 #foreach ($attachReversedName in $orderedAttachmentReversedNameList) 102 102 #set ($extensionLastIndex = $attachReversedName.indexOf('|')) 103 103 #set ($nameIndex = $extensionLastIndex + 1) ... ... @@ -111,7 +111,7 @@ 111 111 ## 112 112 ## Determine the attachments sub list to display. 113 113 ## ------------------------------- 114 -#if ($ xwiki.hasAccessLevel('view', $context.user, $aDoc.getPrefixedFullName()))111 +#if ($services.security.authorization.hasAccess('view', $aDoc.documentReference)) 115 115 #set ($totalRows = $orderedAttachmentNameList.size()) 116 116 #set ($returnedRows = $mathtool.min($limit, $totalRows)) 117 117 #if ($offset + $returnedRows > $totalRows) ... ... @@ -118,7 +118,7 @@ 118 118 #set ($returnedRows = $totalRows - $offset + 1) 119 119 #end 120 120 #if ($request.dir == 'desc') 121 - #set ($discard = $collection stool.reverse($orderedAttachmentNameList))118 + #set ($discard = $collectiontool.reverseModifiable($orderedAttachmentNameList)) 122 122 #end 123 123 #set ($start = $offset - 1) 124 124 #set ($end = $start + $returnedRows) ... ... @@ -143,21 +143,19 @@ 143 143 "reqNo": $numbertool.integer($request.reqNo), 144 144 "rows": [] 145 145 }) 146 -## $type is required by the user display. 147 -#set ($type = 'view') 148 148 #foreach ($attachName in $attachNames) 149 149 #set ($attach = $aDoc.getAttachment($attachName)) 150 - ## $value is required by the user display 151 - #set ($value = $attach.author) 152 152 #set ($discard = $json.rows.add({ 153 153 "name": $attachName, 154 154 "name_url": $aDoc.getAttachmentURL($attachName), 155 155 "type": "#mimetypeimg($attach.mimeType.toLowerCase() $attach.filename.toLowerCase())", 156 - "size": "#dynamicsize($attach. filesize)",157 - "author": "# template('displayer_users.vm')",149 + "size": "#dynamicsize($attach.longSize)", 150 + "author": "#displayUser($attach.author)", 158 158 "date": "$!xwiki.formatDate($attach.date)", 159 159 "doc_viewable": true 160 160 })) 161 161 #end 162 -$jsontool.serialize($json) 155 +#if ($xcontext.action == 'get') 156 + #jsonResponse($json) 157 +#end 163 163 {{/velocity}}
- XWiki.WikiMacroClass[0]
-
- Cached
-
... ... @@ -1,0 +1,1 @@ 1 +No - Asynchronous rendering
-
... ... @@ -1,0 +1,1 @@ 1 +No - Macro code
-
... ... @@ -1,33 +1,33 @@ 1 1 {{velocity}} 2 2 #set ($discard = $xwiki.ssfx.use('uicomponents/widgets/userpicker/userPicker.css', true)) 3 3 #set ($discard = $services.localization.use('document', 'Main.AttachmentsMacroTranslations')) 4 -## 4 +## 5 5 ## Sort parameter 6 -## ------------------------------- 6 +## ------------------------------- 7 7 #set ($sortList = ['name', 'type', 'size', 'author', 'date']) 8 -#set ($aSort = "$!context.macro.params.get('sort').toLowerCase()") 8 +#set ($aSort = "$!xcontext.macro.params.get('sort').toLowerCase()") 9 9 #if (!$sortList.contains($aSort)) 10 10 #set ($aSort = 'name') 11 11 #end 12 -## 12 +## 13 13 ## Order parameter 14 14 ## ------------------------------- 15 -#set ($aOrder = "$!context.macro.params.get('order').toLowerCase()") 15 +#set ($aOrder = "$!xcontext.macro.params.get('order').toLowerCase()") 16 16 #if ($aOrder != 'desc') 17 17 #set ($aOrder = 'asc') 18 18 #end 19 -## 19 +## 20 20 ## Limit parameter 21 21 ## ------------------------------- 22 -#set ($limit = "$!context.macro.params.get('limit')") 22 +#set ($limit = "$!xcontext.macro.params.get('limit')") 23 23 #if ($limit == '') 24 24 #set ($limit = '10') 25 25 #end 26 26 #set ($aLimit = $numbertool.integer($limit)) 27 -## 27 +## 28 28 ## Document parameter 29 29 ## ------------------------------- 30 -#set ($aDocFullName = "$!context.macro.params.get('document')") 30 +#set ($aDocFullName = "$!xcontext.macro.params.get('document')") 31 31 #if ($aDocFullName != '' && $xwiki.exists($aDocFullName)) 32 32 #set ($aDoc = $aDocFullName) 33 33 #else