Skip to content

Commit

Permalink
Started Mail module implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Nov 11, 2015
1 parent 1303e48 commit 54e32b0
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 27 deletions.
8 changes: 7 additions & 1 deletion src/SidebarMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -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); },
]
],
],
],
];
Expand Down
24 changes: 24 additions & 0 deletions src/controllers/MailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
56 changes: 54 additions & 2 deletions src/grid/MailGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,68 @@

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
{
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' => '<br>',
'data' => $model->forwards,
'button' => [
'label' => '+{count}',
'popoverOptions' => ['html' => true]
],
]);
}
],
'actions' => [
'class' => ActionColumn::className(),
'template' => '{view} {delete}'
],
];
}
Expand Down
25 changes: 15 additions & 10 deletions src/models/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
]);
}
}
3 changes: 2 additions & 1 deletion src/models/MailSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace hipanel\modules\hosting\models;

class MailSearch extends Mail{
class MailSearch extends Mail
{
use \hipanel\base\SearchModelTrait;
}
44 changes: 44 additions & 0 deletions src/views/mail/_search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\modules\client\widgets\combo\SellerCombo;
use hipanel\modules\server\widgets\combo\ServerCombo;
use hiqdev\combo\StaticCombo;
use yii\web\View;

/**
* @var $this View
*/

?>

<div class="col-md-6">
<?= $search->field('mail_like') ?>
<?= $search->field('server')->widget(ServerCombo::className(), ['formElementSelector' => '.form-group']) ?>
<?= $search->field('state')->widget(StaticCombo::classname(), [
'data' => $stateData,
'hasId' => true,
'pluginOptions' => [
'select2Options' => [
'multiple' => false,
]
],
]) ?>

</div>

<div class="col-md-6">
<?= $search->field('client_id')->widget(ClientCombo::classname(), ['formElementSelector' => '.form-group']) ?>
<?= $search->field('seller_id')->widget(SellerCombo::classname(), ['formElementSelector' => '.form-group']) ?>
<?= $search->field('type')->widget(StaticCombo::classname(), [
'data' => $typeData,
'hasId' => true,
'pluginOptions' => [
'select2Options' => [
'multiple' => false,
]
],
]) ?>
</div>


53 changes: 44 additions & 9 deletions src/views/mail/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'; ?>

?>
<?php Pjax::begin(array_merge(Yii::$app->params['pjax'], ['enablePushState' => true])); ?>

<?= mailGridView::widget([
<?php $box = ActionBox::begin(['model' => $model, 'dataProvider' => $dataProvider]) ?>
<?php $box->beginActions() ?>
<?= $box->renderCreateButton(Yii::t('app', 'Create mailbox')) . '&nbsp;' ?>
<?= $box->renderSearchButton() ?>
<?= $box->renderSorter([
'attributes' => [
'client',
'seller',
'account',
'state',
'server',
'mail',
],
]) ?>
<?= $box->renderPerPage() ?>
<?php $box->endActions() ?>
<?php $box->beginBulkActions() ?>

<?= $box->renderDeleteButton() ?>
<?php $box->endBulkActions() ?>
<?= $box->renderSearchForm(['stateData' => $stateData, 'typeData' => $typeData]) ?>
<?php $box->end() ?>

<?php $box->beginBulkForm() ?>
<?= MailGridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $model,
'columns' => [
'filterModel' => $model,
'columns' => [
'checkbox',
'seller',
'mail',
'type',
'forwards',
'client',
'mail'
'seller',
'server',
'state',
'actions',
],
]) ?>
<?php $box->endBulkForm() ?>
<?php Pjax::end();
13 changes: 9 additions & 4 deletions src/widgets/account/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ class State extends Label
{
public $model = [];

public function init () {
public function init()
{
$state = $this->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);
Expand Down
27 changes: 27 additions & 0 deletions src/widgets/mail/State.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace hipanel\modules\hosting\widgets\mail;

use hipanel\widgets\Label;
use Yii;

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

public function init()
{
$state = $this->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();
}
}
51 changes: 51 additions & 0 deletions src/widgets/mail/Type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace hipanel\modules\hosting\widgets\mail;

use hipanel\widgets\Label;
use Yii;
use yii\base\Model;

class Type extends Label
{
/**
* @var Model
*/
public $model;

public $default = null;

/**
* {@inheritdoc}
*/
public function init()
{
if ($this->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();
}
}

0 comments on commit 54e32b0

Please sign in to comment.