View | Details | Raw Unified | Return to bug 31666
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/job_progress.inc (+5 lines)
Line 0 Link Here
1
<div class="progress">
2
    <div id="progress-bar-[% job_id %]" class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:100%">
3
        <span id="job-percent-[% job_id %]">0</span>% <span id="job-status-[% job_id %]"></span>
4
    </div>
5
</div>
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/str/job_progess.inc (+7 lines)
Line 0 Link Here
1
<!-- str/job_progess.inc -->
2
<script>
3
    var JOB_PROGRESS_NOT_STARTED = _("Not started");
4
    var JOB_PROGRESS_STARTED     = _("Started");
5
    var JOB_PROGRESS_FINISHED    = _("Finished");
6
    var JOB_PROGRESS_FAILED      = _("Failed");
7
</script>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/stage-marc-import.tt (-4 / +5 lines)
Lines 74-79 Link Here
74
            <h1>MARC staging</h1>
74
            <h1>MARC staging</h1>
75
            <div class="dialog message">
75
            <div class="dialog message">
76
              <p>The job has been enqueued! It will be processed as soon as possible.</p>
76
              <p>The job has been enqueued! It will be processed as soon as possible.</p>
77
               [% INCLUDE "job_progress.inc" job_id=job_id %]
77
              <p><a class="job_details" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job_id | uri %]" title="View detail of the enqueued job">View detail of the enqueued job</a>
78
              <p><a class="job_details" href="/cgi-bin/koha/admin/background_jobs.pl?op=view&id=[% job_id | uri %]" title="View detail of the enqueued job">View detail of the enqueued job</a>
78
            </div>
79
            </div>
79
        [% ELSE %]
80
        [% ELSE %]
Lines 258-263 Link Here
258
    [% Asset.js("js/tools-menu.js") | $raw %]
259
    [% Asset.js("js/tools-menu.js") | $raw %]
259
    [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
260
    [% Asset.js("lib/jquery/plugins/humanmsg.js") | $raw %]
260
    [% Asset.js("js/file-upload.js") | $raw %]
261
    [% Asset.js("js/file-upload.js") | $raw %]
262
263
    [% INCLUDE 'str/job_progess.inc' job_id=job_id %]
264
    [% Asset.js("js/job_progess.js") | $raw %]
261
    <script>
265
    <script>
262
        var xhr;
266
        var xhr;
263
        var PROFILE_SAVE_MSG = _("Profile saved");
267
        var PROFILE_SAVE_MSG = _("Profile saved");
Lines 422-431 Link Here
422
                })
426
                })
423
            });
427
            });
424
            [% IF job_enqueued %]
428
            [% IF job_enqueued %]
425
                setTimeout(
429
                updateProgress([% job_id %]);
426
                    function() { window.location.href=$('a.job_details').attr('href'); },
427
                    5000, // 5 secs to read
428
                );
429
            [% END %]
430
            [% END %]
430
        });
431
        });
431
432
(-)a/koha-tmpl/intranet-tmpl/prog/js/job_progess.js (-1 / +34 lines)
Line 0 Link Here
0
- 
1
function updateProgress(job_id) {
2
    $.getJSON('/api/v1/jobs/' + job_id, function(job){
3
        let recheck = true;
4
5
        if ( job.status == "new" ) {
6
            $(`#job-percent-${job_id}`).text(0);
7
            $(`#job-status-${job_id}`).text(JOB_PROGRESS_NOT_STARTED);
8
            $(`#progress-bar-${job_id}`).attr('aria-valuenow', 0).css("width", "100%");
9
        } else if ( job.status == "started" ) {
10
            const progress = job["progress"];
11
            const size = job["size"];
12
            const percent = progress > 0 ? ( progress / size ) * 100 : 0;
13
            $(`#job-percent-${job_id}`).text(percent.toFixed(2));
14
            $(`#job-status-${job_id}`).text(JOB_PROGRESS_STARTED);
15
            $(`#progress-bar-${job_id}`).attr('aria-valuenow', percent).css("width", `${percent}%`);
16
        } else if ( job.status == "finished" ) {
17
            $(`#job-percent-${job_id}`).text(100);
18
            $(`#job-status-${job_id}`).text(JOB_PROGRESS_FINISHED);
19
            $(`#progress-bar-${job_id}`).addClass("progress-bar-success");
20
            $(`#progress-bar-${job_id}`).attr('aria-valuenow', 100).css("width", "100%");
21
            recheck = false;
22
        } else if ( job.status == "failed" ) {
23
            $(`#job-percent-${job_id}`).text(0);
24
            $(`#job-status-${job_id}`).text(JOB_PROGRESS_FAILED);
25
            $(`#progress-bar-${job_id}`).addClass("progress-bar-danger");
26
            $(`#progress-bar-${job_id}`).attr('aria-valuenow', 0).css("width", "100%");
27
            recheck = false;
28
        }
29
30
        if ( recheck ) {
31
            setTimeout(function(){updateProgress(job_id)}, 1 * 1000);
32
        }
33
    });
34
}

Return to bug 31666