Skip to content

Commit

Permalink
Updates to release v1.3.1 fix #260 fix #261
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Sep 24, 2018
1 parent a554039 commit 30ecff8
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 38 deletions.
8 changes: 8 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
Change Log: `yii2-export`
=========================

## version 1.3.1

**Date:** 24-Sep-2018

- Enhance link file view markup for rendering Bootstrap 4.x styles.
- (bug #261): Correct headers sending.
- (enh #260): New property `enableAutoFormat` to control autoformatting excel based on grid format.

## version 1.3.0

**Date:** 07-Sep-2018
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ echo \kartik\grid\GridView::widget([

## License

**yii2-export** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.
**yii2-export** is released under the BSD-3-Clause License. See the bundled `LICENSE.md` for details.
2 changes: 1 addition & 1 deletion src/ExportColumnAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright © Kartik Visweswaran, Krajee.com, 2015 - 2018
* @package yii2-export
* @version 1.3.0
* @version 1.3.1
*/

namespace kartik\export;
Expand Down
30 changes: 24 additions & 6 deletions src/ExportMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-export
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2018
* @version 1.3.0
* @version 1.3.1
*/

namespace kartik\export;
Expand All @@ -29,6 +29,7 @@
use Yii;
use yii\base\InvalidConfigException;
use yii\base\Model;
use yii\base\Widget;
use yii\data\ActiveDataProvider;
use yii\data\BaseDataProvider;
use yii\db\ActiveQueryInterface;
Expand Down Expand Up @@ -173,6 +174,12 @@ class ExportMenu extends GridView
*/
public $showColumnSelector = true;

/**
* @var boolean enable or disable cell formatting by auto detecting the grid column alignment and format.
* If set to `false` the format will not be applied but improve performance configured in [[dynagridOptions]].
*/
public $enableAutoFormat = true;

/**
* @var array the configuration of the column names in the column selector. Note: column names will be generated
* automatically by default. Any setting in this property will override the auto-generated column names. This
Expand Down Expand Up @@ -764,10 +771,10 @@ public function run()
$writer->save($file);
if ($this->stream) {
$this->clearOutputBuffers();
$this->setHttpHeaders();
if ($this->_exportType === self::FORMAT_PDF) {
$this->renderPDF($file);
} else {
$this->setHttpHeaders();
readfile($file);
}
$this->cleanup($file, $config);
Expand All @@ -786,6 +793,7 @@ public function run()
echo $this->render(
$this->afterSaveView,
[
'isBs4' => $this->isBs4(),
'file' => $fileName,
'icon' => $config['icon'],
'href' => Url::to([self::slash($this->linkPath, '/') . $fileName]),
Expand Down Expand Up @@ -834,6 +842,7 @@ public function initExport()
* Renders the export menu
*
* @return string the export menu markup
* @throws InvalidConfigException
* @throws \Exception
*/
public function renderExportMenu()
Expand Down Expand Up @@ -910,14 +919,21 @@ public function renderExportMenu()
if (!isset($this->exportContainer['class'])) {
$this->exportContainer['class'] = 'btn-group';
}
/**
* @var Widget $class
*/
$class = $isBs4 ? 'kartik\bs4dropdown\ButtonDropdown' : 'yii\bootstrap\ButtonDropdown';
if (!class_exists($class)) {
throw new InvalidConfigException("The '{$class}' does not exist and must be installed for dropdown rendering when 'ExportMenu::asDropdown' is set to 'true'.");
}
if ($isBs4) {
$opts['buttonOptions'] = $this->dropdownOptions;
$opts['renderContainer'] = false;
$out = Html::tag('div', \kartik\bs4dropdown\ButtonDropdown::widget($opts), $this->exportContainer);
$out = Html::tag('div', $class::widget($opts), $this->exportContainer);
} else {
$opts['options'] = $this->dropdownOptions;
$opts['containerOptions'] = $this->exportContainer;
$out = \yii\bootstrap\ButtonDropdown::widget($opts);
$out = $class::widget($opts);
}
$replacePairs = ['{menu}' => $out, '{columns}' => $this->renderColumnSelector()];
$content = strtr($this->template, $replacePairs) . "\n" . $form;
Expand Down Expand Up @@ -1233,7 +1249,9 @@ public function generateRow($model, $key, $index)
self::columnName($this->_endCol) . ($index + $this->_beginRow + 1),
$value
);
$this->autoFormat($model, $key, $index, $column, $cell);
if ($this->enableAutoFormat) {
$this->autoFormat($model, $key, $index, $column, $cell);
}
$this->raiseEvent('onRenderDataCell', [$cell, $value, $model, $key, $index, $this]);
}
}
Expand Down Expand Up @@ -1666,7 +1684,7 @@ protected function getColumnLabel($key, $column)
} elseif (isset($column->attribute)) {
$label = $this->getAttributeLabel($column->attribute);
} elseif (!$column instanceof DataColumn) {
$class = explode('\\', $column::classname());
$class = explode('\\', get_class($column));
$label = Inflector::camel2words(end($class));
}
return trim(strip_tags(str_replace(['<br>', '<br/>'], ' ', $label)));
Expand Down
2 changes: 1 addition & 1 deletion src/ExportMenuAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2015 - 2018
* @package yii2-export
* @version 1.3.0
* @version 1.3.1
*/

