Skip to content

Commit

Permalink
Updates to release v1.4.3 fix #363 fix #364 fix #366 fix #372 fix #373
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Jul 25, 2023
1 parent ec1040c commit 5c033d4
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 77 deletions.
9 changes: 7 additions & 2 deletions CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@ Change Log: `yii2-export`

## version 1.4.3

**Date:** _under development_
**Date:** 25-Jul-2023

- (enh #355): Correct dropdown init for Bootstrap v5.x.
- (enh #373): *BC Breaking*: Enhance ExportMenu template parts rendering to prevent wrong Bootstrap 5 plugin initializations.
- (enh #372): Enhance export to consider grid table filters.
- (enh #366): Introduce a custom delimiter option for the export config FORMAT_CSV.
- (enh #364): Fix contentOptions in `generateRow`.
- (enh #363): Catch throwable exception in `generateRow`.
- (enh #360): Check for web context before accessing `post()`
- (enh #355): Correct dropdown init for Bootstrap v5.x.

## version 1.4.2

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 - 2021, 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-dynagrid": ">=1.4.5",
"kartik-v/yii2-dynagrid": ">=1.5.5",
"kartik-v/yii2-mpdf": ">=1.0",
"phpoffice/phpspreadsheet": ">=1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/ExportColumnAsset.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @package yii2-export
* @version 1.4.3
*/
Expand Down
136 changes: 74 additions & 62 deletions src/ExportMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package yii2-export
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.4.3
*/

Expand All @@ -25,6 +25,7 @@
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Writer\BaseWriter;
use PhpOffice\PhpSpreadsheet\Writer\Csv as WriterCsv;
use Throwable;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\Model;
Expand All @@ -44,6 +45,7 @@
use yii\helpers\Json;
use yii\helpers\Url;
use yii\web\JsExpression;
use yii\web\Request;
use yii\web\View;

/**
Expand Down Expand Up @@ -860,9 +862,9 @@ protected function initSettings()
}
$this->_columnSelectorEnabled = $this->showColumnSelector && $this->asDropdown;
$request = Yii::$app->request;
if ($request instanceof \yii\web\Request) {
$this->_triggerDownload = $request->post($this->exportRequestParam, $this->triggerDownload);
$this->_exportType = $request->post($this->exportTypeParam, $this->exportType);
if ($request instanceof Request) {
$this->_triggerDownload = $request->post($this->exportRequestParam, $this->triggerDownload);
$this->_exportType = $request->post($this->exportTypeParam, $this->exportType);
} else {
$this->_triggerDownload = $this->triggerDownload;
$this->_exportType = $this->exportType;
Expand All @@ -874,7 +876,7 @@ protected function initSettings()
if ($this->stream) {
Yii::$app->controller->layout = false;
}
$this->_columnSelectorEnabled = $request instanceof \yii\web\Request ?
$this->_columnSelectorEnabled = $request instanceof Request ?
$request->post($this->colSelFlagParam, $this->_columnSelectorEnabled) :
$this->_columnSelectorEnabled;
$this->initSelectedColumns();
Expand Down Expand Up @@ -977,10 +979,11 @@ public function initExport()
if (!isset($this->exportFormOptions['id'])) {
$this->exportFormOptions['id'] = $this->options['id'].'-export-form';
}
$this->_provider->refresh();
}

/**
* Renders the export menu
* Renders the export menu widget.
*
* @return string the export menu markup
* @throws InvalidConfigException
Expand All @@ -989,8 +992,6 @@ public function initExport()
public function renderExportMenu()
{
$items = $this->asDropdown ? [] : '';
$notBs3 = !$this->isBs(3);
Html::addCssClass($this->dropdownOptions, ['btn', $this->getDefaultBtnCss()]);
foreach ($this->exportConfig as $format => $settings) {
if (!isset($settings) || $settings === false) {
continue;
Expand Down Expand Up @@ -1020,55 +1021,70 @@ public function renderExportMenu()
} else {
$tag = ArrayHelper::remove($options, 'tag', 'li');
if ($tag !== false) {
$items .= Html::tag($tag, Html::a($label, '#', $linkOptions), $options);
$items .= Html::tag($tag, Html::a($label, '#', $linkOptions), $options) . "\n";
} else {
$items .= Html::a($label, '#', $linkOptions);
$items .= Html::a($label, '#', $linkOptions) . "\n";
}
}
}
$iconCss = $notBs3 ? 'fas fa-external-link-alt' : 'glyphicon glyphicon-export';
if ($this->asDropdown) {
$icon = ArrayHelper::remove($this->dropdownOptions, 'icon', '<i class="'.$iconCss.'"></i>');
$label = ArrayHelper::remove($this->dropdownOptions, 'label');
$label = $label === null ? $icon : $icon.' '.$label;
if (!isset($this->dropdownOptions['title'])) {
$this->dropdownOptions['title'] = Yii::t('kvexport', 'Export data in selected format');
}
$menuOptions = ArrayHelper::remove($this->dropdownOptions, 'menuOptions', []);
$itemsBefore = ArrayHelper::remove($this->dropdownOptions, 'itemsBefore', []);
$itemsAfter = ArrayHelper::remove($this->dropdownOptions, 'itemsAfter', []);
$items = ArrayHelper::merge($itemsBefore, $items, $itemsAfter);
$opts = [
'label' => $label,
'dropdown' => ['items' => $items, 'encodeLabels' => false, 'options' => $menuOptions,],
'encodeLabel' => false,
];

if (!isset($this->exportContainer['class'])) {
$this->exportContainer['class'] = 'btn-group';
}
/**
* @var Widget $class
*/
$class = $this->getDropdownClass(true);
if ($notBs3) {
$opts['buttonOptions'] = $this->dropdownOptions;
$opts['renderContainer'] = false;
$out = Html::tag('div', $class::widget($opts), $this->exportContainer);
} else {
$opts['options'] = $this->dropdownOptions;
$opts['containerOptions'] = $this->exportContainer;
$out = $class::widget($opts);
}
$replacePairs = ['{menu}' => $out, '{columns}' => $this->renderColumnSelector()];
$content = strtr($this->template, $replacePairs);
$this->replacePart('template', '{menu}', [$this, 'renderDropdownMenu'], [$items]);
$this->replacePart('template', '{columns}', [$this, 'renderColumnSelector']);

return Html::tag('div', $content, $this->container);
return Html::tag('div', $this->template, $this->container);
} else {
return $items;
}
}

/**
* Renders the dropdown menu button and items.
*
* @param array $items
* @return string
* @throws InvalidConfigException|Throwable
*/
public function renderDropdownMenu($items)
{
Html::addCssClass($this->dropdownOptions, ['btn', $this->getDefaultBtnCss()]);
$notBs3 = !$this->isBs(3);
$iconCss = $notBs3 ? 'fas fa-external-link-alt' : 'glyphicon glyphicon-export';
$icon = ArrayHelper::remove($this->dropdownOptions, 'icon', '<i class="'.$iconCss.'"></i>');
$label = ArrayHelper::remove($this->dropdownOptions, 'label');
$label = $label === null ? $icon : $icon.' '.$label;
if (!isset($this->dropdownOptions['title'])) {
$this->dropdownOptions['title'] = Yii::t('kvexport', 'Export data in selected format');
}
$menuOptions = ArrayHelper::remove($this->dropdownOptions, 'menuOptions', []);
$itemsBefore = ArrayHelper::remove($this->dropdownOptions, 'itemsBefore', []);
$itemsAfter = ArrayHelper::remove($this->dropdownOptions, 'itemsAfter', []);
$items = ArrayHelper::merge($itemsBefore, $items, $itemsAfter);
$opts = [
'label' => $label,
'dropdown' => ['items' => $items, 'encodeLabels' => false, 'options' => $menuOptions,],
'encodeLabel' => false,
];

if (!isset($this->exportContainer['class'])) {
$this->exportContainer['class'] = 'btn-group';
}
/**
* @var Widget $class
*/
$class = $this->getDropdownClass(true);
if ($notBs3) {
$opts['buttonOptions'] = $this->dropdownOptions;
$opts['renderContainer'] = false;
$out = Html::tag('div', $class::widget($opts), $this->exportContainer);
} else {
$opts['options'] = $this->dropdownOptions;
$opts['containerOptions'] = $this->exportContainer;
$out = $class::widget($opts);
}

return $out;
}

/**
* Renders the columns selector
*
Expand Down Expand Up @@ -1149,7 +1165,7 @@ public function initPhpSpreadsheetWriter($type)
/**
* @var WriterCsv $writer
*/
if ($t === self::FORMAT_TEXT) {
if ($t === self::FORMAT_TEXT || $t === self::FORMAT_CSV) {
$delimiter = $this->getSetting('delimiter', "\t");
$writer->setDelimiter($delimiter);
}
Expand Down Expand Up @@ -1403,14 +1419,13 @@ public function generateRow($model, $key, $index)
}
$contentOptions = $column->contentOptions;
if (is_callable($contentOptions)) {
/** @noinspection PhpUnusedLocalVariableInspection */
$contentOptions = $contentOptions($model, $key, $index, $column);
}

//20201026 Scott: To avoid 'Closure object cannot have properties' error
try {
$format = ArrayHelper::getValue($contentOptions, 'cellFormat');
} catch (Exception $e) {
} catch (Exception|Throwable $e) {
$format = null;
}

Expand Down Expand Up @@ -1867,6 +1882,7 @@ protected function setDefaultExportConfig()
'mime' => 'application/csv',
'extension' => 'csv',
'writer' => self::FORMAT_CSV,
'delimiter' => ",",
],
self::FORMAT_TEXT => [
'label' => Yii::t('kvexport', 'Text'),
Expand Down Expand Up @@ -1920,7 +1936,6 @@ protected function setDefaultExportConfig()

/**
* Registers client assets needed for Export Menu widget
* @throws Exception
*/
protected function registerAssets()
{
Expand Down Expand Up @@ -2017,16 +2032,13 @@ protected function getStyleOpts($settings = [])
}

/**
* Search all groupable columns
* Search all group-able columns
*/
protected function findGroupedColumn()
{
foreach ($this->getVisibleColumns() as $key => $column) {
if (isset($column->group) && $column->group == true) {
$this->_groupedColumn[$key] = ['firstLine' => -1, 'value' => null];
} else {
$this->_groupedColumn[$key] = null;
}
$this->_groupedColumn[$key] = empty($column) || empty($column->group) ? null :
['firstLine' => -1, 'value' => null];
}
$this->_groupedColumn[] = null; //prevent the overflow
$this->_groupedColumn[] = null; //prevent the overflow
Expand Down Expand Up @@ -2087,7 +2099,7 @@ protected function checkGroupedRow($model, $nextModel, $key, $index)
*/
protected function generateGroupedRow($groupFooter, $groupedCol)
{
$endGroupedCol = 0;
//$endGroupedCol = 0;
$this->_groupedRow = [];
$fLine = ArrayHelper::getValue($this->_groupedColumn[$groupedCol], 'firstLine', -1);
$fLine = ($fLine == $this->_beginRow) ? $this->_beginRow + 1 : ($fLine + 3);
Expand All @@ -2096,27 +2108,27 @@ protected function generateGroupedRow($groupFooter, $groupedCol)
list($endLine, $firstLine) = ($endLine > $firstLine) ? [$endLine, $firstLine] : [$firstLine, $endLine];
foreach ($this->getVisibleColumns() as $key => $column) {
$value = $groupFooter[$key] ?? '';
$endGroupedCol++;
//$endGroupedCol++;
$groupedRange = self::columnName($key + 1).$firstLine.':'.self::columnName($key + 1).$endLine;
//$lastCell = self::columnName($key + 1) . $endLine - 1;
if (isset($column->group) && $column->group) {
$this->_objWorksheet->mergeCells($groupedRange);
}
switch ($value) {
case self::F_SUM:
$value = "=sum($groupedRange)";
$value = "=SUM($groupedRange)";
break;
case self::F_COUNT:
$value = '=countif('.$groupedRange.',"*")';
$value = '=COUNTIF('.$groupedRange.',"*")';
break;
case self::F_AVG:
$value = "=AVERAGE($groupedRange)";
break;
case self::F_MAX:
$value = "=max($groupedRange)";
$value = "=MAX($groupedRange)";
break;
case self::F_MIN:
$value = "=min($groupedRange)";
$value = "=MIN($groupedRange)";
break;
}
if ($value instanceof Closure) {
Expand Down
2 changes: 1 addition & 1 deletion src/ExportMenuAsset.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @package yii2-export
* @version 1.4.3
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ExportWriterPdf.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @package yii2-export
* @version 1.4.3
*/
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/kv-export-columns.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @package yii2-export
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.4.3
*
* Export Columns Selector Style Sheet
Expand Down
2 changes: 1 addition & 1 deletion src/assets/css/kv-export-columns.min.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @package yii2-export
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.4.3
*
* Export Columns Selector Style Sheet
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/kv-export-columns.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @package yii2-export
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.4.3
*
* Export Columns Selector Validation Module.
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/kv-export-columns.min.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @package yii2-export
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.4.3
*
* Export Columns Selector Validation Module.
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/kv-export-data.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @package yii2-export
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2021
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2023
* @version 1.4.3
*
* Export Data Validation Module.
Expand Down
2 changes: 1 addition & 1 deletion src/assets/js/kv-export-data.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5c033d4

Please sign in to comment.