From c9cb0670f039fb59b1608300b0b12aba322eef45 Mon Sep 17 00:00:00 2001 From: Adrian Jones Date: Wed, 3 Apr 2024 16:00:58 -0700 Subject: [PATCH] Standalone option for Adminer. Propagate querystring to parent from Adminer iframe. Shift+Click to open links in full Adminer vs panel. --- ProcessTracyAdminer.module.php | 19 ++++++++- TracyDebugger.module.php | 40 ++++++++++++------- .../plugins/AdminerProcessWireLogin.php | 2 +- panels/Adminer/scripts/framed-check.js | 1 - panels/Adminer/scripts/main.js | 4 ++ panels/AdminerPanel.php | 6 +-- scripts/adminer.js | 9 +++-- 7 files changed, 58 insertions(+), 23 deletions(-) delete mode 100644 panels/Adminer/scripts/framed-check.js create mode 100644 panels/Adminer/scripts/main.js diff --git a/ProcessTracyAdminer.module.php b/ProcessTracyAdminer.module.php index 953a70e..60ad98a 100644 --- a/ProcessTracyAdminer.module.php +++ b/ProcessTracyAdminer.module.php @@ -22,7 +22,24 @@ public static function getModuleInfo() { } public function ___execute() { - return ''; + + $data = wire('modules')->getModuleConfigData('TracyDebugger'); + + if($data['adminerStandAlone']) { + return $this->wire('modules')->get('ProcessTracyAdminerRenderer')->execute(); + } + else { + // push querystring to parent window + return ' + + '; + } } } diff --git a/TracyDebugger.module.php b/TracyDebugger.module.php index 5431d69..e3bd064 100644 --- a/TracyDebugger.module.php +++ b/TracyDebugger.module.php @@ -27,7 +27,7 @@ public static function getModuleInfo() { 'summary' => __('Tracy debugger from Nette with many PW specific custom tools.', __FILE__), 'author' => 'Adrian Jones', 'href' => 'https://processwire.com/talk/forum/58-tracy-debugger/', - 'version' => '4.26.9', + 'version' => '4.26.10', 'autoload' => 100000, // in PW 3.0.114+ higher numbers are loaded first - we want Tracy first 'singular' => true, 'requires' => 'ProcessWire>=2.7.2, PHP>=5.4.4', @@ -254,8 +254,9 @@ static public function getDefaultData() { "linksNewTab" => null, "pWInfoPanelLinksNewTab" => null, "customPWInfoPanelLinks" => array(11, 16, 22, 21, 29, 30, 31, 304), - "adminerThemeColor" => 'blue', "adminerEditFieldLink" => 1, + "adminerStandAlone" => null, + "adminerThemeColor" => 'blue', "adminerJsonMaxLevel" => 3, "adminerJsonInTable" => 1, "adminerJsonInEdit" => 1, @@ -1148,10 +1149,12 @@ public function init() { $event->page->addHookAfter('render', function($event) { if(!$event->return) return; - $adminerModuleId = $this->wire('modules')->getModuleID("ProcessTracyAdminerRenderer"); + $adminerRendererModuleId = $this->wire('modules')->getModuleID("ProcessTracyAdminerRenderer"); + $adminerRendererUrl = $this->wire('pages')->get("process=$adminerRendererModuleId")->url; + $adminerModuleId = $this->wire('modules')->getModuleID("ProcessTracyAdminer"); $adminerUrl = $this->wire('pages')->get("process=$adminerModuleId")->url; - $event->return = str_replace("", "", $event->return); + $event->return = str_replace("", "", $event->return); $tracyErrors = Debugger::getBar()->getPanel('Tracy:errors'); if(!is_array($tracyErrors->data) || count($tracyErrors->data) === 0) { @@ -4033,15 +4036,13 @@ public function getModuleConfigInputfields(array $data) { $fieldset->label = __('Adminer panel', __FILE__); $wrapper->add($fieldset); - $f = $this->wire('modules')->get("InputfieldSelect"); - $f->attr('name', 'adminerThemeColor'); - $f->label = __('Theme color', __FILE__); - $f->addOption('blue', 'Blue'); - $f->addOption('green', 'Green'); - $f->addOption('orange', 'Orange'); - $f->required = true; - $f->columnWidth = 50; - if($this->data['adminerThemeColor']) $f->attr('value', $this->data['adminerThemeColor']); + $f = $this->wire('modules')->get("InputfieldCheckbox"); + $f->attr('name', 'adminerStandAlone'); + $f->label = __('Standalone mode', __FILE__); + $f->description = __('Load Setup > Adminer in standalone mode.', __FILE__); + $f->notes = __('Adminer won\'t be embedded in PW admin via iframe.', __FILE__); + $f->columnWidth = 33; + $f->attr('checked', $this->data['adminerStandAlone'] == '1' ? 'checked' : ''); $fieldset->add($f); $f = $this->wire('modules')->get("InputfieldCheckbox"); @@ -4049,10 +4050,21 @@ public function getModuleConfigInputfields(array $data) { $f->label = __('Field edit links', __FILE__); $f->description = __('Add adminer links to each field in the page edit interface.', __FILE__); $f->notes = __('Will only appear when Adminer panel is enabled', __FILE__); - $f->columnWidth = 50; + $f->columnWidth = 34; $f->attr('checked', $this->data['adminerEditFieldLink'] == '1' ? 'checked' : ''); $fieldset->add($f); + $f = $this->wire('modules')->get("InputfieldSelect"); + $f->attr('name', 'adminerThemeColor'); + $f->label = __('Theme color', __FILE__); + $f->addOption('blue', 'Blue'); + $f->addOption('green', 'Green'); + $f->addOption('orange', 'Orange'); + $f->required = true; + $f->columnWidth = 33; + if($this->data['adminerThemeColor']) $f->attr('value', $this->data['adminerThemeColor']); + $fieldset->add($f); + $f = $this->wire('modules')->get("InputfieldText"); $f->attr('name', 'adminerJsonMaxLevel'); $f->label = __('JSON max level', __FILE__); diff --git a/panels/Adminer/plugins/AdminerProcessWireLogin.php b/panels/Adminer/plugins/AdminerProcessWireLogin.php index d53de4f..b64ea36 100644 --- a/panels/Adminer/plugins/AdminerProcessWireLogin.php +++ b/panels/Adminer/plugins/AdminerProcessWireLogin.php @@ -18,7 +18,7 @@ public function __construct($pwAdminUrl, $server = false, $db = false, $name = f public function head() { ?> - + wire('modules')->getModuleID("ProcessTracyAdminerRenderer"); - $adminerUrl = $this->wire('pages')->get("process=$adminerModuleId")->url; + $adminerRendererModuleId = $this->wire('modules')->getModuleID("ProcessTracyAdminerRenderer"); + $adminerRendererUrl = $this->wire('pages')->get("process=$adminerRendererModuleId")->url; $contextLink = ''; if(\TracyDebugger::getDataValue('referencePageEdited') && $this->wire('input')->get('id') && @@ -128,7 +128,7 @@ public function getPanel() { if($this->wire('modules')->isInstalled("ProcessTracyAdminer")) { $out .= '
- '; + '; } else { $out .= ' diff --git a/scripts/adminer.js b/scripts/adminer.js index f821cf4..9b415dd 100644 --- a/scripts/adminer.js +++ b/scripts/adminer.js @@ -1,5 +1,5 @@ function openAdminer(queryStr) { - var url = window.AdminerUrl + "?" + queryStr; + var url = window.AdminerRendererUrl + "?" + queryStr; if(document.getElementById("tracy-debug-panel-AdminerPanel").classList.contains("tracy-mode-window")) { document.getElementById('adminer-iframe').src = url; } @@ -18,7 +18,6 @@ function openAdminer(queryStr) { } } } - document.body.addEventListener("click", function(e) { if(e.target) { var curEl = e.target; @@ -28,7 +27,11 @@ document.body.addEventListener("click", function(e) { if(curEl && curEl.href && curEl.href.indexOf("adminer://") !== -1) { e.preventDefault(); var queryStr = curEl.href.split('?')[1]; - openAdminer(queryStr); + if (e.shiftKey) { + window.location = curEl.href.replace("adminer://", window.AdminerUrl); + } else { + openAdminer(queryStr); + } } } });