namespace kartik\export;
Expand Down
4 changes: 2 additions & 2 deletions src/assets/css/kv-export-data.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/
.kv-export-full-form {
margin:0;
.kv-export-full-form {
margin: 0;
padding: 0;
display: none;
}
2 changes: 1 addition & 1 deletion src/assets/js/kv-export-columns.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
* Copyright: 2015, Kartik Visweswaran, Krajee.com
* For more JQuery plugins visit http://plugins.krajee.com
* For more Yii related demos visit http://demos.krajee.com
*/!function(n){var t=function(t,o){var e=this;e.$element=n(t),e.options=o,e.listen()};t.prototype={constructor:t,listen:function(){var n=this,t=n.$element,o=t.find('input[name="export_columns_toggle"]');t.off("click").on("click",function(n){n.stopPropagation()}),o.off("change").on("change",function(){var n=o.is(":checked");t.find('input[name="export_columns_selector[]"]:not([disabled])').prop("checked",n)})}},n.fn.exportcolumns=function(o){var e=Array.apply(null,arguments);return e.shift(),this.each(function(){var c=n(this),i=c.data("exportcolumns"),a="object"==typeof o&&o;i||c.data("exportcolumns",i=new t(this,n.extend({},n.fn.exportcolumns.defaults,a,n(this).data()))),"string"==typeof o&&i[o].apply(i,e)})},n.fn.exportcolumns.defaults={}}(window.jQuery);
*/!function(t){"use strict";var n=function(n,o){var e=this;e.$element=t(n),e.options=o,e.listen()};n.prototype={constructor:n,listen:function(){var t=this,n=t.$element,o=n.find('input[name="export_columns_toggle"]');n.off("click").on("click",function(t){t.stopPropagation()}),o.off("change").on("change",function(){var t=o.is(":checked");n.find('input[name="export_columns_selector[]"]:not([disabled])').prop("checked",t)})}},t.fn.exportcolumns=function(o){var e=Array.apply(null,arguments);return e.shift(),this.each(function(){var c=t(this),i=c.data("exportcolumns"),s="object"==typeof o&&o;i||c.data("exportcolumns",i=new n(this,t.extend({},t.fn.exportcolumns.defaults,s,t(this).data()))),"string"==typeof o&&i[o].apply(i,e)})},t.fn.exportcolumns.defaults={}}(window.jQuery);
41 changes: 21 additions & 20 deletions src/assets/js/kv-export-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@
(function ($) {
"use strict";

var isEmpty = function (value, trim) {
var $h = {
isEmpty: function (value, trim) {
return value === null || value === undefined || value === [] || value === '' || trim && $.trim(value) === '';
},
popupDialog = function (url, name, w, h) {
popupDialog: function (url, name, w, h) {
var left = (screen.width / 2) - (w / 2), top = 60,
existWin = window.open('', name, '', true);
existWin.close();
return window.open(url, name,
'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
},
popupTemplate = '<html style="display:table;width:100%;height:100%;">' +
'<title>Export Data - &copy; Krajee</title>' +
'<body style="display:table-cell;font-family:Helvetica,Arial,sans-serif;color:#888;font-weight:bold;line-height:1.4em;text-align:center;vertical-align:middle;width:100%;height:100%;padding:0 10px;">' +
'{msg}' +
'</body>' +
'</html>';

popupTemplate: '<html style="display:table;width:100%;height:100%;">' +
'<title>Export Data - &copy; Krajee</title>' +
'<body style="display:table-cell;font-family:Helvetica,Arial,sans-serif;color:#888;font-weight:bold;line-height:1.4em;text-align:center;vertical-align:middle;width:100%;height:100%;padding:0 10px;">' +
'{msg}' +
'</body>' +
'</html>'
};
var ExportData = function (element, options) {
var self = this;
self.$element = $(element);
Expand All @@ -57,7 +58,7 @@
el[0].innerHTML = msg;
}, 4000);
} else {
var newmsg = popupTemplate.replace('{msg}', msg);
var newmsg = $h.popupTemplate.replace('{msg}', msg);
self.popup.document.write(newmsg);
}
},
Expand All @@ -73,15 +74,15 @@
});
}
},
processExport: function(fmt) {
processExport: function (fmt) {
var self = this, $selected, cols = [];
self.$form.find('[name="export_type"]').val(fmt);
if (self.target === '_popup') {
self.popup = popupDialog('', 'kvExportFullDialog', 350, 120);
self.popup = $h.popupDialog('', 'kvExportFullDialog', 350, 120);
self.popup.focus();
self.setPopupAlert(self.messages.downloadProgress);
}
if (!isEmpty(self.columnSelectorId)) {
if (!$h.isEmpty(self.columnSelectorId)) {
$selected = $('#' + self.columnSelectorId).parent().find('input[name="export_columns_selector[]"]');
$selected.each(function () {
var $el = $(this);
Expand All @@ -91,9 +92,9 @@
});
self.$form.find('input[name="export_columns"]').val(JSON.stringify(cols));
}
self.$form.trigger('submit');
self.$form.trigger('submit');
},
listenClick: function() {
listenClick: function () {
var self = this;
self.$element.off('click.exportmenu').on('click.exportmenu', function (e) {
var fmt, msgs, msg = '', msg1, msg2, msg3, lib = window[self.dialogLib];
Expand All @@ -105,9 +106,9 @@
return;
}
msgs = self.messages;
msg1 = isEmpty(self.alertMsg) ? '' : self.alertMsg;
msg2 = isEmpty(msgs.allowPopups) ? '' : msgs.allowPopups;
msg3 = isEmpty(msgs.confirmDownload) ? '' : msgs.confirmDownload;
msg1 = $h.isEmpty(self.alertMsg) ? '' : self.alertMsg;
msg2 = $h.isEmpty(msgs.allowPopups) ? '' : msgs.allowPopups;
msg3 = $h.isEmpty(msgs.confirmDownload) ? '' : msgs.confirmDownload;
if (msg1.length && msg2.length) {
msg = msg1 + '\n\n' + msg2;
} else {
Expand All @@ -120,11 +121,11 @@
if (msg3.length) {
msg = msg + '\n\n' + msg3;
}
if (isEmpty(msg)) {
if ($h.isEmpty(msg)) {
self.processExport(fmt);
return;
}
lib.confirm(msg, function(result) {
lib.confirm(msg, function (result) {
if (result) {
self.processExport(fmt);
}
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.

2 changes: 1 addition & 1 deletion src/views/_columns.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 - 2018
* @version 1.3.0
* @version 1.3.1
*
* Column Selector View
*
Expand Down
2 changes: 1 addition & 1 deletion src/views/_form.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 - 2018
* @version 1.3.0
* @version 1.3.1
*
* Export Submission Form
*
Expand Down
Loading

0 comments on commit 30ecff8

Please sign in to comment.