From e4d1a1add23713294fbe49a88db8e30547220b83 Mon Sep 17 00:00:00 2001 From: Andrey Klochok Date: Tue, 17 Nov 2015 18:39:51 +0200 Subject: [PATCH] Initial Crontabs --- src/SidebarMenu.php | 4 +++ src/controllers/CrontabController.php | 15 ++++++++- src/grid/CrontabGridView.php | 33 +++++++++++++++++-- src/models/Crontab.php | 32 +++++++++++++----- src/views/crontab/_search.php | 13 ++++++++ src/views/crontab/index.php | 40 ++++++++++++++++++----- src/views/crontab/view.php | 47 ++++++++++++++++++--------- 7 files changed, 149 insertions(+), 35 deletions(-) create mode 100644 src/views/crontab/_search.php diff --git a/src/SidebarMenu.php b/src/SidebarMenu.php index cb475b3b..a9ce8ea4 100644 --- a/src/SidebarMenu.php +++ b/src/SidebarMenu.php @@ -54,6 +54,10 @@ public function items() 'label' => Yii::t('app', 'Backup settings'), 'url' => ['/hosting/backuping/index'], ], + 'crontab' => [ + 'label' => Yii::t('app', 'Crons'), + 'url' => ['/hosting/crontab/index'], + ], ], ], ]; diff --git a/src/controllers/CrontabController.php b/src/controllers/CrontabController.php index f172600a..e494d694 100644 --- a/src/controllers/CrontabController.php +++ b/src/controllers/CrontabController.php @@ -9,5 +9,18 @@ class CrontabController extends \hipanel\base\CrudController { - + public function actions() + { + return [ + 'index' => [ + 'class' => 'hipanel\actions\IndexAction', + ], + 'view' => [ + 'class' => 'hipanel\actions\ViewAction', + ], + 'update' => [ + 'class' => 'hipanel\actions\SmartUpdateAction', + ], + ]; + } } diff --git a/src/grid/CrontabGridView.php b/src/grid/CrontabGridView.php index 9554cba4..16b48abf 100644 --- a/src/grid/CrontabGridView.php +++ b/src/grid/CrontabGridView.php @@ -7,7 +7,10 @@ namespace hipanel\modules\hosting\grid; -use hipanel\grid\MainColumn; +use hipanel\grid\ActionColumn; +use hipanel\modules\server\grid\ServerColumn; +use Yii; +use yii\helpers\Html; class CrontabGridView extends \hipanel\grid\BoxedGridView { @@ -15,8 +18,32 @@ static public function defaultColumns() { return [ 'crontab' => [ - 'class' => MainColumn::className(), - 'filterAttribute' => 'crontab_like', + 'attribute' => 'crontab', + 'format' => 'html', + 'enableSorting' => false, + 'value' => function($model, $key, $index) { + $label = Yii::t('app', '{0, plural, one{# record} other{# records}}', $model->cronRecordCount); + return Html::a($label, ['view', 'id' => $key], ['class' => 'bold', 'data-pjax' => 0]); + } + ], + 'server' => [ + 'sortAttribute' => 'server', + 'attribute' => 'server_id', + 'class' => ServerColumn::className(), + ], + 'account' => [ + 'sortAttribute' => 'account', + 'attribute' => 'account_id', + 'class' => AccountColumn::className() + ], + 'client', + 'state' => [ + 'enableSorting' => false, + 'attribute' => 'state', + ], + 'actions' => [ + 'class' => ActionColumn::className(), + 'template' => '{view}', ], ]; } diff --git a/src/models/Crontab.php b/src/models/Crontab.php index 4b1c00d7..8b6390fa 100644 --- a/src/models/Crontab.php +++ b/src/models/Crontab.php @@ -11,21 +11,37 @@ class Crontab extends \hipanel\base\Model { - use \hipanel\base\ModelTrait; /** @inheritdoc */ - public function rules () { + public function rules() + { return [ - [['id', 'account_id', 'server_id', 'client_id'], 'integer'], - [['crontab', 'account', 'server', 'client'], 'safe'], - [['state', 'state_label'], 'safe'], - [['exists'], 'boolean'], + [['id', 'account_id', 'server_id', 'client_id'], 'integer'], + [['crontab', 'account', 'server', 'client'], 'safe'], + [['state', 'state_label'], 'safe'], + [['exists'], 'boolean'], + [['id', 'crontab'], 'safe', 'on' => ['update']], ]; } /** @inheritdoc */ - public function attributeLabels () { + public function attributeLabels() + { return $this->mergeAttributeLabels([]); } -} + + /** + * @return int + */ + public function getCronRecordCount() + { + $count = 0; + $regex = '/^(\s+)?(#.*)?$/'; + foreach (explode("\n", $this->crontab) as $line) { + if (!preg_match($regex, trim($line))) $count++; + } + + return $count; + } +} \ No newline at end of file diff --git a/src/views/crontab/_search.php b/src/views/crontab/_search.php new file mode 100644 index 00000000..49c452d0 --- /dev/null +++ b/src/views/crontab/_search.php @@ -0,0 +1,13 @@ + + +
field('account')->widget(AccountCombo::className()) ?>
+ +
field('server')->widget(ServerCombo::className(), ['formElementSelector' => '.form-group']) ?>
+ +
field('client_id')->widget(ClientCombo::classname(), ['formElementSelector' => '.form-group']) ?>
+ \ No newline at end of file diff --git a/src/views/crontab/index.php b/src/views/crontab/index.php index 8d766741..22da54e1 100644 --- a/src/views/crontab/index.php +++ b/src/views/crontab/index.php @@ -6,20 +6,44 @@ */ use hipanel\modules\hosting\grid\CrontabGridView; +use hipanel\widgets\ActionBox; +use hipanel\widgets\Pjax; -$this->title = Yii::t('app', 'Crontabs'); -$this->params['breadcrumbs'][] = $this->title; -$this->params['subtitle'] = array_filter(Yii::$app->request->get($model->formName(), [])) ? 'filtered list' : 'full list'; +$this->title = Yii::t('app', 'Crontabs'); +$this->params['breadcrumbs'][] = $this->title; +$this->params['subtitle'] = array_filter(Yii::$app->request->get($model->formName(), [])) ? 'filtered list' : 'full list'; ?> +params['pjax'], ['enablePushState' => true])) ?> + $model, 'dataProvider' => $dataProvider]) ?> +beginActions() ?> -renderSearchButton() ?> +renderSorter([ + 'attributes' => [ + 'account', + 'client', + 'server', + ], +]) ?> +renderPerPage() ?> +endActions() ?> + +renderSearchForm(compact('objectOptions')) ?> +end() ?> +beginBulkForm() ?> + $dataProvider, - 'filterModel' => $searchModel, - 'columns' => [ + 'filterModel' => $searchModel, + 'columns' => [ 'checkbox', - 'seller', + 'crontab', + 'account', + 'server', 'client', - 'crontab' + 'state', + 'actions', ], ]) ?> +endBulkForm() ?> + \ No newline at end of file diff --git a/src/views/crontab/view.php b/src/views/crontab/view.php index 15b7a50f..25c25f53 100644 --- a/src/views/crontab/view.php +++ b/src/views/crontab/view.php @@ -7,26 +7,43 @@ use hipanel\modules\hosting\grid\CrontabGridView; use hipanel\widgets\Pjax; +use hiqdev\xeditable\widgets\XEditable; use yii\helpers\Html; -$this->title = Html::encode($model->domain); -$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Domains'), 'url' => ['index']]; +$this->title = Html::encode($model->id); +$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Crontabs'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; +$model->scenario = 'update'; ?> -params['pjax']) ?>
- -
- $model, - 'columns' => [ - 'seller_id','client_id', - ['attribute' => 'crontab'], - ], - ]) ?> -
- +
+ $model, + 'columns' => [ + 'account', + 'server', + 'client', + [ + 'attribute' => 'crontab', + 'format' => 'raw', + 'value' => function ($model) { + return XEditable::widget([ + 'model' => $model, + 'attribute' => 'crontab', + 'pluginOptions' => [ + 'mode' => 'inline', + 'type' => 'textarea', + 'rows' => 20, + 'select2Options' => [ + 'width' => '50rem', + ], + ] + ]); + } + ] + ] + ]) ?> +
-