Skip to content

Commit

Permalink
refactor: adiciona filtro de log
Browse files Browse the repository at this point in the history
  • Loading branch information
valdeir2000 committed Aug 29, 2020
1 parent c5b064c commit 8e21361
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
30 changes: 30 additions & 0 deletions upload/admin/controller/extension/payment/pagseguro.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ class ControllerExtensionPaymentPagseguro extends Controller
*/
public function index()
{
if (!defined('PAGSEGURO_LOG')) {
define('PAGSEGURO_LOG', DIR_SYSTEM . '/library/PagSeguro/log');
}

$data = $this->load->language('extension/payment/pagseguro');

$this->document->setTitle($this->language->get('heading_title'));

$this->document->addScript('https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js');
$this->document->addScript('https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/js/bootstrap-datetimepicker.min.js');
$this->document->addStyle('https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.47/css/bootstrap-datetimepicker-standalone.min.css');

if ($this->request->server['REQUEST_METHOD'] == 'POST' && $this->validate()) {
$this->load->model('setting/setting');
Expand Down Expand Up @@ -87,6 +93,16 @@ public function index()
'name' => $this->config->get('config_name') . $this->language->get('text_default')
];

$logs = new DirectoryIterator(PAGSEGURO_LOG);

$data['logs_date'] = [];

foreach ($logs as $log) {
if ($log->isFile()) {
$data['logs_date'][] = preg_replace('/^(\d{4}-\d{2}-\d{2}).+/', '$1', $log->getFilename());
}
}

$data['action'] = $this->buildUrl('extension/payment/pagseguro');
$data['cancel'] = $this->buildUrl('marketplace/extension', [
'type' => 'payment'
Expand All @@ -99,6 +115,20 @@ public function index()
$this->response->setOutput($this->load->view('extension/payment/pagseguro', $data));
}

public function log()
{
if (!defined('PAGSEGURO_LOG')) {
define('PAGSEGURO_LOG', DIR_SYSTEM . '/library/PagSeguro/log');
}

$date = $this->request->get['date'] ?? null;

if ($date && file_exists(PAGSEGURO_LOG . "/{$date}.log")) {
$this->response->addHeader('Content-Type: text/html; charset=utf-8');
$this->response->setOutput(file_get_contents(PAGSEGURO_LOG . "/{$date}.log"));
}
}

/**
* Realiza a validação dos campos
*
Expand Down
33 changes: 32 additions & 1 deletion upload/admin/view/template/extension/payment/pagseguro.twig
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@
<div class="tab-pane" id="tab-debug">
<div class="row">
<div class="col-sm-3">
<input type="date" class="form-control" />
<input type="text" class="form-control" id="filter-log-date" />
</div>

<div class="col-sm-3">
Expand Down Expand Up @@ -619,11 +619,42 @@
$(floats.join(',')).mask("#.00", {reverse: true});
})
$(function() {
$('#filter-log-date').datetimepicker({
format: 'YYYY-MM-DD',
date: '{{ logs_date|last }}',
enabledDates: JSON.parse('{{ logs_date|json_encode }}'),
icons: {
previous: 'fa fa-arrow-left',
next: 'fa fa-arrow-right',
}
})
.on('dp.change', function(newDate, oldDate) {
loadLog(newDate.currentTarget.value)
})
loadLog('{{ logs_date|last }}')
})
function loadLog(date) {
fetch(`/admin/index.php?route=extension/payment/pagseguro/log&user_token=${getURLVar('user_token')}&date=${date}`)
.then(response => response.text())
.then(response => {
const code = document.querySelector('#tab-debug pre > code')
code.innerHTML = '';
code.insertAdjacentHTML('beforeEnd', response)
})
}
</script>

<style>
#debug-clear, #debug-download {
display: none
}
.day:not([disabled]) {
background: #337ab76b;
}
</style>
{{ footer }}

0 comments on commit 8e21361

Please sign in to comment.