Changes for page api

Last modified by Ophion Admin on 2026/10/06 19:32

From version 6.1
edited by Ophion Admin
on 2026/10/06 17:01
Change comment: There is no comment for this version
To version 1.1
edited by Ophion Admin
on 2026/10/06 15:57
Change comment: Update LiveTable

Summary

Details

Page properties
Content
... ... @@ -1,129 +1,6 @@
1 1  {{velocity}}
2 -#set ($appSpace = 'api')
3 -#set ($appClass = 'api.Code.apiClass')
4 -## Lowercase letters and digits, single hyphens only between the parts
5 -#set ($namePattern = '[a-z0-9]+(-[a-z0-9]+)*')
6 -## Collect all AWM apps: data class name -> app title
7 -#set ($apps = {})
8 -#set ($xwql = "select doc.fullName from Document doc, doc.object(AppWithinMinutes.LiveTableClass) as app order by doc.fullName")
9 -#foreach ($homeName in $services.query.xwql($xwql).execute())
10 - #set ($home = $xwiki.getDocument($homeName))
11 - #if ($home)
12 - #set ($cls = "$!home.getObject('AppWithinMinutes.LiveTableClass').getValue('class')")
13 - ## Skip empty entries and the API app itself
14 - #if ($cls != '' && $cls != $appClass)
15 - #set ($discard = $apps.put($cls, $home.plainTitle))
16 - #end
17 - #end
18 -#end
19 -## Current state of the form
20 -#set ($name = "$!request.name")
21 -#set ($sourceClass = "$!request.sourceClass")
22 -#set ($filterField = "$!request.filterField")
23 -#set ($filterValue = "$!request.filterValue")
24 -## Preselect the first app on the first page load
25 -#if ($sourceClass == '')
26 - #foreach ($key in $apps.keySet())
27 - #set ($sourceClass = $key)
28 - #break
29 - #end
30 -#end
31 -## Fields of the selected source app
32 -#set ($fields = [])
33 -#if ($apps.containsKey($sourceClass))
34 - #foreach ($p in $xwiki.getDocument($sourceClass).getxWikiClass().properties)
35 - #set ($discard = $fields.add($p.name))
36 - #end
37 -#end
38 -## Reset the filter if the field does not belong to the selected app
39 -#if (!$fields.contains($filterField))
40 - #set ($filterField = '')
41 - #set ($filterValue = '')
42 -#end
43 -## Existing values of the selected field
44 -#set ($values = [])
45 -#if ($filterField != '')
46 - #set ($template = $sourceClass.replaceAll('Class$', 'Template'))
47 - #set ($hql = "select distinct doc.fullName from XWikiDocument doc, BaseObject obj where obj.name = doc.fullName and obj.className = :cls and doc.fullName <> :tpl order by doc.fullName")
48 - #foreach ($entryName in $services.query.hql($hql).bindValue('cls', $sourceClass).bindValue('tpl', $template).execute())
49 - #set ($entry = $xwiki.getDocument($entryName))
50 - #if ($entry)
51 - #set ($value = "$!entry.getObject($sourceClass).getValue($filterField)")
52 - #if ($value != '' && !$values.contains($value))
53 - #set ($discard = $values.add($value))
54 - #end
55 - #end
56 - #end
57 -#end
58 -#set ($errorMsg = '')
59 -#if ("$!request.createEntry" == '1')
60 - #if (!$services.csrf.isTokenValid("$!request.form_token"))
61 - #set ($errorMsg = 'Invalid form token, please try again.')
62 - #elseif (!$name.matches($namePattern))
63 - #set ($errorMsg = 'Only lowercase letters, digits and hyphens are allowed.')
64 - #elseif (!$apps.containsKey($sourceClass))
65 - #set ($errorMsg = 'Invalid source application.')
66 - #elseif ($filterField != '' && !$values.contains($filterValue))
67 - #set ($errorMsg = 'Please select a filter value.')
68 - #else
69 - #set ($ref = $services.model.createDocumentReference('', [$appSpace, $name], 'WebHome'))
70 - #if ($xwiki.exists($ref))
71 - #set ($errorMsg = "An API named '${name}' already exists.")
72 - #else
73 - ## Create and save the entry directly, no edit form needed
74 - #set ($newDoc = $xwiki.getDocument($ref))
75 - #set ($discard = $newDoc.setTitle($name))
76 - #set ($discard = $newDoc.setParent("${appSpace}.WebHome"))
77 - #set ($newObj = $newDoc.newObject($appClass))
78 - #set ($discard = $newObj.set('sourceClass', $sourceClass))
79 - #set ($discard = $newObj.set('filterField', $filterField))
80 - #set ($discard = $newObj.set('filterValue', $filterValue))
81 - #set ($discard = $newDoc.save('Created API entry'))
82 - $response.sendRedirect($doc.getURL())
83 - #end
84 - #end
85 -#end
86 -#if ($errorMsg != '')
87 - {{error}}$errorMsg{{/error}}
88 -#end
89 -{{html clean="false"}}
90 -<style>
91 - /* Hide the default AWM "Add new entry" button */
92 - ul.actions a.action.add, a.action.add { display: none !important; }
93 -</style>
94 -<form action="$doc.getURL()" method="post" class="form-inline">
95 - <input type="hidden" name="form_token" value="$!services.csrf.token"/>
96 - <!-- Changing the app or the field reloads the form without creating anything -->
97 - <select name="sourceClass" class="form-control" onchange="this.form.submit()">
98 - #foreach ($app in $apps.entrySet())
99 - <option value="$escapetool.xml($app.key)" #if ($app.key == $sourceClass)selected="selected"#end>$escapetool.xml($app.value)</option>
100 - #end
101 - </select>
102 - <select name="filterField" class="form-control" onchange="this.form.submit()">
103 - <option value="">(no filter)</option>
104 - #foreach ($field in $fields)
105 - <option value="$escapetool.xml($field)" #if ($field == $filterField)selected="selected"#end>$escapetool.xml($field)</option>
106 - #end
107 - </select>
108 - #if ($filterField != '')
109 - <select name="filterValue" class="form-control">
110 - #foreach ($value in $values)
111 - <option value="$escapetool.xml($value)" #if ($value == $filterValue)selected="selected"#end>$escapetool.xml($value)</option>
112 - #end
113 - </select>
114 - #end
115 - <input type="text" name="name" class="form-control" required="required" value="$escapetool.xml($name)"
116 - pattern="$namePattern" title="Lowercase letters, digits and hyphens only"/>
117 - <button type="submit" name="createEntry" value="1" class="btn btn-primary">Create API</button>
118 -</form>
119 -{{/html}}
120 -{{/velocity}}
121 -
122 -{{velocity}}
123 123  #set ($columnsProperties = {
124 124   'doc.title': {"link":"view"},
125 - 'sourceClass': {},
126 - 'getUrl': {"html":true,"sortable":false,"filterable":false},
127 127   'doc.location': {"html":true},
128 128   'doc.date': {},
129 129   'doc.author': {"link":"author"},
... ... @@ -138,6 +138,6 @@
138 138   'selectedColumn': 'doc.title',
139 139   'defaultOrder': 'asc'
140 140  })
141 -#set ($columns = ['doc.title', 'sourceClass', 'getUrl', 'doc.location', 'doc.date', 'doc.author', '_actions'])
18 +#set ($columns = ['doc.title', 'doc.location', 'doc.date', 'doc.author', '_actions'])
142 142  #livetable('api' $columns $columnsProperties $options)
143 143  {{/velocity}}
XWiki.UIExtensionClass[0]
Extension ID
... ... @@ -1,1 +1,0 @@
1 -platform.panels.apiApplication
Extension Parameters
... ... @@ -1,3 +1,0 @@
1 -label=api
2 -target=api.WebHome
3 -icon=icon:application