From 0bff5ada1f315fb9e5165415160c06dffb8b8dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 5 Oct 2021 15:22:29 +0200 Subject: [PATCH 1/5] Adjust to CS fixer v3.2 rules --- demos/basic/button.php | 2 +- src/Form/Control/Calendar.php | 6 +++--- src/Form/Control/Multiline.php | 2 +- src/Form/Control/ScopeBuilder.php | 2 +- src/JsSse.php | 2 +- src/Table/Column/ColorRating.php | 2 +- src/UserAction/ConfirmationExecutor.php | 2 +- src/UserAction/ModalExecutor.php | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/demos/basic/button.php b/demos/basic/button.php index 1cc9c62a5e..0189833bd2 100644 --- a/demos/basic/button.php +++ b/demos/basic/button.php @@ -56,7 +56,7 @@ // Creating your own button component example /** @var Button $forkButtonClass */ -$forkButtonClass = get_class(new class(0) extends Button { // need 0 argument here for constructor +$forkButtonClass = get_class(new class(0) /* need 0 argument here for constructor */ extends Button { public function __construct($n) { Icon::addTo(Button::addTo($this, ['Forks', 'blue']), ['fork']); diff --git a/src/Form/Control/Calendar.php b/src/Form/Control/Calendar.php index 4d1d27ea67..37575bb000 100644 --- a/src/Form/Control/Calendar.php +++ b/src/Form/Control/Calendar.php @@ -80,14 +80,14 @@ protected function init(): void if ($this->type === 'datetime' || $this->type === 'time') { $this->options['enableTime'] = true; - $this->options['time_24hr'] = $this->options['time_24hr'] ?? $this->use24hrTimeFormat($this->options['altFormat'] ?? $this->options['dateFormat']); + $this->options['time_24hr'] ??= $this->use24hrTimeFormat($this->options['altFormat'] ?? $this->options['dateFormat']); $this->options['noCalendar'] = ($this->type === 'time'); // Add seconds picker if set - $this->options['enableSeconds'] = $this->options['enableSeconds'] ?? $this->useSeconds($this->options['altFormat'] ?? $this->options['dateFormat']); + $this->options['enableSeconds'] ??= $this->useSeconds($this->options['altFormat'] ?? $this->options['dateFormat']); // Allow edit if microseconds is set. - $this->options['allowInput'] = $this->options['allowInput'] ?? $this->allowMicroSecondsInput($this->options['altFormat'] ?? $this->options['dateFormat']); + $this->options['allowInput'] ??= $this->allowMicroSecondsInput($this->options['altFormat'] ?? $this->options['dateFormat']); } } diff --git a/src/Form/Control/Multiline.php b/src/Form/Control/Multiline.php index 26fe7c099b..4a63cf8b26 100644 --- a/src/Form/Control/Multiline.php +++ b/src/Form/Control/Multiline.php @@ -553,7 +553,7 @@ protected function getLookupProps(Field $field): array $props['config']['search'] = true; } - $props['config']['placeholder'] = $props['config']['placeholder'] ?? 'Select ' . $field->getCaption(); + $props['config']['placeholder'] ??= 'Select ' . $field->getCaption(); $this->valuePropsBinding[$field->short_name] = [__CLASS__, 'setLookupOptionValue']; diff --git a/src/Form/Control/ScopeBuilder.php b/src/Form/Control/ScopeBuilder.php index 47122de59f..fb6a2364a2 100644 --- a/src/Form/Control/ScopeBuilder.php +++ b/src/Form/Control/ScopeBuilder.php @@ -417,7 +417,7 @@ protected function getLookupProps(Field $field): array $props['search'] = true; } - $props['placeholder'] = $props['placeholder'] ?? 'Select ' . $field->getCaption(); + $props['placeholder'] ??= 'Select ' . $field->getCaption(); return $props; } diff --git a/src/JsSse.php b/src/JsSse.php index 0ce1240e8c..01224325ab 100644 --- a/src/JsSse.php +++ b/src/JsSse.php @@ -137,7 +137,7 @@ public function sendBlock(string $id, string $data, string $name = null): void } $this->output('id: ' . $id . "\n"); - if (strlen($name) > 0) { + if ($name !== null) { $this->output('event: ' . $name . "\n"); } $this->output($this->wrapData($data) . "\n"); diff --git a/src/Table/Column/ColorRating.php b/src/Table/Column/ColorRating.php index 9453dd9d4f..a9708217cb 100644 --- a/src/Table/Column/ColorRating.php +++ b/src/Table/Column/ColorRating.php @@ -183,7 +183,7 @@ private function createGradientSingle(&$gradients, $hexFrom, $hexTo, $steps) public function getTagAttributes($position, array $attr = []): array { - $attr['style'] = $attr['style'] ?? ''; + $attr['style'] ??= ''; $attr['style'] .= '{$_' . $this->short_name . '_color_rating}'; return parent::getTagAttributes($position, $attr); diff --git a/src/UserAction/ConfirmationExecutor.php b/src/UserAction/ConfirmationExecutor.php index fae64f4d7d..c32698103d 100644 --- a/src/UserAction/ConfirmationExecutor.php +++ b/src/UserAction/ConfirmationExecutor.php @@ -100,7 +100,7 @@ public function setAction(Model\UserAction $action): Modal $this->action = $action; $this->afterActionInit($action); - $this->title = $this->title ?? $action->getDescription(); + $this->title ??= $action->getDescription(); $this->step = $this->stickyGet('step'); $this->actionInitialized = true; diff --git a/src/UserAction/ModalExecutor.php b/src/UserAction/ModalExecutor.php index 73c0ec8d56..1270e86f01 100644 --- a/src/UserAction/ModalExecutor.php +++ b/src/UserAction/ModalExecutor.php @@ -78,7 +78,7 @@ public function setAction(Model\UserAction $action): View // get necessary step need prior to execute action. if ($this->steps = $this->getSteps($action)) { - $this->title = $this->title ?? $action->getDescription(); + $this->title ??= $action->getDescription(); // get current step. $this->step = $this->stickyGet('step') ?? $this->steps[0]; From 494581b0c27186ee561affd616d436fe679a95e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 5 Oct 2021 16:41:51 +0200 Subject: [PATCH 2/5] fix unit test --- demos/_unit-test/modal-reload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/_unit-test/modal-reload.php b/demos/_unit-test/modal-reload.php index 3fa59ae738..0d0dee9427 100644 --- a/demos/_unit-test/modal-reload.php +++ b/demos/_unit-test/modal-reload.php @@ -15,7 +15,7 @@ Header::addTo($app, ['Testing ModalExecutor reload']); -$modal = Modal::addTo($app->html, ['title' => 'Modal Executor', 'region' => 'Modals']); +$modal = Modal::addTo($app->html, ['title' => 'Modal Executor']); $modal->set(function ($modal) { ReloadTest::addTo($modal); From 6b74312429188eb8bb5fabdc7c81907b5f73cf76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 5 Oct 2021 16:41:51 +0200 Subject: [PATCH 3/5] fix unit test --- demos/_unit-test/modal-reload.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/_unit-test/modal-reload.php b/demos/_unit-test/modal-reload.php index 3fa59ae738..0d0dee9427 100644 --- a/demos/_unit-test/modal-reload.php +++ b/demos/_unit-test/modal-reload.php @@ -15,7 +15,7 @@ Header::addTo($app, ['Testing ModalExecutor reload']); -$modal = Modal::addTo($app->html, ['title' => 'Modal Executor', 'region' => 'Modals']); +$modal = Modal::addTo($app->html, ['title' => 'Modal Executor']); $modal->set(function ($modal) { ReloadTest::addTo($modal); From 32f874dacb74c4b3e6b3d856db4a47237d7642df Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Tue, 5 Oct 2021 16:31:44 -0400 Subject: [PATCH 4/5] no special rendering of modal in virtual page --- demos/_unit-test/modal-reload.php | 2 +- demos/interactive/virtual.php | 69 +++++++++++++++++++------------ src/VirtualPage.php | 10 ----- tests-behat/virtual-page.feature | 2 + 4 files changed, 46 insertions(+), 37 deletions(-) diff --git a/demos/_unit-test/modal-reload.php b/demos/_unit-test/modal-reload.php index 0d0dee9427..3ac660ef99 100644 --- a/demos/_unit-test/modal-reload.php +++ b/demos/_unit-test/modal-reload.php @@ -15,7 +15,7 @@ Header::addTo($app, ['Testing ModalExecutor reload']); -$modal = Modal::addTo($app->html, ['title' => 'Modal Executor']); +$modal = Modal::addTo($app, ['title' => 'Modal Executor']); $modal->set(function ($modal) { ReloadTest::addTo($modal); diff --git a/demos/interactive/virtual.php b/demos/interactive/virtual.php index 31c52d1b4b..bbdd0fd6bb 100644 --- a/demos/interactive/virtual.php +++ b/demos/interactive/virtual.php @@ -4,71 +4,88 @@ namespace Atk4\Ui\Demos; +use Atk4\Ui\Button; +use Atk4\Ui\Header; +use Atk4\Ui\LoremIpsum; +use Atk4\Ui\Message; +use Atk4\Ui\Modal; +use Atk4\Ui\Text; +use Atk4\Ui\View; +use Atk4\Ui\VirtualPage; + /** @var \Atk4\Ui\App $app */ require_once __DIR__ . '/../init-app.php'; // Demonstrate the use of Virtual Page. // define virtual page. -$virtualPage = \Atk4\Ui\VirtualPage::addTo($app->layout, ['urlTrigger' => 'in']); +$virtualPage = VirtualPage::addTo($app->layout, ['urlTrigger' => 'in']); // Add content to virtual page. if (isset($_GET['p_id'])) { - \Atk4\Ui\Header::addTo($virtualPage, [$_GET['p_id']])->addClass('__atk-behat-test-car'); + Header::addTo($virtualPage, [$_GET['p_id']])->addClass('__atk-behat-test-car'); } -\Atk4\Ui\LoremIpsum::addTo($virtualPage, ['size' => 1]); -$virtualPageButton = \Atk4\Ui\Button::addTo($virtualPage, ['Back', 'icon' => 'left arrow']); +LoremIpsum::addTo($virtualPage, ['size' => 1]); +$virtualPageButton = Button::addTo($virtualPage, ['Back', 'icon' => 'left arrow']); $virtualPageButton->link('virtual.php'); $virtualPage->ui = 'grey inverted segment'; -$msg = \Atk4\Ui\Message::addTo($app, ['Virtual Page']); +$modal = Modal::addTo($virtualPage); +$modal->set(function ($modal) { + Text::addTo($modal)->set('This is yet another modal'); + LoremIpsum::addTo($modal, ['size' => 2]); +}); +$button = Button::addTo($virtualPage)->set('Open Lorem Ipsum'); +$button->on('click', $modal->show()); + +$msg = Message::addTo($app, ['Virtual Page']); $msg->text->addParagraph('Virtual page content are not rendered on page load. They will ouptput their content when trigger.'); $msg->text->addParagraph('Click button below to trigger it.'); // button that trigger virtual page. -$btn = \Atk4\Ui\Button::addTo($app, ['More info on Car']); +$btn = Button::addTo($app, ['More info on Car']); $btn->link($virtualPage->cb->getUrl() . '&p_id=Car'); -$btn = \Atk4\Ui\Button::addTo($app, ['More info on Bike']); +$btn = Button::addTo($app, ['More info on Bike']); $btn->link($virtualPage->cb->getUrl() . '&p_id=Bike'); // Test 1 - Basic reloading -\Atk4\Ui\Header::addTo($app, ['Virtual Page Logic']); +Header::addTo($app, ['Virtual Page Logic']); -$virtualPage = \Atk4\Ui\VirtualPage::addTo($app); // this page will not be visible unless you trigger it specifically -\Atk4\Ui\View::addTo($virtualPage, ['Contents of your pop-up here'])->addClass('ui header __atk-behat-test-content'); -\Atk4\Ui\LoremIpsum::addTo($virtualPage, ['size' => 2]); +$virtualPage = VirtualPage::addTo($app); // this page will not be visible unless you trigger it specifically +View::addTo($virtualPage, ['Contents of your pop-up here'])->addClass('ui header __atk-behat-test-content'); +LoremIpsum::addTo($virtualPage, ['size' => 2]); Counter::addTo($virtualPage); -\Atk4\Ui\View::addTo($virtualPage, ['ui' => 'hidden divider']); -\Atk4\Ui\Button::addTo($virtualPage, ['Back', 'icon' => 'left arrow'])->link('virtual.php'); +View::addTo($virtualPage, ['ui' => 'hidden divider']); +Button::addTo($virtualPage, ['Back', 'icon' => 'left arrow'])->link('virtual.php'); -$bar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']); -\Atk4\Ui\Button::addTo($bar)->set('Inside current layout')->link($virtualPage->getUrl()); -\Atk4\Ui\Button::addTo($bar)->set('On a blank page')->link($virtualPage->getUrl('popup')); -\Atk4\Ui\Button::addTo($bar)->set('No layout at all')->link($virtualPage->getUrl('cut')); +$bar = View::addTo($app, ['ui' => 'buttons']); +Button::addTo($bar)->set('Inside current layout')->link($virtualPage->getUrl()); +Button::addTo($bar)->set('On a blank page')->link($virtualPage->getUrl('popup')); +Button::addTo($bar)->set('No layout at all')->link($virtualPage->getUrl('cut')); -\Atk4\Ui\Header::addTo($app, ['Inside Modal', 'subHeader' => 'Virtual page content can be display using JsModal Class.']); +Header::addTo($app, ['Inside Modal', 'subHeader' => 'Virtual page content can be display using JsModal Class.']); -$bar = \Atk4\Ui\View::addTo($app, ['ui' => 'buttons']); -\Atk4\Ui\Button::addTo($bar)->set('Load in Modal')->on('click', new \Atk4\Ui\JsModal('My Popup Title', $virtualPage->getJsUrl('cut'))); +$bar = View::addTo($app, ['ui' => 'buttons']); +Button::addTo($bar)->set('Load in Modal')->on('click', new \Atk4\Ui\JsModal('My Popup Title', $virtualPage->getJsUrl('cut'))); -\Atk4\Ui\Button::addTo($bar)->set('Simulate slow load')->on('click', new \Atk4\Ui\JsModal('My Popup Title', $virtualPage->getJsUrl('cut') . '&slow=true')); +Button::addTo($bar)->set('Simulate slow load')->on('click', new \Atk4\Ui\JsModal('My Popup Title', $virtualPage->getJsUrl('cut') . '&slow=true')); if (isset($_GET['slow'])) { sleep(1); } -\Atk4\Ui\Button::addTo($bar)->set('No title')->on('click', new \Atk4\Ui\JsModal(null, $virtualPage->getJsUrl('cut'))); +Button::addTo($bar)->set('No title')->on('click', new \Atk4\Ui\JsModal(null, $virtualPage->getJsUrl('cut'))); -\Atk4\Ui\View::addTo($app, ['ui' => 'hidden divider']); -$text = \Atk4\Ui\Text::addTo($app); +View::addTo($app, ['ui' => 'hidden divider']); +$text = Text::addTo($app); $text->addParagraph('Can also be trigger from a js event, like clicking on a table row.'); $table = \Atk4\Ui\Table::addTo($app, ['celled' => true]); $table->setModel(new SomeData()); -$frame = \Atk4\Ui\VirtualPage::addTo($app); +$frame = VirtualPage::addTo($app); $frame->set(function ($frame) { - \Atk4\Ui\Header::addTo($frame, ['Clicked row with ID = ' . ($_GET['id'] ?? '')]); + Header::addTo($frame, ['Clicked row with ID = ' . ($_GET['id'] ?? '')]); }); $table->onRowClick(new \Atk4\Ui\JsModal('Row Clicked', $frame, ['id' => $table->jsRow()->data('id')])); diff --git a/src/VirtualPage.php b/src/VirtualPage.php index 844a38efe2..1702030a41 100644 --- a/src/VirtualPage.php +++ b/src/VirtualPage.php @@ -136,20 +136,10 @@ public function getHtml() } } - // Prepare modals in order to include them in VirtualPage. - $modalHtml = ''; - foreach ($this->getApp()->html !== null ? $this->getApp()->html->elements : [] as $view) { - if ($view instanceof Modal) { - $modalHtml .= $view->getHtml(); - $this->getApp()->layout->_js_actions = array_merge($this->getApp()->layout->_js_actions, $view->_js_actions); - } - } - $this->getApp()->layout->template->dangerouslySetHtml('Content', parent::getHtml()); $this->getApp()->layout->_js_actions = array_merge($this->getApp()->layout->_js_actions, $this->_js_actions); $this->getApp()->html->template->dangerouslySetHtml('Content', $this->getApp()->layout->template->renderToHtml()); - $this->getApp()->html->template->dangerouslySetHtml('Modals', $modalHtml); $this->getApp()->html->template->dangerouslyAppendHtml('HEAD', $this->getApp()->layout->getJs()); diff --git a/tests-behat/virtual-page.feature b/tests-behat/virtual-page.feature index 9635735116..0cf55b19da 100644 --- a/tests-behat/virtual-page.feature +++ b/tests-behat/virtual-page.feature @@ -4,6 +4,8 @@ Feature: VirtualPage Given I am on "interactive/virtual.php" Then I click link 'More info on Car' Then text in container using '.__atk-behat-test-car' should contains 'Car' + Then I press button "Open Lorem Ipsum" + Then Modal is open with text 'This is yet another modal' Scenario: Given I am on "interactive/virtual.php" From 8b01985265b3bba6cfb0fe732dda8b099cac4cf0 Mon Sep 17 00:00:00 2001 From: Alain Belair Date: Tue, 5 Oct 2021 16:46:31 -0400 Subject: [PATCH 5/5] fix comment --- src/App.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/App.php b/src/App.php index 60673d056e..38b8535fe2 100644 --- a/src/App.php +++ b/src/App.php @@ -1154,7 +1154,7 @@ private function outputResponseJson($data, array $headers = []): void } /** - * Generated html and js for modals attached to $html view. + * Generated html and js for portal view registered to app. */ private function getRenderedPortals(): array {