From 54e32b0041dbca60d9ce4fe9081ae8a63f1e1c6d Mon Sep 17 00:00:00 2001 From: SilverFire - Dima Naumenko Date: Wed, 11 Nov 2015 19:17:41 +0200 Subject: [PATCH] Started Mail module implementation --- src/SidebarMenu.php | 8 ++++- src/controllers/MailController.php | 24 +++++++++++++ src/grid/MailGridView.php | 56 ++++++++++++++++++++++++++++-- src/models/Mail.php | 25 +++++++------ src/models/MailSearch.php | 3 +- src/views/mail/_search.php | 44 +++++++++++++++++++++++ src/views/mail/index.php | 53 +++++++++++++++++++++++----- src/widgets/account/State.php | 13 ++++--- src/widgets/mail/State.php | 27 ++++++++++++++ src/widgets/mail/Type.php | 51 +++++++++++++++++++++++++++ 10 files changed, 277 insertions(+), 27 deletions(-) create mode 100644 src/views/mail/_search.php create mode 100644 src/widgets/mail/State.php create mode 100644 src/widgets/mail/Type.php diff --git a/src/SidebarMenu.php b/src/SidebarMenu.php index a52b18c3..c973ad6a 100644 --- a/src/SidebarMenu.php +++ b/src/SidebarMenu.php @@ -40,12 +40,18 @@ public function items() 'icon' => 'fa-globe', 'visible' => function () { return (bool)Yii::getAlias('@domain', false); }, ], + 'mails' => [ + 'label' => Yii::t('app', 'Mailboxes'), + 'url' => ['/hosting/mail/index'], + 'icon' => 'fa-mail', + 'visible' => function () { return (bool)Yii::getAlias('@mail', false); }, + ], 'Backups' => [ 'label' => Yii::t('app', 'Backups'), 'url' => ['/hosting/backup/index'], // 'icon' => 'fa-globe', 'visible' => function () { return (bool)Yii::getAlias('@domain', false); }, - ] + ], ], ], ]; diff --git a/src/controllers/MailController.php b/src/controllers/MailController.php index ba9cd475..686c292b 100644 --- a/src/controllers/MailController.php +++ b/src/controllers/MailController.php @@ -7,7 +7,31 @@ namespace hipanel\modules\hosting\controllers; +use hipanel\models\Ref; + class MailController extends \hipanel\base\CrudController { + public function actions() { + return [ + 'index' => [ + 'class' => 'hipanel\actions\IndexAction', + 'data' => function ($action) { + return [ + 'stateData' => $action->controller->getStateData(), + 'typeData' => $action->controller->getTypeData(), + ]; + } + ] + ]; + } + + public function getStateData() + { + return Ref::getList('state,mail'); + } + public function getTypeData() + { + return Ref::getList('type,mail'); + } } diff --git a/src/grid/MailGridView.php b/src/grid/MailGridView.php index 8d581ef5..d4f86a1b 100644 --- a/src/grid/MailGridView.php +++ b/src/grid/MailGridView.php @@ -7,7 +7,15 @@ namespace hipanel\modules\hosting\grid; +use hipanel\grid\ActionColumn; use hipanel\grid\MainColumn; +use hipanel\grid\RefColumn; +use hipanel\modules\hosting\widgets\mail\State; +use hipanel\modules\hosting\widgets\mail\Type; +use hipanel\modules\server\grid\ServerColumn; +use hipanel\widgets\ArraySpoiler; +use Yii; +use yii\helpers\StringHelper; class MailGridView extends \hipanel\grid\BoxedGridView { @@ -15,8 +23,52 @@ static public function defaultColumns() { return [ 'mail' => [ - 'class' => MainColumn::className(), - 'filterAttribute' => 'mail_like', + 'class' => MainColumn::className(), + 'filterAttribute' => 'mail_like', + ], + 'state' => [ + 'class' => RefColumn::className(), + 'format' => 'raw', + 'value' => function ($model) { + return State::widget(compact('model')); + }, + 'gtype' => 'state,mail', + ], + 'server' => [ + 'class' => ServerColumn::className() + ], +// 'sshftp_ips' => [ +// 'attribute' => 'sshftp_ips', +// 'format' => 'raw', +// 'value' => function ($model) { +// return ArraySpoiler::widget([ +// 'data' => $model->sshftp_ips, +// 'visibleCount' => 3 +// ]); +// } +// ], + 'type' => [ + 'format' => 'raw', + 'value' => function ($model) { + return Type::widget(compact('model')); + } + ], + 'forwards' => [ + 'format' => 'raw', + 'value' => function ($model) { + return ArraySpoiler::widget([ + 'delimiter' => '
', + 'data' => $model->forwards, + 'button' => [ + 'label' => '+{count}', + 'popoverOptions' => ['html' => true] + ], + ]); + } + ], + 'actions' => [ + 'class' => ActionColumn::className(), + 'template' => '{view} {delete}' ], ]; } diff --git a/src/models/Mail.php b/src/models/Mail.php index c246030e..7155c4c9 100644 --- a/src/models/Mail.php +++ b/src/models/Mail.php @@ -15,22 +15,27 @@ class Mail extends \hipanel\base\Model use \hipanel\base\ModelTrait; /** @inheritdoc */ - public function rules () { + public function rules() + { return [ - [['id', 'hdomain_id', 'client_id', 'account_id', 'server_id'], 'integer'], - [['mail', 'nick', 'hdomain', 'client', 'account', 'server', 'domain'], 'safe'], - [['type', 'state', 'state_label'], 'safe'], - [['forwards', 'spam_action', 'autoanswer', 'du_limit'], 'safe'], + [['id', 'hdomain_id', 'client_id', 'seller_id', 'account_id', 'server_id'], 'integer'], + [['mail', 'nick', 'hdomain', 'client', 'seller', 'account', 'server', 'domain'], 'safe'], + [['type', 'state', 'state_label'], 'safe'], + [['forwards', 'spam_action', 'autoanswer', 'du_limit'], 'safe'], + [['is_alias'], 'boolean'], ]; } /** @inheritdoc */ - public function attributeLabels () { + public function attributeLabels() + { return $this->mergeAttributeLabels([ - 'hdomain' => Yii::t('app', 'Domain Name'), - 'domain' => Yii::t('app', 'Domain Name'), - 'forwards' => Yii::t('app', 'Forwarding'), - 'du_limit' => Yii::t('app', 'Disk usage limit'), + 'hdomain' => Yii::t('app', 'Domain Name'), + 'domain' => Yii::t('app', 'Domain Name'), + 'forwards' => Yii::t('app', 'Forwarding'), + 'du_limit' => Yii::t('app', 'Disk usage limit'), + 'mail' => Yii::t('app', 'E-mail'), + 'mail_like' => Yii::t('app', 'E-mail'), ]); } } diff --git a/src/models/MailSearch.php b/src/models/MailSearch.php index 6913fdad..2a787449 100644 --- a/src/models/MailSearch.php +++ b/src/models/MailSearch.php @@ -7,6 +7,7 @@ namespace hipanel\modules\hosting\models; -class MailSearch extends Mail{ +class MailSearch extends Mail +{ use \hipanel\base\SearchModelTrait; } diff --git a/src/views/mail/_search.php b/src/views/mail/_search.php new file mode 100644 index 00000000..35972df9 --- /dev/null +++ b/src/views/mail/_search.php @@ -0,0 +1,44 @@ + + +
+ field('mail_like') ?> + field('server')->widget(ServerCombo::className(), ['formElementSelector' => '.form-group']) ?> + field('state')->widget(StaticCombo::classname(), [ + 'data' => $stateData, + 'hasId' => true, + 'pluginOptions' => [ + 'select2Options' => [ + 'multiple' => false, + ] + ], + ]) ?> + +
+ +
+ field('client_id')->widget(ClientCombo::classname(), ['formElementSelector' => '.form-group']) ?> + field('seller_id')->widget(SellerCombo::classname(), ['formElementSelector' => '.form-group']) ?> + field('type')->widget(StaticCombo::classname(), [ + 'data' => $typeData, + 'hasId' => true, + 'pluginOptions' => [ + 'select2Options' => [ + 'multiple' => false, + ] + ], + ]) ?> +
+ + diff --git a/src/views/mail/index.php b/src/views/mail/index.php index 98db9096..b602b606 100644 --- a/src/views/mail/index.php +++ b/src/views/mail/index.php @@ -6,20 +6,55 @@ */ use hipanel\modules\hosting\grid\MailGridView; +use hipanel\widgets\ActionBox; +use hipanel\widgets\Pjax; -$this->title = Yii::t('app', 'Mails'); -$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', 'Mailboxes'); +$this->breadcrumbs->setItems([ + $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() ?> + renderCreateButton(Yii::t('app', 'Create mailbox')) . ' ' ?> + renderSearchButton() ?> + renderSorter([ + 'attributes' => [ + 'client', + 'seller', + 'account', + 'state', + 'server', + 'mail', + ], + ]) ?> + renderPerPage() ?> +endActions() ?> +beginBulkActions() ?> + +renderDeleteButton() ?> +endBulkActions() ?> +renderSearchForm(['stateData' => $stateData, 'typeData' => $typeData]) ?> +end() ?> + +beginBulkForm() ?> + $dataProvider, - 'filterModel' => $model, - 'columns' => [ + 'filterModel' => $model, + 'columns' => [ 'checkbox', - 'seller', + 'mail', + 'type', + 'forwards', 'client', - 'mail' + 'seller', + 'server', + 'state', + 'actions', ], ]) ?> +endBulkForm() ?> +model->state; - if ($state=='ok') $class = 'info'; - elseif ($state=='blocked') $class = 'danger'; - else $class = 'warning'; + if ($state == 'ok') { + $class = 'info'; + } elseif ($state == 'blocked') { + $class = 'danger'; + } else { + $class = 'warning'; + } $this->color = $class; $this->label = Yii::t('app', $this->model->state_label); diff --git a/src/widgets/mail/State.php b/src/widgets/mail/State.php new file mode 100644 index 00000000..4c5c3d9b --- /dev/null +++ b/src/widgets/mail/State.php @@ -0,0 +1,27 @@ +model->state; + if ($state == 'ok') { + $class = 'info'; + } elseif ($state == 'blocked') { + $class = 'danger'; + } else { + $class = 'warning'; + } + + $this->color = $class; + $this->label = Yii::t('app', $this->model->state_label); + parent::init(); + } +} diff --git a/src/widgets/mail/Type.php b/src/widgets/mail/Type.php new file mode 100644 index 00000000..b9598d19 --- /dev/null +++ b/src/widgets/mail/Type.php @@ -0,0 +1,51 @@ +model->is_alias) { + $this->label = Yii::t('app', 'Forward only'); + $this->color = 'primary'; + $this->labelOptions = [ + 'title' => Yii::t('app', 'You can not login ...') // TODO + ]; + } elseif ($this->model->forwards) { + $this->label = Yii::t('app', 'Mailbox with forwards'); + $this->color = 'warning'; + } else { + $this->label = Yii::t('app', 'Mailbox'); + $this->color = 'default'; + } + + parent::init(); + } + + /** + * {@inheritdoc} + */ + protected function renderLabel() + { + if ($this->color === null) { + return; + } + + parent::renderLabel(); + } +}