Commit f5769826473208c14ce6271fec7a20a5862282aa
1 parent
2cdc93f0
add modal form for create importer prefix and add handaling for delimiter
Showing
10 changed files
with
81 additions
and
37 deletions
Show diff stats
backend/controllers/ImportersPrefixController.php
... | ... | @@ -54,9 +54,10 @@ class ImportersPrefixController extends BaseController |
54 | 54 | $model = new ImportersPrefix(); |
55 | 55 | |
56 | 56 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
57 | - return $this->redirect(['view', 'id' => $model->id]); | |
57 | + //return $this->redirect(['view', 'id' => $model->id]); | |
58 | + return $this->redirect('index'); | |
58 | 59 | } else { |
59 | - return $this->render('create', [ | |
60 | + return $this->renderAjax('create', [ | |
60 | 61 | 'model' => $model, |
61 | 62 | ]); |
62 | 63 | } |
... | ... | @@ -73,7 +74,8 @@ class ImportersPrefixController extends BaseController |
73 | 74 | $model = $this->findModel($id); |
74 | 75 | |
75 | 76 | if ($model->load(Yii::$app->request->post()) && $model->save()) { |
76 | - return $this->redirect(['view', 'id' => $model->id]); | |
77 | + // return $this->redirect(['view', 'id' => $model->id]); | |
78 | + return $this->redirect('index'); | |
77 | 79 | } else { |
78 | 80 | return $this->render('update', [ |
79 | 81 | 'model' => $model, | ... | ... |
backend/controllers/ParserController.php
... | ... | @@ -111,7 +111,12 @@ class ParserController extends BaseController |
111 | 111 | |
112 | 112 | // === ручная загрузка =========== |
113 | 113 | //запускаем парсинг |
114 | - $data = $model->readFile(); | |
114 | + // доп. опции для парсера | |
115 | + $options = []; | |
116 | + if( ! $model->action ) // обработка с кастомным разделителем | |
117 | + $options['$delimiter'] = $model->delimiter; | |
118 | + | |
119 | + $data = $model->readFile( $options ); | |
115 | 120 | // сохраняем в кеш отпарсенные даные |
116 | 121 | Yii::$app->getCache()->set('parser_data', json_encode($data)); |
117 | 122 | // сохраняем в кеш модель - в ней настройки для дальнейшей обработки данных | ... | ... |
backend/models/ImportersPrefix.php
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | namespace backend\models; |
4 | 4 | |
5 | 5 | use Yii; |
6 | +use backend\models\Importers; | |
6 | 7 | |
7 | 8 | /** |
8 | 9 | * This is the model class for table "w_importers_prefix". |
... | ... | @@ -15,13 +16,6 @@ use Yii; |
15 | 16 | */ |
16 | 17 | class ImportersPrefix extends \backend\components\base\BaseActiveRecord |
17 | 18 | { |
18 | - /** | |
19 | - * @inheritdoc | |
20 | - */ | |
21 | - public static function tableName() | |
22 | - { | |
23 | - return 'w_importers_prefix'; | |
24 | - } | |
25 | 19 | |
26 | 20 | /** |
27 | 21 | * @inheritdoc |
... | ... | @@ -38,6 +32,11 @@ class ImportersPrefix extends \backend\components\base\BaseActiveRecord |
38 | 32 | ]; |
39 | 33 | } |
40 | 34 | |
35 | + | |
36 | + public function getImporterName () | |
37 | + { | |
38 | + return Importers::findOne($this->importer_id)->name; | |
39 | + } | |
41 | 40 | /** |
42 | 41 | * @inheritdoc |
43 | 42 | */ |
... | ... | @@ -45,10 +44,10 @@ class ImportersPrefix extends \backend\components\base\BaseActiveRecord |
45 | 44 | { |
46 | 45 | return [ |
47 | 46 | 'id' => Yii::t('app', 'ID'), |
48 | - 'importer_id' => Yii::t('app', 'Importer ID'), | |
49 | - 'brand' => Yii::t('app', 'Brand'), | |
50 | - 'prefix' => Yii::t('app', 'Prefix'), | |
51 | - 'timestamp' => Yii::t('app', 'Timestamp'), | |
47 | + 'importer_id' => Yii::t('app', 'Поставщик'), | |
48 | + 'brand' => Yii::t('app', 'Бренд'), | |
49 | + 'prefix' => Yii::t('app', 'Префикс'), | |
50 | + 'timestamp' => Yii::t('app', 'Дата создания'), | |
52 | 51 | ]; |
53 | 52 | } |
54 | 53 | } | ... | ... |
backend/views/check-price/index.php
... | ... | @@ -16,8 +16,7 @@ $this->title = 'Проверка прайсов'; |
16 | 16 | $this->params['breadcrumbs'][] = $this->title; |
17 | 17 | // зарегистрируем скрипт для обработки загрузки модального окна |
18 | 18 | ParserAsset::register($this); |
19 | -// убрал Pjax потому что он при выполнении блокирует скрипт вызова модального окна | |
20 | -//Pjax::begin(); | |
19 | +Pjax::begin(['id' => 'gridViewContent']); | |
21 | 20 | ?> |
22 | 21 | <div class="catalog-index"> |
23 | 22 | |
... | ... | @@ -73,7 +72,7 @@ ParserAsset::register($this); |
73 | 72 | 'size' => 'modal-lg', |
74 | 73 | ]); |
75 | 74 | |
76 | - echo "<div id='modalContent'></div>"; | |
75 | + echo "<div class='modalContent'></div>"; | |
77 | 76 | Modal::end(); |
78 | 77 | // Pjax::end(); |
79 | 78 | ?> | ... | ... |
backend/views/importers-prefix/_form.php
... | ... | @@ -2,6 +2,9 @@ |
2 | 2 | |
3 | 3 | use yii\helpers\Html; |
4 | 4 | use yii\widgets\ActiveForm; |
5 | +use backend\models\Importers; | |
6 | +use yii\helpers\ArrayHelper; | |
7 | + | |
5 | 8 | |
6 | 9 | /* @var $this yii\web\View */ |
7 | 10 | /* @var $model backend\models\ImportersPrefix */ |
... | ... | @@ -10,18 +13,19 @@ use yii\widgets\ActiveForm; |
10 | 13 | |
11 | 14 | <div class="importers-prefix-form"> |
12 | 15 | |
13 | - <?php $form = ActiveForm::begin(); ?> | |
16 | + <?php $form = ActiveForm::begin(); | |
17 | + | |
18 | + ?> | |
14 | 19 | |
15 | - <?= $form->field($model, 'importer_id')->textInput(['maxlength' => true]) ?> | |
20 | + <?= $form->field($model, 'importer_id')->dropDownList(ArrayHelper::map( Importers::find()->all(), 'id','name' )); ?> | |
16 | 21 | |
17 | 22 | <?= $form->field($model, 'brand')->textInput(['maxlength' => true]) ?> |
18 | 23 | |
19 | 24 | <?= $form->field($model, 'prefix')->textInput(['maxlength' => true]) ?> |
20 | 25 | |
21 | - <?= $form->field($model, 'timestamp')->textInput() ?> | |
22 | 26 | |
23 | 27 | <div class="form-group"> |
24 | - <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | |
28 | + <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Добавить') : Yii::t('app', 'Редактировать'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary',]) ?> | |
25 | 29 | </div> |
26 | 30 | |
27 | 31 | <?php ActiveForm::end(); ?> | ... | ... |
backend/views/importers-prefix/create.php
... | ... | @@ -6,7 +6,7 @@ use yii\helpers\Html; |
6 | 6 | /* @var $this yii\web\View */ |
7 | 7 | /* @var $model backend\models\ImportersPrefix */ |
8 | 8 | |
9 | -$this->title = Yii::t('app', 'Create Importers Prefix'); | |
9 | +$this->title = Yii::t('app', 'Добавление'); | |
10 | 10 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Importers Prefixes'), 'url' => ['index']]; |
11 | 11 | $this->params['breadcrumbs'][] = $this->title; |
12 | 12 | ?> | ... | ... |
backend/views/importers-prefix/index.php
... | ... | @@ -2,6 +2,10 @@ |
2 | 2 | |
3 | 3 | use yii\helpers\Html; |
4 | 4 | use yii\grid\GridView; |
5 | +use yii\widgets\Pjax; | |
6 | +use yii\bootstrap\Modal; | |
7 | +use backend\assets\ParserAsset; | |
8 | +use yii\helpers\Url; | |
5 | 9 | |
6 | 10 | /* @var $this yii\web\View */ |
7 | 11 | /* @var $searchModel backend\models\ImportersPrefixSearсh */ |
... | ... | @@ -9,30 +13,62 @@ use yii\grid\GridView; |
9 | 13 | |
10 | 14 | $this->title = Yii::t('app', 'Список префиксов поставщиков'); |
11 | 15 | $this->params['breadcrumbs'][] = $this->title; |
16 | +ParserAsset::register($this); | |
17 | +$url = Url::to(['create']); | |
18 | + | |
12 | 19 | ?> |
13 | 20 | |
14 | 21 | <div class="importers-prefix-index"> |
15 | 22 | |
16 | 23 | <h1><?= Html::encode($this->title) ?></h1> |
17 | - <?= Html::a(Yii::t('app', 'Create Importers Prefix'), ['create'], ['class' => 'btn btn-success']) ?> | |
18 | - <?php // echo $this->render('_search', ['model' => $searchModel]); ?> | |
19 | - | |
24 | + <p> | |
25 | + <?= Html::a(Yii::t('app', 'Добавление'), '#', ['class' => 'btn btn-success modalButton', 'value' => $url]) ?> | |
26 | + </p> | |
27 | + <?php // echo $this->render('_search', ['model' => $searchModel]); | |
28 | + Pjax::begin(['id' => 'gridViewContent']); | |
20 | 29 | |
30 | + ?> | |
21 | 31 | |
22 | 32 | <?= GridView::widget([ |
23 | 33 | 'dataProvider' => $dataProvider, |
24 | 34 | 'filterModel' => $searchModel, |
25 | 35 | 'columns' => [ |
26 | 36 | ['class' => 'yii\grid\SerialColumn'], |
27 | - | |
28 | - 'importer_id', | |
29 | - 'brand', | |
30 | - 'prefix', | |
31 | - 'timestamp', | |
37 | + [ | |
38 | + 'attribute' => 'importer_id', | |
39 | + 'label' => 'ПОСТАВЩИК', | |
40 | + 'value' => function ($data) { | |
41 | + return $data->importerName;} | |
42 | + ], | |
43 | + [ | |
44 | + 'attribute' => 'brand', | |
45 | + 'label' => 'БРЕНД', | |
46 | + ], | |
47 | + [ | |
48 | + 'attribute' => 'prefix', | |
49 | + 'label' => 'ПРЕФИКСЫ (ЧЕРЕЗ ,)', | |
50 | + ], | |
51 | + [ | |
52 | + 'attribute' => 'timestamp', | |
53 | + 'label' => 'ДАТА ДОБАВЛЕНИЯ', | |
54 | + ], | |
32 | 55 | |
33 | 56 | ['class' => 'yii\grid\ActionColumn', |
34 | 57 | 'template' => '{update},{delete}'], |
35 | 58 | ], |
36 | - ]); ?> | |
59 | + ]); | |
60 | + | |
61 | + | |
62 | + | |
63 | + // сюда будем всавлять контент модального окна | |
64 | + Modal::begin([ | |
65 | + 'id' => 'modal', | |
66 | + 'size' => 'modal-lg', | |
67 | + ]); | |
68 | + | |
69 | + echo "<div class='modalContent'></div>"; | |
70 | + Modal::end(); | |
71 | + Pjax::end(); | |
72 | + ?> | |
37 | 73 | |
38 | 74 | </div> | ... | ... |
backend/views/importers-prefix/update.php
... | ... | @@ -5,9 +5,7 @@ use yii\helpers\Html; |
5 | 5 | /* @var $this yii\web\View */ |
6 | 6 | /* @var $model backend\models\ImportersPrefix */ |
7 | 7 | |
8 | -$this->title = Yii::t('app', 'Update {modelClass}: ', [ | |
9 | - 'modelClass' => 'Importers Prefix', | |
10 | -]) . ' ' . $model->id; | |
8 | +$this->title = Yii::t('app', "Редактирование префикса поставщика") . ' ' . $model->importerName; | |
11 | 9 | $this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Importers Prefixes'), 'url' => ['index']]; |
12 | 10 | $this->params['breadcrumbs'][] = ['label' => $model->id, 'url' => ['view', 'id' => $model->id]]; |
13 | 11 | $this->params['breadcrumbs'][] = Yii::t('app', 'Update'); | ... | ... |
backend/web/js/parser.js
... | ... | @@ -5,9 +5,9 @@ $(function(){ |
5 | 5 | $('.modalButton').click(function (){ |
6 | 6 | // находим контейнер с модальным контентом и подгружаем в него по оджаксу результат |
7 | 7 | $('#modal').modal('show') |
8 | - .find('#modalContent') | |
8 | + .find('.modalContent') | |
9 | 9 | .load($(this).attr('value')); // в 'value' - у нас указан путь с гет параметрами к конроллеру |
10 | - | |
10 | + $.pjax.reload({container:'#gridViewContent'}); | |
11 | 11 | }); |
12 | 12 | |
13 | 13 | ... | ... |
vendor/yiisoft/multiparser/CsvParser.php