Changes for page Job Progress Macro

Last modified by Drunk Monkey on 2023-04-26 18:21

From version 2.1
edited by Drunk Monkey
on 2022-11-14 09:13
Change comment: Install extension [org.xwiki.contrib:macro-job-ui/2.0]
To version 1.1
edited by Drunk Monkey
on 2022-11-01 08:21
Change comment: Install extension [org.xwiki.contrib:macro-job-ui/1.4]

Summary

Details

XWiki.WikiMacroClass[0]
Macro code
... ... @@ -1,7 +1,7 @@
1 1  {{template name="job_macros.vm"/}}
2 2  
3 3  {{velocity output="false"}}
4 -#set ($discard = $xwiki.jsfx.use('uicomponents/job/job.js', true))
4 +#set ($discard = $xwiki.jsx.use('JobMacro.JobProgressMacro'))
5 5  {{/velocity}}
6 6  
7 7  {{velocity}}
XWiki.JavaScriptExtension[0]
Caching policy
... ... @@ -1,0 +1,1 @@
1 +long
Code
... ... @@ -1,0 +1,69 @@
1 +require.config({
2 + paths: {
3 + JobRunner: "$!services.webjars.url('org.xwiki.platform:xwiki-platform-job-webjar', 'jobRunner.min')"
4 + }
5 +});
6 +
7 +require(['jquery', 'JobRunner'], function($, JobRunner) {
8 + 'use strict';
9 + var updateProgress = function(jobUI, job) {
10 + var percent = Math.floor((job.progress.offset || 0) * 100);
11 + jobUI.find('.ui-progress-bar').css('width', percent + '%');
12 + var jobLog = job.log.items || [];
13 + if (jobLog.size() > 0) {
14 + jobUI.find('.ui-progress-message').html(jobLog[jobLog.size() - 1].renderedMessage);
15 + }
16 + };
17 +
18 + var updateLog = function(jobUI, job) {
19 + var jobLog = job.log.items || [];
20 + var jobLogUI = jobUI.find('.log');
21 + if (job.log.offset === 0) {
22 + jobLogUI.html('');
23 + }
24 + jobLogUI.find('.log-item-loading').removeClass('log-item-loading');
25 + $.each(jobLog, function(index, item) {
26 + var classNames = ['log-item', 'log-item-' + item.level];
27 + if (job.state !== 'FINISHED' && index === jobLog.size() - 1) {
28 + classNames.push('log-item-loading');
29 + }
30 + $(document.createElement('li')).addClass(classNames.join(' ')).html(item.renderedMessage).appendTo(jobLogUI);
31 + })
32 + };
33 +
34 + var updateStatus = function(job) {
35 + var jobUI = $(this);
36 + updateProgress(jobUI, job);
37 + updateLog(jobUI, job);
38 + };
39 +
40 + var notifyJobDone = function(job) {
41 + var jobUI = $(this);
42 + jobUI.find('.ui-progress').replaceWith(job.message);
43 + jobUI.trigger('job:done', job);
44 + };
45 +
46 + var notifyConnectionFailure = function() {
47 + };
48 +
49 + $('.job-status').has('.ui-progress').each(function() {
50 + var jobStatus = $(this);
51 + var url = jobStatus.attr('data-url');
52 + if (url !== '') {
53 + var jobLog = jobStatus.find('.log');
54 + JobRunner({
55 + createStatusRequest: function() {
56 + return {
57 + url: url,
58 + data: {
59 + 'logOffset': jobLog.find('.log-item').size()
60 + }
61 + };
62 + }
63 + }).resume()
64 + .progress($.proxy(updateStatus, this))
65 + .done($.proxy(notifyJobDone, this))
66 + .fail($.proxy(notifyConnectionFailure, this));
67 + }
68 + });
69 +});
Name
... ... @@ -1,0 +1,1 @@
1 +job.js fixed
Parse content
... ... @@ -1,0 +1,1 @@
1 +Yes
Use this extension
... ... @@ -1,0 +1,1 @@
1 +currentPage