Wiki source code of api

Version 3.1 by Ophion Admin on 2026/10/06 16:01

Show last authors
1 {{velocity}}
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}}
62 #set ($columnsProperties = {
63 'doc.title': {"link":"view"},
64 'sourceClass': {},
65 'doc.location': {"html":true},
66 'doc.date': {},
67 'doc.author': {"link":"author"},
68 '_actions': {"sortable":false,"filterable":false,"html":true,"actions":["edit","delete"]}
69 })
70 #set ($options = {
71 'className': 'api.Code.apiClass',
72 'translationPrefix': 'api.livetable.',
73 'tagCloud': true,
74 'rowCount': 15,
75 'maxPages': 10,
76 'selectedColumn': 'doc.title',
77 'defaultOrder': 'asc'
78 })
79 #set ($columns = ['doc.title', 'sourceClass', 'doc.location', 'doc.date', 'doc.author', '_actions'])
80 #livetable('api' $columns $columnsProperties $options)
81 {{/velocity}}