Skip to content

Commit

Permalink
Updates to release v3.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Sep 6, 2018
1 parent 0e6ff6c commit 08ac983
Show file tree
Hide file tree
Showing 42 changed files with 2,106 additions and 917 deletions.
7 changes: 6 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ Change Log: `yii2-grid`

## Version 3.1.9

**Date:** _under development_
**Date:** 07-Sep-2018

- Refactor code and consolidate / optimize properties within traits.
- Enhancements to grid sort (include numerical indicators).
- Enhancements to support bootstrap v4.x.
- Enhancements for updated perfect scrollbar plugin.
- (bug #813, #814): Correct Krajee Dialog plugin init.
- (enh #805): Configure translated properties for MPDF .

## Version 3.1.8

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ Refer [detailed documentation](http://demos.krajee.com/grid) and/or a [complete

![GridView Screenshot](https://lh4.googleusercontent.com/-4x-CdyyZAsY/VNxLPmaaAXI/AAAAAAAAAQ8/XYYxTiQZvJk/w868-h516-no/krajee-yii2-grid.jpg)

## Latest Release
The latest version of the module is v3.1.8 (_under development_). Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-grid/blob/master/CHANGE.md) for details.
## Release Changes
> NOTE: Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-grid/blob/master/CHANGE.md) for details on changes to various releases.
New features with release 2.7.0.

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"require": {
"kartik-v/yii2-krajee-base": "~1.7",
"kartik-v/yii2-krajee-base": ">=1.9",
"kartik-v/yii2-dialog": "~1.0"
},
"autoload": {
Expand Down
138 changes: 38 additions & 100 deletions src/ActionColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2014 - 2018
* @package yii2-grid
* @version 3.1.8
* @version 3.1.9
*/

namespace kartik\grid;
Expand All @@ -13,6 +13,7 @@
use yii\grid\ActionColumn as YiiActionColumn;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\base\InvalidConfigException;

/**
* The ActionColumn is a column that displays buttons for viewing and manipulating the items and extends the
Expand All @@ -37,33 +38,21 @@ class ActionColumn extends YiiActionColumn
{
use ColumnTrait;

/**
* @var boolean whether the column is hidden from display. This is different than the `visible` property, in the
* sense, that the column is rendered, but hidden from display. This will allow you to still export the column
* using the export function.
*/
public $hidden;

/**
* @var boolean|array whether the column is hidden in export output. If set to boolean `true`, it will hide the
* column for all export formats. If set as an array, it will accept the list of GridView export `formats` and
* hide output only for them.
*/
public $hiddenFromExport = true;

/**
* @var boolean whether the action buttons are to be displayed as a dropdown
*/
public $dropdown = false;

/**
* @var array the HTML attributes for the Dropdown container. The class `dropdown` will be added. To align a
* dropdown at the right edge of the page container, you set the class to `pull-right`.
* dropdown at the right edge of the page container, you set the class to `pull-right` for Bootstrap v3.x and
* for Bootstrap v4.x add `dropdown-menu-right` class in [[dropdownMenu]].
*/
public $dropdownOptions = [];

/**
* @var array the HTML attributes for the Dropdown menu. Applicable if `dropdown` is `true`.
* @var array the HTML attributes for the Dropdown menu. Applicable if `dropdown` is `true`. To align a
* dropdown at the right edge of the page container, you set the class to `dropdown-menu-right` for Bootstrap v4.x.
*/
public $dropdownMenu = ['class' => 'text-left'];

Expand All @@ -75,31 +64,7 @@ class ActionColumn extends YiiActionColumn
* - `caret`: _string_', the caret symbol to be appended to the dropdown button.
* Defaults to ` <span class="caret"></span>`.
*/
public $dropdownButton = ['class' => 'btn btn-default'];

/**
* @var string the horizontal alignment of each column. Should be one of [[GridView::ALIGN_LEFT]],
* [[GridView::ALIGN_RIGHT]], or [[GridView::ALIGN_CENTER]].
*/
public $hAlign = GridView::ALIGN_CENTER;

/**
* @var string the vertical alignment of each column. Should be one of [[GridView::ALIGN_TOP]],
* [[GridView::ALIGN_BOTTOM]], or [[GridView::ALIGN_MIDDLE]].
*/
public $vAlign = GridView::ALIGN_MIDDLE;

/**
* @var boolean whether to force no wrapping on all table cells in the column
* @see http://www.w3schools.com/cssref/pr_text_white-space.asp
*/
public $noWrap = false;

/**
* @var string the width of each column (matches the CSS width property).
* @see http://www.w3schools.com/cssref/pr_dim_width.asp
*/
public $width = '80px';
public $dropdownButton = [];

/**
* @var array HTML attributes for the view action button. The following additional options are recognized:
Expand Down Expand Up @@ -135,54 +100,6 @@ class ActionColumn extends YiiActionColumn
*/
public $deleteOptions = [];

/**
* @var boolean|string|Closure the page summary that is displayed above the footer. You can set it to one of the
* following:
* - `false`: the summary will not be displayed.
* - `true`: the page summary for the column will be calculated and displayed using the
* [[pageSummaryFunc]] setting.
* - `string`: will be displayed as is.
* - `Closure`: you can set it to an anonymous function with the following signature:
*
* ```php
* // example 1
* function ($summary, $data, $widget) { return 'Count is ' . $summary; }
* // example 2
* function ($summary, $data, $widget) { return 'Range ' . min($data) . ' to ' . max($data); }
* ```
*
* where:
*
* - the `$summary` variable will be replaced with the calculated summary using the [[pageSummaryFunc]] setting.
* - the `$data` variable will contain array of the selected page rows for the column.
*/
public $pageSummary = false;

/**
* @var string the summary function that will be used to calculate the page summary for the column.
*/
public $pageSummaryFunc = GridView::F_SUM;

/**
* @var array HTML attributes for the page summary cell. The following special attributes are available:
* - `prepend`: _string_, a prefix string that will be prepended before the pageSummary content
* - `append`: _string_, a suffix string that will be appended after the pageSummary content
*/
public $pageSummaryOptions = [];

/**
* @var boolean whether to just hide the page summary display but still calculate the summary based on
* [[pageSummary]] settings
*/
public $hidePageSummary = false;

/**
* @var boolean whether to merge the header title row and the filter row This will not render the filter for the
* column and can be used when `filter` is set to `false`. Defaults to `false`. This is only applicable when
* [[GridView::filterPosition]] for the grid is set to [[GridView::FILTER_POS_BODY]].
*/
public $mergeHeader = true;

/**
* @var array the HTML attributes for the header cell tag.
* @see Html::renderTagAttributes() for details on how attributes are being rendered.
Expand All @@ -206,23 +123,35 @@ class ActionColumn extends YiiActionColumn

/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
$this->initColumnSettings([
'hiddenFromExport' => true,
'mergeHeader' => true,
'hAlign' => GridView::ALIGN_CENTER,
'vAlign' => GridView::ALIGN_MIDDLE,
'width' => '50px',
]);
/** @noinspection PhpUndefinedFieldInspection */
$this->_isDropdown = ($this->grid->bootstrap && $this->dropdown);
if (!isset($this->header)) {
$this->header = Yii::t('kvgrid', 'Actions');
}
$this->parseFormat();
$this->parseVisibility();
if (!isset($this->dropdownButton['class'])) {
$this->dropdownButton['class'] = 'btn ' . $this->grid->getDefaultBtnCss();
}
parent::init();
$this->initDefaultButtons();
$this->setPageRows();
}

/**
* @inheritdoc
* @throws InvalidConfigException
*/
public function renderDataCell($model, $key, $index)
{
Expand Down Expand Up @@ -283,13 +212,15 @@ protected function renderLabel(&$options, $title, $iconOptions = [])
* @param string $name button name as written in the [[template]]
* @param string $title the title of the button
* @param string $icon the meaningful glyphicon suffix name for the button
* @throws InvalidConfigException
*/
protected function setDefaultButton($name, $title, $icon)
{
$isBs4 = $this->grid->isBs4();
if (isset($this->buttons[$name])) {
return;
}
$this->buttons[$name] = function ($url) use ($name, $title, $icon) {
$this->buttons[$name] = function ($url) use ($name, $title, $icon, $isBs4) {
$opts = "{$name}Options";
$options = ['title' => $title, 'aria-label' => $title, 'data-pjax' => '0'];
if ($name === 'delete') {
Expand All @@ -298,11 +229,11 @@ protected function setDefaultButton($name, $title, $icon)
$options['data-confirm'] = Yii::t('kvgrid', 'Are you sure to delete this {item}?', ['item' => $item]);
}
$options = array_replace_recursive($options, $this->buttonOptions, $this->$opts);
$label = $this->renderLabel($options, $title, ['class' => "glyphicon glyphicon-{$icon}"]);
$label = $this->renderLabel($options, $title, ['class' => $this->grid->getDefaultIconPrefix() . $icon]);
$link = Html::a($label, $url, $options);
if ($this->_isDropdown) {
$options['tabindex'] = '-1';
return "<li>{$link}</li>\n";
return $isBs4 ? $link : "<li>{$link}</li>\n";
} else {
return $link;
}
Expand All @@ -311,31 +242,38 @@ protected function setDefaultButton($name, $title, $icon)

/**
* @inheritdoc
* @throws InvalidConfigException
*/
protected function initDefaultButtons()
{
$this->setDefaultButton('view', Yii::t('kvgrid', 'View'), 'eye-open');
$this->setDefaultButton('update', Yii::t('kvgrid', 'Update'), 'pencil');
$this->setDefaultButton('delete', Yii::t('kvgrid', 'Delete'), 'trash');
$isBs4 = $this->grid->isBs4();
$this->setDefaultButton('view', Yii::t('kvgrid', 'View'), $isBs4 ? 'eye' : 'eye-open');
$this->setDefaultButton('update', Yii::t('kvgrid', 'Update'), $isBs4 ? 'pencil-alt' : 'pencil');
$this->setDefaultButton('delete', Yii::t('kvgrid', 'Delete'), $isBs4 ? 'trash-alt' : 'trash');
}

/**
* @inheritdoc
* @throws InvalidConfigException
*/
protected function renderDataCellContent($model, $key, $index)
{
$isBs4 = $this->grid->isBs4();
if ($isBs4 && $this->_isDropdown) {
Html::addCssClass($this->buttonOptions, 'dropdown-item');
}
$content = parent::renderDataCellContent($model, $key, $index);
$options = $this->dropdownButton;
$trimmed = trim($content);
if ($this->_isDropdown && !empty($trimmed)) {
if ($this->_isDropdown && !empty($trimmed)) {
$label = ArrayHelper::remove($options, 'label', Yii::t('kvgrid', 'Actions'));
$caret = ArrayHelper::remove($options, 'caret', ' <span class="caret"></span>');
$caret = $isBs4 ? '' : ArrayHelper::remove($options, 'caret', ' <span class="caret"></span>');
$options = array_replace_recursive($options, ['type' => 'button', 'data-toggle' => 'dropdown']);
Html::addCssClass($options, 'dropdown-toggle');
$button = Html::button($label . $caret, $options);
Html::addCssClass($this->dropdownMenu, 'dropdown-menu');
$dropdown = $button . PHP_EOL . Html::tag('ul', $content, $this->dropdownMenu);
Html::addCssClass($this->dropdownOptions, 'dropdown');
$dropdown = $button . PHP_EOL . Html::tag($isBs4 ? 'div' : 'ul', $content, $this->dropdownMenu);
Html::addCssClass($this->dropdownOptions, $isBs4 ? 'btn-group' : 'dropdown');
return Html::tag('div', $dropdown, $this->dropdownOptions);
}
return $content;
Expand Down
2 changes: 1 addition & 1 deletion src/ActionColumnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.1.8
* @version 3.1.9
*/

namespace kartik\grid;
Expand Down
25 changes: 10 additions & 15 deletions src/BooleanColumn.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-grid
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2018
* @version 3.1.8
* @version 3.1.9
*/

namespace kartik\grid;
Expand Down Expand Up @@ -32,16 +32,6 @@
*/
class BooleanColumn extends DataColumn
{
/**
* @inheritdoc
*/
public $hAlign = GridView::ALIGN_CENTER;

/**
* @inheritdoc
*/
public $width = '90px';

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -76,25 +66,30 @@ class BooleanColumn extends DataColumn

/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
*/
public function init()
{
$this->initColumnSettings([
'hAlign' => GridView::ALIGN_CENTER,
'width' => '90px'
]);
if (empty($this->trueLabel)) {
$this->trueLabel = Yii::t('kvgrid', 'Active');
}
if (empty($this->falseLabel)) {
$this->falseLabel = Yii::t('kvgrid', 'Inactive');
}
$this->filter = [true => $this->trueLabel, false => $this->falseLabel];
$bs = $this->grid->bootstrap;
$isBs4 = $this->grid->isBs4();

if (empty($this->trueIcon)) {
/** @noinspection PhpUndefinedFieldInspection */
$this->trueIcon = ($this->grid->bootstrap) ? GridView::ICON_ACTIVE : $this->trueLabel;
$this->trueIcon = $bs ? ($isBs4 ? GridView::ICON_ACTIVE_BS4 : GridView::ICON_ACTIVE) : $this->trueLabel;
}

if (empty($this->falseIcon)) {
/** @noinspection PhpUndefinedFieldInspection */
$this->falseIcon = ($this->grid->bootstrap) ? GridView::ICON_INACTIVE : $this->falseLabel;
$this->falseIcon = $bs ? ($isBs4 ? GridView::ICON_INACTIVE_BS4 : GridView::ICON_INACTIVE) : $this->falseLabel;
}

parent::init();
Expand Down
Loading

0 comments on commit 08ac983

Please sign in to comment.