Skip to content

Commit

Permalink
Use sub tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
vpietri committed Jun 25, 2015
1 parent 4cf8519 commit b2f7030
Show file tree
Hide file tree
Showing 22 changed files with 419 additions and 118 deletions.
6 changes: 4 additions & 2 deletions Block/Tab/Event.php → Block/Tab/Content/Event.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace ADM\QuickDevBar\Block\Tab;
namespace ADM\QuickDevBar\Block\Tab\Content;

class Event extends DefaultTab
use \ADM\QuickDevBar\Block\Tab;

class Event extends \ADM\QuickDevBar\Block\Tab\DefaultContent
{
protected $_manager;

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

namespace ADM\QuickDevBar\Block\Tab\Content;

class General extends \ADM\QuickDevBar\Block\Tab\DefaultContent
{
public function getStore()
{
return $this->_storeManager->getStore();
}

public function getStore()
{
return $this->_storeManager->getWebsite();
}
}
40 changes: 12 additions & 28 deletions Block/Tab/Layout.php → Block/Tab/Content/Layout.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace ADM\QuickDevBar\Block\Tab;
namespace ADM\QuickDevBar\Block\Tab\Content;

class Layout extends DefaultTab
class Layout extends \ADM\QuickDevBar\Block\Tab\DefaultContent
{
protected $_structure;

Expand All @@ -18,7 +18,7 @@ public function __construct(\Magento\Framework\View\Element\Template\Context $co

$this->_structure = $structure;

$this->setTemplate('ADM_QuickDevBar::tab/layout.phtml');
//$this->setTemplate('ADM_QuickDevBar::tab/layout.phtml');

parent::__construct($context, $data);
}
Expand All @@ -29,23 +29,11 @@ public function getHandles()
return $this->getLayout()->getUpdate()->getHandles();
}

public function getContent()
public function getHtmlBlocksHierarchy()
{
$html = '';
$layout = $this->getLayout();

// $xml = $layout->getUpdate()->asSimplexml();
// $html .= '<ul>';
// foreach ($xml->body as $xmlNode) {
// if($xmlNode->hasChildren()) {
// foreach ($xmlNode->children() as $k => $child) {
// $html .= '<li>' . $child->getElementName() . ' ('.$child->getName().')</li>';
// }
// }
// }
// $html .= '</ul>';

$html .= '<strong>Blocks hierarchy</strong><br/>';
$blocks = $layout->getAllBlocks();
$containers = array('CONTAINER'=>array());
foreach ($blocks as $alias=>$block) {
Expand All @@ -59,9 +47,6 @@ public function getContent()
}

$containers[$type][$parentName] = $parentName;
// $ancestortName = $this->getAncestor($alias);
// $containers['CONTAINER'][$ancestortName] = $ancestortName;

}

$html .= '<ul>';
Expand All @@ -75,19 +60,18 @@ public function getContent()
}
$html .= '</ul>';

//Other blocks
$html .= '<strong>Other block</strong><br/>';
$html .= '<ul>';
$containers = $layout->getUpdate()->getContainers();
foreach ($containers as $containerAlias=>$containerLable) {
$html .= '<li>' . $containerAlias . '</li>';
}
$html .= '</ul>';

return $html;
}


public function getContainers()
{
$containers = $this->getLayout()->getUpdate()->getContainers();

return $containers;
}


