Commit 525e8ee58e5540f3e46d24da65214b16c942fc18

Authored by Mihail
2 parents 9d57a9ea ae27b007

Merge branch 'draft'

.htaccess
... ... @@ -53,4 +53,10 @@
53 53  
54 54 RewriteRule ^.*$ frontend/web/index.php
55 55  
  56 +</IfModule>
  57 +
  58 +#для возможности загрузки файлов парсера
  59 +<IfModule mod_php5.c>
  60 + php_value upload_max_filesize 20M
  61 + php_value post_max_size 30M
56 62 </IfModule>
57 63 \ No newline at end of file
... ...
backend/assets/ParserAsset.php 0 → 100644
  1 +<?php
  2 +/**
  3 + * Created by PhpStorm.
  4 + * User: Cibermag
  5 + * Date: 28.09.2015
  6 + * Time: 11:40
  7 + */
  8 +
  9 +namespace backend\assets;
  10 +
  11 +use yii\web\AssetBundle;
  12 +
  13 +class ParserAsset extends AssetBundle {
  14 + public $basePath = '@webroot';
  15 + public $baseUrl = '@web';
  16 + public $css = [
  17 + 'css/site.css',
  18 + ];
  19 + public $js = [
  20 + 'js/parser.js',
  21 + ];
  22 + public $depends = [
  23 + 'yii\web\YiiAsset',
  24 + 'yii\bootstrap\BootstrapAsset',
  25 + ];
  26 +}
0 27 \ No newline at end of file
... ...
backend/controllers/CheckPriceController.php
... ... @@ -62,7 +62,7 @@ class CheckPriceController extends BaseController
62 62 public function actionIndex()
63 63 {
64 64 if(Yii::$app->request->isAjax){
65   - CustomVarDamp::dumpAndDie(1);
  65 + CustomVarDamp::dumpAndDie('Ajax!!!');
66 66 }
67 67  
68 68 //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]);
... ... @@ -81,18 +81,18 @@ class CheckPriceController extends BaseController
81 81 }
82 82  
83 83  
84   - public function actionView ($id)
  84 + public function actionView ($id, $date_update)
