Wiki source code of api
Version 2.1 by Ophion Admin on 2026/10/06 15:59
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{velocity}} |
| |
2.1 | 2 | #set ($appSpace = 'api') |
| 3 | #set ($appClass = 'api.Code.apiClass') | ||
| 4 | #set ($templateRef = 'api.Code.apiTemplate') | ||
| 5 | ## Lowercase letters and digits, single hyphens only between the parts | ||
| 6 | #set ($namePattern = '[a-z0-9]+(-[a-z0-9]+)*') | ||
| 7 | ## Collect all AWM apps: data class name -> app title | ||
| 8 | #set ($apps = {}) | ||
| 9 | #set ($xwql = "select doc.fullName from Document doc, doc.object(AppWithinMinutes.LiveTableClass) as app order by doc.fullName") | ||
| 10 | #foreach ($homeName in $services.query.xwql($xwql).execute()) | ||
| 11 | #set ($home = $xwiki.getDocument($homeName)) | ||
| 12 | #if ($home) | ||
| 13 | #set ($cls = "$!home.getObject('AppWithinMinutes.LiveTableClass').getValue('class')") | ||
| 14 | ## Skip empty entries and the API app itself | ||
| 15 | #if ($cls != '' && $cls != $appClass) | ||
| 16 | #set ($discard = $apps.put($cls, $home.plainTitle)) | ||
| 17 | #end | ||
| 18 | #end | ||
| 19 | #end | ||
| 20 | #set ($errorMsg = '') | ||
| 21 | #if ("$!request.createEntry" == '1') | ||
| 22 | #set ($name = "$!request.name") | ||
| 23 | #set ($sourceClass = "$!request.sourceClass") | ||
| 24 | #if (!$name.matches($namePattern)) | ||
| 25 | #set ($errorMsg = 'Only lowercase letters, digits and hyphens are allowed.') | ||
| 26 | #elseif (!$apps.containsKey($sourceClass)) | ||
| 27 | #set ($errorMsg = 'Invalid source application.') | ||
| 28 | #else | ||
| 29 | #set ($ref = $services.model.createDocumentReference('', [$appSpace, $name], 'WebHome')) | ||
| 30 | #if ($xwiki.exists($ref)) | ||
| 31 | #set ($errorMsg = "An API named '${name}' already exists.") | ||
| 32 | #else | ||
| 33 | ## The last parameter prefills the sourceClass field of the new entry | ||
| 34 | #set ($qs = $escapetool.url({'template': $templateRef, 'parent': "${appSpace}.WebHome", 'title': $name, "${appClass}_0_sourceClass": $sourceClass})) | ||
| 35 | $response.sendRedirect($xwiki.getURL($ref, 'edit', $qs)) | ||
| 36 | #end | ||
| 37 | #end | ||
| 38 | #end | ||
| 39 | #if ($errorMsg != '') | ||
| 40 | {{error}}$errorMsg{{/error}} | ||
| 41 | #end | ||
| 42 | {{html clean="false"}} | ||
| 43 | <style> | ||
| 44 | /* Hide the default AWM "Add new entry" button */ | ||
| 45 | ul.actions a.action.add, a.action.add { display: none !important; } | ||
| 46 | </style> | ||
| 47 | <form action="$doc.getURL()" method="get" class="form-inline"> | ||
| 48 | <input type="hidden" name="createEntry" value="1"/> | ||
| 49 | <select name="sourceClass" class="form-control"> | ||
| 50 | #foreach ($app in $apps.entrySet()) | ||
| 51 | <option value="$escapetool.xml($app.key)">$escapetool.xml($app.value)</option> | ||
| 52 | #end | ||
| 53 | </select> | ||
| 54 | <input type="text" name="name" class="form-control" required="required" | ||
| 55 | pattern="$namePattern" title="Lowercase letters, digits and hyphens only"/> | ||
| 56 | <input type="submit" class="btn btn-primary" value="Create API"/> | ||
| 57 | </form> | ||
| 58 | {{/html}} | ||
| 59 | {{/velocity}} | ||
| 60 | |||
| 61 | {{velocity}} | ||
| |
1.1 | 62 | #set ($columnsProperties = { |
| 63 | 'doc.title': {"link":"view"}, | ||
| 64 | 'doc.location': {"html":true}, | ||
| 65 | 'doc.date': {}, | ||
| 66 | 'doc.author': {"link":"author"}, | ||
| 67 | '_actions': {"sortable":false,"filterable":false,"html":true,"actions":["edit","delete"]} | ||
| 68 | }) | ||
| 69 | #set ($options = { | ||
| 70 | 'className': 'api.Code.apiClass', | ||
| 71 | 'translationPrefix': 'api.livetable.', | ||
| 72 | 'tagCloud': true, | ||
| 73 | 'rowCount': 15, | ||
| 74 | 'maxPages': 10, | ||
| 75 | 'selectedColumn': 'doc.title', | ||
| 76 | 'defaultOrder': 'asc' | ||
| 77 | }) | ||
| 78 | #set ($columns = ['doc.title', 'doc.location', 'doc.date', 'doc.author', '_actions']) | ||
| 79 | #livetable('api' $columns $columnsProperties $options) | ||
| 80 | {{/velocity}} |