Skip to content

Commit

Permalink
Javascript cleaning
Browse files Browse the repository at this point in the history
Add sunnywalker/filterTable
Fix bugs on log tab
Css improvements
  • Loading branch information
vpietri committed Jun 19, 2015
1 parent 0fe1cc2 commit a274ecc
Show file tree
Hide file tree
Showing 27 changed files with 592 additions and 168 deletions.
29 changes: 23 additions & 6 deletions Block/Tab/DefaultTab.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public function getId()
return ($this->getData('id')) ? $this->getData('id') : $this->getNameInLayout();
}

public function getClass()
{
return str_replace('.', '-', $this->getId());
}

public function isAjax()
{
return (($this->hasData('ajax_url') || $this->hasData('is_ajax'))? "true" : "false");
Expand All @@ -37,14 +42,26 @@ public function getTabUrl()
}
}

public function getHtmlLoader()
public function getHtmlBigLoader()
{
$html = '<div id="loading-mask">';
$html .= '<p class="loader" id="loading_mask_loader">';
$html .= '<img src="' . $this->getViewFileUrl('images/loader-1.gif') .'">';
$html .= '<br/>'.__('Please wait. Content is loading.');
$html .= '</p></div>';
return $this->getHtmlLoader($this->getViewFileUrl('images/loader-1.gif'), 'big');
}


public function getHtmlSmallLoader()
{
return $this->getHtmlLoader($this->getViewFileUrl('images/loader-2.gif'), 'small', false);
}

public function getHtmlLoader($imgSrc, $class, $showText = true)
{
$html = '<div class="qdn-loading-mask ' . $class . '">';
$html .= $showText ? '<p>' . __('Please wait.') . '</p>' : '';
$html .= '<img src="' . $imgSrc .'">';
$html .= $showText ? '<p>' . __('Content is loading ...') . '</p>' : '';
$html .= '</div>';

return $html;
}

}
4 changes: 2 additions & 2 deletions Block/Tab/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getTitle()

public function getTailLines()
{
return 30;
return 20;
}

public function getLogFiles()
Expand All @@ -46,7 +46,7 @@ public function getLogFiles()

public function getJsonLogFiles()
{
return $this->_jsonHelper->jsonEncode($this->getLogFiles());
return $this->_jsonHelper->jsonEncode($this->_qdbHelper->getLogFiles());
}

public function getLogContent($file)
Expand Down
3 changes: 3 additions & 0 deletions Controller/AjaxBlock.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class AjaxBlock extends Index
*/
protected $_layoutFactory;

protected $_qdbHelper;