85 85 {
86   - // @todo переписать запрос - нужно условие на равенство даты, а также вьюшка должна быть модальным окном вызываемой по аджаксу
87   - $query = Details::find()->where(['IMPORT_ID' => $id])->orderBy(['timestamp' => SORT_DESC]);
  86 +
  87 + $query = Details::find()->where(['IMPORT_ID' => $id, 'timestamp' => $date_update])->limit(20);
88 88  
89 89 $provider = new ActiveDataProvider([
90 90 'query' => $query,
91   - 'pagination' => [
92   - 'pageSize' => 16,
93   - ],
  91 + 'pagination' => false,
  92 + 'sort' => false,
94 93 ]);
95   - return $this->render('view',
  94 +
  95 + return $this->renderAjax('view',
96 96 ['dataProvider' => $provider]);
97 97 }
98 98  
... ...
backend/controllers/Check_priceController.php deleted
1   -<?php
2   -namespace backend\controllers;
3   -
4   -use Yii;
5   -use yii\bootstrap\Modal;
6   -use yii\data\ActiveDataProvider;
7   -use yii\filters\AccessControl;
8   -use backend\components\base\BaseController;
9   -use yii\filters\VerbFilter;
10   -use backend\models\UploadFileParsingForm;
11   -use yii\web\UploadedFile;
12   -use yii\data\ArrayDataProvider;
13   -use yii\multiparser\DynamicFormHelper;
14   -use backend\components\parsers\CustomParserConfigurator;
15   -use backend\models\Details;
16   -use backend\models\ImporterFiles;
17   -use backend\models\Importer;
18   -use yii\base\ErrorException;
19   -use yii\db\Query;
20   -
21   -use common\components\CustomVarDamp;
22   -
23   -/**
24   - * Parser controller
25   - */
26   -class Check_priceController extends BaseController
27   -{
28   - public $layout = "/column";
29   -
30   - /**
31   - * @inheritdoc
32   - */
33   - public function behaviors()
34   - {
35   - return [
36   - 'access' => [
37   - 'class' => AccessControl::className(),
38   - 'rules' => [
39   - [
40   - 'actions' => ['index', 'view'],
41   - 'allow' => true,
42   - 'roles' => ['@'],
43   - ],
44   - ],
45   - ],
46   -// 'verbs' => [
47   -// 'class' => VerbFilter::className(),
48   -// 'actions' => [
49   -// 'logout' => ['post'],
50   -// ],
51   -// ],
52   - ];
53   - }
54   -
55   - /**
56   - * @inheritdoc
57   - */
58   - public function actions()
59   - {
60   - return [
61   - 'error' => [
62   - 'class' => 'yii\web\ErrorAction',
63   - ],
64   - ];
65   - }
66   -
67   -
68   - public function actionIndex()
69   - {
70   -
71   - if(Yii::$app->request->isAjax){
72   - CustomVarDamp::dumpAndDie(1);
73   - }
74   -
75   - //$query = (new Query())->select('*')->from('{{%importer_files}}')->where(['not', ['time_end' => null]])->orderBy(['upload_time' => SORT_DESC]);
76   - $query = Importer::find()->where(['active' => true])->orderBy(['price_date_update' => SORT_DESC]);
77   -
78   - $provider = new ActiveDataProvider([
79   - 'query' => $query,
80   - 'pagination' => [
81   - 'pageSize' => 10,
82   - ],
83   - ]);
84   - return $this->render('index',
85   - [
86   - 'dataProvider' => $provider,
87   - ]);
88   - }
89   -
90   -
91   - public function actionView ($id)
92   - {
93   -
94   -
95   -
96   -
97   - $query = Details::find()->where(['IMPORT_ID' => $id])->orderBy(['timestamp' => SORT_DESC]);
98   -
99   - $provider = new ActiveDataProvider([
100   - 'query' => $query,
101   - 'pagination' => [
102   - 'pageSize' => 16,
103   - ],
104   - ]);
105   - return $this->render('view',
106   - ['dataProvider' => $provider]);
107   - }
108   -}
backend/controllers/ParserController.php
... ... @@ -275,14 +275,14 @@ class ParserController extends BaseController
275 275  
276 276 public function actionServerFiles ()
277 277 {
278   - $arr_id = [];
  278 + $arr_id_files = [];
279 279 // получим список файлов которые ожидают к загрузке
280 280 foreach (glob(Yii::getAlias('@auto_upload') . '/*') as $server_file) {
281 281 $file_id = basename($server_file,".csv");
282   - $arr_id[] = (int) $file_id;
  282 + $arr_id_files[] = (int) $file_id;
283 283 }
284   -
285   - $query = ImporterFiles::find()->where(['in', 'id', $arr_id])->orderBy(['upload_time' => SORT_DESC]);
  284 + Yii::$app->cache->set( 'files_to_delete',json_encode( $arr_id_files ) );
  285 + $query = ImporterFiles::find()->where(['in', 'id', $arr_id_files])->orderBy(['upload_time' => SORT_DESC]);
286 286  
287 287 $provider = new ActiveDataProvider([
288 288 'query' => $query,
... ... @@ -295,24 +295,35 @@ class ParserController extends BaseController
295 295 'dataProvider' => $provider]);
296 296 }
297 297  
298   - public function actionDelete ($id)
  298 + public function actionDelete ()
299 299 {
300   - if(Yii::$app->request->isAjax){
301   - CustomVarDamp::dumpAndDie(1);
302   - }
303   -
304   - $files_model = new ImporterFiles();
305   - try {
  300 + if ( Yii::$app->request->isAjax ) {
306 301  
307   - $files_model->delete($id);
308   - unlink(Yii::getAlias('@auto_upload') . '/' . $id . '.csv' );
309   -
310   - } catch (ErrorException $e) {
  302 + $files_model = new ImporterFiles();
  303 + if ( isset(Yii::$app->request->post()['id'] )) {
  304 + $id = Yii::$app->request->post()['id'];
  305 + try {
  306 + $files_model->delete($id);
  307 + unlink(Yii::getAlias('@auto_upload') . '/' . $id . '.csv' );
  308 +
  309 + // удалим этот id и из кэша
  310 + if( $arr_id_files = Yii::$app->cache->get( 'files_to_delete' ) ){
  311 + $arr_id_files = json_decode($arr_id_files);
  312 + if (isset( $arr_id_files[$id] ) ) {
  313 + unset( $arr_id_files[$id] );
  314 + // положем уже обновленный массив
  315 + Yii::$app->cache->set( 'files_to_delete',json_encode( $arr_id_files ) );
  316 + }
  317 + }
  318 + // сообщим скрипту что все ОК
  319 + echo 1;
  320 + } catch (ErrorException $e) {
311 321  
312   - CustomVarDamp::dump($e->getMessage());
  322 + CustomVarDamp::dump($e->getMessage());
313 323  
  324 + }
  325 + }
314 326 }
315 327  
316   - $this->redirect('server-files');
317 328 }
318 329 }
... ...
backend/views/check-price/index.php
... ... @@ -2,8 +2,10 @@
2 2 use yii\helpers\Html;
3 3 use yii\grid\GridView;
4 4 use yii\grid\SerialColumn;
5   -use yii\grid\ActionColumn;
6 5 use yii\widgets\Pjax;
  6 +use yii\bootstrap\Modal;
  7 +use yii\helpers\Url;
  8 +use backend\assets\ParserAsset;
7 9  
8 10  
9 11 /* @var $this yii\web\View */
... ... @@ -12,47 +14,69 @@ use yii\widgets\Pjax;
12 14  
13 15 $this->title = 'Проверка прайсов';
14 16 $this->params['breadcrumbs'][] = $this->title;
  17 +// зарегистрируем скрипт для обработки загрузки модального окна
  18 +ParserAsset::register($this);
  19 +Pjax::begin();
15 20 ?>
16 21 <div class="catalog-index">
17 22  
18 23 <h1><?= Html::encode($this->title) ?></h1>
19 24  
20 25  
21   - <?= GridView::widget( ['dataProvider' => $dataProvider,
22   - 'columns' => [['class' => SerialColumn::className()],
23   - [
24   - 'class' => ActionColumn::className(),
25   - 'template'=>'{view}',
26   - 'contentOptions' => function ($model, $key, $index, $column){
27   - return ['data' => ['id' => $model->id, 'date' => $model->price_date_update]];
28   - }
  26 + <?= GridView::widget(['dataProvider' => $dataProvider,
  27 + 'columns' => [
  28 + ['class' => SerialColumn::className()],
  29 +
  30 + ['content' => function ($model) {
  31 + $url = Url::to(['view', 'id' => $model->id, 'date_update' => $model->price_date_update]);
  32 + return Html::a('<span class="glyphicon glyphicon-remove"> Просмотреть </span>', '#', [
  33 + 'class' => 'modalButton',
  34 + 'value' => $url,
  35 + ]);
  36 + },
29 37 ],
  38 +
30 39 [
31   - 'label' =>'Поставщик',
  40 + 'label' => 'Поставщик',
32 41 'value' => function ($data) {
33   - return '№ ' .$data->id . ' ' . $data->name;
  42 + return '№ ' . $data->id . ' ' . $data->name;
34 43 },
35 44 ],
36   - ['label' =>'Дата обновления',
37   - 'attribute' => 'price_date_update' ],
38   - ['label' => 'Кол-во дней',
39   - 'value' => function ($data) {
40   - $date1 = new DateTime("now");
41   - $date2 = new DateTime( $data->price_date_update );
42   - $quo_days = $date2->diff($date1)->format('%R%a');
43   - // уберем первый символ - там знак "+"
44   - $quo_days = substr( $quo_days, 1, strlen($quo_days) );
45   - $quo_days = (int) $quo_days;
46   -
47   - if($quo_days > 15)
48   - $quo_days = '>15';
49   -
50   - return $quo_days;
51   - }
52   - ],
53   - ]] );?>
54 45  
  46 + ['label' => 'Дата обновления',
  47 + 'attribute' => 'price_date_update'],
  48 +
  49 + ['label' => 'Кол-во дней',
  50 + 'value' => function ($data) {
  51 + $date1 = new DateTime("now");
  52 + $date2 = new DateTime($data->price_date_update);
  53 + $quo_days = $date2->diff($date1)->format('%R%a');
  54 + // уберем первый символ - там знак "+"
  55 + $quo_days = substr($quo_days, 1, strlen($quo_days));
  56 + $quo_days = (int)$quo_days;
  57 +
  58 + if ($quo_days > 15)
  59 + $quo_days = '>15';
  60 +
  61 + return $quo_days;
  62 + }
  63 + ],
  64 + ]
  65 + ]); ?>
  66 +
  67 + <?php
  68 + // сюда будем всавлять контент модального окна
  69 + Modal::begin([
  70 + // 'header'=>'<h4>Прайс</h4>',
  71 + 'id' => 'modal',
  72 + 'size' => 'modal-lg',
  73 + ]);
  74 +
  75 + echo "<div id='modalContent'></div>";
55 76  
  77 + Modal::end();
  78 + Pjax::end();
  79 + ?>
56 80  
57 81  
58 82 </div>
59 83 \ No newline at end of file
... ...
backend/views/check_price/index.php deleted
1   -<?php
2   -use yii\helpers\Html;
3   -use yii\grid\GridView;
4   -use yii\grid\SerialColumn;
5   -use yii\grid\ActionColumn;
6   -use yii\widgets\Pjax;
7   -
8   -
9   -/* @var $this yii\web\View */
10   -/* @var $searchModel backend\models\CatalogSearch */
11   -/* @var $dataProvider yii\data\ActiveDataProvider */
12   -
13   -$this->title = 'Проверка прайсов';
14   -$this->params['breadcrumbs'][] = $this->title;
15   -?>
16   -<div class="catalog-index">
17   -
18   - <h1><?= Html::encode($this->title) ?></h1>
19   -
20   -
21   - <?= GridView::widget( ['dataProvider' => $dataProvider,
22   - 'columns' => [['class' => SerialColumn::className()],
23   - [
24   - 'class' => ActionColumn::className(),
25   - 'template'=>'{view}',
26   - 'contentOptions' => function ($model, $key, $index, $column){
27   - return ['data' => ['id' => $model->id, 'date' => $model->price_date_update]];
28   - }
29   - ],
30   - [
31   - 'label' =>'Поставщик',
32   - 'value' => function ($data) {
33   - return '№ ' .$data->id . ' ' . $data->name;
34   - },
35   - ],
36   - ['label' =>'Дата обновления',
37   - 'attribute' => 'price_date_update' ],
38   - ['label' => 'Кол-во дней',
39   - 'value' => function ($data) {
40   - $date1 = new DateTime("now");
41   - $date2 = new DateTime( $data->price_date_update );
42   - $quo_days = $date2->diff($date1)->format('%R%a');
43   - // уберем первый символ - там знак "+"
44   - $quo_days = substr( $quo_days, 1, strlen($quo_days) );
45   - $quo_days = (int) $quo_days;
46   -
47   - if($quo_days > 15)
48   - $quo_days = '>15';
49   -
50   - return $quo_days;
51   - }
52   - ],
53   - ]] );?>
54   -
55   -
56   -
57   -
58   -</div>
59 0 \ No newline at end of file
backend/views/check_price/view.php deleted
1   -<?php
2   -use yii\helpers\Html;
3   -use yii\grid\GridView;
4   -use yii\grid\SerialColumn;
5   -use yii\bootstrap\Modal;
6   -
7   -
8   -/* @var $this yii\web\View */
9   -/* @var $searchModel backend\models\CatalogSearch */
10   -/* @var $dataProvider yii\data\ActiveDataProvider */
11   -
12   -$this->title = 'Проверка прайсов';
13   -$this->params['breadcrumbs'][] = $this->title;
14   -
15   -?>
16   -<div class="catalog-index">
17   -
18   - <h1><?= Html::encode($this->title) ?></h1>
19   -
20   - <?= GridView::widget( ['dataProvider' => $dataProvider,
21   -
22   - ] );
23   -
24   -
25   - ?>
26   -
27   -
28   -
29   -</div>
30   -<?php
31   -
32   -?>
33 0 \ No newline at end of file
backend/views/parser/server-files.php
... ... @@ -4,15 +4,17 @@ use yii\grid\GridView;
4 4 use yii\grid\SerialColumn;
5 5 use yii\grid\ActionColumn;
6 6 use yii\widgets\Pjax;
  7 +use backend\assets\ParserAsset;
7 8  
8 9  
9 10 /* @var $this yii\web\View */
10 11 /* @var $searchModel backend\models\CatalogSearch */
11 12 /* @var $dataProvider yii\data\ActiveDataProvider */
12 13  
13   -$this->title = 'Проверка прайсов';
  14 +$this->title = 'Файлы на сервере';
14 15 $this->params['breadcrumbs'][] = $this->title;
15   -Pjax::begin();
  16 +ParserAsset::register($this);
  17 +Pjax::begin(['id' => 'server_files_grid']);
16 18  
17 19 ?>
18 20 <div class="catalog-index">
... ... @@ -30,19 +32,15 @@ Pjax::begin();
30 32 ['label' =>'Дата загрузки',
31 33 'attribute' => 'upload_time' ],
32 34  
33   - ['class' => ActionColumn::className(),
34   - 'template'=>'{delete}',
35   - 'buttons' => [
36   - 'delete' => function ($url, $model, $key) {
37   - return Html::a('<span class="glyphicon glyphicon-remove"></span>', $url, [
38   - 'title' => Yii::t('yii', 'Удалить файл'),
39   - 'data-confirm' => 'Вы уверены что хотите удалить этот файл?',
40   - 'data-method' => 'post',
41   - 'data-pjax' => '1',
42   - ]);
43   - },
44   - ],
45   - ]
  35 + ['content' => function ($model) {
  36 + //Url::to(['delete', 'id' => $model->id, 'date_update' => $model->price_date_update]);
  37 + return Html::a('<span class="glyphicon glyphicon-remove"> Удалить </span>', '#', [
  38 + 'value' => $model->id,
  39 + 'class' => 'deleteLink',
  40 + ]);
  41 + },
  42 + ],
  43 +
46 44  
47 45 ]] );?>
48 46  
... ...
backend/web/js/parser.js 0 → 100644
  1 +$(function(){
  2 +
  3 + // для каждой строки обрабатываем клик по ссылке
  4 + $('.modalButton').click(function (){
  5 + // находим контейнер с модальным контентом и подгружаем в него по оджаксу результат
  6 + $('#modal').modal('show')
  7 + .find('#modalContent')
  8 + .load($(this).attr('value')); // в 'value' - у нас указан путь с гет параметрами к конроллеру
  9 + });
  10 +
  11 + $('.deleteLink').click(function ()
  12 + {
  13 + if ( confirm('Вы уверены что хотите удалить этот файл?') ){
  14 + var data = $(this).attr('value');// здесь у нас id удаляемой модели
  15 +
  16 + $.post( 'delete',{'id':data} )
  17 + .done(function(result) {
  18 + if(result == 1)
  19 + {
  20 + $.pjax.reload({container:'#server_files_grid'});
  21 + }else
  22 + {
  23 + $("#message").html(result);
  24 + }
  25 + }).fail(function()
  26 + {
  27 + console.log("server error");
  28 + });
  29 + }
  30 +
  31 +
  32 +
  33 +
  34 +});
  35 +});
... ...