Wiki source code of GitLabConfigSheet
Last modified by René Vögeli on 2026/01/23 08:43
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{velocity output="false"}} |
| 2 | #if($request.action=="compare") | ||
| 3 | #template('diff_macros.vm') | ||
| 4 | #end | ||
| 5 | |||
| 6 | #macro(displayProperty $object $propertyName) | ||
| 7 | #set($tooltip = $object.xWikiClass.get($propertyName).propertyClass.getTooltip($xcontext.context)) | ||
| 8 | <dt> | ||
| 9 | <label#if ($xcontext.action == 'edit') for="${object.xWikiClass.name}_${object.number}_${propertyName}"#end>$escapetool.xml($doc.displayPrettyName($propertyName, false, false))</label> | ||
| 10 | #if ("$!tooltip" != '')<span class="xHint">$escapetool.xml($tooltip)</span>#end | ||
| 11 | </dt> | ||
| 12 | <dd>{{/html}}${doc.display($propertyName, $object)}{{html clean="false"}}</dd> | ||
| 13 | #end | ||
| 14 | {{/velocity}} | ||
| 15 | |||
| 16 | {{velocity}} | ||
| 17 | #if ("$!request.action" == "compare") | ||
| 18 | = $services.localization.render('gitlab.configsheet.compare.title'): $request.page = | ||
| 19 | #elseif($request.action) | ||
| 20 | = $services.localization.render('gitlab.configsheet.title'): $doc.documentReference.name = | ||
| 21 | #end | ||
| 22 | |||
| 23 | #if(!$xwiki.hasProgrammingRights()) | ||
| 24 | #warning("This application cannot work without programming rights on the current page. Resave this page as an admin and retry.") | ||
| 25 | #else | ||
| 26 | #set($configLoaded = "") | ||
| 27 | #if(!$request.action) | ||
| 28 | #set($configObj = $doc.getObject('GitLab.Code.GitLabConfigClass')) | ||
| 29 | #set($authObj = $doc.getObject("GitLab.Code.GitLabAuthClass", "contextuser", $xcontext.user)) | ||
| 30 | #if(!$authObj) | ||
| 31 | #set($authObj = $doc.newObject("GitLab.Code.GitLabAuthClass")) | ||
| 32 | #if($xcontext.action == 'edit') | ||
| 33 | #set($discard = $doc.use($authObj)) | ||
| 34 | #set($discard = $doc.set('contextuser', $xcontext.user)) | ||
| 35 | #set($discard = $doc.use("GitLab.Code.GitLabConfigClass")) | ||
| 36 | #set($discard = $doc.save()) | ||
| 37 | #end | ||
| 38 | #end | ||
| 39 | {{html clean="false"}} | ||
| 40 | <div class="xform"> | ||
| 41 | <h3>$escapetool.xml($services.localization.render('gitlab.configsheet.header.projectConfig'))</h3> | ||
| 42 | <div class="row"> | ||
| 43 | <div class="col-md-8"> | ||
| 44 | <dl> | ||
| 45 | #displayProperty($configObj, 'name') | ||
| 46 | #displayProperty($configObj, 'description') | ||
| 47 | </dl> | ||
| 48 | </div> | ||
| 49 | <div class="col-md-4"> | ||
| 50 | <dl> | ||
| 51 | #displayProperty($configObj, 'version') | ||
| 52 | #displayProperty($configObj, 'contribVersion') | ||
| 53 | #displayProperty($configObj, 'xarXmlVersion') | ||
| 54 | </dl> | ||
| 55 | </div> | ||
| 56 | </div> | ||
| 57 | <h3>$escapetool.xml($services.localization.render('gitlab.configsheet.header.repositoryConfig'))</h3> | ||
| 58 | <div class="row"> | ||
| 59 | <div class="col-md-8"> | ||
| 60 | <dl> | ||
| 61 | #displayProperty($configObj, 'repository_user') | ||
| 62 | #displayProperty($configObj, 'repository_name') | ||
| 63 | #displayProperty($configObj, 'repository_path') | ||
| 64 | #displayProperty($configObj, 'repository_branch') | ||
| 65 | </dl> | ||
| 66 | </div> | ||
| 67 | <div class="col-md-4"> | ||
| 68 | <dl> | ||
| 69 | #displayProperty($configObj, 'gitlab_url') | ||
| 70 | #if ($xcontext.action == 'edit') | ||
| 71 | #displayProperty($authObj, 'token') | ||
| 72 | ##set($discard = $doc.use($authObj)) | ||
| 73 | ##set($discard = $doc.set('contextuser', $xcontext.user)) | ||
| 74 | {{/html}} | ||
| 75 | $authObj.display('contextuser', 'hidden') | ||
| 76 | {{html clean="false"}} | ||
| 77 | #end | ||
| 78 | </dl> | ||
| 79 | </div> | ||
| 80 | </div> | ||
| 81 | <h3>$escapetool.xml($services.localization.render('gitlab.configsheet.header.commitConfig'))</h3> | ||
| 82 | <div class="row"> | ||
| 83 | <div class="col-md-8"> | ||
| 84 | <dl> | ||
| 85 | #displayProperty($configObj, 'defaultspace') | ||
| 86 | #displayProperty($configObj, 'defaultuser') | ||
| 87 | #displayProperty($configObj, 'license') | ||
| 88 | #displayProperty($configObj, 'parentDefinitionStrategy') | ||
| 89 | #displayProperty($configObj, 'defaultLanguageDefinitionStrategy') | ||
| 90 | </dl> | ||
| 91 | </div> | ||
| 92 | <div class="col-md-4"> | ||
| 93 | <dl> | ||
| 94 | #displayProperty($configObj, 'removeDates') | ||
| 95 | #displayProperty($configObj, 'defaultdate') | ||
| 96 | </dl> | ||
| 97 | </div> | ||
| 98 | </div> | ||
| 99 | </div> | ||
| 100 | {{/html}} | ||
| 101 | #else | ||
| 102 | #set($gitlabgroovy = $xwiki.parseGroovyFromPage("GitLab.Code.GitLabGroovy","GitLab.Code.GitLabGroovy")) | ||
| 103 | #set($ok = $gitlabgroovy.setXWiki($xwiki, $xcontext, $services)) | ||
| 104 | #if(!$gitlabgroovy.hasProgrammingRights()) | ||
| 105 | #warning("This application cannot work without programming rights on [[GitLab.Code.GitLabGroovy]]. Resave this page as an admin and retry.") | ||
| 106 | #end | ||
| 107 | #set($configLoaded = $gitlabgroovy.setGitLabConfig($doc.fullName)) | ||
| 108 | #if($request.spaces) | ||
| 109 | #set($spaces = $request.spaces) | ||
| 110 | #set($savedlist = "") | ||
| 111 | #else | ||
| 112 | #set($savedlist = $gitlabgroovy.getSavedList()) | ||
| 113 | #set($spaces = $gitlabgroovy.getDefaultSpace()) | ||
| 114 | #end | ||
| 115 | #end | ||
| 116 | #if($configLoaded!="") | ||
| 117 | ## it was not possible to connect to gitlab | ||
| 118 | $configLoaded | ||
| 119 | #else | ||
| 120 | ## CUSTOM action | ||
| 121 | #if($request.action=="custom") | ||
| 122 | {{html wiki=true clean=false}} | ||
| 123 | <form action="" method="get"> | ||
| 124 | <input type="hidden" name="action" value="list" /> | ||
| 125 | $services.localization.render('gitlab.configsheet.custom.spacelist'): <input type="text" name="spaces" value="" /><input type="submit" value="$services.localization.render('gitlab.configsheet.listpages')" /> | ||
| 126 | </form> | ||
| 127 | <form action="" method="get"> | ||
| 128 | <input type="hidden" name="action" value="list" /> | ||
| 129 | $services.localization.render('gitlab.configsheet.custom.space'): <select name="spaces"> | ||
| 130 | #foreach($space in $xwiki.spaces) | ||
| 131 | <option value="$space">$space</option> | ||
| 132 | #end | ||
| 133 | </select> | ||
| 134 | <input type="submit" value="$services.localization.render('gitlab.configsheet.listpages')" /> | ||
| 135 | </form> | ||
| 136 | {{/html}} | ||
| 137 | ## LIST ACTION | ||
| 138 | #elseif($request.action=="list") | ||
| 139 | #macro(displayEntry $status) | ||
| 140 | <tr> | ||
| 141 | <td width="20px" align="center" style="line-height: 1;border: none;"> | ||
| 142 | <input type="checkbox" name="page" value="${status.fullname}.$!{status.language}" /> | ||
| 143 | </td> | ||
| 144 | <td width="20px" align="center" style="line-height: 1;border: none;"> | ||
| 145 | <span class="label label-default">$status.status</span> | ||
| 146 | </td> | ||
| 147 | <td valign="middle" style="line-height: 1;border: none;"> | ||
| 148 | <a href="$xwiki.getURL($status.fullname, 'view', "language=${status.language}")" target="_blank">${page}</a> | ||
| 149 | </td> | ||
| 150 | #if($status.status!="N") | ||
| 151 | <td width="125px" align="center" style="line-height: 1;border: none;"> | ||
| 152 | <div class="btn-group" style="margin-top:0px; margin-bottom:0px"> | ||
| 153 | <a class="btn btn-xs btn-default" title="$services.localization.render('gitlab.configsheet.viewdiff')" href="$xwiki.getURL($doc,'view',"action=compare&page=${status.fullname}&gitlablanguage=${status.language}&spaces=$!{spaces}&filePath=${status.filePath}")" role="button" rel="nofollow" target="_blank"> | ||
| 154 | <span class="fa fa-not-equal"></span> | ||
| 155 | <span class="btn-label">$services.localization.render('gitlab.configsheet.viewdiff')</span> | ||
| 156 | </a> | ||
| 157 | <button type="button" class="btn btn-xs btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
| 158 | <span class="caret"></span> | ||
| 159 | <span class="sr-only">Toggle dropdown</span> | ||
| 160 | </button> | ||
| 161 | <ul class="dropdown-menu dropdown-menu-right"> | ||
| 162 | <li> | ||
| 163 | <a title="$services.localization.render('gitlab.configsheet.viewdiffunformatted')" href="$xwiki.getURL($doc,'view',"action=compare&page=${status.fullname}&gitlablanguage=${status.language}&spaces=$!{spaces}&filePath=${status.filePath}&unformatted=1")" rel="nofollow" target="_blank"> | ||
| 164 | <span class="fa fa-not-equal"></span> $services.localization.render('gitlab.configsheet.viewdiffunformatted') | ||
| 165 | </a> | ||
| 166 | </li> | ||
| 167 | </ul> | ||
| 168 | </div> | ||
| 169 | </td> | ||
| 170 | #else | ||
| 171 | <td></td> | ||
| 172 | #end | ||
| 173 | #end | ||
| 174 | #macro(listActions) | ||
| 175 | <input class="btn btn-primary" type="submit" name="commit" value="$services.localization.render('gitlab.configsheet.commitall')" /> <input class="btn btn-warning" type="submit" name="update" value="$services.localization.render('gitlab.configsheet.updateall')" /> <input class="btn btn-default" type="submit" name="export" value="$services.localization.render('gitlab.configsheet.exportall')" /> | ||
| 176 | #end | ||
| 177 | #macro(showQuickSelect) | ||
| 178 | $xwiki.jsx.use('GitLab.Code.GitLabConfigSheet') | ||
| 179 | $services.localization.render('gitlab.configsheet.select') <a href="#" class="selectAll">$services.localization.render('gitlab.configsheet.select.all')</a> / <a href="#" class="deselectAll">$services.localization.render('gitlab.configsheet.select.none')</a> | ||
| 180 | #end | ||
| 181 | |||
| 182 | {{html wiki=true clean=false}} | ||
| 183 | <form action="$doc.documentReference.name" method="post"> | ||
| 184 | <input type="hidden" name="action" value="commit" /> | ||
| 185 | <input type="hidden" name="spaces" value="$!{spaces}" /> | ||
| 186 | #listActions() | ||
| 187 | <table cellpadding="0" cellspacing="0" border="0" style="margin-bottom: 0px; margin-top: 20px;"> | ||
| 188 | <tr> | ||
| 189 | <th width="10%">#showQuickSelect()</th> | ||
| 190 | <th width="20%"></th> | ||
| 191 | <th style="font-family: sans-serif;"><strong>Updated documents</strong></th> | ||
| 192 | <th width="15%"></th> | ||
| 193 | </tr> | ||
| 194 | #set($cmap = $!gitlabgroovy.getChangedPages($spaces, $savedlist)) | ||
| 195 | #foreach($page in $cmap.keySet()) | ||
| 196 | #set($status = $cmap.get($page)) | ||
| 197 | #if($status.status!='N' && $status.status!='A' && $status.status!='F') | ||
| 198 | #displayEntry($status) | ||
| 199 | #end | ||
| 200 | #end | ||
| 201 | </table> | ||
| 202 | <table cellpadding="0" cellspacing="0" border="0" style="margin-bottom: 0px"> | ||
| 203 | <tr> | ||
| 204 | <th width="10%">#showQuickSelect()</th> | ||
| 205 | <th width="20%"></th> | ||
| 206 | <th style="font-family: sans-serif;"><strong>New documents</strong></th> | ||
| 207 | <th width="15%"></th> | ||
| 208 | </tr> | ||
| 209 | #foreach($page in $cmap.keySet()) | ||
| 210 | #set($status = $cmap.get($page)) | ||
| 211 | #if($status.status=='N' || $status.status=='A') | ||
| 212 | #displayEntry($status) | ||
| 213 | #end | ||
| 214 | #end | ||
| 215 | </table> | ||
| 216 | <table cellpadding="0" cellspacing="0" border="0"> | ||
| 217 | <tr> | ||
| 218 | <th width="10%">#showQuickSelect()</th> | ||
| 219 | <th width="20%"></th> | ||
| 220 | <th style="font-family: sans-serif;"><strong>Minor format changes</strong></th> | ||
| 221 | <th width="15%"></th> | ||
| 222 | </tr> | ||
| 223 | #foreach($page in $cmap.keySet()) | ||
| 224 | #set($status = $cmap.get($page)) | ||
| 225 | #if($status.status=='F') | ||
| 226 | #displayEntry($status) | ||
| 227 | #end | ||
| 228 | #end | ||
| 229 | </table> | ||
| 230 | #listActions() | ||
| 231 | </form> | ||
| 232 | {{/html}} | ||
| 233 | #elseif($request.export) | ||
| 234 | #set($pagelist = $xwiki.arrayList) | ||
| 235 | #foreach($page in $request.getParameterValues("page")) | ||
| 236 | #set($ok = $pagelist.add($page)) | ||
| 237 | #end | ||
| 238 | $gitlabgroovy.exportPages($doc.documentReference.name, $pagelist) | ||
| 239 | #set($ok = $xcontext.setFinished(true)) | ||
| 240 | #elseif($request.update) | ||
| 241 | #set($pagelist = $xwiki.arrayList) | ||
| 242 | #foreach($page in $request.getParameterValues("page")) | ||
| 243 | #set($ok = $pagelist.add({ "page" : $page, "sha" : $request.get("${page}_sha")})) | ||
| 244 | #end | ||
| 245 | #set($list = $gitlabgroovy.updatePages($pagelist,$spaces)) | ||
| 246 | |||
| 247 | $services.localization.render('gitlab.configsheet.pagesupdated') | ||
| 248 | |||
| 249 | #foreach($page in $list.keySet()) | ||
| 250 | * $page | ||
| 251 | #end | ||
| 252 | |||
| 253 | [[$services.localization.render('gitlab.configsheet.backtolist')>>${doc.fullName}?action=list]] - [[$services.localization.render('gitlab.configsheet.backtocustom')>>${doc.fullName}?action=custom]] | ||
| 254 | |||
| 255 | ## COMMIT ACTION with confirm | ||
| 256 | #elseif($request.action=="commit" && $request.confirm=="1") | ||
| 257 | $services.localization.render('gitlab.configsheet.committingpages'): | ||
| 258 | |||
| 259 | #set($pagelist = $xwiki.arrayList) | ||
| 260 | #foreach($page in $request.getParameterValues("page")) | ||
| 261 | * $page | ||
| 262 | #set($ok = $pagelist.add($page)) | ||
| 263 | #end | ||
| 264 | |||
| 265 | $gitlabgroovy.commitFiles($pagelist, $request.message, $!request.pom) | ||
| 266 | |||
| 267 | $services.localization.render('gitlab.configsheet.committsuccessfull') | ||
| 268 | |||
| 269 | |||
| 270 | [[$services.localization.render('gitlab.configsheet.backtolist')>>${doc.fullName}?action=list]] - [[$services.localization.render('gitlab.configsheet.backtocustom')>>${doc.fullName}?action=custom]] | ||
| 271 | |||
| 272 | ## COMMIT ACTION before confirm | ||
| 273 | #elseif($request.action=="commit") | ||
| 274 | ## confirm commit | ||
| 275 | $services.localization.render('gitlab.configsheet.confirmcommittingpage') | ||
| 276 | |||
| 277 | {{html wiki=true}} | ||
| 278 | <form action="$doc.documentReference.name" method="post"> | ||
| 279 | <input type="hidden" name="action" value="commit" /> | ||
| 280 | <input type="hidden" name="confirm" value="1" /> | ||
| 281 | <input type="hidden" name="spaces" value="$!{spaces}" /> | ||
| 282 | ## just pass the pages to commit further | ||
| 283 | #foreach($page in $request.getParameterValues("page")) | ||
| 284 | * $page | ||
| 285 | <input type="hidden" name="page" value="$!{page}" /> | ||
| 286 | #end | ||
| 287 | |||
| 288 | $services.localization.render('gitlab.configsheet.commitmessage'): | ||
| 289 | <br /> | ||
| 290 | <textarea name="message" rows="5" cols="80"> | ||
| 291 | </textarea> | ||
| 292 | <br /> | ||
| 293 | <input type="checkbox" name="pom" value="1" /> $services.localization.render('gitlab.configsheet.commitpom') | ||
| 294 | <br /> | ||
| 295 | <input type="submit" value="Commit" /> | ||
| 296 | </form> | ||
| 297 | {{/html}} | ||
| 298 | ## VIEW STATUS ACTION | ||
| 299 | #elseif($request.action=="status") | ||
| 300 | |||
| 301 | $gitlabgroovy.getCommitStatus("|", "|", false) | ||
| 302 | |||
| 303 | ## VIEW STATUS ACTION | ||
| 304 | #elseif($request.action=="compare") | ||
| 305 | #set($pagedoc = $xwiki.getDocument($request.page)) | ||
| 306 | #if($request.gitlablanguage) | ||
| 307 | #set($pagedoc = $pagedoc.getTranslatedDocument($request.gitlablanguage)) | ||
| 308 | #end | ||
| 309 | #if("1"=="$!{request.unformatted}") | ||
| 310 | #set ($xmls = $gitlabgroovy.getXMLForDiff($pagedoc, $request.filePath, false)) | ||
| 311 | #else | ||
| 312 | #set ($xmls = $gitlabgroovy.getXMLForDiff($pagedoc, $request.filePath, true)) | ||
| 313 | #end | ||
| 314 | |||
| 315 | {{html clean="false"}} | ||
| 316 | #unifiedDiff($xmls[0] $xmls[1]) | ||
| 317 | {{/html}} | ||
| 318 | #elseif($request.action=="compare") | ||
| 319 | {{html clean=false}} | ||
| 320 | <style type="text/css"> | ||
| 321 | .diffremoveword { | ||
| 322 | background-color: #FFAAAA; | ||
| 323 | } | ||
| 324 | .diffaddword { | ||
| 325 | background-color: #AAFFAA; | ||
| 326 | } | ||
| 327 | </style> | ||
| 328 | #set($pagedoc = $xwiki.getDocument($request.page)) | ||
| 329 | #if($request.gitlablanguage) | ||
| 330 | #set($pagedoc = $pagedoc.getTranslatedDocument($request.gitlablanguage)) | ||
| 331 | #end | ||
| 332 | #if("1"=="$!{request.unformatted}") | ||
| 333 | $gitlabgroovy.showXMLDiff($pagedoc, $request.filePath, false) | ||
| 334 | #else | ||
| 335 | $gitlabgroovy.showXMLDiff($pagedoc, $request.filePath, true) | ||
| 336 | #end | ||
| 337 | {{/html}} | ||
| 338 | |||
| 339 | ## OTHER ACTION | ||
| 340 | #else | ||
| 341 | |||
| 342 | [[$services.localization.render('gitlab.configsheet.listpages')>>${doc.fullName}?action=list]] - [[$services.localization.render('gitlab.configsheet.customlist')>>${doc.fullName}?action=custom]] | ||
| 343 | #end | ||
| 344 | |||
| 345 | #end ## end set config failed | ||
| 346 | #end ## Programming right check | ||
| 347 | {{/velocity}} |