Wiki source code of New Livetable Macro as a XWiki Syntax 2.0 macro
Last modified by Vincent Massol on 2024/11/19 16:12
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{include document="XWiki.DesignClassSheet"/}} | ||
| 2 | |||
| 3 | {{toc/}} | ||
| 4 | |||
| 5 | = Livetable Macro = | ||
| 6 | |||
| 7 | {{code}} | ||
| 8 | {{livetable source="hint of livetable data source component" id="..." tags="true|false" order="asc|desc" params="param=value,..." ...}} | ||
| 9 | // Optional definition of how to display columns, it's optional as column definition will be defined in the returned JSON | ||
| 10 | columnname1: { "sort" : "true", "filter" : "true", "visible" : "true" } | ||
| 11 | columnname2: { "sort" : "true", "filter" : "true", "visible" : "true" } | ||
| 12 | ... | ||
| 13 | columnnameN: { "sort" : "true", "filter" : "true", "visible" : "true" } | ||
| 14 | {{/livetable}} | ||
| 15 | {{/code}} | ||
| 16 | |||
| 17 | == Livetable Data Source == | ||
| 18 | |||
| 19 | * They are java components with one method ##Map generateData()## | ||
| 20 | * We have a LivetableDataSourceClass with an "id" (the component hint), and the document content acting as the content for the data source that return the Map (store it in some context variable) | ||
| 21 | * Works the same as Wiki Macros | ||
| 22 | * Thus data source can be defined either in Java or in wiki pages | ||
| 23 | |||
| 24 | == REST Services == | ||
| 25 | |||
| 26 | * A REST Service receives the calls from the livetable JS and return JSON by calling the Livetable Data Source corresponding the passed hint | ||
| 27 | |||
| 28 | == Script Service == | ||
| 29 | |||
| 30 | * A Livetable SS is provided to call a given Livetable DS from a wiki DS for example | ||
| 31 | * Example of a wiki DS that customize some other DS:((( | ||
| 32 | {{code language="none"}} | ||
| 33 | ## Customize params for the DS here | ||
| 34 | ... | ||
| 35 | #set ($map = $services.livetable.generateData()) | ||
| 36 | ## Customize generate Map here | ||
| 37 | ... | ||
| 38 | ## Save back the map | ||
| 39 | $services.livetable.saveData($map) | ||
| 40 | {{/code}} | ||
| 41 | ))) | ||
| 42 | |||
| 43 | == UC: display table from XClass == | ||
| 44 | |||
| 45 | {{code}} | ||
| 46 | {{livetable source="xclass" params="class=XWiki.XWikiUsers"/}} | ||
| 47 | {{/code}} | ||
| 48 | |||
| 49 | To make it even easier to use we'll have a new wiki macro: | ||
| 50 | |||
| 51 | {{code}} | ||
| 52 | {{classes class="XWiki.XWikiUsers"/}} | ||
| 53 | {{/code}} | ||
| 54 | |||
| 55 | == UC: data is small enough to be in memory == | ||
| 56 | |||
| 57 | In a custom wiki DS: | ||
| 58 | |||
| 59 | {{code}} | ||
| 60 | {{velocity}} | ||
| 61 | #set ($map = .. construct map ...) | ||
| 62 | ... | ||
| 63 | #set ($filteredMap = $services.livetable.filter($map)) <-- filter map based on livetable params: offset, start, number of items, sort column and order, etc | ||
| 64 | $services.livetable.saveData($filteredMap) | ||
| 65 | {{/velocity}} | ||
| 66 | {{/code}} | ||
| 67 | |||
| 68 | == UC: Displays documents == | ||
| 69 | |||
| 70 | {{code}} | ||
| 71 | {{livetable source="documents" params="query=..."/}} | ||
| 72 | {{/code}} | ||
| 73 | |||
| 74 | To make it even easier to use we'll have a new wiki macro: | ||
| 75 | |||
| 76 | {{code}} | ||
| 77 | {{documents query="...where clause of a XWQL query..."/}} | ||
| 78 | {{/code}} | ||
| 79 | |||
| 80 | Note: Can be used for AllDocs or Space index. |