Skip to content

Commit

Permalink
XWIKI-19041: Replace the Livetable from DocumentsMacro with a Live Da…
Browse files Browse the repository at this point in the history
…ta macro
  • Loading branch information
manuelleduc committed Jan 5, 2024
1 parent 7882a63 commit 788ca73
Showing 1 changed file with 26 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,64 +257,52 @@ Generates:
<property>
<code>{{velocity}}
#if ("$!xcontext.macro.params.columns" != "")
#set ($collist = [])
#set ($properties = [])
#foreach ($colname in $xcontext.macro.params.columns.split(','))
#set ($discard = $collist.add($colname.trim()))
#set ($discard = $properties.add($colname.trim()))
#end
#else
#set($collist = ['doc.title', 'doc.location', 'doc.date', 'doc.author'])
#set($properties = ['doc.title', 'doc.location', 'doc.date', 'doc.author'])
#end
#set($colprops = {
'doc.title' : { 'size' : 30, 'link' : 'view' },
'doc.location' : { 'html': true },
'doc.fullName' : { 'size' : 30, 'link' : 'view' },
'doc.name' : { 'size' : 30, 'link' : 'view' },
'doc.space' : { 'link' : 'space' },
'doc.author' : { 'link' : 'author' }
})
#set($options = {
#set($sourceParameters = {
'translationPrefix' : 'platform.index.',
'rowCount' : $xcontext.macro.params.count,
'description' : 'This table lists documents found on this wiki based on passed criteria. The columns can be sorted and some can be filtered.'
})
#if ("$!xcontext.macro.params.space" != "")
#set ($extraParams = "&amp;space=$escapetool.url($xcontext.macro.params.space)")
#end
#if ("$!xcontext.macro.params.location" != "")
#set ($extraParams = "$!{extraParams}&amp;location=$escapetool.url($xcontext.macro.params.location)")
#set ($discard = $sourceParameters.put('space', $xcontext.macro.params.space))
#end
#if ("$!xcontext.macro.params.parent" != "")
#set ($extraParams = "$!{extraParams}&amp;parent=$escapetool.url($xcontext.macro.params.parent)")
#if ("$!xcontext.macro.params.location" != "")
#set ($discard = $sourceParameters.put('location', $xcontext.macro.params.location))
#end
#if ("$!extraParams" != "")
#set($discard = $options.put('extraParams', $extraParams))
#if ("$!xcontext.macro.params.parent" != "")
#set ($discard = $sourceParameters.put('parent', $xcontext.macro.params.parent))
#end
#set ($propertyDescriptors = [])
#if(!$isGuest &amp;&amp; $xcontext.macro.params.actions == "true")
#set($discard = $collist.add('_actions'))
#set($discard = $colprops.put('_actions', {
'actions': ['copy', 'rename', 'rights', 'delete'],
'filterable': false,
'sortable': false
}))
#set ($discard = $propertyDescriptors.add({ 'id': '_actions', 'displayer': { 'id': 'actions', 'actions': ['copy', 'rename', 'rights', 'delete'] }}))
#set ($discard = $properties.add('_actions'))
#end
#if ("$!services.like" != "")
#set($discard = $collist.add('_likes'))
## We can't make it sortable or filterable right now since it's not stored in DB.
#set($discard = $colprops.put('_likes', {
'filterable': false,
'sortable': false
}))
#end
#if ($collist.contains('doc.location'))
#set ($discard = $options.put('selectedColumn','doc.location'))
#set ($discard = $propertyDescriptors.add({ 'id': '_likes', 'sortable': false, 'filterable': false }))
#set ($discard = $properties.add('_likes'))
#end
#set ($liveDataConfig = {'meta': {'propertyDescriptors': $propertyDescriptors}})
#if ("$!xcontext.macro.params.id" != "")
#set ($livetableId = $xcontext.macro.params.id)
#set ($livedataId = $xcontext.macro.params.id)
#else
## TODO: Improve this since we could have several livetables on the same page with same ids
#set ($livetableId = "documents-$mathtool.random(1, 1000)")
#set ($livedataId = "documents-$mathtool.random(1, 1000)")
#end
#livetable($livetableId $collist $colprops $options)

{{liveData
id="$livedataId"
properties="$stringtool.join($properties, ',')"
source="liveTable"
sourceParameters="$escapetool.url($sourceParameters)"
#if ($properties.contains('doc.location'))sort="doc.location"#end
#if ("$!xcontext.macro.params.count" != '')limit="$xcontext.macro.params.count"#end
}}$jsontool.serialize($liveDataConfig){{/liveData}}
{{/velocity}}</code>
</property>
<property>
Expand Down

0 comments on commit 788ca73

Please sign in to comment.