<commit_before><?php
/**
 * Created by PhpStorm.
 * User: execut
 * Date: 11/15/17
 * Time: 12:14 PM
 */

namespace execut\actions\widgets;

use execut\actions\action\adapter\viewRenderer\DynaGridRow;
use execut\yii\jui\WidgetTrait;
use kartik\export\ExportMenu;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use \kartik\dynagrid\DynaGrid as KartikDynaGrid;
use yii\web\JsExpression;

class DynaGrid extends KartikDynaGrid
{
    use WidgetTrait;
    public $dataProvider = null;
    public $storage = KartikDynaGrid::TYPE_DB;
    public $filter = null;

    public function init()
    {
        if ($this->filter !== null) {
            $columns = array_values($this->filter->getGridColumns());
            if ($this->dataProvider === null) {
                $this->dataProvider = $this->filter->search();
            }
        } else {
            $columns = $this->columns;
        }
//        foreach ($exportColumns as &$column) {
//            unset($column['visible']);
//        }

        $id = $this->getId();
        if (\yii::$app->request->post('exportFull_' . $id . '-export')) {
            ini_set('max_execution_time', 1200);
        }

        if (empty($this->options['id'])) {
            $this->options['id'] = $id;
        }

        $fullExportMenu = ExportMenu::widget([
            'id' => $id . '-export',
            'dataProvider' => $this->dataProvider,
            'columns' => $columns,
            'showColumnSelector' => true,
            'target' => ExportMenu::TARGET_BLANK,
            'batchSize' => 1000,
            'fontAwesome' => true,
            'asDropdown' => false,
            'dynagrid' => true,
            'dynagridOptions' => [
                'options' => ['id' => $id],
                'gridOptions' => [
                    'columns' => $columns,
                ],
            ],
            'dropdownOptions' => [
                'label' => '<i class="glyphicon glyphicon-export"></i> Full'
            ],
        ]);

        $this->columns = $columns;

        if ($this->gridOptions === null) {
            $this->gridOptions = [];
        }

        $this->gridOptions = ArrayHelper::merge([
            'class' => GridView::class,
            'responsive' => false,
            'responsiveWrap' => false,
            'rowOptions' => function ($row) {
                if ($row instanceof DynaGridRow) {
                    return $row->getRowOptions();
                }
            },
            'panel' => false,
            'floatHeader' => true,
            'floatHeaderOptions' => [
                'top' => 50,
                'zIndex' => 989,
                'autoReflow' => true,
                'top' => new JsExpression(<<<JS
function(table) {
    if ($('.container-logo').length !== 0 && $('.container-logo').css('position') !== 'fixed') {
        return 0;
    }

    var menusSelectors = ['.navbar', '#search-tabs', '#header-menu'],
        result = 0;
    for (var key = 0; key < menusSelectors.length; key++) {
        if ($(menusSelectors[key]).length) {
            result += $(menusSelectors[key]).height();
        }
    }
    
    return result;
}
JS
                )
            ],
            'export' => [
                'fontAwesome' => true,
                'itemsAfter'=> [
                    '<li role="presentation" class="divider"></li>',
                    '<li class="dropdown-header">Export All Data</li>',
                    $fullExportMenu
                ]
            ],
            'toggleDataOptions' => [
                'maxCount' => 100000,
            ],
            'filterModel' => $this->filter,
//            'toolbar' => $this->getToolbarConfig(),
            'dataProvider' => $this->dataProvider,
        ], $this->gridOptions);

        parent::init(); // TODO: Change the autogenerated stub
    }


    public function getGridId() {
        return $this->id . '-grid';
    }

    /**
     * @inheritdoc
     */
    public function run()
    {
        if (method_exists($this, 'initWidget')) {
            $this->initWidget();
        }

        if (empty($this->gridOptions['options']['id'])) {
            $this->gridOptions['options']['id'] = $this->id;
        }

        Html::addCssClass($this->options, $this->getDefaultCssClass());
        $this->_registerBundle();
        if (!empty($this->filter->errors)) {
            echo Html::errorSummary($this->filter);
        }

        if (!empty($this->gridOptions['class'])) {
            $widgetClass = $this->gridOptions['class'];
        } else {
            $widgetClass = GridView::class;
        }

        echo Html::tag('div', $widgetClass::widget($this->gridOptions), $this->options);
    }
}<commit_msg>fixed bug with full export columns<commit_after><?php
/**
 * Created by PhpStorm.
 * User: execut
 * Date: 11/15/17
 * Time: 12:14 PM
 */

namespace execut\actions\widgets;

