Code source wiki de Statistiques et Graphiques
Modifié par Christophe PEZET le 2026/05/31 18:16
Afficher les derniers auteurs
| author | version | line-number | content |
|---|---|---|---|
| 1 | {{velocity}} | ||
| 2 | $services.localization.render("awm.statistics.desc") | ||
| 3 | #set($currentUserRef = $xcontext.userReference) | ||
| 4 | #set($inputError = false) | ||
| 5 | #set($safeAppName = $!request.appname) | ||
| 6 | #set($safeClassName = $!request.className) | ||
| 7 | #set($safeProperty = $!request.property) | ||
| 8 | #set($safeType = $!request.type) | ||
| 9 | #set($safeFunction = $!request.function) | ||
| 10 | #set($safeAggregate = $!request.aggregate) | ||
| 11 | #set($safeAggregateFunction = $!request.aggregateFunction) | ||
| 12 | #set($safeOrderDirection = $!request.orderDirection) | ||
| 13 | #if(!$safeType || $safeType=="") | ||
| 14 | #set($safeType = "pie") | ||
| 15 | #end | ||
| 16 | #if(!$inputError && $safeAppName && $safeAppName!="") | ||
| 17 | #set($sanitizedValue = $safeAppName.replace('"', '').replace("'", "")) | ||
| 18 | #if($sanitizedValue != $safeAppName) | ||
| 19 | #set($inputError = $services.localization.render("awm.statistics.error.invalidQuotes")) | ||
| 20 | #else | ||
| 21 | #set($safeAppName = $sanitizedValue) | ||
| 22 | #end | ||
| 23 | #end | ||
| 24 | #if(!$inputError && $safeClassName && $safeClassName!="") | ||
| 25 | #set($sanitizedValue = $safeClassName.replace('"', '').replace("'", "")) | ||
| 26 | #if($sanitizedValue != $safeClassName) | ||
| 27 | #set($inputError = $services.localization.render("awm.statistics.error.invalidQuotes")) | ||
| 28 | #else | ||
| 29 | #set($safeClassName = $sanitizedValue) | ||
| 30 | #end | ||
| 31 | #end | ||
| 32 | #if(!$inputError && $safeProperty && $safeProperty!="") | ||
| 33 | #set($sanitizedValue = $safeProperty.replace('"', '').replace("'", "")) | ||
| 34 | #if($sanitizedValue != $safeProperty) | ||
| 35 | #set($inputError = $services.localization.render("awm.statistics.error.invalidQuotes")) | ||
| 36 | #else | ||
| 37 | #set($safeProperty = $sanitizedValue) | ||
| 38 | #end | ||
| 39 | #end | ||
| 40 | #if(!$inputError && $safeType && $safeType!="") | ||
| 41 | #set($sanitizedValue = $safeType.replace('"', '').replace("'", "")) | ||
| 42 | #if($sanitizedValue != $safeType) | ||
| 43 | #set($inputError = $services.localization.render("awm.statistics.error.invalidQuotes")) | ||
| 44 | #else | ||
| 45 | #set($safeType = $sanitizedValue) | ||
| 46 | #end | ||
| 47 | #end | ||
| 48 | #if(!$inputError && $safeFunction && $safeFunction!="") | ||
| 49 | #set($sanitizedValue = $safeFunction.replace('"', '').replace("'", "")) | ||
| 50 | #if($sanitizedValue != $safeFunction) | ||
| 51 | #set($inputError = $services.localization.render("awm.statistics.error.invalidQuotes")) | ||
| 52 | #else | ||
| 53 | #set($safeFunction = $sanitizedValue) | ||
| 54 | #end | ||
| 55 | #end | ||
| 56 | #if(!$inputError && $safeAggregate && $safeAggregate!="") | ||
| 57 | #set($sanitizedValue = $safeAggregate.replace('"', '').replace("'", "")) | ||
| 58 | #if($sanitizedValue != $safeAggregate) | ||
| 59 | #set($inputError = $services.localization.render("awm.statistics.error.invalidQuotes")) | ||
| 60 | #else | ||
| 61 | #set($safeAggregate = $sanitizedValue) | ||
| 62 | #end | ||
| 63 | #end | ||
| 64 | #if(!$inputError && $safeAggregateFunction && $safeAggregateFunction!="") | ||
| 65 | #set($sanitizedValue = $safeAggregateFunction.replace('"', '').replace("'", "")) | ||
| 66 | #if($sanitizedValue != $safeAggregateFunction) | ||
| 67 | #set($inputError = $services.localization.render("awm.statistics.error.invalidQuotes")) | ||
| 68 | #else | ||
| 69 | #set($safeAggregateFunction = $sanitizedValue) | ||
| 70 | #end | ||
| 71 | #end | ||
| 72 | #if(!$inputError && $safeOrderDirection && $safeOrderDirection!="") | ||
| 73 | #set($sanitizedValue = $safeOrderDirection.replace('"', '').replace("'", "")) | ||
| 74 | #if($sanitizedValue != $safeOrderDirection) | ||
| 75 | #set($inputError = $services.localization.render("awm.statistics.error.invalidQuotes")) | ||
| 76 | #else | ||
| 77 | #set($safeOrderDirection = $sanitizedValue) | ||
| 78 | #end | ||
| 79 | #end | ||
| 80 | #if(!$inputError && $safeFunction && $safeFunction!="") | ||
| 81 | #set($safeFunctionNormalized = $safeFunction.toLowerCase().replace(" ", "")) | ||
| 82 | #if(!$safeFunctionNormalized.matches("^(year|month|day|dayofmonth|dayofweek|dayofyear|week|hour|minute|second)$") && !$safeFunctionNormalized.matches("^(year|month|day|dayofmonth|dayofweek|dayofyear|week|hour|minute|second)\\((prop\\.value|doc\\.[A-Za-z0-9_]+)\\)$")) | ||
| 83 | #set($inputError = $services.localization.render("awm.statistics.error.invalidFunction")) | ||
| 84 | #else | ||
| 85 | #set($safeFunction = $safeFunctionNormalized) | ||
| 86 | #end | ||
| 87 | #end | ||
| 88 | #if(!$inputError && !$safeType.matches("^(pie|bar|bar3D|line)$")) | ||
| 89 | #set($inputError = $services.localization.render("awm.statistics.error.invalidType")) | ||
| 90 | #end | ||
| 91 | #if(!$inputError && $safeOrderDirection && $safeOrderDirection!="" && !$safeOrderDirection.matches("^(asc|desc)$")) | ||
| 92 | #set($inputError = $services.localization.render("awm.statistics.error.invalidDirection")) | ||
| 93 | #end | ||
| 94 | #if(!$inputError && $safeAggregateFunction && $safeAggregateFunction!="" && !$safeAggregateFunction.matches("^(count|sum|avg|min|max)$")) | ||
| 95 | #set($inputError = $services.localization.render("awm.statistics.error.invalidAggregateFunction")) | ||
| 96 | #end | ||
| 97 | #set($hasSourceSelection = false) | ||
| 98 | #if(($safeAppName && $safeAppName!="") || ($safeClassName && $safeClassName!="")) | ||
| 99 | #set($hasSourceSelection = true) | ||
| 100 | #end | ||
| 101 | |||
| 102 | #set($appDoc = $null) | ||
| 103 | #set($className = "") | ||
| 104 | #set($classDoc = $null) | ||
| 105 | #if($hasSourceSelection && !$inputError) | ||
| 106 | #if($safeAppName && $safeAppName!="") | ||
| 107 | #set($appDoc = $xwiki.getDocument($safeAppName)) | ||
| 108 | #if($appDoc.isNew() && !$safeAppName.endsWith(".WebHome")) | ||
| 109 | #set($appHomeDoc = $xwiki.getDocument("${safeAppName}.WebHome")) | ||
| 110 | #if(!$appHomeDoc.isNew()) | ||
| 111 | #set($appDoc = $appHomeDoc) | ||
| 112 | #end | ||
| 113 | #end | ||
| 114 | #set($appDocRef = $services.model.resolveDocument($appDoc.fullName)) | ||
| 115 | #set($canViewApp = $services.security.authorization.hasAccess('view', $currentUserRef, $appDocRef)) | ||
| 116 | #if(!$canViewApp) | ||
| 117 | #set($inputError = $services.localization.render("awm.statistics.error.appNotViewable")) | ||
| 118 | #end | ||
| 119 | #end | ||
| 120 | #if(!$inputError) | ||
| 121 | #if($safeClassName && $safeClassName!="") | ||
| 122 | #set($className = $safeClassName) | ||
| 123 | #else | ||
| 124 | #set($className = $!appDoc.getValue("class")) | ||
| 125 | #end | ||
| 126 | #end | ||
| 127 | #if(!$inputError) | ||
| 128 | #if(!$className || $className=="") | ||
| 129 | #set($inputError = $services.localization.render("awm.statistics.error.invalidClass")) | ||
| 130 | #else | ||
| 131 | #set($classDocRef = $services.model.resolveDocument($className)) | ||
| 132 | #set($canViewClass = $services.security.authorization.hasAccess('view', $currentUserRef, $classDocRef)) | ||
| 133 | #if(!$canViewClass) | ||
| 134 | #set($inputError = $services.localization.render("awm.statistics.error.classNotViewable")) | ||
| 135 | #else | ||
| 136 | #set($classDoc = $xwiki.getDocument($className).getxWikiClass()) | ||
| 137 | #if(!$classDoc) | ||
| 138 | #set($inputError = $services.localization.render("awm.statistics.error.invalidClass")) | ||
| 139 | #end | ||
| 140 | #end | ||
| 141 | #end | ||
| 142 | #end | ||
| 143 | #end | ||
| 144 | #if(!$inputError && $safeProperty && $safeProperty!="" && $classDoc) | ||
| 145 | #set($propertyIsAllowed = false) | ||
| 146 | #foreach($prop in $classDoc.getProperties()) | ||
| 147 | #if($safeProperty == $prop.name) | ||
| 148 | #set($propertyIsAllowed = true) | ||
| 149 | #end | ||
| 150 | #end | ||
| 151 | #if(!$propertyIsAllowed) | ||
| 152 | #set($inputError = $services.localization.render("awm.statistics.error.invalidProperty")) | ||
| 153 | #end | ||
| 154 | #end | ||
| 155 | #if($inputError && $inputError!="") | ||
| 156 | {{error}}$inputError{{/error}} | ||
| 157 | #end | ||
| 158 | #if($hasSourceSelection && $classDoc) | ||
| 159 | |||
| 160 | {{html}} | ||
| 161 | <form action=""> | ||
| 162 | <table> | ||
| 163 | <tbody> | ||
| 164 | <tr> | ||
| 165 | <th> | ||
| 166 | $services.localization.render("awm.statistics.field") | ||
| 167 | </th> | ||
| 168 | <td> | ||
| 169 | <select name="property"> | ||
| 170 | #foreach($prop in $classDoc.getProperties()) | ||
| 171 | <option value="${escapetool.xml($prop.name)}" #if($safeProperty==$prop.name)selected#end>${escapetool.xml($prop.prettyName)}</option> | ||
| 172 | #end | ||
| 173 | </select> | ||
| 174 | </td></tr> | ||
| 175 | <tr> | ||
| 176 | <th> | ||
| 177 | $services.localization.render("awm.statistics.type") | ||
| 178 | </th> | ||
| 179 | <td> | ||
| 180 | <select name="type"> | ||
| 181 | <option value="pie" #if($safeType=="pie")selected#end>$services.localization.render("awm.statistics.type.pie")</option> | ||
| 182 | <option value="bar" #if($safeType=="bar")selected#end>$services.localization.render("awm.statistics.type.bar") | ||
| 183 | </option> | ||
| 184 | <option value="bar3D" #if($safeType=="bar3D")selected#end>$services.localization.render("awm.statistics.type.bar3D") | ||
| 185 | </option> | ||
| 186 | <option value="line" #if($safeType=="line")selected#end>$services.localization.render("awm.statistics.type.line") | ||
| 187 | </option> | ||
| 188 | </select></td></tr> | ||
| 189 | <tr> | ||
| 190 | <th>$services.localization.render("awm.statistics.function")</th> | ||
| 191 | <td><input type="text" size="40" name="function" value="$!{escapetool.xml($!safeFunction)}" /></td> | ||
| 192 | </tr> | ||
| 193 | <tr> | ||
| 194 | <th>$services.localization.render("awm.statistics.aggregate")</th> | ||
| 195 | <td><input type="text" size="40" name="aggregate" value="$!{escapetool.xml($!safeAggregate)}" /></td> | ||
| 196 | </tr> | ||
| 197 | <tr> | ||
| 198 | <th>$services.localization.render("awm.statistics.aggregateFunction")</th> | ||
| 199 | <td><input type="text" size="40" name="aggregateFunction" value="$!{escapetool.xml($!safeAggregateFunction)}" /></td> | ||
| 200 | </tr> | ||
| 201 | <tr> | ||
| 202 | <th></th> | ||
| 203 | <td> | ||
| 204 | #if($safeAppName) | ||
| 205 | <input name="appname" type="hidden" value="${escapetool.xml($safeAppName)}" /> | ||
| 206 | #end | ||
| 207 | #if($safeClassName) | ||
| 208 | <input name="className" type="hidden" value="${escapetool.xml($safeClassName)}" /> | ||
| 209 | #end | ||
| 210 | <input type="submit" value="$services.localization.render("awm.statistics.continue")" class="button" /> | ||
| 211 | </td> | ||
| 212 | </tr> | ||
| 213 | </tbody> | ||
| 214 | </table> | ||
| 215 | </form> | ||
| 216 | {{/html}} | ||
| 217 | |||
| 218 | #if($safeProperty && $safeProperty!="" && !$inputError) | ||
| 219 | |||
| 220 | {{awmchart type="${safeType}" #if($safeAppName)app="${appDoc.space}"#end #if($safeClassName)className="${className}"#end category="${safeProperty}" #if($safeFunction && $safeFunction!="")function="$!{safeFunction}"#end #if($safeAggregate && $safeAggregate!="")aggregate="$!{safeAggregate}"#end #if($safeAggregateFunction && $safeAggregateFunction!="")aggregateFunction="$!{safeAggregateFunction}"#end #if($safeOrderDirection && $safeOrderDirection!="")orderDirection="${safeOrderDirection}"#end /}} | ||
| 221 | |||
| 222 | $services.localization.render("awm.statistics.insert") | ||
| 223 | {{{ | ||
| 224 | |||
| 225 | {{awmchart type="${safeType}" #if($safeAppName)app="${appDoc.space}"#end #if($safeClassName)className="${className}"#end category="${safeProperty}" #if($safeFunction && $safeFunction!="")function="$!{safeFunction}"#end #if($safeAggregate && $safeAggregate!="")aggregate="$!{safeAggregate}"#end #if($safeAggregateFunction && $safeAggregateFunction!="")aggregateFunction="$!{safeAggregateFunction}"#end #if($safeOrderDirection && $safeOrderDirection!="")orderDirection="${safeOrderDirection}"#end /}} | ||
| 226 | |||
| 227 | }}} | ||
| 228 | #end | ||
| 229 | #elseif($request.showClasses) | ||
| 230 | #set($list = $xwiki.classList) | ||
| 231 | |||
| 232 | {{html}} | ||
| 233 | <form action=""> | ||
| 234 | $services.localization.render("awm.statistics.chooseclass") <select name="className"> | ||
| 235 | #foreach($className in $list) | ||
| 236 | #set($classDocRef = $services.model.resolveDocument($className)) | ||
| 237 | #if($services.security.authorization.hasAccess('view', $currentUserRef, $classDocRef)) | ||
| 238 | <option value="${escapetool.xml($className)}">${escapetool.xml($className)}</option> | ||
| 239 | #end | ||
| 240 | #end | ||
| 241 | </select> | ||
| 242 | <input type="submit" value="$services.localization.render("awm.statistics.continue")" class="button" /> | ||
| 243 | </form> | ||
| 244 | {{/html}} | ||
| 245 | |||
| 246 | #else | ||
| 247 | #set($list = $services.query.xwql("from doc.object(AppWithinMinutes.LiveTableClass) as obj order by doc.title").execute()) | ||
| 248 | |||
| 249 | {{html}} | ||
| 250 | <form action=""> | ||
| 251 | $services.localization.render("awm.statistics.chooseapp") <select name="appname"> | ||
| 252 | #foreach($appname in $list) | ||
| 253 | #set($appDocRef = $services.model.resolveDocument($appname)) | ||
| 254 | #if($services.security.authorization.hasAccess('view', $currentUserRef, $appDocRef)) | ||
| 255 | #set($optionLabel = $xwiki.getDocument($appname).getDisplayTitle()) | ||
| 256 | <option value="${escapetool.xml($appname)}">${escapetool.xml($optionLabel)}</option> | ||
| 257 | #end | ||
| 258 | #end | ||
| 259 | </select> | ||
| 260 | <input type="submit" value="$services.localization.render("awm.statistics.continue")" class="button" /> | ||
| 261 | </form> | ||
| 262 | {{/html}} | ||
| 263 | |||
| 264 | [[$services.localization.render("awm.statistics.showclasses")>>||queryString="showClasses=1"]] | ||
| 265 | #end | ||
| 266 | {{/velocity}} |