mirror of https://github.com/MISP/MISP
chg: [UI] Correctly handle progress for jobs
parent
a09db135b7
commit
fa77fa4eb6
|
@ -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)
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue