Skip to content

Commit

Permalink
Add ObjctLabelWidget, add Backuping
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Nov 13, 2015
1 parent 746cc98 commit bc0f60c
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 40 deletions.
8 changes: 5 additions & 3 deletions src/SidebarMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,13 @@ public function items()
'icon' => 'fa-mail',
'visible' => function () { return (bool)Yii::getAlias('@mail', false); },
],
'backups' => [
'backup' => [
'label' => Yii::t('app', 'Backups'),
'url' => ['/hosting/backup/index'],
// 'icon' => 'fa-globe',
'visible' => function () { return (bool)Yii::getAlias('@backup', false); },
],
'backuping' => [
'label' => Yii::t('app', 'Backup settings'),
'url' => ['/hosting/backuping/index'],
],
],
],
Expand Down
35 changes: 35 additions & 0 deletions src/controllers/BackupingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,42 @@

namespace hipanel\modules\hosting\controllers;

use hipanel\models\Ref;
use Yii;

class BackupingController extends \hipanel\base\CrudController
{
public function actions()
{
return [
'index' => [
'class' => 'hipanel\actions\IndexAction',
'data' => function ($action) {
return [
'stateOptions' => $action->controller->getStateOptions(),
'typeOptions' => $action->controller->getTypeOptions(),
];
},
],
'update' => [
'class' => 'hipanel\actions\SmartUpdateAction',
],
'view' => [
'class' => 'hipanel\actions\ViewAction',
],
];
}

public function getTypeOptions()
{
return Ref::getList('type,backuping');
}
public function getStateOptions()
{
return [
'ok' => Yii::t('app', 'Ok'),
'disabled'=> Yii::t('app', 'Disabled'),
'deleted' => Yii::t('app', 'Deleted'),
];
}
}
10 changes: 7 additions & 3 deletions src/grid/BackupGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace hipanel\modules\hosting\grid;

use hipanel\grid\ActionColumn;
use hipanel\grid\MainColumn;
use hipanel\modules\hosting\widgets\backup\ObjectLabelWidget;
use hipanel\modules\server\grid\ServerColumn;
use Yii;
use yii\helpers\Html;
Expand Down Expand Up @@ -40,9 +42,7 @@ static public function defaultColumns()
'format' => 'raw',
'attribute' => 'name',
'value' => function($model) {
$labelType = $model->object === 'db' ?
Html::tag('span', Yii::t('app', 'Data Base'), ['class' => 'label label-info']) :
Html::tag('span', Yii::t('app', 'Domain'), ['class' => 'label label-default']);
$labelType = ObjectLabelWidget::widget(compact('model'));
return $labelType
. ' ' .
Html::a($model->name, [sprintf('/hosting/%s/view', $model->object), 'id' => $model->object_id], ['data-pjax' => 0]);
Expand All @@ -62,6 +62,10 @@ static public function defaultColumns()
return sprintf('%s GB', $model->size_gb);
}
],
'actions' => [
'class' => ActionColumn::className(),
'template' => '{view} {delete}',
],
];
}
}
70 changes: 67 additions & 3 deletions src/grid/BackupingGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,79 @@
namespace hipanel\modules\hosting\grid;

use hipanel\grid\MainColumn;
use hipanel\helpers\Url;
use hipanel\modules\hosting\widgets\backup\ObjectLabelWidget;
use hipanel\modules\server\grid\ServerColumn;
use hiqdev\xeditable\widgets\XEditable;

class BackupingGridView extends \hipanel\grid\BoxedGridView
{
public static $typeOptions;

/**
* @param mixed $typeOptions
*/
public static function setTypeOptions($typeOptions)
{
self::$typeOptions = $typeOptions;
}

static public function defaultColumns()
{
$typeOptions = self::$typeOptions;
return [
'backuping' => [
'class' => MainColumn::className(),
'filterAttribute' => 'backuping_like',
'name' => [
'class' => MainColumn::className(),
'filterAttribute' => 'backuping_like',
],
'account' => [
'attribute' => 'account_id',
'class' => AccountColumn::className(),
],
'server' => [
'attribute' => 'server_id',
'class' => ServerColumn::className(),
],
'object' => [
'filter' => false,
'format' => 'raw',
'value' => function ($model) {
return ObjectLabelWidget::widget(compact('model'));
}
],
'backup_count' => [
'filter' => false,
],
'type' => [
'attribute' => 'type',
'format' => 'raw',
'filter' => false,
'enableSorting' => false,
'value' => function($model) use ($typeOptions) {
return XEditable::widget([
'model' => $model,
'attribute' => 'type',
'pluginOptions' => [
'type' => 'select',
'source' => $typeOptions,
'url' => Url::to('update'),
]
]);
}
],
'state_label' => [
'filter' => false,
'enableSorting' => false,
],
'backup_last' => [
'filter' => false,
],
'total_du_gb' => [
'filter' => false,
'format' => 'html',
'value' => function($model) {
return sprintf('%s GB', $model->total_du_gb);
}
],
];
}
Expand Down
40 changes: 24 additions & 16 deletions src/models/Backuping.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,36 @@ class Backuping extends \hipanel\base\Model
use \hipanel\base\ModelTrait;

/** @inheritdoc */
public function rules () {
public function rules()
{
return [
[['id', 'service_id', 'server_id', 'account_id', 'client_id'], 'integer'],
[['skip_lock'], 'boolean'],
[['day','hour', 'path', 'include', 'exclude'], 'safe'],
[['method', 'method_label','server', 'account', 'client', 'name', 'object', 'service'], 'safe'],
[['backup_last' ], 'date'],
[['backup_count', 'total_du', 'total_du_gb',], 'integer'],
[['type', 'type_label', 'state', 'state_label'], 'safe'],
[['id', 'service_id', 'server_id', 'account_id', 'client_id'], 'integer'],
[['skip_lock'], 'boolean'],
[['day', 'hour', 'path', 'include', 'exclude'], 'safe'],
[['method', 'method_label', 'server', 'account', 'client', 'name', 'object', 'service'], 'safe'],
[['backup_last'], 'date'],
[['backup_count', 'total_du', 'total_du_gb',], 'integer'],
[['type', 'type_label', 'state', 'state_label'], 'safe'],

[['id', 'type'], 'safe', 'on' => ['update']],
];
}

/** @inheritdoc */
public function attributeLabels () {
public function attributeLabels()
{
return $this->mergeAttributeLabels([
'day' => Yii::t('app', 'Date'),
'hour' => Yii::t('app', 'Time'),
'backup_last' => Yii::t('app', 'Last backup'),
'backup_count' => Yii::t('app', 'Count'),
'total_du' => Yii::t('app', 'Total of backup uses'),
'total_du_gb' => Yii::t('app', 'Total of backup uses in GB'),
'method_label' => Yii::t('app', 'Method label'),
'day' => Yii::t('app', 'Date'),
'hour' => Yii::t('app', 'Time'),
'backup_last' => Yii::t('app', 'Last'),
'backup_count' => Yii::t('app', 'Count'),
'total_du' => Yii::t('app', 'Total of backup uses'),
'total_du_gb' => Yii::t('app', 'Disk'),
'method_label' => Yii::t('app', 'Method label'),
'account_id' => Yii::t('app', 'Account'),
'server_id' => Yii::t('app', 'Server'),
'state_label' => Yii::t('app', 'State'),

]);
}
}
5 changes: 3 additions & 2 deletions src/views/backup/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

$this->title = Yii::t('app', 'Backups');
$this->params['breadcrumbs'][] = $this->title;
$this->params['subtitle'] = array_filter(Yii::$app->request->get($model->formName(), [])) ? 'filtered list' : 'full list';
$this->params['subtitle'] = array_filter(Yii::$app->request->get($model->formName(), [])) ? Yii::t('app', 'filtered list') : Yii::t('app', 'full list');

?>
<?php Pjax::begin(array_merge(Yii::$app->params['pjax'], ['enablePushState' => true])) ?>
Expand Down Expand Up @@ -50,7 +50,8 @@
'server',
'object',
'time',
'size_gb'
'size_gb',
'actions',
],
]) ?>
<?php $box->endBulkForm() ?>
Expand Down
26 changes: 26 additions & 0 deletions src/views/backuping/_search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\modules\hosting\widgets\combo\AccountCombo;
use hipanel\modules\server\widgets\combo\ServerCombo;
use hiqdev\combo\StaticCombo;

?>

<div class="col-md-6">
<?= $search->field('state')->widget(StaticCombo::classname(), [
'data' => $stateOptions,
'hasId' => true,
'pluginOptions' => [
'select2Options' => [
'multiple' => false,
],
],
]) ?>
<?= $search->field('account')->widget(AccountCombo::className()) ?>
</div>

<div class="col-md-6">
<?= $search->field('server')->widget(ServerCombo::className(), ['formElementSelector' => '.form-group']) ?>
<?= $search->field('client_id')->widget(ClientCombo::classname(), ['formElementSelector' => '.form-group']) ?>
</div>
64 changes: 51 additions & 13 deletions src/views/backuping/index.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,63 @@
<?php
/**
* @link http://hiqdev.com/hipanel-module-hosting
* @license http://hiqdev.com/hipanel-module-hosting/license
* @copyright Copyright (c) 2015 HiQDev
*/

use hipanel\modules\hosting\grid\BackupingGridView;
use hipanel\widgets\ActionBox;
use hipanel\widgets\Pjax;

$this->title = Yii::t('app', 'Backupings');
$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', 'Backup settings');
$this->params['breadcrumbs'][] = $this->title;
$this->params['subtitle'] = array_filter(Yii::$app->request->get($model->formName(), [])) ? Yii::t('app', 'filtered list') : Yii::t('app', 'full list');

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

<?= backupingGridView::widget([
<?= $box->renderSearchButton() ?>
<?= $box->renderSorter([
'attributes' => [
'client',
'account',
'server',
'object',
'name',

// 'backupcount',
// 'type',
// 'backuplast',
// 'disk',
],
]) ?>
<?= $box->renderPerPage() ?>
<?php $box->endActions() ?>
<?php $box->renderBulkActions([
'items' => [
$box->renderBulkButton(Yii::t('app', 'Enable'), 'enable'),
$box->renderBulkButton(Yii::t('app', 'Disable'), 'disable'),
$box->renderDeleteButton(Yii::t('app', 'Delete')),
],
]) ?>
<?= $box->renderSearchForm(compact('stateOptions')) ?>
<?php $box->end() ?>
<?php $box->beginBulkForm() ?>

<?= BackupingGridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $model,
'columns' => [
'filterModel' => $model,
'typeOptions' => $typeOptions,
'columns' => [
'checkbox',
'seller',
'name',
'client',
'backuping'
'account',
'server',
'object',
'backup_count',
'type',
'state_label',
'backup_last',
'total_du_gb',
],
]) ?>
<?php $box->endBulkForm() ?>
<?php Pjax::end() ?>
27 changes: 27 additions & 0 deletions src/widgets/backup/ObjectLabelWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace hipanel\modules\hosting\widgets\backup;

use hipanel\widgets\Label;
use Yii;

class ObjectLabelWidget extends Label
{
public $model = [];

public function init ()
{
$object = $this->model->object;
if ($object === 'db') {
$class = 'info';
$label = Yii::t('app', 'Database');
} else {
$class = 'default';
$label = Yii::t('app', 'Domain');
}

$this->color = $class;
$this->label = $label;
parent::init();
}
}

0 comments on commit bc0f60c

Please sign in to comment.