From c5d70243ae840560e8d3feaac7970dcd65badcf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Thu, 19 Aug 2021 14:17:39 +0200 Subject: [PATCH] DEBUG better understand the issue/render tree --- demos/interactive/modal.php | 10 ---------- src/Callback.php | 2 ++ src/JsReload.php | 22 +++++++++++++++++++++- src/View.php | 8 +++++++- 4 files changed, 30 insertions(+), 12 deletions(-) diff --git a/demos/interactive/modal.php b/demos/interactive/modal.php index efb1f5f0df..2bc6ebd1b7 100644 --- a/demos/interactive/modal.php +++ b/demos/interactive/modal.php @@ -210,16 +210,6 @@ $stepModal->js(true)->modal('refresh'); }); -// Bind next action to modal next button. -$nextAction->on('click', $stepModal->js()->atkReloadView( - ['uri' => $stepModal->cb->getJsUrl(), 'uri_options' => ['move' => 'next']] -)); - -// Bin prev action to modal previous button. -$prevAction->on('click', $stepModal->js()->atkReloadView( - ['uri' => $stepModal->cb->getJsUrl(), 'uri_options' => ['move' => 'prev']] -)); - // Bind display modal to page display button. $menuBar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']); $button = \Atk4\Ui\Button::addTo($menuBar)->set('Multi Step Modal'); diff --git a/src/Callback.php b/src/Callback.php index ebe4be0304..a9df3bab5a 100644 --- a/src/Callback.php +++ b/src/Callback.php @@ -54,6 +54,8 @@ protected function init(): void public function setUrlTrigger(string $trigger = null) { $this->urlTrigger = $trigger ?: $this->name; + + // $this->getOwner()->stickyGet(self::URL_QUERY_TRIGGER_PREFIX . $this->urlTrigger); } public function getUrlTrigger(): string diff --git a/src/JsReload.php b/src/JsReload.php index 0b82b969e9..ded0835968 100644 --- a/src/JsReload.php +++ b/src/JsReload.php @@ -49,9 +49,29 @@ public function __construct($view, $args = [], $afterSuccess = null, $apiConfig $this->apiConfig = $apiConfig; $this->includeStorage = $includeStorage; } - + + public function dumpRenderTree(View $view, bool $rec = false): void + { + if ($view->issetOwner() && $view->getOwner() instanceof View) { + $this->dumpRenderTree($view->getOwner(), true); + } + + echo get_class($view); + + echo "\n" . (!$rec ? "\n\n" : ''); + } public function jsRender(): string { + ini_set('output_buffering', (string) (1024 * 1024)); + ob_start(); + $this->dumpRenderTree($this->view); + // test URL: /demos/interactive/modal.php?__atk_m=atk_layout_maestro_modal_5&__atk_cbtarget=atk_layout_maestro_modal_5_view_callbacklater&__atk_cb_atk_layout_maestro_modal_5_view_callbacklater=ajax&__atk_json=1 + $url = $this->view->jsUrl(['__atk_reload' => $this->view->name]); + echo 'actual: '; var_dump($url); + echo 'expected: string(166) "modal.php?__atk_m=atk_layout_maestro_modal_5&__atk_cb_atk_layout_maestro_modal_5_view_callbacklater=ajax&__atk_reload=atk_layout_maestro_modal_5_view_demos_viewtester"' . "\n"; + ob_end_flush(); + exit; + $final = (new Jquery($this->view)) ->atkReloadView( [ diff --git a/src/View.php b/src/View.php index a1a244205a..e66bcf4f1d 100644 --- a/src/View.php +++ b/src/View.php @@ -619,6 +619,7 @@ public function url($page = []) protected function getRunningCallbackArgs(bool $isTerminated, array $page): array { $args = []; + foreach ($this->elements as $v) { if ($v instanceof Callback) { // @phpstan-ignore-line if (($page[Callback::URL_QUERY_TARGET] ?? null) === $v->getUrlTrigger()) { @@ -631,8 +632,13 @@ protected function getRunningCallbackArgs(bool $isTerminated, array $page): arra } } + $parentRenderView = null; if ($this->issetOwner() && $this->getOwner() instanceof self) { - $args = array_merge($this->getOwner()->getRunningCallbackArgs($isTerminated, $page), $args); + $parentRenderView = $this->getOwner(); + } // else + + if ($parentRenderView !== null) { + $args = array_merge($parentRenderView->getRunningCallbackArgs($isTerminated, $page), $args); } return $args;