Modifications pour le document Service JSON des fichiers attachés

Modifié par Florent Charton le 2026/01/08 10:56

Depuis la version 2.1
modifié par Florent Charton
sur 2024/08/08 18:43
Commentaire de modification : Install extension [org.xwiki.platform:xwiki-platform-index-ui/15.10.11]
À la version 1.1
modifié par superadmin
sur 2022/06/20 08:48
Commentaire de modification : Install extension [org.xwiki.platform:xwiki-platform-index-ui/13.10.6]

Résumé

Détails

Propriétés de la Page
Auteur du document
... ... @@ -1,1 +1,1 @@
1 -xwiki:XWiki.fcharton
1 +XWiki.superadmin
Contenu
... ... @@ -1,6 +1,99 @@
1 1  {{template name="hierarchy_macros.vm" /}}
2 -{{template name="attachment_macros.vm" /}}
3 3  
3 +{{velocity output="false"}}
4 +#macro (maybeApplyStringFilter $fieldName $defaultMatchType $constraints $queryParameters)
5 + #if ("$!request.getParameter($fieldName)" != '')
6 + #set ($fieldNameWithAlias = $fieldName)
7 + #if ($fieldName.indexOf('.') < 0)
8 + #set ($fieldNameWithAlias = 'attachment.' + $fieldName)
9 + #end
10 + #set ($matchType = $request.getParameter("${fieldName}_match"))
11 + #if ("$!matchType" == '')
12 + #set ($matchType = $defaultMatchType)
13 + #end
14 + #set ($parameterName = $fieldNameWithAlias.replace('.', '_'))
15 + #if ($matchType == 'exact')
16 + #set ($discard = $constraints.add("$fieldNameWithAlias = :$parameterName"))
17 + #set ($parameterValue = $request.getParameter($fieldName))
18 + #else
19 + #set ($discard = $constraints.add("lower($fieldNameWithAlias) like lower(:$parameterName)"))
20 + #set ($parameterValue = $request.getParameter($fieldName).trim())
21 + #end
22 + #set ($discard = $queryParameters.add({
23 + 'name': $parameterName,
24 + 'match': $matchType,
25 + 'value': $parameterValue
26 + }))
27 + #end
28 +#end
29 +
30 +#macro (maybeApplyIntegerRangeFilter $fieldName $constraints $queryParameters)
31 + #set ($fieldValue = $request.getParameter($fieldName))
32 + #if ("$!fieldValue" != '')
33 + #set ($range = $fieldValue.split('-'))
34 + #set ($range = [$numbertool.toNumber($range.get(0)).intValue(), $numbertool.toNumber($range.get(1)).intValue()])
35 + #applyRangeFilter($fieldName $range $constraints $queryParameters)
36 + #end
37 +#end
38 +
39 +#macro (maybeApplyDateRangeFilter $fieldName $constraints $queryParameters)
40 + #set ($fieldValue = $request.getParameter($fieldName))
41 + #if ("$!fieldValue" != '')
42 + #set ($range = $fieldValue.split('-'))
43 + #set ($range = [
44 + $datetool.toDate($numbertool.toNumber($range.get(0))),
45 + $datetool.toDate($numbertool.toNumber($range.get(1)))
46 + ])
47 + #applyRangeFilter($fieldName $range $constraints $queryParameters)
48 + #end
49 +#end
50 +
51 +#macro (applyRangeFilter $fieldName $range $constraints $queryParameters)
52 + #set ($fieldNameWithAlias = $fieldName)
53 + #if ($fieldName.indexOf('.') < 0)
54 + #set ($fieldNameWithAlias = 'attachment.' + $fieldName)
55 + #end
56 + #set ($parameterNamePrefix = $fieldNameWithAlias.replace('.', '_'))
57 + #set ($start = $range.get(0))
58 + #if ($start)
59 + #set ($startParameterName = $parameterNamePrefix + '_start')
60 + #set ($discard = $constraints.add("$fieldNameWithAlias >= :$startParameterName"))
61 + #set ($discard = $queryParameters.add({
62 + 'name': $startParameterName,
63 + 'match': 'exact',
64 + 'value': $start
65 + }))
66 + #end
67 + #set ($end = $range.get(1))
68 + #if ($end)
69 + #set ($endParameterName = $parameterNamePrefix + '_end')
70 + #set ($discard = $constraints.add("$fieldNameWithAlias < :$endParameterName"))
71 + #set ($discard = $queryParameters.add({
72 + 'name': $endParameterName,
73 + 'match': 'exact',
74 + 'value': $end
75 + }))
76 + #end
77 +#end
78 +
79 +#macro (displayAttachmentMimeType $attachment)
80 + <div class="mime" data-type="$!escapetool.xml($attachment.mimeType)">
81 + #if ($attachment.isImage())
82 + <span title="$escapetool.xml($services.localization.render('core.viewers.attachments.mime.image'))">
83 + <img src="$xwiki.getURL($attachmentReference, 'download', 'width=48')"
84 + alt="$escapetool.xml($attachment.filename)" />
85 + </span>
86 + #else
87 + #mimetypeimg($attachment.mimeType.toLowerCase() $attachment.filename.toLowerCase())
88 + #end
89 + </div>
90 +#end
91 +
92 +#macro (displayAttachmentSize $attachment)
93 + <span class="size" data-size="$!escapetool.xml($attachment.longSize)">#dynamicsize($attachment.longSize)</span>
94 +#end
95 +{{/velocity}}
96 +
4 4  {{velocity wiki="false"}}
5 5  ## ========================================================================================
6 6  ## This page is requested asynchronously by the Attachments live table and returns a set of
... ... @@ -85,12 +85,9 @@
85 85   'local': true,
86 86   'displayTitle': false
87 87   })")
88 - ## The field "fullName" was used by Livetable and is needed for backwards-compatibility.
89 - ## The field "doc.fullName" is needed by LiveData as doc.fullName is the actual field name.
90 90   #set ($row = {
91 91   'acclev': $hasAccess,
92 92   'fullName': $location,
93 - 'doc.fullName': $location,
94 94   'filename': $attachmentReference.name,
95 95   'fileurl': $xwiki.getURL($attachmentReference)
96 96   })
... ... @@ -100,9 +100,9 @@
100 100   #set ($authorReference = $services.model.resolveDocument($attachment.author))
101 101   #set ($discard = $row.putAll({
102 102   'mimeType': "#displayAttachmentMimeType($attachment)",
103 - 'filesize': "#displayAttachmentSize($attachment.longSize)",
193 + 'filesize': "#displayAttachmentSize($attachment)",
104 104   'date': $xwiki.formatDate($attachment.date),
105 - 'author': "#displayUserNameWithAvatar($attachment.author)"
195 + 'author': $xwiki.getUserName($attachment.author)
106 106   }))
107 107   #end
108 108   #set ($discard = $results.rows.add($row))