Wiki source code of $services.localization.render('xe.scheduler')
Version 2.1 by Mark Kohlmann on 2020/04/03 03:54
Hide last authors
author | version | line-number | content |
---|---|---|---|
![]() |
1.1 | 1 | {{velocity}} |
2 | ## First, set a shortcut to our Scheduler plugin | ||
3 | ## | ||
4 | #set ($scheduler = $xwiki.scheduler) | ||
5 | ## | ||
6 | ## If the sheet is called with an action ($request.do), let us first process this action | ||
7 | ## Possible values are : "schedule", "pause", "resume", "unschedule", "delete" | ||
8 | ## | ||
9 | #if ("$!request.do" != '' && "$!request.which" != '') | ||
10 | ## | ||
11 | ## Obtain the Job document and object for which the action has been called | ||
12 | ## | ||
13 | #set ($tJobHolder = $request.which) | ||
14 | #set ($jobDoc = $xwiki.getDocument($tJobHolder)) | ||
15 | #set ($jobObj = $jobDoc.getObject('XWiki.SchedulerJobClass')) | ||
16 | #if ($request.do == 'schedule') | ||
17 | ## | ||
18 | ## Schedule a job | ||
19 | ## | ||
20 | #set ($ok = $scheduler.scheduleJob($jobObj)) | ||
21 | #if (!$ok) | ||
22 | {{error}}$xcontext.get('error'){{/error}} | ||
23 | |||
24 | #else | ||
25 | #set ($jobName = "$jobObj.get('jobName')") | ||
26 | {{info}}$services.localization.render('xe.scheduler.jobscheduled', [$jobName, $scheduler.getNextFireTime($jobObj)]){{/info}} | ||
27 | |||
28 | #end | ||
29 | #elseif ($request.do == 'pause') | ||
30 | ## | ||
31 | ## Pause a scheduled job | ||
32 | ## | ||
33 | #set ($ok = $scheduler.pauseJob($jobObj)) | ||
34 | #if (!$ok) | ||
35 | {{error}}$xcontext.get('error'){{/error}} | ||
36 | |||
37 | #else | ||
38 | {{info}}$services.localization.render('xe.scheduler.paused', [$jobObj.get('jobName')]){{/info}} | ||
39 | |||
40 | #end | ||
41 | #elseif ($request.do == 'resume') | ||
42 | ## | ||
43 | ## Resume a paused job | ||
44 | ## | ||
45 | #set ($ok = $scheduler.resumeJob($jobObj)) | ||
46 | #if (!$ok) | ||
47 | {{error}}$xcontext.get('error'){{/error}} | ||
48 | |||
49 | #else | ||
50 | {{info}}$services.localization.render('xe.scheduler.resumed', [$jobObj.get('jobName'), $scheduler.getNextFireTime($jobObj)]){{/info}} | ||
51 | |||
52 | #end | ||
53 | #elseif ($request.do == 'unschedule') | ||
54 | ## | ||
55 | ## Unschedule a scheduled job (paused or not) | ||
56 | ## | ||
57 | #set ($ok = $scheduler.unscheduleJob($jobObj)) | ||
58 | #if (!$ok) | ||
59 | {{error}}$xcontext.get('error'){{/error}} | ||
60 | |||
61 | #else | ||
62 | {{info}}$services.localization.render('xe.scheduler.unscheduled', [$jobObj.get('jobName')]){{/info}} | ||
63 | |||
64 | #end | ||
65 | #elseif ($request.do == 'delete') | ||
66 | ## | ||
67 | ## Delete a job | ||
68 | ## First unschedule it (if needed), then delete its document holder | ||
69 | ## | ||
70 | #set ($jobName = $jobObj.get('jobName')) | ||
71 | #if ($jobObj.get('status') == 'Normal' || $jobObj.get('status') == 'Paused') | ||
72 | #set ($ok = $scheduler.unscheduleJob($jobObj)) | ||
73 | #if ($ok) | ||
74 | #set ($deleteRedirect = $xwiki.getURL($jobObj.getName(), 'delete')) | ||
75 | $response.sendRedirect($deleteRedirect) | ||
76 | #else | ||
77 | {{error}}$xcontext.get('error'){{/error}} | ||
78 | |||
79 | #end | ||
80 | #else | ||
81 | #set ($deleteRedirect = $xwiki.getURL($jobObj.getName(), 'delete')) | ||
82 | $response.sendRedirect($deleteRedirect)) | ||
83 | #end | ||
84 | #elseif ($request.do == 'trigger') | ||
85 | ## | ||
86 | ## Trigger a job (execute it now) | ||
87 | ## | ||
88 | #set ($ok = $scheduler.triggerJob($jobObj)) | ||
89 | #if (!$ok) | ||
90 | {{error}}$xcontext.get('error'){{/error}} | ||
91 | |||
92 | #else | ||
93 | {{info}}$services.localization.render('xe.scheduler.triggered', [$jobObj.get('jobName')]){{/info}} | ||
94 | |||
95 | #end | ||
96 | #end | ||
97 | #end | ||
98 | $services.localization.render('xe.scheduler.welcome') | ||
99 | |||
100 | = $services.localization.render('xe.scheduler.jobs.list') = | ||
101 | |||
102 | ## | ||
103 | ## Retrieve all scheduler jobs | ||
104 | ## Display their name, status, possible next fire time, and available actions | ||
105 | ## | ||
106 | |=(%scope="col"%)$services.localization.render('xe.scheduler.jobs.name')|=(%scope="col"%)$services.localization.render('xe.scheduler.jobs.status')|=(%scope="col"%)$services.localization.render('xe.scheduler.jobs.next')|=(%scope="col"%)$services.localization.render('xe.scheduler.jobs.actions') | ||
107 | #foreach ($docName in $services.query.xwql('from doc.object(XWiki.SchedulerJobClass) as jobs where doc.fullName <> ''XWiki.SchedulerJobTemplate''').execute()) | ||
108 | #set ($actions = {}) | ||
109 | #set ($jobHolder = $xwiki.getDocument($docName)) | ||
110 | #set ($job = $jobHolder.getObject('XWiki.SchedulerJobClass')) | ||
111 | #set ($status = $scheduler.getJobStatus($job).value) | ||
112 | #if ($status == '') | ||
113 | #set ($status = 'None') | ||
114 | #end | ||
115 | #set ($firetime = '') | ||
116 | #if ($status != 'None') | ||
117 | #set ($firetime = $scheduler.getNextFireTime($job)) | ||
118 | #else | ||
119 | #set ($firetime = $services.localization.render('xe.scheduler.jobs.next.undefined')) | ||
120 | #end | ||
121 | #set ($ok = $!actions.put('trigger', $doc.getURL('view', "do=trigger&which=${jobHolder.fullName}"))) | ||
122 | #if ($status == 'None') | ||
123 | #set ($ok = $!actions.put('schedule', $doc.getURL('view', "do=schedule&which=${jobHolder.fullName}"))) | ||
124 | #elseif($status == 'Normal') | ||
125 | #set ($ok = $!actions.put('pause', $doc.getURL('view', "do=pause&which=${jobHolder.fullName}"))) | ||
126 | #set ($ok = $!actions.put('unschedule', $doc.getURL('view', "do=unschedule&which=${jobHolder.fullName}"))) | ||
127 | #elseif ($status == 'Paused') | ||
128 | #set ($ok = $!actions.put('resume', $doc.getURL('view', "do=resume&which=${jobHolder.fullName}"))) | ||
129 | #set ($ok = $!actions.put('unschedule', $doc.getURL('view', "do=unschedule&which=${jobHolder.fullName}"))) | ||
130 | #end | ||
131 | #set ($ok = $!actions.put('delete', $doc.getURL('view', "do=delete&which=${jobHolder.fullName}"))) | ||
132 | |$job.get('jobName')|$status|$firetime|**$services.localization.render('xe.scheduler.jobs.actions.access')** [[$services.localization.render('xe.scheduler.jobs.actions.view')>>$jobHolder.fullName]]#if($jobHolder.hasAccessLevel('programming')) [[$services.localization.render('xe.scheduler.jobs.actions.edit')>>path:${jobHolder.getURL('edit')}]]#end **$services.localization.render('xe.scheduler.jobs.actions.manage')**#foreach($action in $actions.entrySet()) [[$services.localization.render("xe.scheduler.jobs.actions.${action.key}")>>path:${action.value}]]#end | ||
133 | |||
134 | #end | ||
135 | #if ($doc.hasAccessLevel('programming')) | ||
136 | ## | ||
137 | ## Job creation is offered only for programmers, because the job page needs to be saved | ||
138 | ## with programming right for groovy jobs to be executed. | ||
139 | ## However, this page should stay accessible to admins, that can manipulate existing jobs: | ||
140 | ## schedule, pause, etc. | ||
141 | ## | ||
142 | |||
143 | = $services.localization.render('xe.scheduler.jobs.create') = | ||
144 | |||
145 | ## | ||
146 | ## Form to create a new Job | ||
147 | ## | ||
148 | {{info}}$services.localization.render('xe.scheduler.jobs.explaincreate'){{/info}} | ||
149 | |||
150 | {{html}} | ||
![]() |
2.1 | 151 | <form action="$doc.getURL('create')" id="newdoc" class="form-inline"><div> |
![]() |
1.1 | 152 | <input type="hidden" name="form_token" value="$!{services.csrf.getToken()}" /> |
153 | <input type="hidden" name="parent" value="Scheduler.WebHome" /> | ||
154 | <input type="hidden" name="template" value="XWiki.SchedulerJobTemplate" /> | ||
155 | <input type="hidden" name="sheet" value="1" /> | ||
156 | <input type="hidden" name="space" value="Scheduler"/> | ||
157 | <label class="hidden" for="page">$services.localization.render('xe.scheduler.jobs.create.nameTip')</label> | ||
![]() |
2.1 | 158 | <input id="page" name="page" size="30" type="text" |
159 | value="$escapetool.xml($services.localization.render('xe.scheduler.jobs.create.nameTip'))" /> | ||
160 | <span class="buttonwrapper"> | ||
161 | <input type="submit" class="btn btn-success" | ||
162 | value="$escapetool.xml($services.localization.render('xe.scheduler.jobs.create.submit'))"/> | ||
163 | </span> | ||
![]() |
1.1 | 164 | </div></form> |
165 | {{/html}} | ||
166 | |||
167 | #else | ||
168 | |||
![]() |
2.1 | 169 | {{warning}}$services.localization.render('xe.scheduler.jobs.warning'){{/warning}} |
![]() |
1.1 | 170 | |
171 | #end | ||
172 | {{/velocity}} |