Skip to content

Commit

Permalink
Initial Crontabs
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Nov 17, 2015
1 parent d8d9ee4 commit e4d1a1a
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 35 deletions.
4 changes: 4 additions & 0 deletions src/SidebarMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
],
],
],
];
Expand Down
15 changes: 14 additions & 1 deletion src/controllers/CrontabController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
],
];
}
}
33 changes: 30 additions & 3 deletions src/grid/CrontabGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,43 @@

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
{
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}',
],
];
}
Expand Down
32 changes: 24 additions & 8 deletions src/models/Crontab.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
13 changes: 13 additions & 0 deletions src/views/crontab/_search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\modules\hosting\widgets\combo\AccountCombo;
use hipanel\modules\server\widgets\combo\ServerCombo;
?>

<div class="col-md-4"><?= $search->field('account')->widget(AccountCombo::className()) ?></div>
<!-- /.col-md-4 -->
<div class="col-md-4"><?= $search->field('server')->widget(ServerCombo::className(), ['formElementSelector' => '.form-group']) ?></div>
<!-- /.col-md-4 -->
<div class="col-md-4"><?= $search->field('client_id')->widget(ClientCombo::classname(), ['formElementSelector' => '.form-group']) ?></div>
<!-- /.col-md-4 -->
40 changes: 32 additions & 8 deletions src/views/crontab/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

?>
<?php Pjax::begin(array_merge(Yii::$app->params['pjax'], ['enablePushState' => true])) ?>
<?php $box = ActionBox::begin(['model' => $model, 'dataProvider' => $dataProvider]) ?>
<?php $box->beginActions() ?>

<?= crontabGridView::widget([
<?= $box->renderSearchButton() ?>
<?= $box->renderSorter([
'attributes' => [
'account',
'client',
'server',
],
]) ?>
<?= $box->renderPerPage() ?>
<?php $box->endActions() ?>

<?= $box->renderSearchForm(compact('objectOptions')) ?>
<?php $box->end() ?>
<?php $box->beginBulkForm() ?>
<?= CrontabGridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'filterModel' => $searchModel,
'columns' => [
'checkbox',
'seller',
'crontab',
'account',
'server',
'client',
'crontab'
'state',
'actions',
],
]) ?>
<?php $box->endBulkForm() ?>
<?php Pjax::end() ?>
47 changes: 32 additions & 15 deletions src/views/crontab/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

?>

<? Pjax::begin(Yii::$app->params['pjax']) ?>
<div class="row">

<div class="col-md-4">
<?= CrontabGridView::detailView([
'model' => $model,
'columns' => [
'seller_id','client_id',
['attribute' => 'crontab'],
],
]) ?>
</div>

<div class="col-md-12">
<?= CrontabGridView::detailView([
'model' => $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',
],
]
]);
}
]
]
]) ?>
</div>
</div>
<?php Pjax::end() ?>

0 comments on commit e4d1a1a

Please sign in to comment.