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

XWIKI-11338: Be able to sort attachments by type on the Document Index page

* Add the mimeType field to the list of allowed sort fields
* Rename the "type" column into "mimeType" in order to match the actual attachment field from the database.
* Make the mimeType column filterable (using multilist) and sortable.
* Add a class definition to XWiki.AllAttachments in order to be able to configure the known file types that are listed in the mimeType filter drop down.
* Refactor XWiki.AllAttachmentsResults to use the matchType specified on the request for each filtered field.
parent 91c1a944
No related branches found
No related tags found
No related merge requests found
......@@ -42,14 +42,14 @@
<content>{{velocity}}
#set ($discard = $xwiki.jsx.use('XWiki.AllAttachments'))
##
#set ($collist = ['filename', 'doc.name', 'doc.space', 'date', 'author', 'type'])
#set ($collist = ['filename', 'doc.name', 'doc.space', 'date', 'author', 'mimeType'])
#set ($colprops = {
'filename' : { 'type' : 'text', 'size' : 10 },
'doc.name' : { 'type' : 'text', 'size' : 10 },
'doc.space' : { 'type' : 'text', 'size' : 10 },
'date' : { 'type' : 'date', 'size' : 10, 'filterable' : false },
'author' : { 'type' : 'text', 'size' : 10 },
'type' : { 'sortable' : false }
'mimeType' : { 'type' : 'multilist', 'class': 'XWiki.AllAttachments' }
})
#set($options = { 'url' : $xwiki.getURL('XWiki.AllAttachmentsResults', 'get', 'xpage=plain&amp;outputSyntax=plain'),
'callback' : 'XWiki.index.displayAttachmentEntry',
......@@ -61,6 +61,37 @@
{{info}}$services.localization.render('rightsmanager.documentrequireviewrights'){{/info}}
)))
{{/velocity}}</content>
<class>
<name>XWiki.AllAttachments</name>
<customClass/>
<customMapping/>
<defaultViewSheet/>
<defaultEditSheet/>
<defaultWeb/>
<nameField/>
<validationScript/>
<mimeType>
<cache>0</cache>
<customDisplay/>
<disabled>0</disabled>
<displayType>select</displayType>
<multiSelect>1</multiSelect>
<name>mimeType</name>
<number>1</number>
<picker>0</picker>
<prettyName>Mime Type</prettyName>
<relationalStorage>0</relationalStorage>
<separator> </separator>
<separators>|, </separators>
<size>1</size>
<sort>none</sort>
<unmodifiable>0</unmodifiable>
<validationMessage/>
<validationRegExp/>
<values>audio/=Audio|image/=Image|application/pdf=PDF|text/=Text|video/=Video</values>
<classType>com.xpn.xwiki.objects.classes.StaticListClass</classType>
</mimeType>
</class>
<object>
<name>XWiki.AllAttachments</name>
<number>0</number>
......@@ -232,7 +263,7 @@
tr.appendChild(new Element('td').update(row.date));
var aa = new Element('a', {'href' : row.authorurl}).update(row.authorname);
tr.appendChild(new Element('td').update(aa));
var type = new Element('td').update(getMimeTypeImage(row.type));
var type = new Element('td').update(getMimeTypeImage(row.mimeType));
tr.appendChild(type);
return tr;
} else {
......
......@@ -39,13 +39,41 @@
<minorEdit>false</minorEdit>
<syntaxId>xwiki/2.0</syntaxId>
<hidden>true</hidden>
<content>{{velocity wiki="false"}}
<content>{{velocity output="false"}}
#macro (maybeApplyStringFilter $fieldName $defaultMatchType $constraints $queryParameters)
#if ("$!request.getParameter($fieldName)" != '')
#set ($fieldNameWithAlias = $fieldName)
#if ($fieldName.indexOf('.') &lt; 0)
#set ($fieldNameWithAlias = 'attachment.' + $fieldName)
#end
#set ($matchType = $request.getParameter("${fieldName}_match"))
#if ("$!matchType" == '')
#set ($matchType = $defaultMatchType)
#end
#set ($parameterName = $fieldNameWithAlias.replace('.', '_'))
#if ($matchType == 'exact')
#set ($discard = $constraints.add("$fieldNameWithAlias = :$parameterName"))
#set ($parameterValue = $request.getParameter($fieldName))
#else
#set ($discard = $constraints.add("lower($fieldNameWithAlias) like :$parameterName"))
#set ($parameterValue = $request.getParameter($fieldName).trim().toLowerCase())
#end
#set ($discard = $queryParameters.add({
'name': $parameterName,
'match': $matchType,
'value': $parameterValue
}))
#end
#end
{{/velocity}}
{{velocity wiki="false"}}
## ============================================================================================
## This page is called from live grids via Ajax with the argument xpage=plain. It returns a
## set of results serialized in JSON.
## ============================================================================================
#if ("$!request.get('xpage')" == 'plain')
$response.setContentType('application/json')##
#set ($discard = $response.setContentType('application/json'))
#set ($offset = $mathtool.toInteger($request.get('offset')))
## offset starts from 0 in velocity and 1 in javascript
#set ($offset = $offset - 1)
......@@ -56,50 +84,20 @@
#if (!$limit)
#set ($limit = 15)
#end
#set ($page = $request.get('doc.name'))
#set ($author = $request.get('author'))
#set ($space = $request.get('doc.space'))
#set ($filename = $request.filename)
#set ($formatDate = 'yyyy MMMM dd, HH:mm')
##
## Apply live table filters.
##
#set ($constraints = [])
#set ($queryParameters = [])
#if ($filename)
#set ($filename = $filename.trim().toLowerCase())
#set ($discard = $constraints.add('lower(attachment.filename) like :fileName'))
#set ($discard = $queryParameters.add({
'name': 'fileName',
'match': 'partial',
'value': $filename
}))
#end
#if ($space)
#set ($space = $space.trim().toLowerCase())
#set ($discard = $constraints.add('lower(doc.space) like :space'))
#set ($discard = $queryParameters.add({
'name': 'space',
'match': 'partial',
'value': $space
}))
#end
#if ($page)
#set ($page = $page.trim().toLowerCase())
#set ($discard = $constraints.add('lower(doc.name) like :page'))
#set ($discard = $queryParameters.add({
'name': 'page',
'match': 'partial',
'value': $page
}))
#end
#if ($author)
#set ($author = $author.trim().toLowerCase())
#set ($discard = $constraints.add('lower(attachment.author) like :author'))
#set ($discard = $queryParameters.add({
'name': 'author',
'match': 'partial',
'value': $author
}))
#end
#set ($validSortOptions = ['filename', 'doc.name', 'doc.space', 'date', 'author'])
#maybeApplyStringFilter('filename' 'partial' $constraints $queryParameters)
#maybeApplyStringFilter('doc.space' 'partial' $constraints $queryParameters)
#maybeApplyStringFilter('doc.name' 'partial' $constraints $queryParameters)
#maybeApplyStringFilter('author' 'partial' $constraints $queryParameters)
#maybeApplyStringFilter('mimeType' 'prefix' $constraints $queryParameters)
##
## Sort the results.
##
#set ($validSortOptions = ['filename', 'doc.name', 'doc.space', 'date', 'author', 'mimeType'])
#if ($validSortOptions.contains($request.sort))
#set ($order = $request.sort)
#else
......@@ -127,7 +125,10 @@
#foreach ($queryParameter in $queryParameters)
#if ($queryParameter.match == 'exact')
#set ($discard = $query.bindValue($queryParameter.name, $queryParameter.value))
#elseif ($queryParameter.match == 'partial')
#elseif ($queryParameter.match == 'prefix')
#set ($query = $query.bindValue($queryParameter.name).literal($queryParameter.value).anyChars().query())
#else
## Partial match.
#set ($query = $query.bindValue($queryParameter.name).anyChars().literal($queryParameter.value).anyChars().query())
#end
#end
......@@ -150,6 +151,7 @@
#if ($hasAccess)
#set ($document = $xwiki.getDocument($attachmentReference.parent))
#set ($attach = $document.getAttachment($attachmentReference.name))
#set ($formatDate = 'yyyy MMMM dd, HH:mm')
"page" : "$escapetool.javascript($document.name)",
"space" : "$escapetool.javascript($document.space)",
"fullname" : "$escapetool.javascript($document.fullName)",
......@@ -161,7 +163,7 @@
"author" : "$!escapetool.javascript($attach.author)",
"authorname" : "$!escapetool.javascript($xwiki.getUserName($attach.author, false))",
"authorurl" : "$xwiki.getURL($attach.author)",
"type" : "$!escapetool.javascript($attach.getMimeType())"
"mimeType" : "$!escapetool.javascript($attach.getMimeType())"
#else
"fullname": "$escapetool.javascript($services.model.serialize($attachmentReference.parent, 'local'))"
#end
......
......@@ -2814,7 +2814,7 @@ platform.index.attachments.doc.name=Page
platform.index.attachments.doc.space=Space
platform.index.attachments.date=Date
platform.index.attachments.author=Author
platform.index.attachments.type=Type
platform.index.attachments.mimeType=Type
platform.index.attachments.emptyvalue=
platform.index.documentsTrash=Deleted Pages
......@@ -5156,6 +5156,8 @@ core.delete.confirm.no=No, take me back!
#######################################
## until 9.7-rc-1
#######################################
#@deprecated platform.index.attachments.mimeType
platform.index.attachments.type=Type
####################
# Wiki Macro Bridge Module
......
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