From d3ff728d432ef98cfe6f4c630d2f40319ae75983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Sat, 9 Apr 2022 19:05:54 +0200 Subject: [PATCH] Remove View::id prop in favor of NameTrait::name (#1769) --- README.md | 27 +++++++++++++++------------ demos/_unit-test/scope-builder.php | 2 +- demos/basic/columns.php | 2 +- demos/collection/card-deck.php | 3 ++- demos/data-action/jsactionsgrid.php | 11 ++++++----- demos/javascript/js.php | 2 +- docs/render.rst | 2 +- docs/view.rst | 10 +++++----- src/Card.php | 3 ++- src/CardDeck.php | 3 ++- src/Crud.php | 3 ++- src/Form/Control.php | 4 ++-- src/Form/Control/Calendar.php | 2 +- src/Form/Control/Dropdown.php | 2 +- src/Form/Control/Input.php | 5 +++-- src/Form/Control/Lookup.php | 2 +- src/Form/Control/Textarea.php | 2 +- src/Form/Control/TreeItemSelector.php | 11 +++++++++-- src/Form/Layout.php | 4 ++-- src/Grid.php | 5 +++-- src/JsCallback.php | 2 +- src/Table/Column/ActionButtons.php | 2 +- src/Table/Column/ActionMenu.php | 2 +- src/UserAction/BasicExecutor.php | 2 +- src/UserAction/ExecutorFactory.php | 2 +- src/UserAction/StepExecutorTrait.php | 2 +- src/View.php | 13 +++---------- tests/JsIntegrationTest.php | 16 ++++++++-------- tests/TableColumnColorRatingTest.php | 5 +---- tests/TableColumnLinkTest.php | 12 ++++++++++-- 30 files changed, 89 insertions(+), 74 deletions(-) diff --git a/README.md b/README.md index 875e19194c..5fe45643ab 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,6 @@ $app = new \Atk4\Ui\App(); $app->initLayout([\Atk4\Ui\Layout\Centered::class]); $form = \Atk4\Ui\Form::addTo($app); - $form->addField('email'); $form->onSubmit(function (Form $form) { // implement subscribe here @@ -93,7 +92,8 @@ $app = new \Atk4\Ui\App('hello world'); $app->initLayout([\Atk4\Ui\Layout\Admin::class]); $app->db = \Atk4\Data\Persistence::connect('mysql://user:pass@localhost/atk'); -\Atk4\Ui\Crud::addTo($app)->setModel(new User($app->db)); +\Atk4\Ui\Crud::addTo($app) + ->setModel(new User($app->db)); ``` ATK Data allows you to set up relations between models: @@ -104,7 +104,7 @@ class User extends Model { parent::init(); $this->addField('name'); - $this->addField('gender', ['enum' => 'female','male','other']); + $this->addField('gender', ['enum' => 'female', 'male', 'other']); $this->hasMany('Purchases', ['model' => [Purchase::class]]); } } @@ -117,10 +117,10 @@ use \Atk4\Mastercrud\MasterCrud; // set up $app here -$master_crud = MasterCrud::addTo($app); -$master_crud->setModel(new User($app->db), [ - 'Purchases' => [] -]); +$master_crud = MasterCrud::addTo($app) + ->setModel(new User($app->db), [ + 'Purchases' => [], + ]); ``` @@ -136,7 +136,7 @@ As of version 2.0 - Agile Toolkit offers support for User Actions. Those are eas ``` php $this->addAction('archive', function (Model $m) { - $m->get('is_archived') = true; + $m->set('is_archived', true); $this->saveAndUnload(); }); ``` @@ -159,7 +159,8 @@ $tabs = \Atk4\Ui\Tabs::addTo($app); $tabs->addTab('Users', function (\Atk4\Ui\VirtualPage $p) use ($app) { // this tab is loaded dynamically, but also contains dynamic component - \Atk4\Ui\Crud::addTo($p)->setModel(new User($app->db)); + \Atk4\Ui\Crud::addTo($p) + ->setModel(new User($app->db)); }); $tabs->addTab('Settings', function (\Atk4\Ui\VirtualPage $p) use ($app) { @@ -167,7 +168,8 @@ $tabs->addTab('Settings', function (\Atk4\Ui\VirtualPage $p) use ($app) { $m = new Settings($app->db); $m = $m->load(2); - \Atk4\Ui\Form::addTo($p)->setModel($m); + \Atk4\Ui\Form::addTo($p) + ->setModel($m); }); ``` @@ -210,7 +212,8 @@ class User extends \Atk4\Data\Model { } } -\Atk4\Ui\Crud::addTo($app)->setModel(new User($app->db)); +\Atk4\Ui\Crud::addTo($app) + ->setModel(new User($app->db)); ``` The result is here: @@ -221,7 +224,7 @@ The result is here: Agile UI comes with many built-in components: -_All components can be view using the [demos](ui.agiletoolkit.org/demos) application._ +_All components can be view using the [demos](https://ui.agiletoolkit.org/demos/) application._ | Component | Description | Introduced | | ------------------------------------------------------------ | ------------------------------------------------------------ | ---------- | diff --git a/demos/_unit-test/scope-builder.php b/demos/_unit-test/scope-builder.php index 3d1c585531..40058c6d93 100644 --- a/demos/_unit-test/scope-builder.php +++ b/demos/_unit-test/scope-builder.php @@ -40,7 +40,7 @@ $form->onSubmit(function (Form $form) use ($model) { $message = $form->model->get('qb')->toWords($model); - $view = (new \Atk4\Ui\View(['id' => false]))->addClass('atk-scope-builder-response'); + $view = (new \Atk4\Ui\View(['name' => false]))->addClass('atk-scope-builder-response'); $view->invokeInit(); $view->set($message); diff --git a/demos/basic/columns.php b/demos/basic/columns.php index aef9ff85cf..93c43af706 100644 --- a/demos/basic/columns.php +++ b/demos/basic/columns.php @@ -23,7 +23,7 @@ } '); -$page = \Atk4\Ui\View::addTo($app, ['id' => 'example']); +$page = \Atk4\Ui\View::addTo($app, ['name' => 'example']); \Atk4\Ui\Header::addTo($page, ['Basic Usage']); diff --git a/demos/collection/card-deck.php b/demos/collection/card-deck.php index f22326c2bc..ee1e1dc387 100644 --- a/demos/collection/card-deck.php +++ b/demos/collection/card-deck.php @@ -6,6 +6,7 @@ use Atk4\Ui\Button; use Atk4\Ui\Header; +use Atk4\Ui\UserAction\ExecutorFactory; /** @var \Atk4\Ui\App $app */ require_once __DIR__ . '/../init-app.php'; @@ -24,7 +25,7 @@ ]); // Create custom button for this action in card. -$app->getExecutorFactory()->registerTrigger($app->getExecutorFactory()::CARD_BUTTON, [Button::class, null, 'blue', 'icon' => 'plane'], $action); +$app->getExecutorFactory()->registerTrigger(ExecutorFactory::CARD_BUTTON, [Button::class, null, 'blue', 'icon' => 'plane'], $action); $action->args = [ 'email' => ['type' => 'string', 'required' => true, 'caption' => 'Please let us know your email address:'], diff --git a/demos/data-action/jsactionsgrid.php b/demos/data-action/jsactionsgrid.php index b80a221a06..cc14bc8562 100644 --- a/demos/data-action/jsactionsgrid.php +++ b/demos/data-action/jsactionsgrid.php @@ -7,6 +7,7 @@ use Atk4\Core\Factory; use Atk4\Data\Model\UserAction; use Atk4\Ui\Icon; +use Atk4\Ui\UserAction\ExecutorFactory; use Atk4\Ui\View; /** @var \Atk4\Ui\App $app */ @@ -20,22 +21,22 @@ // creating special menu item for multi_step action. $multiAction = $country->getUserAction('multi_step'); -$specialItem = Factory::factory([View::class], ['id' => false, 'class' => ['item'], 'content' => 'Multi Step']); +$specialItem = Factory::factory([View::class], ['name' => false, 'class' => ['item'], 'content' => 'Multi Step']); Icon::addTo($specialItem, ['content' => 'window maximize outline']); // register this menu item in factory. -$app->getExecutorFactory()->registerTrigger($app->getExecutorFactory()::TABLE_MENU_ITEM, $specialItem, $multiAction); +$app->getExecutorFactory()->registerTrigger(ExecutorFactory::TABLE_MENU_ITEM, $specialItem, $multiAction); \Atk4\Ui\Header::addTo($app, ['Execute model action from Grid menu items', 'subHeader' => 'Setting grid menu items in order to execute model actions or javascript.']); $grid = \Atk4\Ui\Grid::addTo($app, ['menu' => false]); $grid->setModel($country); -$divider = Factory::factory([View::class], ['id' => false, 'class' => ['divider'], 'content' => '']); +$divider = Factory::factory([View::class], ['name' => false, 'class' => ['divider'], 'content' => '']); -$modelHeader = Factory::factory([View::class], ['id' => false, 'class' => ['header'], 'content' => 'Model Actions']); +$modelHeader = Factory::factory([View::class], ['name' => false, 'class' => ['header'], 'content' => 'Model Actions']); Icon::addTo($modelHeader, ['content' => 'database']); -$jsHeader = Factory::factory([View::class], ['id' => false, 'class' => ['header'], 'content' => 'Js Actions']); +$jsHeader = Factory::factory([View::class], ['name' => false, 'class' => ['header'], 'content' => 'Js Actions']); Icon::addTo($jsHeader, ['content' => 'file code']); $grid->addActionMenuItem($jsHeader); diff --git a/demos/javascript/js.php b/demos/javascript/js.php index e14d79672f..5da20d2f66 100644 --- a/demos/javascript/js.php +++ b/demos/javascript/js.php @@ -19,7 +19,7 @@ $b->js(true)->hide(); // This button hides when clicked -$b = Button::addTo($app, ['id' => 'b2'])->set('Hide on click Button'); +$b = Button::addTo($app, ['name' => 'b2'])->set('Hide on click Button'); $b->js('click')->hide(); Button::addTo($app, ['Redirect'])->on('click', null, $app->jsRedirect(['foo' => 'bar'])); diff --git a/docs/render.rst b/docs/render.rst index 4072569f3a..6603d5dcbb 100644 --- a/docs/render.rst +++ b/docs/render.rst @@ -91,7 +91,7 @@ will create its own tree independent from the main one. Agile UI sometimes uses the following approach to render element on the outside: 1. Create new instance of $sub_view. -2. Set $sub_view->id = false; +2. Set $sub_view->name = false; 3. Calls $view->add($sub_view); 4. executes $sub_view->renderHtml() diff --git a/docs/view.rst b/docs/view.rst index 894ba0b9a9..bf986d5e1a 100644 --- a/docs/view.rst +++ b/docs/view.rst @@ -203,12 +203,12 @@ If you happen to pass more key/values to the constructor or as second argument to add() they will be treated as default values for the properties of that specific view:: - $view = View::addTo($app, ['ui' => 'segment', 'id' => 'test-id']); + $view = View::addTo($app, ['ui' => 'segment', 'name' => 'test-id']); For a more IDE-friendly format, however, I recommend to use the following syntax:: $view = View::addTo($app, ['ui' => 'segment']); - $view->id = 'test-id'; + $view->name = 'test-id'; You must be aware of a difference here - passing array to constructor will override default property before call to `init()`. Most of the components @@ -222,7 +222,7 @@ If you are don't specify key for the properties, they will be considered an extra class for a view:: $view = View::addTo($app, ['inverted', 'orange', 'ui' => 'segment']); - $view->id = 'test-id'; + $view->name = 'test-id'; You can either specify multiple classes one-by-one or as a single string "inverted orange". @@ -407,9 +407,9 @@ Unique ID tag ID to be used with the top-most element. -Agile UI will maintain unique ID for all the elements. The tag is set through 'id' property:: +Agile UI will maintain unique ID for all the elements. The tag is set through 'name' property:: - $b = new \Atk4\Ui\Button(['id' => 'my-button3']); + $b = new \Atk4\Ui\Button(['name' => 'my-button3']); echo $b->render(); Outputs: diff --git a/src/Card.php b/src/Card.php index 13412f20aa..e5456c4e5d 100644 --- a/src/Card.php +++ b/src/Card.php @@ -26,6 +26,7 @@ use Atk4\Core\Factory; use Atk4\Data\Model; +use Atk4\Ui\UserAction\ExecutorFactory; class Card extends View { @@ -285,7 +286,7 @@ public function addClickAction(Model\UserAction $action, Button $button = null, { $defaults = []; - $btn = $this->addButton($button ?? $this->getExecutorFactory()->createTrigger($action, $this->getExecutorFactory()::CARD_BUTTON)); + $btn = $this->addButton($button ?? $this->getExecutorFactory()->createTrigger($action, ExecutorFactory::CARD_BUTTON)); // Setting arg for model id. $args[0] is consider to hold a model id, i.e. as a js expression. if ($this->model && $this->model->isLoaded() && !isset($args[0])) { diff --git a/src/CardDeck.php b/src/CardDeck.php index 763b478edd..1aec5165f2 100644 --- a/src/CardDeck.php +++ b/src/CardDeck.php @@ -10,6 +10,7 @@ use Atk4\Core\Factory; use Atk4\Data\Model; use Atk4\Ui\Component\ItemSearch; +use Atk4\Ui\UserAction\ExecutorFactory; use Atk4\Ui\UserAction\ExecutorInterface; class CardDeck extends View @@ -327,7 +328,7 @@ protected function addExecutorMenuButton(ExecutorInterface $executor): AbstractV $defaults['args'] = $args; } - $btn = $this->btns->add($this->getExecutorFactory()->createTrigger($executor->getAction(), $this->getExecutorFactory()::CARD_BUTTON)); + $btn = $this->btns->add($this->getExecutorFactory()->createTrigger($executor->getAction(), ExecutorFactory::CARD_BUTTON)); if ($executor->getAction()->enabled === false) { $btn->addClass('disabled'); } diff --git a/src/Crud.php b/src/Crud.php index 15b64a84d7..7dc4bf686c 100644 --- a/src/Crud.php +++ b/src/Crud.php @@ -6,6 +6,7 @@ use Atk4\Core\Factory; use Atk4\Data\Model; +use Atk4\Ui\UserAction\ExecutorFactory; /** * Implements a more sophisticated and interactive Data-Table component. @@ -118,7 +119,7 @@ public function setModel(Model $model, array $fields = null): void if ($action->enabled) { $executor = $this->initActionExecutor($action); $this->menuItems[$k]['item'] = $this->menu->addItem( - $this->getExecutorFactory()->createTrigger($action, $this->getExecutorFactory()::MENU_ITEM) + $this->getExecutorFactory()->createTrigger($action, ExecutorFactory::MENU_ITEM) ); $this->menuItems[$k]['executor'] = $executor; } diff --git a/src/Form/Control.php b/src/Form/Control.php index 50dd1758c6..14d2bd6684 100644 --- a/src/Form/Control.php +++ b/src/Form/Control.php @@ -157,7 +157,7 @@ public function onChange($expr, $default = []) $default['stopPropagation'] = $default; } - $this->on('change', '#' . $this->id . '_input', $expr, $default); + $this->on('change', '#' . $this->name . '_input', $expr, $default); } /** @@ -170,7 +170,7 @@ public function onChange($expr, $default = []) */ public function jsInput($when = null, $action = null) { - return $this->js($when, $action, '#' . $this->id . '_input'); + return $this->js($when, $action, '#' . $this->name . '_input'); } /** diff --git a/src/Form/Control/Calendar.php b/src/Form/Control/Calendar.php index b53326355a..7883440aad 100644 --- a/src/Form/Control/Calendar.php +++ b/src/Form/Control/Calendar.php @@ -105,7 +105,7 @@ public function onChange($expr, $default = []) */ public function getJsInstance(): JsExpression { - return (new Jquery('#' . $this->id . '_input'))->get(0)->_flatpickr; + return (new Jquery('#' . $this->name . '_input'))->get(0)->_flatpickr; } private function expandPhpDtFormat(string $phpFormat): string diff --git a/src/Form/Control/Dropdown.php b/src/Form/Control/Dropdown.php index ea15160423..03c6dd3a6e 100644 --- a/src/Form/Control/Dropdown.php +++ b/src/Form/Control/Dropdown.php @@ -134,7 +134,7 @@ public function getInput() return $this->getApp()->getTag('input', array_merge([ 'name' => $this->short_name, 'type' => $this->inputType, - 'id' => $this->id . '_input', + 'id' => $this->name . '_input', 'value' => $this->getValue(), 'readonly' => $this->readonly ? 'readonly' : false, 'disabled' => $this->disabled ? 'disabled' : false, diff --git a/src/Form/Control/Input.php b/src/Form/Control/Input.php index e53eb554dd..86a4b288d7 100644 --- a/src/Form/Control/Input.php +++ b/src/Form/Control/Input.php @@ -9,6 +9,7 @@ use Atk4\Ui\Form; use Atk4\Ui\Icon; use Atk4\Ui\Label; +use Atk4\Ui\UserAction\ExecutorFactory; use Atk4\Ui\UserAction\JsCallbackExecutor; /** @@ -109,7 +110,7 @@ public function getInput() 'name' => $this->short_name, 'type' => $this->inputType, 'placeholder' => $this->placeholder, - 'id' => $this->id . '_input', + 'id' => $this->name . '_input', 'value' => $this->getValue(), 'readonly' => $this->readonly ? 'readonly' : false, 'disabled' => $this->disabled ? 'disabled' : false, @@ -155,7 +156,7 @@ protected function prepareRenderButton($button, $spot) } if ($button instanceof UserAction || $button instanceof JsCallbackExecutor) { $executor = ($button instanceof UserAction) - ? $this->getExecutorFactory()->create($button, $this, $this->getExecutorFactory()::JS_EXECUTOR) + ? $this->getExecutorFactory()->create($button, $this, ExecutorFactory::JS_EXECUTOR) : $button; $button = $this->add($this->getExecutorFactory()->createTrigger($executor->getAction()), $spot); $this->addClass('action'); diff --git a/src/Form/Control/Lookup.php b/src/Form/Control/Lookup.php index 6817a6061f..15de0b37de 100644 --- a/src/Form/Control/Lookup.php +++ b/src/Form/Control/Lookup.php @@ -344,7 +344,7 @@ public function getInput() return $this->getApp()->getTag('input', array_merge([ 'name' => $this->short_name, 'type' => 'hidden', - 'id' => $this->id . '_input', + 'id' => $this->name . '_input', 'value' => $this->getValue(), 'readonly' => $this->readonly ? 'readonly' : false, 'disabled' => $this->disabled ? 'disabled' : false, diff --git a/src/Form/Control/Textarea.php b/src/Form/Control/Textarea.php index e76eaf2e17..9bdb48c4f2 100644 --- a/src/Form/Control/Textarea.php +++ b/src/Form/Control/Textarea.php @@ -26,7 +26,7 @@ public function getInput() 'type' => $this->inputType, 'rows' => $this->rows, 'placeholder' => $this->placeholder, - 'id' => $this->id . '_input', + 'id' => $this->name . '_input', 'readonly' => $this->readonly ? 'readonly' : false, 'disabled' => $this->disabled ? 'disabled' : false, ], $this->inputAttr), diff --git a/src/Form/Control/TreeItemSelector.php b/src/Form/Control/TreeItemSelector.php index d9adbecc8d..27d14f9006 100644 --- a/src/Form/Control/TreeItemSelector.php +++ b/src/Form/Control/TreeItemSelector.php @@ -46,9 +46,16 @@ class TreeItemSelector extends Form\Control * * Each item may have it's own children by adding nodes children to it. * $items = [ - * ['name' => 'Electronics', 'id' => 'P100', 'nodes' => [['name' => 'Phone', 'id' => 'P100', 'nodes' => [['name' => 'iPhone', 'id' => 502], ['name' => 'Google Pixels', 'id' => 503]]], ['name' => 'Tv' , 'id' => 501], ['name' => 'Radio' , 'id' => 601]]], + * ['name' => 'Electronics', 'id' => 'P100', 'nodes' => [ + * ['name' => 'Phone', 'id' => 'P100', 'nodes' => [ + * ['name' => 'iPhone', 'id' => 502], + * ['name' => 'Google Pixels', 'id' => 503], + * ]], + * ['name' => 'Tv' , 'id' => 501], + * ['name' => 'Radio' , 'id' => 601], + * ]], * ['name' => 'Cleaner' , 'id' => 201], - * ['name' => 'Appliances' , 'id' => 301] + * ['name' => 'Appliances' , 'id' => 301], * ]; * * When adding nodes array into an item, it will automatically be treated as a group unless empty. diff --git a/src/Form/Layout.php b/src/Form/Layout.php index a3890fb8d6..f588e783f3 100644 --- a/src/Form/Layout.php +++ b/src/Form/Layout.php @@ -198,7 +198,7 @@ protected function recursiveRender(): void // Controls get extra pampering $template->dangerouslySetHtml('Input', $element->getHtml()); $template->trySet('label', $label); - $template->trySet('label_for', $element->id . '_input'); + $template->trySet('label_for', $element->name . '_input'); $template->set('control_class', $element->getControlClass()); if ($element->entityField->getField()->required) { @@ -211,7 +211,7 @@ protected function recursiveRender(): void if ($element->hint && $template->hasTag('Hint')) { $hint = Factory::factory($this->defaultHint); - $hint->id = $element->id . '_hint'; + $hint->name = $element->name . '_hint'; if (is_object($element->hint) || is_array($element->hint)) { $hint->add($element->hint); } else { diff --git a/src/Grid.php b/src/Grid.php index ea9fe29ef6..3c8f3329a0 100644 --- a/src/Grid.php +++ b/src/Grid.php @@ -9,6 +9,7 @@ use Atk4\Data\Model; use Atk4\Ui\Table\Column\ActionButtons; use Atk4\Ui\UserAction\ConfirmationExecutor; +use Atk4\Ui\UserAction\ExecutorFactory; use Atk4\Ui\UserAction\ExecutorInterface; /** @@ -373,7 +374,7 @@ public function addActionButton($button, $action = null, string $confirmMsg = '' */ public function addExecutorButton(UserAction\ExecutorInterface $executor, Button $button = null) { - $btn = $button ? $this->add($button) : $this->getExecutorFactory()->createTrigger($executor->getAction(), $this->getExecutorFactory()::TABLE_BUTTON); + $btn = $button ? $this->add($button) : $this->getExecutorFactory()->createTrigger($executor->getAction(), ExecutorFactory::TABLE_BUTTON); $confirmation = $executor->getAction()->getConfirmation() ?: ''; $disabled = is_bool($executor->getAction()->enabled) ? !$executor->getAction()->enabled : $executor->getAction()->enabled; @@ -404,7 +405,7 @@ public function addActionMenuItem($view, $action = null, string $confirmMsg = '' public function addExecutorMenuItem(ExecutorInterface $executor) { - $item = $this->getExecutorFactory()->createTrigger($executor->getAction(), $this->getExecutorFactory()::TABLE_MENU_ITEM); + $item = $this->getExecutorFactory()->createTrigger($executor->getAction(), ExecutorFactory::TABLE_MENU_ITEM); // ConfirmationExecutor take care of showing the user confirmation, thus make it empty. $confirmation = !$executor instanceof ConfirmationExecutor ? ($executor->getAction()->getConfirmation() ?: '') : ''; $disabled = is_bool($executor->getAction()->enabled) ? !$executor->getAction()->enabled : $executor->getAction()->enabled; diff --git a/src/JsCallback.php b/src/JsCallback.php index 321259d4c2..921246a289 100644 --- a/src/JsCallback.php +++ b/src/JsCallback.php @@ -186,7 +186,7 @@ private function _jsRenderIntoModal(View $response): JsExpressionable if ($response instanceof Modal) { $html = $response->getHtml(); } else { - $modal = new Modal(['id' => false]); + $modal = new Modal(['name' => false]); $modal->add($response); $html = $modal->getHtml(); } diff --git a/src/Table/Column/ActionButtons.php b/src/Table/Column/ActionButtons.php index 8b79189aea..d47604b7c1 100644 --- a/src/Table/Column/ActionButtons.php +++ b/src/Table/Column/ActionButtons.php @@ -48,7 +48,7 @@ public function addButton($button, $action = null, string $confirmMsg = '', $isD $button = [1 => $button]; } - $button = Factory::factory([Button::class], Factory::mergeSeeds($button, ['id' => false])); + $button = Factory::factory([Button::class], Factory::mergeSeeds($button, ['name' => false])); } if ($isDisabled === true) { diff --git a/src/Table/Column/ActionMenu.php b/src/Table/Column/ActionMenu.php index ab6aae0810..f5e620518c 100644 --- a/src/Table/Column/ActionMenu.php +++ b/src/Table/Column/ActionMenu.php @@ -68,7 +68,7 @@ public function addActionMenuItem($item, $action = null, string $confirmMsg = '' $name = $this->name . '_action_' . (count($this->items) + 1); if (!is_object($item)) { - $item = Factory::factory([\Atk4\Ui\View::class], ['id' => false, 'ui' => 'item', 'content' => $item]); + $item = Factory::factory([\Atk4\Ui\View::class], ['name' => false, 'ui' => 'item', 'content' => $item]); } $this->items[] = $item; diff --git a/src/UserAction/BasicExecutor.php b/src/UserAction/BasicExecutor.php index 7c8d0e3e99..21617882ef 100644 --- a/src/UserAction/BasicExecutor.php +++ b/src/UserAction/BasicExecutor.php @@ -58,7 +58,7 @@ public function setAction(Model\UserAction $action): void { $this->action = $action; if (!$this->executorButton) { - $this->executorButton = $this->getExecutorFactory()->createTrigger($action, $this->getExecutorFactory()::BASIC_BUTTON); + $this->executorButton = $this->getExecutorFactory()->createTrigger($action, ExecutorFactory::BASIC_BUTTON); } } diff --git a/src/UserAction/ExecutorFactory.php b/src/UserAction/ExecutorFactory.php index d3c8fc77e6..016373b1aa 100644 --- a/src/UserAction/ExecutorFactory.php +++ b/src/UserAction/ExecutorFactory.php @@ -217,7 +217,7 @@ protected function getDefaultTrigger(UserAction $action, string $type = null): a break; case self::TABLE_MENU_ITEM: - $seed = [Item::class, $this->getActionCaption($action, $type), 'id' => false, ['class' => 'item']]; + $seed = [Item::class, $this->getActionCaption($action, $type), 'name' => false, ['class' => 'item']]; break; default: diff --git a/src/UserAction/StepExecutorTrait.php b/src/UserAction/StepExecutorTrait.php index 103ab918b7..d806fc1be3 100644 --- a/src/UserAction/StepExecutorTrait.php +++ b/src/UserAction/StepExecutorTrait.php @@ -351,7 +351,7 @@ protected function createButtonBar(Model\UserAction $action): View $this->btns = (new View())->addStyle(['min-height' => '24px']); $this->prevStepBtn = Button::addTo($this->btns, ['Prev'])->addStyle(['float' => 'left !important']); $this->nextStepBtn = Button::addTo($this->btns, ['Next', 'blue']); - $this->execActionBtn = $this->getExecutorFactory()->createTrigger($action, $this->getExecutorFactory()::MODAL_BUTTON); + $this->execActionBtn = $this->getExecutorFactory()->createTrigger($action, ExecutorFactory::MODAL_BUTTON); $this->btns->add($this->execActionBtn); return $this->btns; diff --git a/src/View.php b/src/View.php index b79377ef08..c5f68c5143 100644 --- a/src/View.php +++ b/src/View.php @@ -45,9 +45,6 @@ class View extends AbstractView implements JsExpressionable */ public $ui = false; - /** @var string ID of the element, that's unique and is used in JS operations. */ - public $id; - /** @var array List of classes that needs to be added. */ public $class = []; @@ -237,10 +234,6 @@ protected function init(): void $this->_add_later = []; parent::init(); - if ($this->id === null) { - $this->id = $this->name; - } - if ($this->region && !$this->template && !$this->defaultTemplate && $this->issetOwner() && $this->getOwner()->template) { $this->template = $this->getOwner()->template->cloneRegion($this->region); @@ -641,8 +634,8 @@ function (&$item, $key) { $this->template->tryDel('_ui'); } - if ($this->id) { - $this->template->trySet('_id', $this->id); + if ($this->name) { + $this->template->trySet('_id', $this->name); } if ($this->element) { @@ -1139,7 +1132,7 @@ public function jsRender(): string { $this->assertIsInitialized(); - return json_encode('#' . $this->id, \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR); + return json_encode('#' . $this->name, \JSON_UNESCAPED_UNICODE | \JSON_THROW_ON_ERROR); } /** diff --git a/tests/JsIntegrationTest.php b/tests/JsIntegrationTest.php index ef243fa5d9..616d32bb89 100644 --- a/tests/JsIntegrationTest.php +++ b/tests/JsIntegrationTest.php @@ -14,9 +14,9 @@ public function testIdIntegrity1(): void { $v = new Button(['icon' => 'pencil']); $html = $v->render(); - $this->assertNotNull($v->icon->id); + $this->assertNotNull($v->icon->name); - $this->assertNotSame($v->id, $v->icon->id); + $this->assertNotSame($v->name, $v->icon->name); } public function testIdIntegrity2(): void @@ -26,7 +26,7 @@ public function testIdIntegrity2(): void $b2 = Button::addTo($v); $html = $v->render(); - $this->assertNotSame($b1->id, $b2->id); + $this->assertNotSame($b1->name, $b2->name); } /** @@ -34,7 +34,7 @@ public function testIdIntegrity2(): void */ public function testBasicChain1(): void { - $v = new Button(['id' => 'b']); + $v = new Button(['name' => 'b']); $j = $v->js()->hide(); $v->render(); @@ -46,7 +46,7 @@ public function testBasicChain1(): void */ public function testBasicChain2(): void { - $v = new Button(['id' => 'b']); + $v = new Button(['name' => 'b']); $j = $v->js(true)->hide(); $v->getHtml(); @@ -60,7 +60,7 @@ public function testBasicChain2(): void */ public function testBasicChain3(): void { - $v = new Button(['id' => 'b']); + $v = new Button(['name' => 'b']); $v->js('click')->hide(); $v->getHtml(); @@ -77,8 +77,8 @@ public function testBasicChain3(): void public function testBasicChain4(): void { $bb = new View(['ui' => 'buttons']); - $b1 = Button::addTo($bb, ['id' => 'b1']); - $b2 = Button::addTo($bb, ['id' => 'b2']); + $b1 = Button::addTo($bb, ['name' => 'b1']); + $b2 = Button::addTo($bb, ['name' => 'b2']); $b1->on('click', $b2->js()->hide()); $bb->getHtml(); diff --git a/tests/TableColumnColorRatingTest.php b/tests/TableColumnColorRatingTest.php index 0efc8af985..7ebaf3a892 100644 --- a/tests/TableColumnColorRatingTest.php +++ b/tests/TableColumnColorRatingTest.php @@ -22,10 +22,7 @@ protected function setUp(): void $arr = [ 'table' => [ 1 => [ - 'id' => 1, - 'name' => 'bar', - 'ref' => 'ref123', - 'rating' => 3, + 'id' => 1, 'name' => 'bar', 'ref' => 'ref123', 'rating' => 3, ], ], ]; diff --git a/tests/TableColumnLinkTest.php b/tests/TableColumnLinkTest.php index fd0f95f1ac..ab8f040b26 100644 --- a/tests/TableColumnLinkTest.php +++ b/tests/TableColumnLinkTest.php @@ -18,7 +18,11 @@ class TableColumnLinkTest extends TestCase protected function setUp(): void { - $arr = ['table' => [1 => ['id' => 1, 'name' => 'bar', 'ref' => 'ref123', 'salary' => -123]]]; + $arr = [ + 'table' => [ + 1 => ['id' => 1, 'name' => 'bar', 'ref' => 'ref123', 'salary' => -123], + ], + ]; $db = new Persistence\Array_($arr); $m = new \Atk4\Data\Model($db, ['table' => 'table']); $m->addField('name'); @@ -259,7 +263,11 @@ public function testLink9(): void public function testLink10(): void { // need to reset all to set a nulled value in field name model - $arr = ['table' => [1 => ['id' => 1, 'name' => '', 'ref' => 'ref123', 'salary' => -123]]]; + $arr = [ + 'table' => [ + 1 => ['id' => 1, 'name' => '', 'ref' => 'ref123', 'salary' => -123], + ], + ]; $db = new Persistence\Array_($arr); $m = new \Atk4\Data\Model($db, ['table' => 'table']); $m->addField('name');