Skip to content

Commit

Permalink
Fix missing bulk action input typecast (#2164)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Feb 11, 2024
1 parent a90d044 commit bb240e5
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 48 deletions.
7 changes: 6 additions & 1 deletion demos/_unit-test/scope-builder-to-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,14 @@
],
],
];
$scope = (new Form\Control\ScopeBuilder())->queryToScope($q);

$product = new Product($app->db);

$scopeBuilder = new Form\Control\ScopeBuilder();
$scopeBuilder->setApp($app);
$scopeBuilder->model = $product;

$scope = $scopeBuilder->queryToScope($q);

$g = Grid::addTo($app);
$g->setModel($product->addCondition($scope));
2 changes: 1 addition & 1 deletion demos/collection/lister-ipp.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
$row->iso = mb_strtolower($row->iso);
});
$model = new Country($app->db);
$model->addCondition(Country::hinting()->fieldName()->id, -1); // no such records so model will be empty
$model->addCondition(Country::hinting()->fieldName()->id, null); // no such records so model will be empty
$lister->setModel($model);

View::addTo($app, ['ui' => 'clearing divider']);
Expand Down
3 changes: 3 additions & 0 deletions demos/init-db.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ protected function initPreventModification(): void
}
}

/**
* Improve testing by using prefixed real field and SQL names.
*/
class ModelWithPrefixedFields extends Model
{
use ModelPreventModificationTrait;
Expand Down
2 changes: 1 addition & 1 deletion docs/form-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class MyDropdown extends \Atk4\Ui\Dropdown
public $defaultTemplate = 'my_dropdown.html';
/**
* used when a custom callback is defined for row rendering. Sets
* Used when a custom callback is defined for row rendering. Sets
* values to item template and appends it to main template
*/
protected function _addCallBackRow($row, $key = null)
Expand Down
2 changes: 1 addition & 1 deletion js/src/plugins/scroll.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import AtkPlugin from './atk.plugin';
/**
* Add dynamic scrolling to a View that can accept page argument in URL.
*
* default options are:
* Default options are:
* padding: 20 The amount of padding needed prior to request a page load.
* initialPage: 1 The initial page load when calling this plugin.
* appendTo: null The HTML element where new content should be append to.
Expand Down
2 changes: 1 addition & 1 deletion public/js/atkjs-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1482,7 +1482,7 @@ __webpack_require__.r(__webpack_exports__);
/**
* Add dynamic scrolling to a View that can accept page argument in URL.
*
* default options are:
* Default options are:
* padding: 20 The amount of padding needed prior to request a page load.
* initialPage: 1 The initial page load when calling this plugin.
* appendTo: null The HTML element where new content should be append to.
Expand Down
2 changes: 1 addition & 1 deletion public/js/atkjs-ui.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/atkjs-ui.min.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/Form/Control/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,9 @@ protected function renderView(): void
*/
protected function _renderItemsForModel(): void
{
foreach ($this->model as $key => $row) {
foreach ($this->model as $id => $row) {
$title = $row->getTitle();
$this->_tItem->set('value', (string) $key);
$this->_tItem->set('value', (string) $id);
$this->_tItem->set('title', $title || is_numeric($title) ? (string) $title : '');
// add item to template
$this->template->dangerouslyAppendHtml('Item', $this->_tItem->renderToHtml());
Expand Down
8 changes: 4 additions & 4 deletions src/Form/Control/DropdownCascade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ public function set($value = null)
* Generate new dropdown values based on cascadeInput model selected ID.
* Return an empty value set if ID is null.
*
* @param string|int $id
* @param mixed $id
*/
public function getNewValues($id): array
{
if (!$id) {
if ($id === null) {
return [['value' => '', 'text' => $this->empty, 'name' => $this->empty]];
}

$model = $this->cascadeFrom->model->load($id)->ref($this->reference);
$values = [];
foreach ($model as $k => $row) {
foreach ($model as $row) {
if ($this->renderRowFunction) {
$res = ($this->renderRowFunction)($row, $k);
$res = ($this->renderRowFunction)($row); // @phpstan-ignore-line
$values[] = ['value' => $res['value'], 'text' => $res['title'], 'name' => $res['title']];
} else {
$values[] = ['value' => $row->getId(), 'text' => $row->get($model->titleField), 'name' => $row->get($model->titleField)];
Expand Down
6 changes: 3 additions & 3 deletions src/Form/Control/Multiline.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class Multiline extends Form\Control
/** @var array The fields names used in each row. */
public $rowFields;

/** @var array The data sent for each row. */
/** @var list<array<string, mixed>> The data sent for each row. */
public $rowData;

/** @var int The max number of records (rows) that can be added to Multiline. 0 means no limit. */
Expand Down Expand Up @@ -221,7 +221,7 @@ protected function init(): void
// remove __atml ID from array field
if ($this->form->model->getField($this->shortName)->type === 'json') {
$rows = [];
foreach ($this->rowData as $key => $cols) {
foreach ($this->rowData as $cols) {
unset($cols['__atkml']);
$rows[] = $cols;
}
Expand All @@ -234,7 +234,7 @@ protected function init(): void
// when errors are coming from this Multiline field, then notify Multiline component about them
// otherwise use normal field error
if ($fieldName === $this->shortName) {
// multiline.js component listen to 'multiline-rows-error' event
// multiline js component listen to 'multiline-rows-error' event
$jsError = $this->jsEmitEvent($this->multiLine->name . '-multiline-rows-error', ['errors' => $this->rowErrors]);
} else {
$jsError = $form->js()->form('add prompt', $fieldName, $str);
Expand Down
4 changes: 4 additions & 0 deletions src/Form/Control/ScopeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ public function queryToCondition(array $query): Condition
case self::OPERATOR_NOT_IN:
$value = explode($this->detectDelimiter($value), $value);

break;
default:
$value = $this->getApp()->uiPersistence->typecastLoadField($this->model->getField($key), $value);

break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Control/TreeItemSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*
* Only item ID are store within the input field.
*
* see demos/tree-item-selector.php to see how tree items are build.
* See demos/form-control/tree-item-selector.php to see how tree items are build.
*/
class TreeItemSelector extends Form\Control
{
Expand Down
33 changes: 19 additions & 14 deletions src/Grid.php
Original file line number Diff line number Diff line change
Expand Up @@ -496,11 +496,11 @@ public function addPopup($columnName, $popup = null, $icon = 'caret square down'
* Similar to addActionButton but when button is clicked, modal is displayed
* with the $title and $callback is executed.
*
* @param string|array|View $button
* @param string $title
* @param \Closure(View, string|null): void $callback
* @param array $args extra URL argument for callback
* @param bool|\Closure(Model): bool $isDisabled
* @param string|array|View $button
* @param string $title
* @param \Closure(View, mixed): void $callback
* @param array $args extra URL argument for callback
* @param bool|\Closure(Model): bool $isDisabled
*
* @return View
*/
Expand All @@ -510,20 +510,25 @@ public function addModalAction($button, $title, \Closure $callback, $args = [],
}

/**
* @return list<string>
* @return list<mixed>
*/
private function explodeSelectionValue(string $value): array
{
return $value === '' ? [] : explode(',', $value);
$res = [];
foreach ($value === '' ? [] : explode(',', $value) as $v) {
$res[] = $this->getApp()->uiPersistence->typecastLoadField($this->model->getField($this->model->idField), $v);
}

return $res;
}

/**
* Similar to addActionButton but apply to a multiple records selection and display in menu.
* When menu item is clicked, $callback is executed.
*
* @param string|array|MenuItem $item
* @param \Closure(Js\Jquery, list<string>): JsExpressionable $callback
* @param array $args extra URL argument for callback
* @param string|array|MenuItem $item
* @param \Closure(Js\Jquery, list<mixed>): JsExpressionable $callback
* @param array $args extra URL argument for callback
*
* @return View
*/
Expand All @@ -541,10 +546,10 @@ public function addBulkAction($item, \Closure $callback, $args = [])
* Similar to addModalAction but apply to a multiple records selection and display in menu.
* When menu item is clicked, modal is displayed with the $title and $callback is executed.
*
* @param string|array|MenuItem $item
* @param string $title
* @param \Closure(View, list<string>): void $callback
* @param array $args extra URL argument for callback
* @param string|array|MenuItem $item
* @param string $title
* @param \Closure(View, list<mixed>): void $callback
* @param array $args extra URL argument for callback
*
* @return View
*/
Expand Down
12 changes: 6 additions & 6 deletions src/Table/Column/ActionButtons.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public function addButton($button, $action = null, string $confirmMsg = '', $isD
* Adds a new button which will open a modal dialog and dynamically
* load contents through $callback. Will pass a virtual page.
*
* @param string|array|View $button
* @param string|array $defaults modal title or modal defaults array
* @param \Closure(View, string|null): void $callback
* @param View $owner
* @param array $args
* @param bool|\Closure(Model): bool $isDisabled
* @param string|array|View $button
* @param string|array $defaults modal title or modal defaults array
* @param \Closure(View, mixed): void $callback
* @param View $owner
* @param array $args
* @param bool|\Closure(Model): bool $isDisabled
*
* @return View
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Table/Column/KeyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* 3 => resetting
* 4 => error.
*
* we don't need a table to define this, cause are defined in project
* We don't need a table to define this, cause are defined in project.
*
* using KeyValue Column you can show this values without using DB Relations
* Using KeyValue Column you can show this values without using DB Relations
* need to be defined in field like this:
*
* $this->addField('course_payment_status', [
Expand Down
4 changes: 2 additions & 2 deletions src/UserAction/ConfirmationExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ protected function doFinal(View $modal): void
/**
* Return proper JS statement when action execute.
*
* @param mixed $obj
* @param string|int $id
* @param mixed $obj
* @param mixed $id
*/
protected function jsGetExecute($obj, $id): JsBlock
{
Expand Down
4 changes: 2 additions & 2 deletions src/UserAction/ModalExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ public function jsExecute(array $urlArgs = []): JsBlock
/**
* Return proper JS statement need after action execution.
*
* @param mixed $obj
* @param string|int $id
* @param mixed $obj
* @param mixed $id
*/
protected function jsGetExecute($obj, $id): JsBlock
{
Expand Down
4 changes: 2 additions & 2 deletions src/UserAction/PanelExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ protected function jsSetListState(View $view, string $currentStep): void
/**
* Return proper JS statement need after action execution.
*
* @param mixed $obj
* @param string|int $id
* @param mixed $obj
* @param mixed $id
*/
protected function jsGetExecute($obj, $id): JsBlock
{
Expand Down
4 changes: 2 additions & 2 deletions src/UserAction/VpExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ protected function jsSetListState(View $view, string $currentStep): void
/**
* Return proper JS statement need after action execution.
*
* @param mixed $obj
* @param string|int $id
* @param mixed $obj
* @param mixed $id
*/
protected function jsGetExecute($obj, $id): JsBlock
{
Expand Down
2 changes: 1 addition & 1 deletion src/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ public function vue($component, $initData = [], $componentDefinition = null, $se
/**
* Emit an event on atkEvent bus.
*
* example of adding a listener on for an emit event.
* Example of adding a listener on for an emit event:
*
* atk.eventBus.on('eventName', (data) => {
* console.log(data)
Expand Down

0 comments on commit bb240e5

Please sign in to comment.