diff --git a/AutoloadExample.php b/AutoloadExample.php
deleted file mode 100644
index 01dba4c..0000000
--- a/AutoloadExample.php
+++ /dev/null
@@ -1,14 +0,0 @@
- [
+ 'class' => AccessControl::className(),
+ 'rules' => [
+ [
+ 'allow' => true,
+ 'roles' => [$this->adminPermission]
+ ]
+ ]
+ ]
+ ]
+ );
+ }
+
+ public function init()
+ {
+ parent::init(); // TODO: Change the autogenerated stub
+ $this->registerTranslations();
+ }
+
+ public function registerTranslations()
+ {
+ Yii::$app->i18n->translations['queuemanager'] = [
+ 'class' => 'yii\i18n\PhpMessageSource',
+ 'sourceLanguage' => 'en-US',
+ 'basePath' => '@vendor/ignatenkovnikita/yii2-queuemanager/messages',
+ ];
+
+ }
public function bootstrap($app)
{
diff --git a/README.md b/README.md
index 88b5d20..e41e055 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,9 @@
Yii2 Queue Manager
==================
+
+[![Latest Stable Version](https://poser.pugx.org/ignatenkovnikita/yii2-queuemanager/v/stable)](https://packagist.org/packages/ignatenkovnikita/yii2-queuemanager) [![Total Downloads](https://poser.pugx.org/ignatenkovnikita/yii2-queuemanager/downloads)](https://packagist.org/packages/ignatenkovnikita/yii2-queuemanager) [![Latest Unstable Version](https://poser.pugx.org/ignatenkovnikita/yii2-queuemanager/v/unstable)](https://packagist.org/packages/ignatenkovnikita/yii2-queuemanager) [![License](https://poser.pugx.org/ignatenkovnikita/yii2-queuemanager/license)](https://packagist.org/packages/ignatenkovnikita/yii2-queuemanager)
+
+
Yii2 Queue Manager
![2017-10-21_13-55-13](https://user-images.githubusercontent.com/4436320/31851112-b75f26e8-b667-11e7-8f54-d907daeb26bb.png)
diff --git a/composer.json b/composer.json
index eaeea95..8f4ca04 100644
--- a/composer.json
+++ b/composer.json
@@ -11,7 +11,9 @@
}
],
"require": {
- "yiisoft/yii2": "*"
+ "yiisoft/yii2": "~2.0.0",
+ "yiisoft/yii2-jui": "~2.0.0",
+ "2amigos/yii2-chartjs-widget": "~2.0"
},
"autoload": {
"psr-4": {
diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php
index cd34c47..1e4243d 100644
--- a/controllers/DefaultController.php
+++ b/controllers/DefaultController.php
@@ -16,6 +16,9 @@
*/
class DefaultController extends Controller
{
+ /**
+ * @return array
+ */
public function behaviors()
{
return [
@@ -68,12 +71,15 @@ protected function getWorkersInfo()
}
+ /**
+ * @return array
+ */
public function actionAjax()
{
$workers = [];
if ($workersInfo = $this->getWorkersInfo()) {
foreach ($workersInfo as $name => $info) {
- $workers[] = $name .' '.$info['addr'];
+ $workers[] = $name . ' ' . $info['addr'];
// Console::stdout($this->format("- $name: ", Console::FG_YELLOW));
// Console::output($info['addr']);
}
@@ -104,6 +110,11 @@ public function actionStat()
return $this->render('stat');
}
+ public function actionReport()
+ {
+ return $this->render('report');
+ }
+
/**
* Displays a single QueueManager model.
* @param integer $id
diff --git a/messages/config.php b/messages/config.php
new file mode 100644
index 0000000..d6adac0
--- /dev/null
+++ b/messages/config.php
@@ -0,0 +1,42 @@
+ null,
+ 'interactive' => true,
+ 'help' => null,
+ 'sourcePath' => '@vendor/ignatenkovnikita/yii2-queuemanager',
+ 'messagePath' => 'vendor/ignatenkovnikita/yii2-queuemanager/messages/',
+ 'languages' => ['en', 'ru'],
+ 'translator' => 'Yii::t',
+ 'sort' => false,
+ 'overwrite' => true,
+ 'removeUnused' => false,
+ 'markUnused' => true,
+ 'except' => [
+ '.svn',
+ '.git',
+ '.gitignore',
+ '.gitkeep',
+ '.hgignore',
+ '.hgkeep',
+ '/messages',
+ '/BaseYii.php',
+ ],
+ 'only' => [
+ '*.php',
+ ],
+ 'format' => 'php',
+ 'catalog' => 'messages',
+ 'ignoreCategories' => [],
+ 'phpFileHeader' => '',
+ 'phpDocBlock' => null,
+];
diff --git a/messages/en/queuemanager.php b/messages/en/queuemanager.php
new file mode 100644
index 0000000..d444256
--- /dev/null
+++ b/messages/en/queuemanager.php
@@ -0,0 +1,52 @@
+ '',
+ 'Are you sure you want to delete this item?' => '',
+ 'Class' => '',
+ 'Create' => '',
+ 'Create {modelClass}' => '',
+ 'Created At' => '',
+ 'Data' => '',
+ 'Delay' => '',
+ 'Delete' => '',
+ 'End Execute' => '',
+ 'ID' => '',
+ 'Name' => '',
+ 'Priority' => '',
+ 'Properties' => '',
+ 'Queue Managers' => '',
+ 'Repeat' => '',
+ 'Reset' => '',
+ 'Result' => '',
+ 'Result ID' => '',
+ 'Search' => '',
+ 'Sender' => '',
+ 'Start Execute' => '',
+ 'Status' => '',
+ 'Status Done' => '',
+ 'Status Error' => '',
+ 'Status Reserved' => '',
+ 'Status Waiting' => '',
+ 'Time Execute' => '',
+ 'Ttr' => '',
+ 'Update' => '',
+ 'Update {modelClass}: ' => '',
+ 'Updated At' => '',
+];
diff --git a/messages/ru/queuemanager.php b/messages/ru/queuemanager.php
new file mode 100644
index 0000000..4d240da
--- /dev/null
+++ b/messages/ru/queuemanager.php
@@ -0,0 +1,55 @@
+ 'Отчет',
+ 'Statistics' => 'Статистика',
+ 'Enter date' => 'Укажите дату',
+ 'Are you sure to repeat this item?' => '',
+ 'Are you sure you want to delete this item?' => '',
+ 'Class' => '',
+ 'Create' => '',
+ 'Create {modelClass}' => '',
+ 'Created At' => '',
+ 'Data' => '',
+ 'Delay' => '',
+ 'Delete' => '',
+ 'End Execute' => '',
+ 'ID' => '',
+ 'Name' => '',
+ 'Priority' => '',
+ 'Properties' => '',
+ 'Queue Managers' => '',
+ 'Repeat' => '',
+ 'Reset' => '',
+ 'Result' => '',
+ 'Result ID' => '',
+ 'Search' => '',
+ 'Sender' => '',
+ 'Start Execute' => '',
+ 'Status' => '',
+ 'Status Done' => '',
+ 'Status Error' => '',
+ 'Status Reserved' => '',
+ 'Status Waiting' => '',
+ 'Time Execute' => '',
+ 'Ttr' => '',
+ 'Update' => '',
+ 'Update {modelClass}: ' => '',
+ 'Updated At' => '',
+];
diff --git a/models/generated/QueueManager.php b/models/generated/QueueManager.php
index 64d064c..a767c5d 100644
--- a/models/generated/QueueManager.php
+++ b/models/generated/QueueManager.php
@@ -31,7 +31,7 @@ class QueueManager extends \yii\db\ActiveRecord
*/
public static function tableName()
{
- return 'queue_manager';
+ return '{{%queue_manager}}';
}
/**
diff --git a/models/search/QueueManagerSearch.php b/models/search/QueueManagerSearch.php
index 9cba6a4..ba9a27a 100644
--- a/models/search/QueueManagerSearch.php
+++ b/models/search/QueueManagerSearch.php
@@ -6,6 +6,7 @@
use yii\base\Model;
use yii\data\ActiveDataProvider;
use ignatenkovnikita\queuemanager\models\QueueManager;
+use yii\db\ActiveQuery;
/**
* QueueManagerSearch represents the model behind the search form about `ignatenkovnikita\queuemanager\models\QueueManager`.
@@ -57,12 +58,15 @@ public function search($params)
'delay' => $this->delay,
'priority' => $this->priority,
'result_id' => $this->result_id,
- 'created_at' => $this->created_at,
- 'updated_at' => $this->updated_at,
+// 'created_at' => $this->created_at,
+// 'updated_at' => $this->updated_at,
'start_execute' => $this->start_execute,
'end_execute' => $this->end_execute,
]);
+ $this->dayCondition($query, 'created_at');
+ $this->dayCondition($query, 'updated_at');
+
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'sender', $this->sender])
->andFilterWhere(['like', 'status', $this->status])
@@ -74,4 +78,19 @@ public function search($params)
return $dataProvider;
}
+
+
+ /**
+ * @param ActiveQuery $query
+ * @param $attribute
+ * @return bool
+ */
+ protected function dayCondition(ActiveQuery &$query, $attribute)
+ {
+ if(empty($this->{$attribute})) {
+ return false;
+ }
+ $start = strtotime('midnight', strtotime($this->{$attribute}));
+ $query->andFilterWhere( ['BETWEEN', $attribute, $start, strtotime('+1day - 1sec', $start)]);
+ }
}
diff --git a/views/default/_form.php b/views/default/_form.php
index 539d202..c7ba889 100644
--- a/views/default/_form.php
+++ b/views/default/_form.php
@@ -45,7 +45,7 @@
field($model, 'end_execute')->textInput() ?>
- isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
+ isNewRecord ? Yii::t('queuemanager', 'Create') : Yii::t('queuemanager', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
diff --git a/views/default/_search.php b/views/default/_search.php
index 88afaed..e33c146 100644
--- a/views/default/_search.php
+++ b/views/default/_search.php
@@ -48,8 +48,8 @@
field($model, 'end_execute') ?>
- 'btn btn-primary']) ?>
- 'btn btn-default']) ?>
+ 'btn btn-primary']) ?>
+ 'btn btn-default']) ?>
diff --git a/views/default/create.php b/views/default/create.php
index 0a4d60b..aba501f 100644
--- a/views/default/create.php
+++ b/views/default/create.php
@@ -6,10 +6,10 @@
/* @var $this yii\web\View */
/* @var $model ignatenkovnikita\queuemanager\models\QueueManager */
-$this->title = Yii::t('app', 'Create {modelClass}', [
+$this->title = Yii::t('queuemanager', 'Create {modelClass}', [
'modelClass' => 'Queue Manager',
]);
-$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Queue Managers'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => Yii::t('queuemanager', 'Queue Managers'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
diff --git a/views/default/index.php b/views/default/index.php
index 1bcf6c7..f6aeca2 100644
--- a/views/default/index.php
+++ b/views/default/index.php
@@ -3,19 +3,21 @@
use ignatenkovnikita\queuemanager\models\QueueManager;
use yii\helpers\Html;
use yii\grid\GridView;
+use yii\jui\DatePicker;
/* @var $this yii\web\View */
/* @var $searchModel ignatenkovnikita\queuemanager\models\search\QueueManagerSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
-$this->title = Yii::t('app', 'Queue Managers');
+$this->title = Yii::t('queuemanager', 'Queue Managers');
$this->params['breadcrumbs'][] = $this->title;
?>
render('_search', ['model' => $searchModel]); ?>
- = Html::a('Статистика', ['stat']) ?>
+ = Html::a(Yii::t('queuemanager', 'Report'), ['report']) ?>
+ = Html::a(Yii::t('queuemanager', 'Statistics'), ['stat']) ?>
['width' => '140'],
+ 'attribute' => 'created_at',
+ 'value' => function ($model) {
+
+ return empty($model->created_at) ? null : date('d.m.Y H:i:s', $model->created_at);
+ },
+ 'filter' => DatePicker::widget([
+ 'model' => $searchModel,
+ 'attribute' => 'created_at',
+ 'dateFormat' => 'php:d.m.Y',
+ 'options' => ['class' => 'form-control', 'placeholder' => Yii::t('queuemanager', 'Enter date')],
+ ]),
+ 'format' => 'html',
+ ],
+ [
+ 'headerOptions' => ['width' => '140'],
+ 'attribute' => 'updated_at',
+ 'value' => function ($model) {
+
+ return empty($model->created_at) ? null : date('d.m.Y H:i:s', $model->created_at);
+ },
+ 'filter' => DatePicker::widget([
+ 'model' => $searchModel,
+ 'attribute' => 'updated_at',
+ 'dateFormat' => 'php:d.m.Y',
+ 'options' => ['class' => 'form-control', 'placeholder' => Yii::t('queuemanager', 'Enter date')],
+ ]),
+ 'format' => 'html',
+ ],
// 'updated_at',
'start_execute:datetime',
'end_execute:datetime',
[
- 'label' => Yii::t('backend', 'Time Execute'),
+ 'label' => Yii::t('queuemanager', 'Time Execute'),
'value' => function (\ignatenkovnikita\queuemanager\models\QueueManager $data) {
return Yii::$app->formatter->asTimestamp($data->end_execute - $data->start_execute);
}
diff --git a/views/default/report.php b/views/default/report.php
new file mode 100644
index 0000000..8c5c9fe
--- /dev/null
+++ b/views/default/report.php
@@ -0,0 +1,135 @@
+
+ * @file report.php
+ * @author ignatenkovnikita
+ * @date $date$
+ */
+
+use dosamigos\chartjs\ChartJs;
+use ignatenkovnikita\queuemanager\models\QueueManager;
+
+/**
+ * Created by PhpStorm.
+ * User: ignatenkovnikita
+ * Web Site: http://IgnatenkovNikita.ru
+ */
+
+$this->title = 'Report status job';
+$this->params['breadcrumbs'][] = ['label' => Yii::t('queuemanager', 'Queue Managers'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+
+
+// status
+$db = Yii::$app->db;
+switch ($db->driverName) {
+ case 'pgsql':
+ $selectExpression = "to_char(to_timestamp(created_at), 'YYYY-MM-DD')";
+ break;
+ default:
+ case 'mysql':
+ $selectExpression = "DATE_FORMAT(FROM_UNIXTIME(created_at), '%Y-%m-%d')";
+ break;
+}
+$subQuery = (new \yii\db\Query())
+ ->select([
+ 'dd' => new \yii\db\Expression($selectExpression),
+ 'status',
+ ])->from('queue_manager');
+$data = (new \yii\db\Query())
+ ->select([
+ 'dd',
+ 'status',
+ 'cnt' => 'COUNT(*)',
+ ])
+ ->from(['q' => $subQuery])
+ ->groupBy(['status', 'dd'])
+ ->orderBy('dd')
+ ->all();
+
+$labels = [];
+foreach ($data as $item) {
+ $dd = Yii::$app->formatter->asDate($item['dd']);
+ if (!in_array($dd, $labels)) {
+ $labels[] = $dd;
+ }
+}
+$status1 = array_fill_keys($labels, '0');
+$status2 = array_fill_keys($labels, '0');
+$status3 = array_fill_keys($labels, '0');
+$status4 = array_fill_keys($labels, '0');
+foreach ($data as $item) {
+ $dd = Yii::$app->formatter->asDate($item['dd']);
+ if ($item['status'] == QueueManager::STATUS_WAITING) {
+ $status1[$dd] = $item['cnt'];
+ }
+ if ($item['status'] == QueueManager::STATUS_RESERVED) {
+ $status2[$dd] = $item['cnt'];
+ }
+ if ($item['status'] == QueueManager::STATUS_DONE) {
+ $status3[$dd] = $item['cnt'];
+ }
+ if ($item['status'] == QueueManager::STATUS_ERROR) {
+ $status4[$dd] = $item['cnt'];
+ }
+}
+$status1 = array_values($status1);
+$status2 = array_values($status2);
+$status3 = array_values($status3);
+$status4 = array_values($status4);
+
+
+echo ChartJs::widget([
+ 'type' => 'line',
+ 'options' => [
+// 'height' => 400,
+// 'width' => 400
+ ],
+ 'data' => [
+ 'labels' => $labels,
+ 'datasets' => [
+ [
+ 'label' => "Status Waiting",
+// 'backgroundColor' => "rgba(179,181,198,0.2)",
+ 'borderColor' => "blue",
+// 'pointBackgroundColor' => "rgba(179,181,198,1)",
+// 'pointBorderColor' => "#fff",
+// 'pointHoverBackgroundColor' => "#fff",
+// 'pointHoverBorderColor' => "rgba(179,181,198,1)",
+ 'data' => $status1
+ ],
+ [
+ 'label' => "Status Reserved",
+// 'backgroundColor' => "rgba(255,99,132,0.2)",
+ 'borderColor' => "green",
+// 'pointBackgroundColor' => "rgba(255,99,132,1)",
+// 'pointBorderColor' => "#fff",
+// 'pointHoverBackgroundColor' => "#fff",
+// 'pointHoverBorderColor' => "rgba(255,99,132,1)",
+ 'data' => $status2
+ ],
+ [
+ 'label' => "Status Done",
+// 'backgroundColor' => "rgba(255,99,132,0.2)",
+ 'borderColor' => "green",
+// 'pointBackgroundColor' => "rgba(255,99,132,1)",
+// 'pointBorderColor' => "#fff",
+// 'pointHoverBackgroundColor' => "#fff",
+// 'pointHoverBorderColor' => "rgba(255,99,132,1)",
+ 'data' => $status3
+ ],
+ [
+ 'label' => "Status Error",
+// 'backgroundColor' => "rgba(255,99,132,0.2)",
+ 'borderColor' => "red",
+// 'pointBackgroundColor' => "rgba(255,99,132,1)",
+// 'pointBorderColor' => "#fff",
+// 'pointHoverBackgroundColor' => "#fff",
+// 'pointHoverBorderColor' => "rgba(255,99,132,1)",
+ 'data' => $status4
+ ]
+ ]
+ ]
+]);
\ No newline at end of file
diff --git a/views/default/stat.php b/views/default/stat.php
index ba83dff..6e7dd7f 100644
--- a/views/default/stat.php
+++ b/views/default/stat.php
@@ -14,8 +14,8 @@
/* @var $this yii\web\View */
/* @var $model ignatenkovnikita\queuemanager\models\QueueManager */
-$this->title = 'stat';
-$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Queue Managers'), 'url' => ['index']];
+$this->title = 'Statistic in realtime';
+$this->params['breadcrumbs'][] = ['label' => Yii::t('queuemanager', 'Queue Managers'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\ignatenkovnikita\queuemanager\assets\QueueManagerAsset::register($this);
?>
diff --git a/views/default/update.php b/views/default/update.php
index 9b76976..5672c91 100644
--- a/views/default/update.php
+++ b/views/default/update.php
@@ -5,12 +5,12 @@
/* @var $this yii\web\View */
/* @var $model ignatenkovnikita\queuemanager\models\QueueManager */
-$this->title = Yii::t('app', 'Update {modelClass}: ', [
+$this->title = Yii::t('queuemanager', 'Update {modelClass}: ', [
'modelClass' => 'Queue Manager',
]) . ' ' . $model->name;
-$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Queue Managers'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => Yii::t('queuemanager', 'Queue Managers'), 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]];
-$this->params['breadcrumbs'][] = Yii::t('app', 'Update');
+$this->params['breadcrumbs'][] = Yii::t('queuemanager', 'Update');
?>
diff --git a/views/default/view.php b/views/default/view.php
index 1919fb5..fbf20ef 100644
--- a/views/default/view.php
+++ b/views/default/view.php
@@ -7,17 +7,17 @@
/* @var $model ignatenkovnikita\queuemanager\models\QueueManager */
$this->title = $model->name;
-$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Queue Managers'), 'url' => ['index']];
+$this->params['breadcrumbs'][] = ['label' => Yii::t('queuemanager', 'Queue Managers'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
- $model->id], ['class' => 'btn btn-primary']) ?>
- $model->id], [
+ $model->id], ['class' => 'btn btn-primary']) ?>
+ $model->id], [
'class' => 'btn btn-danger',
'data' => [
- 'confirm' => Yii::t('app', 'Are you sure you want to delete this item?'),
+ 'confirm' => Yii::t('queuemanager', 'Are you sure you want to delete this item?'),
'method' => 'post',
],
]) ?>