Skip to content

Commit

Permalink
Add config list tab
Browse files Browse the repository at this point in the history
  • Loading branch information
vpietri committed Jul 28, 2016
1 parent c695655 commit c0e28db
Show file tree
Hide file tree
Showing 25 changed files with 302 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
namespace ADM\QuickDevBar\Block\System\Config\Form\Fieldset;
namespace ADM\QuickDevBar\Block\Adminhtml\System\Config\Form\Fieldset;

use Magento\Framework\Data\Form\Element\AbstractElement;

Expand Down
67 changes: 67 additions & 0 deletions Block/Tab/Content/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace ADM\QuickDevBar\Block\Tab\Content;

use Magento\Framework\App\ObjectManager;
use Magento\Framework\Interception\DefinitionInterface;


class Config extends \ADM\QuickDevBar\Block\Tab\Panel
{

protected $_config_values;

/**
* @var \Magento\Framework\App\Config\ScopePool
*/
protected $_scopePool;

public function __construct(\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\App\Config\ScopePool $scopePool,
array $data = [])
{
$this->_scopePool = $scopePool;

parent::__construct($context, $data);
}

public function getTitleBadge()
{
return count($this->getConfigValues());
}

public function getConfigValues()
{
if(is_null($this->_config_values)) {
$this->_config_values = [];
$scopePool = ObjectManager::getInstance()->get('Magento\Framework\App\Config\ScopePool');

$reflection = new \ReflectionClass($scopePool);

$scope = $reflection->getProperty('_scopes');
$scope->setAccessible(true);
$scope = $scope->getValue($scopePool);

$scope= current($scope);

$this->_config_values = $this->_buildFlatConfig($scope->getSource());
}

return $this->_config_values;
}

protected function _buildFlatConfig($scope, $path='')
{
$flatConfig = [];
if(is_array($scope)) {
foreach($scope as $scopeKey=>$scopeValue) {
$buildedPath = !empty($path) ? $path . '/' .$scopeKey : $scopeKey;
$flatConfig = array_merge($flatConfig, $this->_buildFlatConfig($scopeValue, $buildedPath));
}
} else {
$flatConfig[$path] = ['path'=>$path, 'value'=>$scope];
}
return $flatConfig;
}

}
29 changes: 29 additions & 0 deletions Block/Tab/Content/Help.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace ADM\QuickDevBar\Block\Tab\Content;

class Help extends \ADM\QuickDevBar\Block\Tab\Panel
{

protected $_qdbHelper;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Json\EncoderInterface $jsonEncoder
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\ADM\QuickDevBar\Helper\Data $qdbHelper,
array $data = []
) {
$this->_qdbHelper= $qdbHelper;

parent::__construct($context, $data);
}

public function getQuickDevBarVersion()
{
return __('Module: %1, version %2', $this->getModuleName(), $this->_qdbHelper->getModuleVersion($this->getModuleName()));
}
}
2 changes: 1 addition & 1 deletion Block/Tab/Content/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function getLogContent($file)

