Skip to content
Snippets Groups Projects
Commit 831e4626 authored by Marius Dumitru Florea's avatar Marius Dumitru Florea
Browse files

XWIKI-7469: Display attachment size in the attachment index

* Add support for sort and filter on the attachment file size
* Switch the attachment mime type and file size filter to single select for now because multiple selection requires more work.
parent f3c24e49
No related branches found
No related tags found
No related merge requests found
...@@ -42,12 +42,13 @@ ...@@ -42,12 +42,13 @@
<content>{{velocity}} <content>{{velocity}}
#set ($discard = $xwiki.ssx.use('XWiki.AllAttachments')) #set ($discard = $xwiki.ssx.use('XWiki.AllAttachments'))
#set ($discard = $xwiki.jsx.use('XWiki.AllAttachments')) #set ($discard = $xwiki.jsx.use('XWiki.AllAttachments'))
#set ($columns = ['mimeType', 'filename', 'doc.fullName', 'date', 'author']) #set ($columns = ['mimeType', 'filename', 'doc.fullName', 'filesize', 'date', 'author'])
#set ($columnsProperties = { #set ($columnsProperties = {
'mimeType': {'type': 'multilist', 'class': 'XWiki.AllAttachments'}, 'mimeType': {'type': 'list', 'class': 'XWiki.AllAttachments'},
'filename': {'type': 'text'}, 'filename': {'type': 'text'},
'doc.fullName': {'type': 'text'}, 'doc.fullName': {'type': 'text'},
'date': {'type': 'date', 'filterable' : false}, 'filesize': {'type': 'list', 'class': 'XWiki.AllAttachments'},
'date': {'type': 'date', 'filterable': false},
'author': {'type': 'text'} 'author': {'type': 'text'}
}) })
#set ($options = { #set ($options = {
...@@ -70,12 +71,33 @@ ...@@ -70,12 +71,33 @@
<defaultWeb/> <defaultWeb/>
<nameField/> <nameField/>
<validationScript/> <validationScript/>
<filesize>
<cache>0</cache>
<customDisplay/>
<disabled>0</disabled>
<displayType>select</displayType>
<multiSelect>0</multiSelect>
<name>filesize</name>
<number>2</number>
<picker>0</picker>
<prettyName>File Size</prettyName>
<relationalStorage>0</relationalStorage>
<separator> </separator>
<separators>|, </separators>
<size>1</size>
<sort>none</sort>
<unmodifiable>0</unmodifiable>
<validationMessage/>
<validationRegExp/>
<values>0-10240=Tiny|10240-512000=Small|512000-5242880=Medium|5242880-x=Large</values>
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
</filesize>
<mimeType> <mimeType>
<cache>0</cache> <cache>0</cache>
<customDisplay/> <customDisplay/>
<disabled>0</disabled> <disabled>0</disabled>
<displayType>select</displayType> <displayType>select</displayType>
<multiSelect>1</multiSelect> <multiSelect>0</multiSelect>
<name>mimeType</name> <name>mimeType</name>
<number>1</number> <number>1</number>
<picker>0</picker> <picker>0</picker>
...@@ -182,6 +204,7 @@ ...@@ -182,6 +204,7 @@
var fileLink = new Element('a', {'href': row.fileurl}).update(row.filename); var fileLink = new Element('a', {'href': row.fileurl}).update(row.filename);
tr.appendChild(new Element('td').update(fileLink)); tr.appendChild(new Element('td').update(fileLink));
tr.appendChild(new Element('td', {'class': 'location'}).update(row.fullName)); tr.appendChild(new Element('td', {'class': 'location'}).update(row.fullName));
tr.appendChild(new Element('td').update(row.filesize));
tr.appendChild(new Element('td').update(row.date)); tr.appendChild(new Element('td').update(row.date));
var authorLink = new Element('a', {'href' : row.authorurl}).update(row.authorname); var authorLink = new Element('a', {'href' : row.authorurl}).update(row.authorname);
tr.appendChild(new Element('td').update(authorLink)); tr.appendChild(new Element('td').update(authorLink));
...@@ -191,6 +214,7 @@ ...@@ -191,6 +214,7 @@
tr.appendChild(new Element('td', {'class': 'location'}).update(row.fullName + '*')); tr.appendChild(new Element('td', {'class': 'location'}).update(row.fullName + '*'));
tr.appendChild(new Element('td')); tr.appendChild(new Element('td'));
tr.appendChild(new Element('td')); tr.appendChild(new Element('td'));
tr.appendChild(new Element('td'));
$('inaccessibleDocsMessage').removeClassName('hidden'); $('inaccessibleDocsMessage').removeClassName('hidden');
} }
return tr; return tr;
......
...@@ -68,6 +68,37 @@ ...@@ -68,6 +68,37 @@
#end #end
#end #end
#macro (maybeApplyRangeFilter $fieldName $constraints $queryParameters)
#if ("$!request.getParameter($fieldName)" != '')
#set ($fieldNameWithAlias = $fieldName)
#if ($fieldName.indexOf('.') &lt; 0)
#set ($fieldNameWithAlias = 'attachment.' + $fieldName)
#end
#set ($parameterNamePrefix = $fieldNameWithAlias.replace('.', '_'))
#set ($range = $request.getParameter($fieldName).split('-'))
#set ($start = $mathtool.toInteger($range.get(0)))
#if ($start)
#set ($startParameterName = $parameterNamePrefix + '_start')
#set ($discard = $constraints.add("$fieldNameWithAlias &gt;= :$startParameterName"))
#set ($discard = $queryParameters.add({
'name': $startParameterName,
'match': 'exact',
'value': $start
}))
#end
#set ($end = $mathtool.toInteger($range.get(1)))
#if ($end)
#set ($endParameterName = $parameterNamePrefix + '_end')
#set ($discard = $constraints.add("$fieldNameWithAlias &lt; :$endParameterName"))
#set ($discard = $queryParameters.add({
'name': $endParameterName,
'match': 'exact',
'value': $end
}))
#end
#end
#end
#macro (displayAttachmentMimeType $attachment) #macro (displayAttachmentMimeType $attachment)
&lt;div class="mime" data-type="$!escapetool.xml($attachment.mimeType)"&gt; &lt;div class="mime" data-type="$!escapetool.xml($attachment.mimeType)"&gt;
#if ($attachment.isImage()) #if ($attachment.isImage())
...@@ -80,6 +111,10 @@ ...@@ -80,6 +111,10 @@
#end #end
&lt;/div&gt; &lt;/div&gt;
#end #end
#macro (displayAttachmentSize $attachment)
&lt;span class="size" data-size="$!escapetool.xml($attachment.longSize)"&gt;#dynamicsize($attachment.longSize)&lt;/span&gt;
#end
{{/velocity}} {{/velocity}}
{{velocity wiki="false"}} {{velocity wiki="false"}}
...@@ -103,10 +138,11 @@ ...@@ -103,10 +138,11 @@
## ##
#set ($constraints = []) #set ($constraints = [])
#set ($queryParameters = []) #set ($queryParameters = [])
#maybeApplyStringFilter('mimeType' 'prefix' $constraints $queryParameters)
#maybeApplyStringFilter('filename' 'partial' $constraints $queryParameters) #maybeApplyStringFilter('filename' 'partial' $constraints $queryParameters)
#maybeApplyStringFilter('doc.fullName' 'partial' $constraints $queryParameters) #maybeApplyStringFilter('doc.fullName' 'partial' $constraints $queryParameters)
#maybeApplyRangeFilter('filesize' $constraints $queryParameters)
#maybeApplyStringFilter('author' 'partial' $constraints $queryParameters) #maybeApplyStringFilter('author' 'partial' $constraints $queryParameters)
#maybeApplyStringFilter('mimeType' 'prefix' $constraints $queryParameters)
#set ($whereClause = '') #set ($whereClause = '')
#if ($constraints.size() &gt; 0) #if ($constraints.size() &gt; 0)
#set ($whereClause = 'where ' + $stringtool.join($constraints, ' and ')) #set ($whereClause = 'where ' + $stringtool.join($constraints, ' and '))
...@@ -114,12 +150,12 @@ ...@@ -114,12 +150,12 @@
## ##
## Determine the sort field and direction. ## Determine the sort field and direction.
## ##
#set ($validSortFields = ['filename', 'doc.fullName', 'date', 'author', 'mimeType']) #set ($validSortFields = ['mimeType', 'filename', 'doc.fullName', 'filesize', 'date', 'author'])
#set ($sortField = $request.sort) #set ($sortField = $request.sort)
#if (!$validSortFields.contains($sortField)) #if (!$validSortFields.contains($sortField))
#set ($sortField = 'filename') #set ($sortField = 'filename')
#end #end
#set ($caseInsensitiveSort = $sortField != 'date') #set ($caseInsensitiveSort = $sortField != 'date' &amp;&amp; $sortField != 'filesize')
#if (!$sortField.startsWith('doc.')) #if (!$sortField.startsWith('doc.'))
#set ($sortField = "attachment.$sortField") #set ($sortField = "attachment.$sortField")
#end #end
...@@ -174,11 +210,12 @@ ...@@ -174,11 +210,12 @@
#set ($document = $xwiki.getDocument($attachmentReference.parent)) #set ($document = $xwiki.getDocument($attachmentReference.parent))
#set ($attachment = $document.getAttachment($attachmentReference.name)) #set ($attachment = $document.getAttachment($attachmentReference.name))
#set ($discard = $row.putAll({ #set ($discard = $row.putAll({
'mimeType': "#displayAttachmentMimeType($attachment)",
'filesize': "#displayAttachmentSize($attachment)",
'date': $xwiki.formatDate($attachment.date, 'yyyy MMMM dd, HH:mm'), 'date': $xwiki.formatDate($attachment.date, 'yyyy MMMM dd, HH:mm'),
'author': $attachment.author, 'author': $attachment.author,
'authorname': $xwiki.getUserName($attachment.author, false), 'authorname': $xwiki.getUserName($attachment.author, false),
'authorurl': $xwiki.getURL($attachment.author), 'authorurl': $xwiki.getURL($attachment.author)
'mimeType': "#displayAttachmentMimeType($attachment)"
})) }))
#end #end
#set ($discard = $results.rows.add($row)) #set ($discard = $results.rows.add($row))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment