diff --git a/Module.php b/Module.php index b5d97f3..110e24b 100644 --- a/Module.php +++ b/Module.php @@ -2,33 +2,48 @@ namespace dominion\cron; +use yii\base\BootstrapInterface; +use yii\i18n\PhpMessageSource; + /** * cron module definition class */ -class Module extends \yii\base\Module +class Module extends \yii\base\Module implements BootstrapInterface { + public $admins = []; + public $project = 'yii'; + /** * {@inheritdoc} */ public $controllerNamespace = 'dominion\cron\controllers'; - /** - * {@inheritdoc} - */ - public function init() - { - parent::init(); - - // custom initialization code goes here - } public function bootstrap($app) { - if ($app instanceof \yii\console\Application) { + if ($app instanceof \yii\web\Application) + { + $app->getUrlManager()->addRules([ + ['class' => 'yii\web\UrlRule', 'pattern' => $this->id, 'route' => $this->id . '/default/index'], + ['class' => 'yii\web\UrlRule', 'pattern' => $this->id . '/', 'route' => $this->id . '/default/view'], + ['class' => 'yii\web\UrlRule', 'pattern' => $this->id . '//', 'route' => $this->id . '//'], + ], false); + } + elseif ($app instanceof \yii\console\Application) + { $app->controllerMap[$this->id] = [ 'class' => 'dominion\cron\console\MoleController', - 'module' => $this, + // 'module' => $this, + ]; + } + + if (!isset($app->get('i18n')->translations['mole*'])) + { + $app->get('i18n')->translations['mole*'] = [ + 'class' => PhpMessageSource::className(), + 'basePath' => __DIR__ . '/messages', + 'sourceLanguage' => 'en-US' ]; } } - + } diff --git a/console/MoleController.php b/console/MoleController.php index 7619ce9..b327387 100644 --- a/console/MoleController.php +++ b/console/MoleController.php @@ -6,11 +6,13 @@ * @license */ -namespace dominion\cron\commands; +namespace dominion\cron\console; +use Yii; use yii\console\Controller; use yii\console\ExitCode; use dominion\cron\models\MoleTask; +use yii\base\InlineAction; /** * Запуск агента по расписанию @@ -20,14 +22,13 @@ use dominion\cron\models\MoleTask; */ class MoleController extends Controller { - /** * Запуск всех агентов для проекта yii из mole_task * @return int Exit code */ public function actionIndex() { - $filePatch = __DIR__.'/../runtime/lock.lock'; + $filePatch = Yii::getAlias('@app/runtime/lock.lock'); if(!file_exists($filePatch)) { $fp = fopen($filePatch, "w"); diff --git a/controllers/DefaultController.php b/controllers/DefaultController.php index 9130a09..65ef016 100644 --- a/controllers/DefaultController.php +++ b/controllers/DefaultController.php @@ -5,12 +5,33 @@ namespace dominion\cron\controllers; use Yii; use yii\web\Controller; use dominion\cron\models\search\MoleTaskSearch; +use dominion\cron\models\MoleTask; +use yii\filters\VerbFilter; +use yii\web\NotFoundHttpException; /** * Default controller for the `cron` module */ class DefaultController extends Controller { + public function behaviors() + { + if (!Yii::$app->user->getIsGuest() && in_array(Yii::$app->user->id, $this->module->admins)) + { + return [ + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + else + { + throw new NotFoundHttpException(Yii::t('mole', 'access denied')); + } + } /** * Renders the index view for the module @@ -27,4 +48,88 @@ class DefaultController extends Controller ]); } + /** + * Displays a single MoleTask model. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + $model = $this->findModel($id); + return $this->render('view', [ + 'model' => $model, + ]); + } + + /** + * Creates a new MoleTask model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return mixed + */ + public function actionCreate() + { + $model = new MoleTask(); + + if ($model->load(Yii::$app->request->post()) && $model->save()) + { + return $this->redirect(['view', 'id' => $model->id]); + } + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing MoleTask model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($model->load(Yii::$app->request->post()) && $model->save()) + { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing MoleTask model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param integer $id + * @return mixed + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the MoleTask model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param integer $id + * @return MoleTask the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = MoleTask::findOne($id)) !== null) + { + return $model; + } + + throw new NotFoundHttpException(Yii::t('mole', 'The requested page does not exist.')); + } + } diff --git a/messages/message.php b/messages/message.php deleted file mode 100644 index 44daf6c..0000000 --- a/messages/message.php +++ /dev/null @@ -1,27 +0,0 @@ - __DIR__ . '/../', - 'messagePath' => __DIR__, - 'languages' => [ - 'ru-RU', - ], - 'translator' => 'Yii::t', - 'sort' => false, - 'overwrite' => true, - 'removeUnused' => false, - 'only' => ['*.php'], - 'except' => [ - '.svn', - '.git', - '.gitignore', - '.gitkeep', - '.hgignore', - '.hgkeep', - '/messages', - '/tests', - '/vendor', - ], - 'format' => 'php', -]; diff --git a/messages/ru-RU/mole.php b/messages/ru-RU/mole.php index e8e7370..2d3c791 100644 --- a/messages/ru-RU/mole.php +++ b/messages/ru-RU/mole.php @@ -1,5 +1,28 @@ 'wwww111', - 'Task List' => 'Список задач' -]; \ No newline at end of file + 'Task List' => 'Список задач', + 'Project' => 'Проект', + 'Parent ID' => 'Родительский процесс', + 'Date Add' => 'Дата создания', + 'Date Start' => 'Дата запуска', + 'Date End' => 'Дата завершения', + 'Module' => 'Модуль', + 'Controller' => 'Контроллер', + 'Type' => 'Тип', + 'Name' => 'Название', + 'Params' => 'Параметры', + 'Is Ready' => 'Готов', + 'Completed' => 'Завершен', + 'Priority' => 'Приоритет', + // 'Childs Total Count' => '', + // 'Childs Completed' => '', + 'Status' => 'Статус', + 'Yes' => 'Да', + 'No' => 'Нет', + 'Create Task' => 'Создать задачу', + 'Save' => 'Сохранить', + 'Update'=> 'Изменить', + 'Update Task: {nameAttribute}' => 'Изменить задачу: {nameAttribute}', + 'Delete' => 'Удалить', + ]; diff --git a/models/MoleTask.php b/models/MoleTask.php index ac0d6a3..b0d69e7 100644 --- a/models/MoleTask.php +++ b/models/MoleTask.php @@ -41,7 +41,7 @@ class MoleTask extends \yii\db\ActiveRecord public function rules() { return [ - [['parentId', 'isReady', 'childsTotalCount', 'childsCompleted', 'status'], 'required'], + //[['parentId', 'isReady', 'childsTotalCount', 'childsCompleted', 'status'], 'required'], [['parentId', 'isReady', 'completed', 'priority', 'childsTotalCount', 'childsCompleted'], 'integer'], [['dateAdd', 'dateStart', 'dateEnd'], 'safe'], [['params'], 'string'], @@ -57,7 +57,7 @@ class MoleTask extends \yii\db\ActiveRecord { return [ 'id' => Yii::t('mole', 'ID'), - /* 'parentId' => Yii::t('mole', 'Parent ID'), + 'parentId' => Yii::t('mole', 'Parent ID'), 'dateAdd' => Yii::t('mole', 'Date Add'), 'dateStart' => Yii::t('mole', 'Date Start'), 'dateEnd' => Yii::t('mole', 'Date End'), @@ -72,7 +72,23 @@ class MoleTask extends \yii\db\ActiveRecord 'childsTotalCount' => Yii::t('mole', 'Childs Total Count'), 'childsCompleted' => Yii::t('mole', 'Childs Completed'), 'status' => Yii::t('mole', 'Status'), - 'project' => Yii::t('mole', 'Project'),*/ + 'project' => Yii::t('mole', 'Project'), ]; } + + /** + * Выбираем все строки с project + */ + public function getAllTask() + { + return self::find() + ->andWhere([ + 'project'=> Yii::$app->getModule('cron')->project, + 'completed' => 0, + ]) + ->andWhere(['IS', 'dateStart', NULL]) + ->andWhere(['IS', 'dateEnd', NULL]) + // ->andWhere(['<=', 'dateAdd', date('Y-m-d H:i:s')]) + ->all(); + } } diff --git a/models/search/MoleTaskSearch.php b/models/search/MoleTaskSearch.php index e2823a6..8dea28e 100644 --- a/models/search/MoleTaskSearch.php +++ b/models/search/MoleTaskSearch.php @@ -19,7 +19,7 @@ class MoleTaskSearch extends MoleTask public function rules() { return [ - [['parentId', 'isReady', 'completed', 'priority', 'childsTotalCount', 'childsCompleted'], 'integer'], + [['id', 'parentId', 'isReady', 'completed', 'priority', 'childsTotalCount', 'childsCompleted'], 'integer'], [['dateAdd', 'dateStart', 'dateEnd'], 'safe'], [['params'], 'string'], [['module', 'controller', 'type', 'name', 'status'], 'string', 'max' => 255], diff --git a/views/default/_form.php b/views/default/_form.php new file mode 100644 index 0000000..ad1f3ed --- /dev/null +++ b/views/default/_form.php @@ -0,0 +1,36 @@ + + + + ['class' => "form-horizontal"]]); ?> +{input}{error}'; ?> + +field($model, 'project', ['template' => $template, 'labelOptions' => ['class' => 'col-sm-2 control-label']]); ?> + +field($model, 'name', ['template' => $template, 'labelOptions' => ['class' => 'col-sm-2 control-label']]); ?> + +field($model, 'dateAdd', ['template' => $template, 'labelOptions' => ['class' => 'col-sm-2 control-label']]); ?> +field($model, 'dateStart', ['template' => $template, 'labelOptions' => ['class' => 'col-sm-2 control-label']]); ?> +field($model, 'dateEnd', ['template' => $template, 'labelOptions' => ['class' => 'col-sm-2 control-label']]); ?> + +field($model, 'module', ['template' => $template, 'labelOptions' => ['class' => 'col-sm-2 control-label']]); ?> + +field($model, 'controller', ['template' => $template, 'labelOptions' => ['class' => 'col-sm-2 control-label']]); ?> +field($model, 'params', ['template' => $template, 'labelOptions' => ['class' => 'col-sm-2 control-label']]); ?> + +
+
+ 'btn btn-success']) ?> +
+
+ + + + diff --git a/views/default/create.php b/views/default/create.php new file mode 100644 index 0000000..97b0811 --- /dev/null +++ b/views/default/create.php @@ -0,0 +1,30 @@ +title = Yii::t('mole', 'Create Task'); +$this->params['breadcrumbs'][] = ['label' => Yii::t('mole', 'Task List'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+
+
+
+
+
+ render('_form', [ + 'model' => $model, + ]) + ?> +
+
+
+
+
+
+
\ No newline at end of file diff --git a/views/default/index.php b/views/default/index.php index c80d368..28faf2e 100644 --- a/views/default/index.php +++ b/views/default/index.php @@ -22,23 +22,65 @@ use yii\widgets\Pjax; $this->title = Yii::t('mole', 'Task List'); $this->params['breadcrumbs'][] = $this->title; ?> -
-
+
+
+
+
+
+
+
- $dataProvider, - 'filterModel' => $searchModel, - 'layout' => "{items}\n{pager}", - 'columns' => [ - 'id', +

+ 'btn btn-success']) ?> +

- [ - 'class' => 'yii\grid\ActionColumn', - 'template' => '{update}', - ], - ], - ]); - ?> -
-
\ No newline at end of file + $dataProvider, + 'filterModel' => $searchModel, + 'layout' => "{items}\n{pager}", + 'columns' => [ + 'id', + 'project', + 'name', + // 'parentId', + 'dateAdd:datetime', + 'dateStart:datetime', + 'dateEnd:datetime', + //'module', + 'controller', + // 'type', + //'params', + [ + 'attribute' => 'isReady', + 'value' => function($model) + { + return $model->isReady ? Yii::t('mole', 'Yes') : Yii::t('mole', 'No'); + }, + // 'filter' => [0 => Yii::t('mole', 'No'), 1 => Yii::t('mole', 'Yes')] + ], + [ + 'attribute' => 'completed', + 'value' => function($model) + { + return $model->completed ? Yii::t('mole', 'Yes') : Yii::t('mole', 'No'); + }, + // 'filter' => [0 => Yii::t('mole', 'No'), 1 => Yii::t('mole', 'Yes')] + ], + 'priority', + //'childsTotalCount', + //'childsCompleted', + // 'status', + [ + 'class' => 'yii\grid\ActionColumn', + ], + ], + ]); + ?> +
+
+
+
+
+
+
diff --git a/views/default/update.php b/views/default/update.php new file mode 100644 index 0000000..c841fdc --- /dev/null +++ b/views/default/update.php @@ -0,0 +1,35 @@ +title = Yii::t('mole', 'Update Task: {nameAttribute}', [ + 'nameAttribute' => $model->name, + ]); +$this->params['breadcrumbs'][] = ['label' => Yii::t('mole', 'Task List'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = Yii::t('mole', 'Update'); +?> +
+
+
+
+
+
+
+ + render('_form', [ + 'model' => $model, + ]) + ?> + +
+
+
+
+
+
+
\ No newline at end of file diff --git a/views/default/view.php b/views/default/view.php new file mode 100644 index 0000000..b7467c3 --- /dev/null +++ b/views/default/view.php @@ -0,0 +1,85 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => Yii::t('mole', 'Task List'), 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+
+
+
+
+
+
+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => Yii::t('mole', 'Are you sure you want to delete this item?'), + 'method' => 'post', + ], + ]) + ?> +

+ + $model, + 'attributes' => [ + 'id', + 'project', + 'name', + 'parentId', + 'dateAdd:datetime', + 'dateStart:datetime', + 'dateEnd:datetime', + 'module', + 'controller', + 'type', + [ + 'attribute' => 'params', + 'value' => function($model) + { + return print_r(json_decode($model->params, true), true); + }, + ], + [ + 'attribute' => 'isReady', + 'value' => function($model) + { + return $model->isReady ? Yii::t('mole', 'Yes') : Yii::t('mole', 'No'); + }, + ], + [ + 'attribute' => 'completed', + 'value' => function($model) + { + return $model->completed ? Yii::t('mole', 'Yes') : Yii::t('mole', 'No'); + }, + ], + 'priority', + 'status', + ], + ]) + ?> + + +
+
+
+
+
+
+
+