mirror of
https://github.com/wavelog/wavelog.git
synced 2026-03-22 10:24:14 +00:00
code formatting and removing some comments
This commit is contained in:
@@ -1,8 +1,5 @@
|
||||
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
// TODO
|
||||
// Add 'add' / 'edit' functions to be able to add/edit the crons in the cron manager view
|
||||
|
||||
class cron extends CI_Controller {
|
||||
function __construct() {
|
||||
|
||||
@@ -88,26 +85,16 @@ class cron extends CI_Controller {
|
||||
|
||||
if ($crun !== false) {
|
||||
echo "CRON: " . $cron->id . " -> CURL Result: " . $crun . "\n";
|
||||
|
||||
$status = 'healthy';
|
||||
|
||||
// TODO Proper testing if '!== false' is enough for all functions.
|
||||
// TODO Make Curl Result available in Cron Manager view?
|
||||
|
||||
} else {
|
||||
echo "ERROR: Something went wrong with " . $cron->id . "\n";
|
||||
|
||||
$status = 'failed';
|
||||
|
||||
// TODO Add a flag or some kind of warning for the cron manager view?
|
||||
|
||||
}
|
||||
} else {
|
||||
$isdue_result = 'false';
|
||||
echo "CRON: " . $cron->id . " -> is due: " . $isdue_result . " -> Next Run: " . $next_run_date . "\n";
|
||||
$status = 'healthy';
|
||||
}
|
||||
|
||||
} else {
|
||||
echo 'CRON: ' . $cron->id . " is disabled. skipped..\n";
|
||||
$status = 'disabled';
|
||||
@@ -116,7 +103,6 @@ class cron extends CI_Controller {
|
||||
$this->cron_model->set_next_run($cron->id, null);
|
||||
}
|
||||
$this->cron_model->set_status($cron->id, $status);
|
||||
|
||||
$this->cronexpression = null;
|
||||
}
|
||||
}
|
||||
@@ -138,10 +124,10 @@ class cron extends CI_Controller {
|
||||
redirect('dashboard');
|
||||
}
|
||||
|
||||
$id = xss_clean($this->input->post('cron_id',true));
|
||||
$description = xss_clean($this->input->post('cron_description',true));
|
||||
$expression = xss_clean($this->input->post('cron_expression',true));
|
||||
$enabled = xss_clean($this->input->post('cron_enabled',true));
|
||||
$id = xss_clean($this->input->post('cron_id', true));
|
||||
$description = xss_clean($this->input->post('cron_description', true));
|
||||
$expression = xss_clean($this->input->post('cron_expression', true));
|
||||
$enabled = xss_clean($this->input->post('cron_enabled', true));
|
||||
|
||||
$data = array(
|
||||
'expression' => $expression,
|
||||
@@ -155,34 +141,33 @@ class cron extends CI_Controller {
|
||||
$this->cronexpression = null;
|
||||
|
||||
header("Content-type: application/json");
|
||||
echo json_encode(['success' => true, 'messagecategory' => 'success', 'message' => 'Changes saved for Cronjob "'.$id.'"']);
|
||||
|
||||
echo json_encode(['success' => true, 'messagecategory' => 'success', 'message' => 'Changes saved for Cronjob "' . $id . '"']);
|
||||
} else {
|
||||
$this->session->set_flashdata('error', 'The Cron Expression you entered is not valid');
|
||||
$this->cronexpression = null;
|
||||
|
||||
header("Content-type: application/json");
|
||||
echo json_encode(['success' => false, 'messagecategory' => 'error', 'message' => 'The expression "'.$expression.'" is not valid. Please try again.']);
|
||||
echo json_encode(['success' => false, 'messagecategory' => 'error', 'message' => 'The expression "' . $expression . '" is not valid. Please try again.']);
|
||||
}
|
||||
}
|
||||
|
||||
public function toogleEnableCronSwitch() {
|
||||
|
||||
$id = xss_clean($this->input->post('id',true));
|
||||
$cron_enabled = xss_clean($this->input->post('checked',true));
|
||||
$id = xss_clean($this->input->post('id', true));
|
||||
$cron_enabled = xss_clean($this->input->post('checked', true));
|
||||
|
||||
if ($id ?? '' != '') {
|
||||
$this->cron_model->set_cron_enabled($id, $cron_enabled);
|
||||
$data['success']=1;
|
||||
$this->cron_model->set_cron_enabled($id, $cron_enabled);
|
||||
$data['success'] = 1;
|
||||
} else {
|
||||
$data['success']=0;
|
||||
$data['flashdata']='Not allowed';
|
||||
$data['success'] = 0;
|
||||
$data['flashdata'] = 'Not allowed';
|
||||
}
|
||||
echo json_encode($data);
|
||||
}
|
||||
|
||||
public function fetchCrons() {
|
||||
$hres=[];
|
||||
$hres = [];
|
||||
$result = $this->cron_model->get_crons();
|
||||
|
||||
foreach ($result as $cron) {
|
||||
@@ -196,16 +181,16 @@ class cron extends CI_Controller {
|
||||
$single->cron_edit = $this->cronEdit2html($cron->id);
|
||||
$single->cron_enabled = $this->cronEnabled2html($cron->id, $cron->enabled);
|
||||
array_push($hres, $single);
|
||||
}
|
||||
}
|
||||
echo json_encode($hres);
|
||||
}
|
||||
|
||||
private function cronStatus2html($enabled, $status) {
|
||||
if ($enabled == '1') {
|
||||
if ($enabled == '1') {
|
||||
if ($status == 'healthy') {
|
||||
$htmlret = '<span class="badge text-bg-success">healthy</span>';
|
||||
} else {
|
||||
$htmlret = '<span class="badge text-bg-warning">'.$status.'</span>';
|
||||
$htmlret = '<span class="badge text-bg-warning">' . $status . '</span>';
|
||||
}
|
||||
} else {
|
||||
$htmlret = '<span class="badge text-bg-secondary">disabled</span>';
|
||||
@@ -214,12 +199,12 @@ class cron extends CI_Controller {
|
||||
}
|
||||
|
||||
private function cronExpression2html($expression) {
|
||||
$htmlret = '<code id="humanreadable_tooltip" data-bs-toggle="tooltip">'.$expression.'</code>';
|
||||
$htmlret = '<code id="humanreadable_tooltip" data-bs-toggle="tooltip">' . $expression . '</code>';
|
||||
return $htmlret;
|
||||
}
|
||||
|
||||
private function cronEdit2html($id) {
|
||||
$htmlret = '<button id="'.$id.'" class="editCron btn btn-outline-primary btn-sm"><i class="fas fa-edit"></i></button>';
|
||||
$htmlret = '<button id="' . $id . '" class="editCron btn btn-outline-primary btn-sm"><i class="fas fa-edit"></i></button>';
|
||||
return $htmlret;
|
||||
}
|
||||
|
||||
@@ -229,7 +214,7 @@ class cron extends CI_Controller {
|
||||
} else {
|
||||
$checked = '';
|
||||
}
|
||||
$htmlret = '<div class="form-check form-switch"><input name="cron_enable_switch" class="form-check-input enableCronSwitch" type="checkbox" role="switch" id="'.$id.'" '.$checked.'></div>';
|
||||
$htmlret = '<div class="form-check form-switch"><input name="cron_enable_switch" class="form-check-input enableCronSwitch" type="checkbox" role="switch" id="' . $id . '" ' . $checked . '></div>';
|
||||
return $htmlret;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,9 +66,7 @@
|
||||
} ?></td>
|
||||
<td style="vertical-align: middle;"><button id="<?php echo $cron->id; ?>" class="editCron btn btn-outline-primary btn-sm"><i class="fas fa-edit"></i></button></td>
|
||||
<td style="vertical-align: middle;">
|
||||
<div class="form-check form-switch"><input name="cron_enable_switch" class="form-check-input enableCronSwitch" type="checkbox" role="switch" id="<?php echo $cron->id; ?>" <?php if ($cron->enabled ?? '0') {
|
||||
echo 'checked';
|
||||
} ?>></div>
|
||||
<div class="form-check form-switch"><input name="cron_enable_switch" class="form-check-input enableCronSwitch" type="checkbox" role="switch" id="<?php echo $cron->id; ?>" <?php if ($cron->enabled ?? '0') { echo 'checked'; } ?>></div>
|
||||
</td>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
|
||||
@@ -31,62 +31,62 @@ function init_expression_tooltips() {
|
||||
}
|
||||
|
||||
function init_datatable() {
|
||||
$('.crontable').DataTable({
|
||||
"pageLength": 25,
|
||||
responsive: true,
|
||||
ordering: true,
|
||||
"scrollY": "600px",
|
||||
"scrollCollapse": true,
|
||||
"paging": false,
|
||||
"scrollX": true,
|
||||
"autoWidth": false,
|
||||
"language": {
|
||||
url: getDataTablesLanguageUrl(),
|
||||
},
|
||||
$('.crontable').DataTable({
|
||||
"pageLength": 25,
|
||||
responsive: true,
|
||||
ordering: true,
|
||||
"scrollY": "600px",
|
||||
"scrollCollapse": true,
|
||||
"paging": false,
|
||||
"scrollX": true,
|
||||
"autoWidth": false,
|
||||
"language": {
|
||||
url: getDataTablesLanguageUrl(),
|
||||
},
|
||||
dom: 'Bfrtip',
|
||||
buttons: [
|
||||
{
|
||||
text: 'Refresh',
|
||||
action: function (e, dt, node, config) {
|
||||
reloadCrons();
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
buttons: [
|
||||
{
|
||||
text: 'Refresh',
|
||||
action: function (e, dt, node, config) {
|
||||
reloadCrons();
|
||||
}
|
||||
}
|
||||
]
|
||||
});
|
||||
init_expression_tooltips();
|
||||
}
|
||||
|
||||
function modalEventListener() {
|
||||
$('#edit_cron_expression_custom').on('input change',function(e){
|
||||
$('#edit_cron_expression_custom').on('input change', function (e) {
|
||||
humanReadableInEditDialog()
|
||||
});
|
||||
|
||||
$('#edit_cron_expression_dropdown').change(function() {
|
||||
$('#edit_cron_expression_dropdown').change(function () {
|
||||
humanReadableInEditDialog()
|
||||
});
|
||||
}
|
||||
|
||||
function displayMessages(category, message) {
|
||||
var html_class;
|
||||
var message_area = $('#cron_message_area');
|
||||
var html_class;
|
||||
var message_area = $('#cron_message_area');
|
||||
|
||||
if (category == 'success') {
|
||||
html_class = 'alert alert-success';
|
||||
} else if (category == 'warning') {
|
||||
html_class = 'alert alert-warning';
|
||||
} else if (category == 'error') {
|
||||
html_class = 'alert alert-danger';
|
||||
} else {
|
||||
html_class = 'alert alert-info';
|
||||
}
|
||||
if (category == 'success') {
|
||||
html_class = 'alert alert-success';
|
||||
} else if (category == 'warning') {
|
||||
html_class = 'alert alert-warning';
|
||||
} else if (category == 'error') {
|
||||
html_class = 'alert alert-danger';
|
||||
} else {
|
||||
html_class = 'alert alert-info';
|
||||
}
|
||||
|
||||
message_area.show();
|
||||
message_area.addClass(html_class);
|
||||
message_area.text(message);
|
||||
message_area.show();
|
||||
message_area.addClass(html_class);
|
||||
message_area.text(message);
|
||||
|
||||
setTimeout(function() {
|
||||
message_area.fadeOut();
|
||||
}, 7000);
|
||||
setTimeout(function () {
|
||||
message_area.fadeOut();
|
||||
}, 7000);
|
||||
}
|
||||
|
||||
function editCronDialog(e) {
|
||||
@@ -115,9 +115,9 @@ function editCronDialog(e) {
|
||||
|
||||
function editCron() {
|
||||
var $cron_id = $('#edit_cron_id').val();
|
||||
var $cron_description = $('#edit_cron_description').val();
|
||||
var $cron_expression = $('#edit_cron_expression_custom').val();
|
||||
var $cron_enabled = $('#edit_' + $cron_id).is(':checked') ? 'true' : 'false';
|
||||
var $cron_description = $('#edit_cron_description').val();
|
||||
var $cron_expression = $('#edit_cron_expression_custom').val();
|
||||
var $cron_enabled = $('#edit_' + $cron_id).is(':checked') ? 'true' : 'false';
|
||||
|
||||
$.ajax({
|
||||
url: base_url + 'index.php/cron/edit',
|
||||
@@ -128,46 +128,46 @@ function editCron() {
|
||||
cron_expression: $cron_expression,
|
||||
cron_enabled: $cron_enabled
|
||||
},
|
||||
success: function(response) {
|
||||
success: function (response) {
|
||||
if (response.success) {
|
||||
reloadCrons();
|
||||
displayMessages(response.messagecategory,response.message);
|
||||
displayMessages(response.messagecategory, response.message);
|
||||
} else {
|
||||
displayMessages(response.messagecategory,response.message);
|
||||
displayMessages(response.messagecategory, response.message);
|
||||
}
|
||||
},
|
||||
error: function(response) {
|
||||
displayMessages('error','The query failed for a unknown reason');
|
||||
error: function (response) {
|
||||
displayMessages('error', 'The query failed for a unknown reason');
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
function humanReadableInEditDialog() {
|
||||
var exp_inputID = $('#edit_cron_expression_custom');
|
||||
var exp_dropdownID = $('#edit_cron_expression_dropdown');
|
||||
var exp_humanreadableID = $('#exp_humanreadable');
|
||||
var humanReadable = '';
|
||||
var exp_inputID = $('#edit_cron_expression_custom');
|
||||
var exp_dropdownID = $('#edit_cron_expression_dropdown');
|
||||
var exp_humanreadableID = $('#exp_humanreadable');
|
||||
var humanReadable = '';
|
||||
|
||||
exp_inputID.on('input', function() {
|
||||
exp_dropdownID.val('');
|
||||
});
|
||||
exp_inputID.on('input', function () {
|
||||
exp_dropdownID.val('');
|
||||
});
|
||||
|
||||
if (exp_dropdownID.val() == '') {
|
||||
exp_humanreadableID.show();
|
||||
if (exp_dropdownID.val() == '') {
|
||||
exp_humanreadableID.show();
|
||||
|
||||
try {
|
||||
humanReadable = cronstrue.toString(exp_inputID.val());
|
||||
} catch (error) {
|
||||
humanReadable = 'waiting for complete expression...';
|
||||
}
|
||||
try {
|
||||
humanReadable = cronstrue.toString(exp_inputID.val());
|
||||
} catch (error) {
|
||||
humanReadable = 'waiting for complete expression...';
|
||||
}
|
||||
|
||||
exp_humanreadableID.text(humanReadable);
|
||||
} else {
|
||||
exp_humanreadableID.hide();
|
||||
exp_humanreadableID.text(humanReadable);
|
||||
} else {
|
||||
exp_humanreadableID.hide();
|
||||
|
||||
exp_inputID.val(exp_dropdownID.val());
|
||||
}
|
||||
exp_inputID.val(exp_dropdownID.val());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user