Skip to content

Commit

Permalink
Updates to release v1.5.5 fixes #241 fixes #242
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Jul 25, 2023
1 parent 02956ed commit 4d81fda
Show file tree
Hide file tree
Showing 23 changed files with 180 additions and 123 deletions.
7 changes: 7 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Change Log: `yii2-dynagrid`
===========================

## Version 1.5.5

**Date:** 25-Jul-2023.

- (enh #242): Enhance Dynagrid layout parts rendering to prevent wrong Bootstrap 5 plugin initializations.
- (enh #241): Proper defaulting of pageSize by cross checking pageSize setting in dataProvider pagination.

## Version 1.5.4

**Date:** 29-Apr-2022
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2015 - 2022, Kartik Visweswaran
Copyright (c) 2015 - 2023, Kartik Visweswaran
Krajee.com
All rights reserved.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
],
"require": {
"kartik-v/yii2-krajee-base": ">= 3.0.4",
"kartik-v/yii2-grid": ">= 3.5.0",
"kartik-v/yii2-grid": ">= 3.5.2",
"kartik-v/yii2-widget-activeform": ">= 1.6.2",
"kartik-v/yii2-widget-select2": ">= 2.2.3",
"kartik-v/yii2-sortable": "~1.2"
Expand Down
218 changes: 134 additions & 84 deletions src/DynaGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @package yii2-dynagrid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
* @version 1.5.4
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.5.5
*/

namespace kartik\dynagrid;
Expand All @@ -17,6 +17,7 @@
use kartik\dynagrid\models\DynaGridConfig;
use kartik\dynagrid\models\DynaGridSettings;
use kartik\grid\GridView;
use Throwable;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\Model;
Expand Down Expand Up @@ -420,6 +421,16 @@ class DynaGrid extends Widget
*/
protected $_store;

/**
* @var DynaGridSettings the settings model
*/
protected $_settingsModel;

/**
* @var array widget options for [[DynaGridDetail]]
*/
protected $_detailOptions;

/**
* @var array the configuration for icons set as `$key => $setting`, where `$key` is the icon property in DynaGrid
* widget and the `$setting` is an array of 2 values - the first value in the array is the icon suffix CSS class for
Expand Down Expand Up @@ -601,12 +612,12 @@ protected function initWidget()
}
/** @var DataProviderInterface $dataProvider */
$dataProvider = $this->gridOptions['dataProvider'];
/** @noinspection PhpStrictComparisonWithOperandsOfDifferentTypesInspection */
if ($dataProvider->getSort() === false) {
$this->showSort = false;
$this->allowSortSetting = false;
}
if ($dataProvider->getPagination() === false) {
$pagination = $dataProvider->getPagination();
if ($pagination === false) {
$this->allowPageSetting = false;
}
if (empty($this->gridOptions['filterModel'])) {
Expand All @@ -616,8 +627,9 @@ protected function initWidget()
if (empty($this->theme)) {
$this->theme = $this->_module->defaultTheme;
}
if (!isset($this->_pageSize) || $this->_pageSize === null) {
$this->_pageSize = $this->_module->defaultPageSize;
if (!isset($this->_pageSize)) {
$this->_pageSize = isset($pagination->pageSize) && $pagination->pageSize != $pagination->defaultPageSize ?
$pagination->pageSize : $this->_module->defaultPageSize;
}
$this->_requestSubmit = $this->options['id'].'-dynagrid';
$this->_model = new DynaGridConfig(['moduleId' => $this->moduleId]);
Expand Down Expand Up @@ -1211,11 +1223,7 @@ protected function applyColumns()
*/
protected function initGrid()
{
$dynagrid = '';
$dynagridFilter = '';
$dynagridSort = '';
$notBs3 = !$this->isBs(3);
$model = new DynaGridSettings(
$this->_settingsModel = new DynaGridSettings(
[
'moduleId' => $this->moduleId,
'dynaGridId' => $this->options['id'],
Expand All @@ -1224,57 +1232,9 @@ protected function initGrid()
'dbUpdateNameOnly' => $this->dbUpdateNameOnly,
]
);
/** @var ActiveDataProvider $dataProvider */
$dataProvider = $this->gridOptions['dataProvider'];
$sort = $dataProvider->getSort();
$isValidSort = ($sort instanceof Sort);
if ($this->showPersonalize) {
$this->setToggleButton(DynaGridStore::STORE_GRID);
if ($this->allowFilterSetting || $this->allowSortSetting) {
$store = new DynaGridStore(
[
'id' => $this->options['id'],
'moduleId' => $this->moduleId,
'category' => DynaGridStore::STORE_GRID,
'storage' => $this->storage,
'userSpecific' => $this->userSpecific,
'dbUpdateNameOnly' => $this->dbUpdateNameOnly,
]
);
if ($this->allowFilterSetting) {
$this->_model->filterId = $this->_filterId;
$this->_model->filterList = $store->getDtlList(DynaGridStore::STORE_FILTER);
}
if ($this->allowSortSetting && $isValidSort) {
$sort->enableMultiSort = $this->enableMultiSort;
$dataProvider->setSort($sort);
$this->_model->sortId = $this->_sortId;
$this->_model->sortList = $store->getDtlList(DynaGridStore::STORE_SORT);
}
}
$dynagrid = $this->render(
$this->_module->configView,
[
'model' => $this->_model,
'toggleButtonGrid' => $this->toggleButtonGrid,
'id' => $this->_gridModalId,
'allowPageSetting' => $this->allowPageSetting,
'allowThemeSetting' => $this->allowThemeSetting,
'allowFilterSetting' => $this->allowFilterSetting,
'allowSortSetting' => $this->allowSortSetting,
'moduleId' => $this->moduleId,
'notBs3' => $notBs3,
'modalClass' => $this->getBSClass('Modal'),
'isPjax' => $this->_isPjax,
'pjaxId' => $this->_pjaxId,
'iconPersonalize' => $this->iconPersonalize,
'iconSortableSeparator' => $this->iconSortableSeparator,
]
);
}
$opts = [
$this->_detailOptions = [
'bsVersion' => $this->bsVersion,
'model' => $model,
'model' => $this->_settingsModel,
'moduleId' => $this->moduleId,
'submitMessage' => $this->submitMessage,
'deleteMessage' => $this->deleteMessage,
Expand All @@ -1288,34 +1248,124 @@ protected function initGrid()
'iconConfirm' => $this->iconConfirm,
'iconRemove' => $this->iconRemove,
];
if ($this->showFilter) {
$this->setToggleButton(DynaGridStore::STORE_FILTER);
$model->category = DynaGridStore::STORE_FILTER;
$model->key = $this->_filterKey;
$model->data = array_filter($this->gridOptions['filterModel']->attributes);
$opts['id'] = $this->_filterModalId;
$opts['toggleButton'] = $this->toggleButtonFilter;
$dynagridFilter = DynaGridDetail::widget($opts);
}
if ($this->showSort) {
$this->setToggleButton(DynaGridStore::STORE_SORT);
$model->category = DynaGridStore::STORE_SORT;
$model->key = $this->_sortKey;
$model->data = $isValidSort ? $sort->getAttributeOrders() : [];
$opts['id'] = $this->_sortModalId;
$opts['toggleButton'] = $this->toggleButtonSort;
$dynagridSort = DynaGridDetail::widget($opts);
}
$tags = ArrayHelper::getValue($this->gridOptions, 'replaceTags', []);
$tags += [
'{dynagrid}' => $dynagrid,
'{dynagridFilter}' => $dynagridFilter,
'{dynagridSort}' => $dynagridSort,
];
$tags['{dynagrid}'] = [$this, 'renderDynagrid'];
$tags['{dynagridFilter}'] = [$this, 'renderDynagridFilter'];
$tags['{dynagridSort}'] = [$this, 'renderDynagridSort'];
$this->gridOptions['replaceTags'] = $tags;
$this->registerAssets();
}

/**
* Renders main dynagrid personalization settings.
*
* @return string
* @throws InvalidConfigException
*/
public function renderDynagrid()
{
if (!$this->showPersonalize) {
return '';
}
/** @var ActiveDataProvider $dataProvider */
$dataProvider = $this->gridOptions['dataProvider'];
$sort = $dataProvider->getSort();
$isValidSort = ($sort instanceof Sort);
$this->setToggleButton(DynaGridStore::STORE_GRID);
if ($this->allowFilterSetting || $this->allowSortSetting) {
$store = new DynaGridStore(
[
'id' => $this->options['id'],
'moduleId' => $this->moduleId,
'category' => DynaGridStore::STORE_GRID,
'storage' => $this->storage,
'userSpecific' => $this->userSpecific,
'dbUpdateNameOnly' => $this->dbUpdateNameOnly,
]
);
if ($this->allowFilterSetting) {
$this->_model->filterId = $this->_filterId;
$this->_model->filterList = $store->getDtlList(DynaGridStore::STORE_FILTER);
}
if ($this->allowSortSetting && $isValidSort) {
$sort->enableMultiSort = $this->enableMultiSort;
$dataProvider->setSort($sort);
$this->_model->sortId = $this->_sortId;
$this->_model->sortList = $store->getDtlList(DynaGridStore::STORE_SORT);
}
}

return $this->render(
$this->_module->configView,
[
'model' => $this->_model,
'toggleButtonGrid' => $this->toggleButtonGrid,
'id' => $this->_gridModalId,
'allowPageSetting' => $this->allowPageSetting,
'allowThemeSetting' => $this->allowThemeSetting,
'allowFilterSetting' => $this->allowFilterSetting,
'allowSortSetting' => $this->allowSortSetting,
'moduleId' => $this->moduleId,
'notBs3' => !$this->isBs(3),
'modalClass' => $this->getBSClass('Modal'),
'isPjax' => $this->_isPjax,
'pjaxId' => $this->_pjaxId,
'iconPersonalize' => $this->iconPersonalize,
'iconSortableSeparator' => $this->iconSortableSeparator,
]
);
}

/**
* Renders dynagrid filter configuration details.
*
* @return string
* @throws InvalidConfigException|Throwable
*/
public function renderDynagridFilter()
{
if (!$this->showFilter) {
return '';
}
$model = $this->_settingsModel;
$options = $this->_detailOptions;
$this->setToggleButton(DynaGridStore::STORE_FILTER);
$model->category = DynaGridStore::STORE_FILTER;
$model->key = $this->_filterKey;
$model->data = array_filter($this->gridOptions['filterModel']->attributes);
$options['id'] = $this->_filterModalId;
$options['toggleButton'] = $this->toggleButtonFilter;

return DynaGridDetail::widget($options);
}

/**
* Renders dynagrid sort configuration details.
*
* @return string
* @throws InvalidConfigException|Throwable
*/
public function renderDynagridSort()
{
if (!$this->showSort) {
return '';
}
$model = $this->_settingsModel;
$options = $this->_detailOptions;
/** @var ActiveDataProvider $dataProvider */
$dataProvider = $this->gridOptions['dataProvider'];
$sort = $dataProvider->getSort();
$isValidSort = ($sort instanceof Sort);
$this->setToggleButton(DynaGridStore::STORE_SORT);
$model->category = DynaGridStore::STORE_SORT;
$model->key = $this->_sortKey;
$model->data = $isValidSort ? $sort->getAttributeOrders() : [];
$options['id'] = $this->_sortModalId;
$options['toggleButton'] = $this->toggleButtonSort;

return DynaGridDetail::widget($options);
}

/**
* Sets the personalization toggle button
*
Expand Down
4 changes: 2 additions & 2 deletions src/DynaGridAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @package yii2-dynagrid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
* @version 1.5.4
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.5.5
*/

namespace kartik\dynagrid;
Expand Down
4 changes: 2 additions & 2 deletions src/DynaGridDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @package yii2-dynagrid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
* @version 1.5.4
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.5.5
*/

namespace kartik\dynagrid;
Expand Down
4 changes: 2 additions & 2 deletions src/DynaGridDetailAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @package yii2-dynagrid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
* @version 1.5.4
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.5.5
*/

namespace kartik\dynagrid;
Expand Down
4 changes: 2 additions & 2 deletions src/DynaGridStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @package yii2-dynagrid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
* @version 1.5.4
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.5.5
*/

namespace kartik\dynagrid;
Expand Down
4 changes: 2 additions & 2 deletions src/DynaGridTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @package yii2-dynagrid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
* @version 1.5.4
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.5.5
*/

namespace kartik\dynagrid;
Expand Down
4 changes: 2 additions & 2 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/**
* @package yii2-dynagrid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
* @version 1.5.4
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.5.5
*/

namespace kartik\dynagrid;
Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/kv-dynagrid.css
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*!
* @package yii2-dynagrid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2022
* @version 1.5.4
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.5.5
*
* Styling for yii2-dynagrid.
*
Expand Down
Loading

0 comments on commit 4d81fda

Please sign in to comment.