From 2d0211f137820f070b0a2403a1a714b1e8b96aa7 Mon Sep 17 00:00:00 2001 From: HB9HIL Date: Fri, 26 Apr 2024 18:58:38 +0200 Subject: [PATCH] code formatting and removing some comments --- application/controllers/Cron.php | 53 +++++------- application/views/cron/index.php | 4 +- assets/js/sections/cron.js | 136 +++++++++++++++---------------- 3 files changed, 88 insertions(+), 105 deletions(-) diff --git a/application/controllers/Cron.php b/application/controllers/Cron.php index 933e16328..74cb08693 100644 --- a/application/controllers/Cron.php +++ b/application/controllers/Cron.php @@ -1,8 +1,5 @@ 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 = 'healthy'; } else { - $htmlret = ''.$status.''; + $htmlret = '' . $status . ''; } } else { $htmlret = 'disabled'; @@ -214,12 +199,12 @@ class cron extends CI_Controller { } private function cronExpression2html($expression) { - $htmlret = ''.$expression.''; + $htmlret = '' . $expression . ''; return $htmlret; } private function cronEdit2html($id) { - $htmlret = ''; + $htmlret = ''; return $htmlret; } @@ -229,7 +214,7 @@ class cron extends CI_Controller { } else { $checked = ''; } - $htmlret = '
'; + $htmlret = '
'; return $htmlret; } } diff --git a/application/views/cron/index.php b/application/views/cron/index.php index f8910185a..e51d9c817 100644 --- a/application/views/cron/index.php +++ b/application/views/cron/index.php @@ -66,9 +66,7 @@ } ?> -
enabled ?? '0') { - echo 'checked'; - } ?>>
+
enabled ?? '0') { echo 'checked'; } ?>>
diff --git a/assets/js/sections/cron.js b/assets/js/sections/cron.js index 95152e0b9..3ce5d6ad4 100644 --- a/assets/js/sections/cron.js +++ b/assets/js/sections/cron.js @@ -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()); + } }