/**
* @param \Magento\Backend\App\Action\Context $context
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
Expand All @@ -25,6 +27,7 @@ public function __construct(
\Magento\Framework\View\LayoutFactory $layoutFactory
) {
parent::__construct($context, $qdnHelper);
$this->_qdbHelper = $qdnHelper;
$this->_resultRawFactory = $resultRawFactory;
$this->_layoutFactory = $layoutFactory;
}
Expand Down
24 changes: 15 additions & 9 deletions Controller/Log/Reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,25 @@ class Reset extends \ADM\QuickDevBar\Controller\AjaxBlock
*/
public function execute()
{
$logKey = $this->getRequest()->getParam('log_key', '');
$this->_view->loadLayout();
$fileKey = $this->getRequest()->getParam('log_key', '');
$output = '';

$logFiles = $this->_qdnHelper->getLogFiles();
if($logKey and !empty($logFiles[$logKey])) {
$filePath = BP . $logFiles[$logKey];
if(file_exists($filePath)) {
unlink($filePath);
$file = $this->_qdbHelper->getLogFiles($fileKey);
if ($file) {
if(!empty($file['is_empty'])) {
if (!unlink($file['is_empty'])) {
$output = 'Cannot reset file.';
} else {
$output = 'File empty.';
}
} else {
$output = 'Cannot find file to reset.';
}
} else {
$output = $file['path'];
}

$output = '';

$this->_view->loadLayout();
$resultRaw = $this->_resultRawFactory->create();
return $resultRaw->setContents($output);
}
Expand Down
11 changes: 9 additions & 2 deletions Controller/Log/View.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ class View extends \ADM\QuickDevBar\Controller\AjaxBlock
*/
public function execute()
{
$fileName = $this->getRequest()->getParam('file', '');
$fileKey = $this->getRequest()->getParam('log_key', '');
$lines = $this->getRequest()->getParam('tail', 20);
$file = $this->_qdbHelper->getLogFiles($fileKey);
if ($file) {
$output = $this->_qdbHelper->tailFile($file['path'], $lines);
} else {
$output = __('No log file.');
}

$this->_view->loadLayout();
$output = $fileName;

$resultRaw = $this->_resultRawFactory->create();
return $resultRaw->setContents($output);
Expand Down
43 changes: 41 additions & 2 deletions Helper/Data.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper

protected $_httpHeader;

protected $_defaultLogFiles = array('exception'=>'exception.log', 'system'=>'system.log', 'debug'=>'debug.log');

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
*/
Expand Down Expand Up @@ -54,12 +56,49 @@ public function isToolbarAccessAllowed()
}


public function getLogFiles()
public function getLogFiles($key=false)
{
$logFiles = array();
foreach ($this->_defaultLogFiles as $fileKey=>$fileName) {
$filepath = BP . '/var/log/' . $fileName;
$logFiles[$fileKey] = array('id'=>$fileName
, 'name' => $fileName
, 'path' => $filepath
, 'reset' => $this->_canResetFile($filepath)
, 'size' => $this->_getFileSize($filepath)
);
}

if (!$key) {
return $logFiles;
} elseif (!empty($logFiles[$key])) {
return $logFiles[$key];
} else {
return false;
}
}

protected function _canResetFile($filepath)
{
if (is_file($filepath) and is_writable($filepath)) {
return true;
} else {
return false;
}
}

protected function _getFileSize($filepath)
{
return array('system'=>'system.log', 'exception'=>'exception.log', 'debug'=>'debug.log');

if (is_file($filepath) and file_exists($filepath)) {
return filesize($filepath);
} else {
return 0;
}
}



/**
*
* Cut an paste from Hackathon_MageMonitoring_Helper_Data::tailFile
Expand Down
2 changes: 1 addition & 1 deletion composer.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vpietri/adm-quickdevbar",
"description": "QuickDevBar is a developer toolbar for magento 2",
"type": "magento2-module",
"version": "0.0.1",
"version": "0.1.1",
"minimum-stability": "beta",
"extra": {
"map": [
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<label>Developer Client Restrictions</label>
<field id="toolbar_header" translate="label comment" type="text" sortOrder="25" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Header for Quick Dev Bar</label>
<frontend_type>text</frontend_type>
<!-- <frontend_type>text</frontend_type> -->
<!-- <backend_model>Magento\Developer\Model\Config\Backend\AllowedIps</backend_model> -->
<comment>You can define a specific pattern that will be check (with preg_match) in request headers to allow toolbar usage.</comment>
</field>
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="ADM_QuickDevBar" setup_version="0.0.1"/>
<module name="ADM_QuickDevBar" setup_version="0.1.1"/>
<!-- Sequence allow to control load order module -->
<sequence>
</sequence>
Expand Down
9 changes: 7 additions & 2 deletions view/frontend/layout/default.xml
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="admin-1column" xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
<update handle="quickdevbar" />
<head>
<link src="ADM_QuickDevBar::js/quickdevbar.js"/>
<css src="ADM_QuickDevBar::css/quickdevbar.css"/>
<css src="ADM_QuickDevBar::css/quickdevbar.css"/>
</head>
<body>
<referenceBlock name="head.components">
<block class="Magento\Framework\View\Element\Js\Components" name="customer_account_edit_head_components" template="ADM_QuickDevBar::js/components.phtml"/>
</referenceBlock>
</body>

</page>


8 changes: 8 additions & 0 deletions view/frontend/requirejs-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var config = {
map: {
'*': {
quickDevBar: 'ADM_QuickDevBar/js/quickdevbar',
filtertable: 'ADM_QuickDevBar/js/sunnywalker/jquery.filtertable.min'
}
}
};
4 changes: 4 additions & 0 deletions view/frontend/templates/js/components.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

?>
<?php echo $block->getChildHtml() ?>
13 changes: 9 additions & 4 deletions view/frontend/templates/tab/event.phtml
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
<p>
<?php echo __('List only events dispatched when Magento generate this page')?>
</p>

<table class="qdn_table">
<?php if($this->getEvents()):?>
<table class="qdn_table striped filterable">
<thead>
<tr>
<th>Event</th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach ($this->getEvents() as $event): ?>
<tr class="<?php echo ($i % 2 ? 'even' : 'odd')?>">
<tr style="border: 1px solid black">
<td><?php echo $event['event']; ?></td>
</tr>
<?php $i++; ?>
<?php endforeach ?>
</table>
</tbody>
</table>
<?php endif;?>
Loading

0 comments on commit a274ecc

Please sign in to comment.