Extensions Wiki » Extensions » All Attachments Livetable

All Attachments Livetable

Last modified by Vincent Massol on 2013/03/11 09:38
page_whiteDisplays a livetable with all attachments present the wiki
TypeSnippet
Developed by

Jerome Velociter

LicenseGNU Lesser General Public License 2.1

Description

This feature is available as a tab in the Document Index of XWiki Enterprise since XE 1.7

Displays in a live grid all attachments in the wiki or in a wiki space, ordered by descending upload time. Filters are available for filenames, document names and attachment author (user that uploaded the attachment).

XWiki.AllAttachmentsTable (The UI)

1.1 All attachments in this wiki

<div id="ajax-loader">$msg.get("ui.ajaxTable.loading")<br />
 <img src="$xwiki.getSkinFile('icons/ajax-loader.gif')" alt="$msg.get('ui.ajaxTable.loading')" title="" />
</div>
<table id="allfilestable">
<tr>
<td colspan="2" style="padding-top:10px;">
  <span id="showLimits"></span>
</td>
</tr>
<tr><td style="width:100%">
     <table class="display">
      <thead class="theader">
         <tr>
           <td>Page</td>
           <td>Filename</td>
           <td>Date</td>
           <td>Author</td>
           <td>Type</td>
         </tr>
         <tr id="table-filters">
             <td><input name="title" type="text"/></td>
             <td><input name="filename" type="text"/></td>
             <td></td> ##date
             <td><input name="author" type="text" /></td>
             <td></td> ##type
         </tr>
      </thead>
      <tbody id="display1"><tr><td>&nbsp;</td></tr></tbody>
     </table></td>
     <td valign="top">
       <div id="scrollbar1" class="scrollbar"><div class="inscrollbar">&nbsp;</div></div>
     </td>
   <td id="buff"></td>
</tr>
</table>
#set($url = "$xwiki.getURL('XWiki.AllAttachmentsResults')?xpage=plain&space=$!space")
OPENPRE
<script type="text/javascript">
//<![CDATA[
function displayAllFiles(row, i, table)
{
    var a = new Element('a', 
{'href' : row.url}).update(row.page);
    var page = new Element('td', 
{'class' : 'pagename'}).update(a);
    var tr = new Element('tr', 
{'class' : (i % 2 == 0) ? 'even' : 'odd'} ).update(page);
    var af = new Element('a', 
{'href' : row.fileurl}).update(row.filename);
    tr.appendChild(new Element('td').update(af));
    var date = new Element('td').update(row.date);
    tr.appendChild(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(row.type);
    tr.appendChild(type);
    return tr;
}
var ta = new ASSTable("
$url", 15, "display1", "scrollbar1", "allfilestable", displayAllFiles, true);
//]]>

</script>
CLOSEPRE
To restrict the results to a certain space, just add the following line at the beginning of XWiki.AllAttachmentsTable :
#set($space="NameOfTheSpace")

XWiki.AllAttachmentsResults (The service)

This document needs to be saved with a user owning programming rights.
OPENPRE
## ============================================================================================
## This page is called from live grids via Ajax with the argument xpage=plain. It returns a
## set of results serialized in JSON.
## !!! NEEDS PROGRAMMING RIGHTS !!!
## ============================================================================================
#if ($request.get("xpage") && $request.get("xpage") == "plain")
#set( $offset = $xwiki.parseInt( $request.get( "offset" ) ) )
## offset starts from 0 in velocity and 1 in javascript
#set( $off = $offset - 1 )
#set( $limit = $xwiki.parseInt( $request.get( "limit" ) ) )
#set($title = $request.get("title"))
#set($author = $request.get("author"))
#set($space = $request.get("space"))
#set($filename = $request.filename)
#set($formatDate = "yyyy MMMM dd, HH:mm")
#if($title)
  #set($title = $title.trim().toLowerCase())
  #set($sql = "and lower(doc.fullName) like '%${title}%' ")
#else #set($sql = "and lower(doc.fullName) <> '' ") #end
#if($author)
  #set($author = $author.trim().toLowerCase())
  #set($sql = $sql + "and lower(attach.author) like '%${author}%' ")
#end
#if($filename)
  #set($filename = $filename.trim().toLowerCase())
  #set($sql = $sql + "and lower(attach.filename) like '%${filename}%' ")
#end
#if($space && $space!="")
  #set($sql = $sql + "and doc.web='$space' ")
#end
#set($sql = "select doc.fullName, attach from XWikiDocument as doc, XWikiAttachment as attach where attach.docId=doc.id " + $sql + " order by attach.date desc")
#set($items = $xwiki.search($sql, $limit, $off))
#set($totalItems = $xwiki.search($sql).size())
#set($returnedItems = $items.size())
## ==============================================
## json starts
## ==============================================
{
"totalrows": $totalItems,
"returnedrows": #if($returnedItems < $limit) $returnedItems #else $limit #end,
"offset": $offset,
"reqNo": $request.reqNo,
"rows": [
#foreach($item in $items)
  #foreach($element in $item)
   #if($velocityCount==1) #set($docName=$element) #else #set($attachment=$element) #end
  #end
  #set($document = $xwiki.getDocument($docName))
  #if($velocityCount > 1) , #end
  {"filename"    : "$attachment.filename",
   "fileurl" : "$document.getAttachmentURL($attachment.filename)",
   "page"  : "$document.fullName",
   "url" : "$document.getURL('view')",
   "date" : "$xwiki.formatDate($attachment.date,$formatDate)",
   "author" : "$attachment.author",
   "authorname" : "$xwiki.getUserName($attachment.author,false)",
   "authorurl" : "$xwiki.getURL($attachment.author,'view')",
   "type" : "$attachment.getMimeType($context.context)"
  }
#end
]}
## ==============================================
## json ended
## ==============================================
#end
CLOSEPRE

Result

AllAttachments.png

Created by Jerome Velociter on 2008/08/14 13:00

Download XWiki