use execut\actions\action\adapter\viewRenderer\DynaGridRow;
use execut\yii\jui\WidgetTrait;
use kartik\export\ExportMenu;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use \kartik\dynagrid\DynaGrid as KartikDynaGrid;
use yii\web\JsExpression;

class DynaGrid extends KartikDynaGrid
{
    use WidgetTrait;
    public $dataProvider = null;
    public $storage = KartikDynaGrid::TYPE_DB;
    public $filter = null;

    public function init()
    {
        if ($this->filter !== null) {
            $columns = array_values($this->filter->getGridColumns());
            if ($this->dataProvider === null) {
                $this->dataProvider = $this->filter->search();
            }
        } else {
            $columns = $this->columns;
        }
//        foreach ($exportColumns as &$column) {
//            unset($column['visible']);
//        }

        $id = $this->getId();
        if (\yii::$app->request->post('exportFull_' . $id . '-export')) {
            ini_set('max_execution_time', 1200);
        }

        if (empty($this->options['id'])) {
            $this->options['id'] = $id;
        }

        $this->columns = $columns;

        if ($this->gridOptions === null) {
            $this->gridOptions = [];
        }

        $this->gridOptions = ArrayHelper::merge([
            'class' => GridView::class,
            'responsive' => false,
            'responsiveWrap' => false,
            'rowOptions' => function ($row) {
                if ($row instanceof DynaGridRow) {
                    return $row->getRowOptions();
                }
            },
            'panel' => false,
            'floatHeader' => true,
            'floatHeaderOptions' => [
                'top' => 50,
                'zIndex' => 989,
                'autoReflow' => true,
                'top' => new JsExpression(<<<JS
function(table) {
    if ($('.container-logo').length !== 0 && $('.container-logo').css('position') !== 'fixed') {
        return 0;
    }

    var menusSelectors = ['.navbar', '#search-tabs', '#header-menu'],
        result = 0;
    for (var key = 0; key < menusSelectors.length; key++) {
        if ($(menusSelectors[key]).length) {
            result += $(menusSelectors[key]).height();
        }
    }
    
    return result;
}
JS
                )
            ],
            'export' => [
                'fontAwesome' => true,
                'itemsAfter'=> [
                    '<li role="presentation" class="divider"></li>',
                    '<li class="dropdown-header">Export All Data</li>',
                ]
            ],
            'toggleDataOptions' => [
                'maxCount' => 100000,
            ],
            'filterModel' => $this->filter,
//            'toolbar' => $this->getToolbarConfig(),
            'dataProvider' => $this->dataProvider,
        ], $this->gridOptions);

        parent::init(); // TODO: Change the autogenerated stub
    }


    public function getGridId() {
        return $this->id . '-grid';
    }

    /**
     * @inheritdoc
     */
    public function run()
    {
        if (method_exists($this, 'initWidget')) {
            $this->initWidget();
        }

        if (empty($this->gridOptions['options']['id'])) {
            $this->gridOptions['options']['id'] = $this->id;
        }

        Html::addCssClass($this->options, $this->getDefaultCssClass());
        $this->_registerBundle();
        if (!empty($this->filter->errors)) {
            echo Html::errorSummary($this->filter);
        }

        if (!empty($this->gridOptions['class'])) {
            $widgetClass = $this->gridOptions['class'];
        } else {
            $widgetClass = GridView::class;
        }

        echo Html::tag('div', $widgetClass::widget($this->gridOptions), $this->options);
    }
    protected function initWidget()
    {
        parent::initWidget();
        $this->initFullExportMenu();
    }

    protected function initFullExportMenu(): void
    {
        $columns = $this->gridOptions['columns'];
        $fullExportMenu = ExportMenu::widget([
            'id' => $this->id . '-export',
            'options' => [
                'id' => $this->id . '-export',
            ],
            'dataProvider' => $this->dataProvider,
            'columns' => $columns,
            'showColumnSelector' => true,
            'target' => ExportMenu::TARGET_BLANK,
            'batchSize' => 1000,
            'fontAwesome' => true,
            'asDropdown' => false,
            'dynagrid' => true,
            'dynagridOptions' => [
                'options' => ['id' => $this->id],
                'gridOptions' => [
                    'class' => $this->gridOptions['class'],
                    'columns' => $columns,
                ],
            ],
            'dropdownOptions' => [
                'label' => '<i class="glyphicon glyphicon-export"></i> Full'
            ],
        ]);
        $this->gridOptions['export']['itemsAfter'][] = $fullExportMenu;
    }
}
{'fraction_non_alphanumeric': 0.16753180661577607, 'fraction_numerical': 0.006717557251908397, 'mean_word_length': 1.7076329567373931, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 171, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '619103', 'n_tokens_mistral': 2902, 'n_tokens_neox': 2761, 'n_words': 505}