public function getAncestor($alias)
{
$parentName = $this->getLayout()->getParentName($alias);
Expand Down
4 changes: 2 additions & 2 deletions Block/Tab/Log.php → Block/Tab/Content/Log.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace ADM\QuickDevBar\Block\Tab;
namespace ADM\QuickDevBar\Block\Tab\Content;

class Log extends DefaultTab
class Log extends \ADM\QuickDevBar\Block\Tab\DefaultContent
{

protected $_jsonHelper;
Expand Down
4 changes: 2 additions & 2 deletions Block/Tab/Observer.php → Block/Tab/Content/Observer.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace ADM\QuickDevBar\Block\Tab;
namespace ADM\QuickDevBar\Block\Tab\Content;

class Observer extends DefaultTab
class Observer extends \ADM\QuickDevBar\Block\Tab\DefaultContent
{
protected $_invoker;

Expand Down
4 changes: 2 additions & 2 deletions Block/Tab/PhpInfo.php → Block/Tab/Content/PhpInfo.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace ADM\QuickDevBar\Block\Tab;
namespace ADM\QuickDevBar\Block\Tab\Content;

class PhpInfo extends DefaultTab
class PhpInfo extends \ADM\QuickDevBar\Block\Tab\DefaultContent
{

public function getTitle()
Expand Down
4 changes: 2 additions & 2 deletions Block/Tab/Request.php → Block/Tab/Content/Request.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace ADM\QuickDevBar\Block\Tab;
namespace ADM\QuickDevBar\Block\Tab\Content;

class Request extends DefaultTab
class Request extends \ADM\QuickDevBar\Block\Tab\DefaultContent
{

public function getTitle()
Expand Down
8 changes: 4 additions & 4 deletions Block/Tab/Sql.php → Block/Tab/Content/Sql.php
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace ADM\QuickDevBar\Block\Tab;
namespace ADM\QuickDevBar\Block\Tab\Content;

class Sql extends DefaultTab
class Sql extends \ADM\QuickDevBar\Block\Tab\DefaultContent
{

protected $_sql_profiler;
Expand Down Expand Up @@ -62,8 +62,8 @@ public function getQueryProfiles()
public function formatSql($sql)
{
$htmlSql = $sql;
$htmlSql = preg_replace('/\b(SET|AS|ASC|COUNT|DESC|IN|LIKE|DISTINCT|INTO|VALUES|LIMIT|DESCRIBE)\b/', '<span class="sqlword">\\1</span>', $sql);
$htmlSql = preg_replace('/\b(UNION ALL)\b/', '<br/><span class="sqljoin">\\1</span>', $htmlSql);
$htmlSql = preg_replace('/\b(SET|AS|ASC|COUNT|DESC|IN|LIKE|DISTINCT|INTO|VALUES|LIMIT)\b/', '<span class="sqlword">\\1</span>', $sql);
$htmlSql = preg_replace('/\b(UNION ALL|DESCRIBE|SHOW|connect|begin|commit)\b/', '<br/><span class="sqlother">\\1</span>', $htmlSql);
$htmlSql = preg_replace('/\b(UPDATE|SELECT|FROM|WHERE|LEFT JOIN|INNER JOIN|RIGHT JOIN|ORDER BY|GROUP BY|DELETE|INSERT)\b/', '<br/><span class="sqlmain">\\1</span>', $htmlSql);
$htmlSql = preg_replace('/^<br\/>/', '', $htmlSql);
return $htmlSql;
Expand Down
64 changes: 60 additions & 4 deletions Block/Tab/DefaultTab.php → Block/Tab/DefaultContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@

namespace ADM\QuickDevBar\Block\Tab;

class DefaultTab extends \Magento\Framework\View\Element\Template
class DefaultContent extends \Magento\Framework\View\Element\Template
{

// protected $_jsonHelper;

// /**
// * @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,
// \Magento\Framework\Json\Helper\Data $jsonHelper,
// array $data = []
// ) {
// $this->_jsonHelper = $jsonHelper;

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



public function getTitle()
{
return ($this->getData('title')) ? $this->getData('title') : $this->getNameInLayout();
Expand All @@ -17,12 +36,22 @@ public function getId()

public function getClass()
{
return str_replace('.', '-', $this->getId());
$class = str_replace('.', '-', $this->getId());
if ($this->isAjax(false)) {
$class .= ' use-ajax';
}

return $class;
}

public function isAjax()
public function isAjax($asString=true)
{
return (($this->hasData('ajax_url') || $this->hasData('is_ajax'))? "true" : "false");
$return = (($this->hasData('ajax_url') || $this->hasData('is_ajax'))? true : false);
if ($asString) {
$return = ($return) ? "true" : "false";
}

return $return;
}

public function getTabUrl()
Expand Down Expand Up @@ -64,4 +93,31 @@ public function getHtmlLoader($imgSrc, $class, $showText = true)
return $html;
}


protected $_mainTabs;

public function getTabBlocks()
{
if (is_null($this->_mainTabs)) {
$this->_mainTabs = $this->getLayout()->getChildBlocks($this->getNameInLayout());
}

return $this->_mainTabs;
}

public function getStore()
{
return $this->_storeManager->getStore();
}

public function getWebsite()
{
return $this->_storeManager->getWebsite();
}

public function getGroup()
{
return $this->_storeManager->getGroup();
}

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

namespace ADM\QuickDevBar\Block\Tab;

class Main extends DefaultContent
{
protected $_mainTabs;

protected $_jsonHelper;

protected $_tab_active = false;

protected $_tab_collapsible = true;

protected $_tab_openState = "ui-tabs-active";

/**
* @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,
\Magento\Framework\Json\Helper\Data $jsonHelper,
array $data = []
) {
$this->_jsonHelper = $jsonHelper;

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

public function getTabBlocks()
{
if (is_null($this->_mainTabs)) {
$this->_mainTabs = $this->getLayout()->getChildBlocks($this->getNameInLayout());
}

return $this->_mainTabs;
}

public function getSubTabSuffix()
{
return '';
}

public function getUiTabClass()
{
return 'qdb-ui-tabs';
}

protected function _getTabConfig()
{
$config = array( "active"=>$this->_tab_active,
"openedState"=>$this->_tab_openState,
"collapsibleElement"=>"[data-role=collapsible".$this->getSubTabSuffix()."]",
"content"=>"[data-role=content".$this->getSubTabSuffix()."]",
"collapsible" => $this->_tab_collapsible,
"ajaxContent" => true
);

return $config;
}


public function getJsonTabConfig()
{
return $this->_jsonHelper->jsonEncode($this->_getTabConfig());
}
}
31 changes: 31 additions & 0 deletions Block/Tab/Sub.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace ADM\QuickDevBar\Block\Tab;

use Magento\Framework\Api\SimpleDataObjectConverter;

class Sub extends Main
{
protected $_mainTabs;

protected $_tab_active = 0;

protected $_tab_collapsible = false;

protected $_tab_openState = "ui-tabs-active";

public function getSubTabSuffix()
{
return SimpleDataObjectConverter::snakeCaseToCamelCase(str_replace('.', '_', $this->getNameInLayout()));
}

public function getUiTabClass()
{
return 'qdb-ui-subtabs';
}

public function getIndexActiveTab()
{
return 0;
}
}
Loading

0 comments on commit b2f7030

Please sign in to comment.