chg: [UI] Correctly handle progress for jobs

pull/7204/head
Jakub Onderka 2021-03-14 22:45:59 +01:00
parent a09db135b7
commit fa77fa4eb6
2 changed files with 19 additions and 13 deletions

View File

@ -75,17 +75,19 @@ class JobsController extends AppController
public function getGenerateCorrelationProgress($id)
{
$progress = $this->Job->find('first', [
'fields' => ['progress'],
$job = $this->Job->find('first', [
'fields' => ['progress', 'process_id'],
'conditions' => ['id' => $id],
'recursive' => -1,
]);
if (!$progress) {
$progress = 0;
} else {
$progress = (int)$progress['Job']['progress'];
if (!$job) {
throw new NotFoundException("Job with ID `$id` not found");
}
return $this->RestResponse->viewData($progress, 'json');
$output = [
'job_status' => $this->__jobStatusConverter(CakeResque::getJobStatus($job['Job']['process_id'])),
'progress' => (int)$job['Job']['progress'],
];
return $this->RestResponse->viewData($output, 'json');
}
public function getProgress($type)

View File

@ -35,12 +35,15 @@
if (!document.hidden) {
$.getJSON('<?php echo $baseurl; ?>/jobs/getGenerateCorrelationProgress/' + id, function(data) {
var x = document.getElementById("bar" + id);
x.style.width = data+"%";
if (data > 0 && data < 100) {
x.innerHTML = data + "%";
}
if (data == 100) {
x.innerHTML = "<?php echo __('Completed.');?>";
if (data.progress == 0) {
x.innerText = data.job_status;
} else if (data.progress > 0 && data.progress < 100) {
x.style.width = data.progress + "%";
x.innerText = data.progress + "%";
} else if (data.progress == 100) {
x.style.width = "100%";
x.innerText = "<?php echo __('Completed.');?>";
x.parentElement.className = "progress";
clearInterval(intervalArray[k]);
}
});
@ -118,6 +121,7 @@
} else if ($item['Job']['progress'] == 0) {
$progress_bar_type = 'progress progress-striped progress-queued active';
$progress_message = $item['Job']['job_status'] === 'Running' ? __('Running') : __('Queued');
$startRefreshing = true;
} else {
$progress = h($item['Job']['progress']);
if ($item['Job']['progress'] == 100) {