Skip to content

Commit

Permalink
AdminerEvo core update and significant improvements to iframed full v…
Browse files Browse the repository at this point in the history
…ersion.
  • Loading branch information
adrianbj committed Apr 12, 2024
1 parent 15cf148 commit c23fbee
Show file tree
Hide file tree
Showing 8 changed files with 553 additions and 528 deletions.
22 changes: 17 additions & 5 deletions ProcessTracyAdminer.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,34 @@ public static function getModuleInfo() {

public function ___execute() {

$data = wire('modules')->getModuleConfigData('TracyDebugger');
$data = $this->wire('modules')->getModuleConfigData('TracyDebugger');

if(isset($data['adminerStandAlone']) && $data['adminerStandAlone'] === 1) {
return $this->wire('modules')->get('ProcessTracyAdminerRenderer')->execute();
}
else {
// push querystring to parent window
return '
<iframe id="adminer-iframe" src="'.str_replace('/adminer/', '/adminer-renderer/', $_SERVER['REQUEST_URI']).'" style="width:calc(100vw - 80px); min-height:600px; border: none; padding:0; margin:0;"></iframe>
<script>
const adminer_iframe = document.getElementById("adminer-iframe");
window.addEventListener("popstate", function (event) {
adminer_iframe.src = location.href.replace("/adminer/", "/adminer-renderer/");
});
window.addEventListener("message", function(event) {
if(event.data && typeof event.data !== "object" && event.data.startsWith("username=&db=")) {
history.pushState(null, null, "?"+event.data);
if(!event.isTrusted) return;
if(event.source && event.origin === "'.trim($this->wire('config')->urls->httpRoot, '/').'" && event.source === adminer_iframe.contentWindow) {
if(event.data && typeof event.data === "string" && event.data.startsWith("username=&db=")) {
if(new URLSearchParams(window.location.search).toString() !== event.data) {
history.replaceState(null, null, "?"+event.data);
}
}
if(event.source.document.body && event.source.document.body.scrollHeight) {
adminer_iframe.style.height = (event.source.document.body.scrollHeight + 20) + "px";
}
}
});
</script>
<iframe src="'.str_replace('/adminer/', '/adminer-renderer/', $_SERVER['REQUEST_URI']).'" style="width:100%; height:calc(100vh - 25px); border: none; padding:0; margin:0;"></iframe>';
</script>';
}
}

Expand Down
3 changes: 0 additions & 3 deletions ProcessTracyAdminerRenderer.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ public static function getModuleInfo() {

public function ___execute() {

error_reporting(0);
ini_set('display_errors', 0);

$_GET['db'] = $this->wire('config')->dbName;

function adminer_object() {
Expand Down
6 changes: 3 additions & 3 deletions TracyDebugger.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.14',
'version' => '4.26.15',
'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',
Expand Down Expand Up @@ -1154,7 +1154,7 @@ public function init() {
$adminerModuleId = $this->wire('modules')->getModuleID("ProcessTracyAdminer");
$adminerUrl = $this->wire('pages')->get("process=$adminerModuleId")->url;

$event->return = str_replace("</body>", "<script>window.AdminerUrl = '".$adminerUrl."'; window.AdminerRendererUrl = '".$adminerRendererUrl."'; window.TracyMaxAjaxRows = ".$this->data['maxAjaxRows']."; window.TracyPanelZIndex = " . ($this->data['panelZindex'] + 1) . ";</script></body>", $event->return);
$event->return = str_replace("</body>", "<script>window.HttpRootUrl = '".$this->wire('config')->urls->httpRoot."'; window.AdminerUrl = '".$adminerUrl."'; window.AdminerRendererUrl = '".$adminerRendererUrl."'; window.TracyMaxAjaxRows = ".$this->data['maxAjaxRows']."; window.TracyPanelZIndex = " . ($this->data['panelZindex'] + 1) . ";</script></body>", $event->return);

$tracyErrors = Debugger::getBar()->getPanel('Tracy:errors');
if(!is_array($tracyErrors->data) || count($tracyErrors->data) === 0) {
Expand Down Expand Up @@ -2537,7 +2537,7 @@ public function addAdminerEditFieldLinks($event) {
$link = '';
// don't add link again unless it's a repeater field
if(strpos($appendedMarkup, 'adminer_EditFieldLink') === false || $inputfield instanceof InputfieldRepeater) {
$link = '<div class="wrap_adminer_EditFieldLink"><a class="adminer_EditFieldLink" title="Edit in Adminer" href="adminer://?'.$adminerQuery.'">'.$adminerIcon.'</a></div>';
$link = '<div class="wrap_adminer_EditFieldLink" style="display: none"><a class="adminer_EditFieldLink" title="Edit in Adminer" href="adminer://?'.$adminerQuery.'">'.$adminerIcon.'</a></div>';
}

$inputfield->appendMarkup = $inputfield->appendMarkup . $link;
Expand Down
Loading

5 comments on commit c23fbee

@adrianbj
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Toutouwai - this commit probably still won't sway you from using the standalone option, but you still might want to give it a try - it handles resizing the iframe dynamically based on the height of the scrollable content and it also fixes issues with the browser history stack so it should be much better now.

@Toutouwai
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adrianbj, very nice!

This isn't a new thing but just more noticeable to me in the iframe: the default-[colour].css files have this rule...
2024-04-13_111516
...which forces a scrollbar on pages that don't need it (on Windows at least).

Not sure why the Adminer crew included that rule but I think it should be overflow:auto. Maybe you could add that to tweaks.css?

html { 
    overflow-y: auto;
}

And also change the CSS file load order so that tweaks.css loads last, so that it can override rules without needing extra specificity.

@adrianbj
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea - I've applied that overflow tweak here, but actually not sure how I can easily get tweaks to load after the theme files - adminer plugin order loading seems delicate - the tweaks don't get applied at all if the PW login plugin is loaded after the theme plugins. Maybe there is another way, but don't think I'll worry about it for now unless it's causing you issues/

@Toutouwai
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add tweaks.css in AdminerTheme.php instead of in AdminerProcessWireLogin.php? If not then no worries, it will just require an !important in the rule.

@adrianbj
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, adding it in AdminerTheme.php works - I forgot I had already had to hack that a bit, so no worries hacking it further :)

New version committed.

Please sign in to comment.