Wiki source code of LoggingAdminTableJson
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{velocity wiki="false"}} | ||
2 | #if("$!{request.xpage}" == 'plain') | ||
3 | $response.setContentType('application/json') | ||
4 | #end | ||
5 | ##============================== | ||
6 | ## Offset = item # at which to start displaying data | ||
7 | ##============================== | ||
8 | #set ($offset = $numbertool.toNumber($request.offset).intValue()) | ||
9 | ## If no offset is specified, start at 0. | ||
10 | #if (!$offset) | ||
11 | #set ($offset = 0) | ||
12 | #else | ||
13 | ## The offset sent by the live table widget starts from 1. | ||
14 | #set ($offset = $mathtool.max($offset, 1) - 1) | ||
15 | #end | ||
16 | ##================== | ||
17 | ## Limit = # of items to display | ||
18 | ##================== | ||
19 | #set($limit = $mathtool.max($numbertool.toNumber($request.limit).intValue(), 0)) | ||
20 | ## If no limit is specified, limit at 15 items | ||
21 | #if (!$limit) | ||
22 | #set ($limit = 15) | ||
23 | #end | ||
24 | ##================== | ||
25 | ## Tag = one parameter per tag | ||
26 | ##================== | ||
27 | #if($request.tag) | ||
28 | #foreach($tag in $request.getParameterValues('tag')) | ||
29 | ## TODO: Add code to filter items based on the selected tags | ||
30 | #end | ||
31 | #end | ||
32 | ##========== | ||
33 | ## Sort direction | ||
34 | ##========== | ||
35 | #set($order = "$!request.sort") | ||
36 | #if($order != '') | ||
37 | #set($orderDirection = "$!{request.get('dir').toLowerCase()}") | ||
38 | #if("$!orderDirection" != '' && "$!orderDirection" != 'asc') | ||
39 | #set($orderDirection = 'desc') | ||
40 | #end | ||
41 | #end | ||
42 | ## =========== | ||
43 | ## Filters | ||
44 | ## =========== | ||
45 | #set ($loggerFilter = "$!request.logger.toLowerCase()") | ||
46 | #set ($levelFilter = "$!request.level.toLowerCase()") | ||
47 | ## === | ||
48 | ## JSON | ||
49 | ## === | ||
50 | #set ($logger_list = $services.logging.getLevels()) | ||
51 | #set ($logs = $logger_list.entrySet()) | ||
52 | ## FIXME: Remove that: workaround a bug in VelocityTool 1.4 which does not properly support sorting on null | ||
53 | ## properties (it is fixed in VelocityTools 2) | ||
54 | #foreach ($log in $logs) | ||
55 | #if (!$log.value) | ||
56 | #set($void = $log.setValue('')) | ||
57 | #else | ||
58 | #set($void = $log.setValue("${log.value.ordinal()}${log.value.name()}")) | ||
59 | #end | ||
60 | #end | ||
61 | ## Filter | ||
62 | #set ($matchingLogs = []) | ||
63 | #foreach ($log in $logs) | ||
64 | #set ($logLevel = "$!log.value") | ||
65 | #if ((!$loggerFilter || $log.key.toLowerCase().contains($loggerFilter)) | ||
66 | && (!$levelFilter || $logLevel.toLowerCase().contains($levelFilter))) | ||
67 | #set ($discard = $matchingLogs.add($log)) | ||
68 | #end | ||
69 | #end | ||
70 | ## Sort | ||
71 | #if ($request.sort) | ||
72 | #if ($request.sort == "logger") | ||
73 | #set ($propertyName = "key") | ||
74 | #else | ||
75 | #set ($propertyName = "value") | ||
76 | #end | ||
77 | #set ($matchingLogs = $collectiontool.sort($matchingLogs, ["${propertyName}:${request.dir}"])) | ||
78 | #end | ||
79 | ## Pagination | ||
80 | #if ($offset >= $matchingLogs.size()) | ||
81 | #set ($offset = 0) | ||
82 | #end | ||
83 | #set($resultLog = $matchingLogs.subList($offset, $mathtool.min($mathtool.add($offset, $limit), $matchingLogs.size()))) | ||
84 | { | ||
85 | "totalrows": $matchingLogs.size(), | ||
86 | "matchingtags": {}, | ||
87 | "tags" : [], | ||
88 | "returnedrows": $resultLog.size(), | ||
89 | "offset": $offset, | ||
90 | "sort": "$request.sort", | ||
91 | "dir": "$request.dir", | ||
92 | "reqNo": $numbertool.toNumber($request.reqNo).intValue(), | ||
93 | "rows": [ | ||
94 | #foreach( $logger in $resultLog ) | ||
95 | #if($foreach.count > 1) , #end | ||
96 | #set($loggLevelName = "$!logger.value") | ||
97 | ## FIXME: Remove that: workaround a bug in VelocityTool 1.4 which does not properly support sorting on null | ||
98 | ## properties (it is fixed in VelocityTools 2) | ||
99 | #if ($loggLevelName != '') | ||
100 | #set ($loggLevelName = $loggLevelName.substring(1)) | ||
101 | #end | ||
102 | { | ||
103 | "doc_viewable" : true, | ||
104 | "logger" : "$escapetool.javascript($logger.key)", | ||
105 | "level" : "$loggLevelName", | ||
106 | "actions" : "${escapetool.javascript("<form action='' method='post'> | ||
107 | <fieldset> | ||
108 | <input name='logger_name' value='$logger.key' type='hidden'/> | ||
109 | <select name='logger_level'> | ||
110 | #if ($loggLevelName != 'TRACE') | ||
111 | <option label='TRACE' value='TRACE'>TRACE</option> | ||
112 | #end | ||
113 | #if ($loggLevelName != 'DEBUG') | ||
114 | <option label='DEBUG' value='DEBUG'>DEBUG</option> | ||
115 | #end | ||
116 | #if ($loggLevelName != 'INFO') | ||
117 | <option label='INFO' value='INFO'>INFO</option> | ||
118 | #end | ||
119 | #if ($loggLevelName != 'WARN') | ||
120 | <option label='WARN' value='WARN'>WARN</option> | ||
121 | #end | ||
122 | #if ($loggLevelName != 'ERROR') | ||
123 | <option label='ERROR' value='ERROR'>ERROR</option> | ||
124 | #end | ||
125 | #if ($loggLevelName && $logger.value != '') | ||
126 | <option label='default' value=''>default</option> | ||
127 | #end | ||
128 | </select> | ||
129 | <span class='buttonwrapper'><input name='loggeraction_set' value='${escapetool.xml($services.localization.render('logging.admin.livetable.actions.set'))}' class='button' type='submit'></span> | ||
130 | </fieldset> | ||
131 | </form>")}" | ||
132 | } | ||
133 | #end | ||
134 | ] | ||
135 | } | ||
136 | {{/velocity}} |