public function getUrlLog($action)
{
return $this->getUrl('quickdevbar/log/'. $action . '/');
return $this->getFrontUrl('quickdevbar/log/'. $action . '/');
}

}
4 changes: 2 additions & 2 deletions Block/Tab/Content/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getPluginsList()
* @see: Magento/Framework/Interception/PluginList/PluginList::_inheritPlugins($type)
*/
foreach($processed as $currentKey=>$processDef) {
if(preg_match('/^(.*)_(.*)___self$/', $currentKey, $matches)) {
if(preg_match('/^(.*)_(.*)___self$/', $currentKey, $matches) or preg_match('/^(.*?)_(.*?)_(.*)$/', $currentKey, $matches)) {
$type= $matches[1];
$method= $matches[2];
if(!empty($inherited[$type])) {
Expand All @@ -60,7 +60,7 @@ public function getPluginsList()

foreach($pluginsNames as $pluginName) {
if(!empty($inherited[$type][$pluginName])) {
$this->_types[] = ['type'=>$type, 'plugin'=>$inherited[$type][$pluginName]['instance'], 'sort_order'=> $inherited[$type][$pluginName]['sortOrder'], 'method'=>$types[$keyType].ucfirst($method)];
$this->_types[] = ['type'=>$type, 'plugin'=>$inherited[$type][$pluginName]['instance'], 'plugin_name'=>$pluginName, 'sort_order'=> $inherited[$type][$pluginName]['sortOrder'], 'method'=>$types[$keyType].ucfirst($method)];
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions Block/Tab/Content/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ public function getRequestData()
{
$request = $this->getRequest();


$requestData[] = ['name'=>'Base Url', 'value'=>$request->getDistroBaseUrl()];
$requestData[] = ['name'=>'Base Url', 'value'=>$request->getDistroBaseUrl(), 'is_url'=>true];
$requestData[] = ['name'=>'Path Info', 'value'=>$request->getPathInfo()];
$requestData[] = ['name'=>'Module Name', 'value'=>$request->getModuleName()];
$requestData[] = ['name'=>'Controller', 'value'=>$request->getControllerName()];
$requestData[] = ['name'=>'Action', 'value'=>$request->getActionName()];
$requestData[] = ['name'=>'Full Action', 'value'=>$request->getFullActionName()];
$requestData[] = ['name'=>'Route', 'value'=>$request->getRouteName()];
$requestData[] = ['name'=>'Area', 'value'=>$this->getArea()];


if ($request->getBeforeForwardInfo()) {
$requestData[] = ['name'=>'Before Forward', 'value'=>$request->getBeforeForwardInfo()];
Expand All @@ -54,17 +55,19 @@ public function getRequestData()
$requestData[] = ['name'=>'Magento', 'value'=>$this->_productMetadata->getVersion()];
$requestData[] = ['name'=>'Mage Mode', 'value'=>$this->_appState->getMode()];

$requestData[] = ['name'=>'Backend frontname', 'value'=>$request->getDistroBaseUrl() . $this->_frontNameResolver->getFrontName()];
$requestData[] = ['name'=>'Backend', 'value'=>$request->getDistroBaseUrl() . $this->_frontNameResolver->getFrontName(), 'is_url'=>true];


return $requestData;
}

public function formatValue($data) {
if(is_array($data)) {
return '<pre>' . print_r($data, true) . '</pre>';
if(is_array($data['value'])) {
return '<pre>' . print_r($data['value'], true) . '</pre>';
} elseif (!empty($data['is_url'])) {
return '<a href="' . $data['value'] . '">' . $data['value'] . '</a>';
} else {
return $data;
return $data['value'];
}
}

Expand Down
42 changes: 34 additions & 8 deletions Block/Tab/Panel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,30 @@

namespace ADM\QuickDevBar\Block\Tab;

use Magento\Framework\App\ObjectManager;

class Panel extends \Magento\Framework\View\Element\Template
{
protected $_frontUrl;

public function getTitle()
{
return ($this->getData('title')) ? $this->getData('title') : $this->getNameInLayout();
}

public function getId()
public function getId($prefix='')
{
return ($this->getData('id')) ? $this->getData('id') : $this->getNameInLayout();
$id = ($this->getData('id')) ? $this->getData('id') : $this->getNameInLayout();
$id = str_replace('.', '-', $id);
if($prefix) {
$id = $prefix . $id;
}
return $id;
}

public function getClass()
{
$class = str_replace('.', '-', $this->getId());
$class = $this->getId();
if ($this->isAjax(false)) {
$class .= ' use-ajax';
}
Expand All @@ -37,17 +45,35 @@ public function isAjax($asString=true)

public function getTabUrl()
{
$tabUrl = '#'.$this->getId();
if ($this->getData('tab_url')) {
return $this->getData('tab_url');
$tabUrl = $this->getData('tab_url');
} else {
if ($this->getData('ajax_url')) {
return $this->getUrl($this->getData('ajax_url'));
$tabUrl = $this->getFrontUrl($this->getData('ajax_url'));
} elseif ($this->getData('is_ajax')) {
return $this->getUrl('quickdevbar/tab/index', ['block'=>$this->getNameInLayout()]) . '?isAjax=1';
} else {
return '#'.$this->getId();
$tabUrl = $this->getFrontUrl('quickdevbar/tab/index', ['block'=>$this->getNameInLayout(), '_query'=>['isAjax'=>1]]);
}
}

return $tabUrl;
}


/**
* Generate url by route and parameters
*
* @param string $route
* @param array $params
* @return string
*/
public function getFrontUrl($route = '', $params = [])
{
if(is_null($this->_frontUrl)) {
$this->_frontUrl = ObjectManager::getInstance()->get('Magento\Framework\Url');
}

return $this->_frontUrl->getUrl($route, $params);
}

public function getHtmlBigLoader($showText = true)
Expand Down
14 changes: 9 additions & 5 deletions Controller/Tab/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ class Index extends \ADM\QuickDevBar\Controller\Index
public function execute()
{
$blockName = $this->getRequest()->getParam('block', '');
$this->_view->loadLayout();

if ($this->_view->getLayout()->getBlock($blockName)) {
$output = $this->_view->getLayout()->getBlock($blockName)->toHtml();
} else {
$output = 'Cannot found block: '. $blockName;
try {
$this->_view->loadLayout();
if ($this->_view->getLayout()->getBlock($blockName)) {
$output = $this->_view->getLayout()->getBlock($blockName)->toHtml();
} else {
$output = 'Cannot found block: '. $blockName;
}
} catch (Exception $e) {
$output = $e->getMessage();
}

$resultRaw = $this->_resultRawFactory->create();
Expand Down
14 changes: 13 additions & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
*/
protected $_controllerMsg = '';

/**
* @var ModuleListInterface
*/
protected $_moduleList;

/**
*
Expand All @@ -28,9 +32,11 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool
\Magento\Framework\App\Cache\Frontend\Pool $cacheFrontendPool,
\Magento\Framework\Module\ModuleListInterface $moduleList
) {
$this->_cacheFrontendPool = $cacheFrontendPool;
$this->_moduleList = $moduleList;

parent::__construct($context);
}
Expand Down Expand Up @@ -224,4 +230,10 @@ public function getControllerMessage()
return $this->_controllerMsg;
}

public function getModuleVersion($moduleName)
{
$moduleInfo = $this->_moduleList->getOne($moduleName);
return !empty($moduleInfo['setup_version']) ? $moduleInfo['setup_version'] : '???';
}

}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The structure of this toolbar is extremely simple you just need to add a new blo

- Info : Information about controller, route, action and store. A dedicated tab output a phpinfo.
- Design : List handles called and display layout structure of nested blocks and containers
- Profile : View current observers, all events dispatched and collections, models loaded
- Profile : View current observers, all events dispatched, collections and models loaded, plugins instanciated
- Queries : Statistics about executed queries and detailed query listing with syntax highlighting of main SQL keywords
- Logs : Display log files with ability to reset these files
- Actions : Easily toggle template hints and inline translation and flush cache
Expand Down
2 changes: 1 addition & 1 deletion composer.json
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.1.8",
"version": "0.1.9",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
28 changes: 16 additions & 12 deletions doc/Changelog.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
Changelog: Quick Developer Toolbar for Magento2
====================================

0.1.8
0.1.9
* Add config list tab
* Use common ajax controller

0.1.8 - 22 Jul 2016
* Add plugin list tab
* Fix bug on action hints. Thanks to [adpeate](https://github.com/vpietri/magento2-developer-quickdevbar/pull/7)

0.1.7
0.1.7 - 7 Jul 2016
* Configuration section improvement
* Code refactoring
* Authorize IPv6 localhost. Thanks to [Dayssam](https://github.com/vpietri/magento2-developer-quickdevbar/pull/5)

0.1.6.1
0.1.6.1 - 30 Jun 2016
* Fix compatibility bugs with Magento 2.1

0.1.6
0.1.6 - 17 Jun 2016
* UI improvement
* Add Block subtab
* Add icon from [iconsdb.com](http://www.iconsdb.com/)

0.1.5.2
0.1.5.2 - 22 Apr 2016
* Fit to PHP coding standards

0.1.5.1
0.1.5.1 - 25 Feb 2016
* Fix tab bug in backoffice

0.1.5
0.1.5 - 12 Dec 2015
* Back office toolbar
* Reorganize tabs
* Add list of collection and model instanciated
* Add [Christian Bach's tablesorter plugin](https://github.com/christianbach/tablesorter)

0.1.4
0.1.4 - 6 Dec 2015
* Fix bug on composer.json with registration.php
* Clean layout display

0.1.3
0.1.3 - 4 Dec 2015
* Compatibility with Magento 2.0.0 Publication
* Add action tab (Template hints, Translate inline, Flush Cache Storage)
* Controller structure cleaning

0.1.2
0.1.2 - 29 Jun 2015
* Add sub-tab and reorganize existing tabs

0.1.1
0.1.1 - 19 Jun 2015
* Javascript cleaning to meet coding standards
* Add [sunnywalker/filterTable](https://github.com/sunnywalker/jQuery.FilterTable)
* Fix bugs on the log screen
* Css improvements

0.0.1
0.0.1 - 18 Jun 2015
* module initialization
Loading

0 comments on commit c0e28db

Please sign in to comment.