Activated button
This commit is contained in:
parent
9b36474e48
commit
9da7c66f89
|
@ -2,6 +2,7 @@ import 'bootstrap';
|
|||
|
||||
$(function() {
|
||||
initDeleteButtons();
|
||||
initRunNowButtons();
|
||||
})
|
||||
|
||||
function initDeleteButtons() {
|
||||
|
@ -20,4 +21,29 @@ function initDeleteButtons() {
|
|||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function initRunNowButtons() {
|
||||
$('.runnow').on('click', function() {
|
||||
let me = $(this)
|
||||
let href = me.data('href');
|
||||
$.ajax({
|
||||
url: href,
|
||||
method: 'GET',
|
||||
success: function(data) {
|
||||
let modal = $('#runnow_result');
|
||||
modal.find('.modal-title').html(data.title);
|
||||
if (data.status == 'deferred') {
|
||||
modal.find('.modal-body').html(data.message);
|
||||
} else if (data.status == 'ran') {
|
||||
let content = '<p>Cronjob ran in ' + data.runtime + 'seconds with exit code ' + data.exitcode +'</p>'
|
||||
content += '<pre>' + data.output + '</pre>'
|
||||
|
||||
modal.find('.modal-body').html(content);
|
||||
}
|
||||
|
||||
modal.modal({show: true})
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
|
@ -133,11 +133,11 @@ class Job extends Repository
|
|||
}
|
||||
if($job['data']['hosttype'] == 'local') {
|
||||
$return = $this->runLocalCommand($command);
|
||||
$return['failed'] = !in_array($return['exitcode'], $job['data']['http-status']);
|
||||
$return['failed'] = !in_array($return['exitcode'], $job['data']['response']);
|
||||
return $return;
|
||||
} elseif($job['data']['hosttype'] == 'ssh') {
|
||||
$return = $this->runSshCommand($command, $job['data']['host'], $job['data']['user'], $job['data']['ssh-privkey'], $job['data']['privkey-password']);
|
||||
$return['failed'] = !in_array($return['exitcode'], $job['data']['http-status']);
|
||||
$return['failed'] = !in_array($return['exitcode'], $job['data']['response']);
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@ -235,19 +235,20 @@ class Job extends Repository
|
|||
public function runNow($job) {
|
||||
$job = $this->getJob($job, true);
|
||||
$runRepo = new Run($this->dbcon);
|
||||
|
||||
if($runRepo->isSlowJob($job['id']) && $job['data']['crontype'] !== 'reboot') {
|
||||
if($runRepo->isSlowJob($job['id']) || $job['data']['crontype'] === 'reboot') {
|
||||
$jobsSql = "UPDATE job SET running = :status WHERE id = :id AND running IN (0,1,2)";
|
||||
$jobsStmt = $this->dbcon->prepare($jobsSql);
|
||||
$jobsStmt->executeQuery([':id' => $job['id'], ':status' => 2]);
|
||||
return ['success' => true, 'message' => 'Job was scheduled to be run. You will find the output soon in the job details'];
|
||||
return ['success' => true, 'status' => 'deferred', 'title' => 'Cronjob has been scheduled', 'message' => 'Job was scheduled to be run. You will find the output soon in the job details'];
|
||||
} else {
|
||||
$this->runJob($job['id'], true);
|
||||
$output = $runRepo->getLastRun($job['id']);
|
||||
return [
|
||||
'status' => 'ran',
|
||||
'output' => $output['output'],
|
||||
'exitcode' => $output['exitcode'],
|
||||
'runtime' => $output['runtime'],
|
||||
'title' => !str_contains($output['flags'], Run::FAILED) ? 'Cronjob successfully ran' : 'Cronjob failed. Please check output below',
|
||||
'success' => !str_contains($output['flags'], Run::FAILED)
|
||||
];
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
<td class="d-block d-md-table-cell">{{ job.interval | interval }}</td>
|
||||
<td class="d-block d-md-table-cell">{{ job.nextrun | date("d/m/Y H:i:s") }}</td>
|
||||
<td class="text-md-right d-block d-md-table-cell">
|
||||
<a href="#" data-id="{{ job.id }}" class="runcron btn btn-outline-primary"><i class="fa fa-play" aria-hidden="true"></i></a>
|
||||
<a href="#" data-href="{{ path('job_runnow', {'id': job.id}) }}" class="runnow btn btn-outline-primary"><i class="fa fa-play" aria-hidden="true"></i></a>
|
||||
<a href="{{ path('job_view', {'id': job.id}) }}" class="btn btn-outline-primary"><i class="fa fa-search" aria-hidden="true"></i></a>
|
||||
<a href="{{ path('job_edit', {'id': job.id}) }}" class="btn btn-outline-primary"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
|
||||
<a href="#" data-confirmation="Are you sure you want to delete this job?" data-href="{{ path('job_delete', {'id': job.id}) }}" class="delete-btn btn btn-outline-primary"><i class="fa fa-trash-o" aria-hidden="true"></i></a>
|
||||
|
@ -30,20 +30,23 @@
|
|||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<div id="resultmodal" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 class="modal-title" id="resulttitle"> </h4>
|
||||
</div>
|
||||
<div class="modal-body"><p id="resultbody"> </p></div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="runnow_result" data-backdrop="static" data-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-scrollable">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="staticBackdropLabel"></h5>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-outline-primary" data-dismiss="modal">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id='ajax_loader' style="position: fixed; left: 50%; top: 50%; display: none;">
|
||||
<img src="/public/images/ajax-loader.gif" alt="loading">
|
||||
|
|
Loading…
Reference in New Issue