Skip to content

Commit

Permalink
Continue hdomains implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Jun 4, 2015
1 parent 95e5af1 commit a351075
Show file tree
Hide file tree
Showing 11 changed files with 243 additions and 16 deletions.
5 changes: 5 additions & 0 deletions SidebarMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ class SidebarMenu extends \hipanel\base\Menu implements \yii\base\BootstrapInter
'url' => ['/hosting/db/index'],
'icon' => 'fa-database',
],
'hdomains' => [
'label' => 'Domains',
'url' => ['/hosting/hdomain/index'],
'icon' => 'fa-globe',
]
],
],
];
Expand Down
54 changes: 54 additions & 0 deletions controllers/HdomainController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,61 @@

namespace hipanel\modules\hosting\controllers;

use hipanel\helpers\ArrayHelper;
use Yii;

class HdomainController extends \hipanel\base\CrudController
{
public function actions()
{
return [
'create' => [
'class' => 'hipanel\actions\SwitchAction',
'success' => Yii::t('app', 'Account create task has been created successfully'),
'error' => Yii::t('app', 'Error while creating account'),
'GET html | GET pjax' => [
'class' => 'hipanel\actions\RenderAction',
'view' => 'create',
'params' => [
'model' => function ($action) {
return $action->controller->newModel(['scenario' => 'create']);
},
],
],
'POST html | POST pjax' => [
'save' => true,
'success' => [
'class' => 'hipanel\actions\RedirectAction',
'url' => function ($action, $model) {
return ['view', 'id' => $model->id];
}
],
'error' => [
'class' => 'hipanel\actions\RenderAction',
'view' => 'create',
'params' => [
'model' => function ($action, $model) {
return $model;
},
'type' => 'user'
],
],
],
],
];
}

/**
* @return string
*/
public function actionIndex()
{
$searchModel = static::searchModel();
$params = Yii::$app->request->queryParams;
$params[$searchModel->formName()] = ArrayHelper::merge($params[$searchModel->formName()],
['with_aliases' => true, 'with_vhosts' => true, 'with_request' => true]);
$dataProvider = $searchModel->search($params);

return $this->render('index', compact('searchModel', 'dataProvider'));
}
}
44 changes: 42 additions & 2 deletions grid/HdomainGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,56 @@

namespace hipanel\modules\hosting\grid;

use hipanel\grid\AccountColumn;
use hipanel\grid\ActionColumn;
use hipanel\grid\MainColumn;
use hipanel\grid\RefColumn;
use hipanel\modules\hosting\widgets\hdomain\State;
use hipanel\modules\server\grid\ServerColumn;
use yii\helpers\Html;

class HdomainGridView extends \hipanel\grid\BoxedGridView
{
static public function defaultColumns()
{
return [
'hdomain' => [
'class' => MainColumn::className(),
'filterAttribute' => 'hdomain_like',
'class' => MainColumn::className(),
'filterAttribute' => 'domain_like',
'attribute' => 'domain'
],
'account' => [
'class' => AccountColumn::className()
],
'server' => [
'class' => ServerColumn::className()
],
'ip' => [
'filter' => false,
'value' => function ($model) {
$html = $model['vhost']['ip'];
if ($model->isProxied) {
$html .= Html::tag('i', ['class' => 'fa fa-long-arrow-right']) . $model['vhost']['backend']['ip'];
}
return $html;
}
],
'service' => [
'value' => function ($model) {
return $model->vhost['service'];
}
],
'state' => [
'class' => RefColumn::className(),
'format' => 'raw',
'value' => function ($model) {
return State::widget(compact('model'));
},
'gtype' => 'state,db',
],
'actions' => [
'class' => ActionColumn::className(),
'template' => '{view} {update} {delete}'
],
];
}
Expand Down
11 changes: 7 additions & 4 deletions models/Hdomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@

class Hdomain extends \hipanel\base\Model
{

use \hipanel\base\ModelTrait;

/** @inheritdoc */
public function rules () {
return [
[
['id', 'server_id', 'client_id', 'seller_id', 'account_id', 'hdomain_id', 'state_id', 'type_id'],
['id', 'server_id', 'client_id', 'seller_id', 'account_id', 'hdomain_id', 'state_id', 'type_id', 'vhost_id', 'device_id'],
'integer'
],
[['server', 'client', 'seller', 'account', 'hdomain', 'state', 'type', 'ip', 'alias'], 'safe'],
[['server', 'vhost', 'device', 'client', 'seller', 'account', 'domain', 'state', 'type', 'ip', 'alias'], 'safe'],
];
}

function getIsProxied() {
return isset($this->vhost['backend']);
}

/** @inheritdoc */
public function attributeLabels () {
return $this->mergeAttributeLabels([
'hdomain' => Yii::t('app', 'Domain Name'),
'domain' => Yii::t('app', 'Domain Name'),
]);
}
}
20 changes: 19 additions & 1 deletion models/HdomainSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@

namespace hipanel\modules\hosting\models;

use hipanel\base\SearchModelTrait;
use yii\helpers\ArrayHelper;

class HdomainSearch extends Hdomain{
use \hipanel\base\SearchModelTrait;
use SearchModelTrait {
searchAttributes as defaultSearchAttributes;
}

/**
* @inheritdoc
*/
public function searchAttributes()
{
return ArrayHelper::merge($this->defaultSearchAttributes(), [
'with_aliases',
'with_request',
'with_vhosts',
'with_dns'
]);
}
}
4 changes: 3 additions & 1 deletion views/account/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
$box = ActionBox::begin(['options' => ['class' => 'box-info']]);
$box->beginActions();
echo Html::a(Yii::t('app', 'Create {modelClass}', ['modelClass' => 'account']), ['create'], ['class' => 'btn btn-success']) . ' ';
echo Html::a(Yii::t('app', 'Create FTP {modelClass}', ['modelClass' => 'account']), ['create-ftp'], ['class' => 'btn btn-success']) . ' ';
echo Html::a(Yii::t('app', 'Create FTP {modelClass}', ['modelClass' => 'account']), ['create-ftponly'], ['class' => 'btn btn-success']) . ' ';
$box->endActions();
$box::end();

Expand All @@ -36,3 +36,5 @@
'actions'
],
]);

Pjax::end();
52 changes: 52 additions & 0 deletions views/hdomain/_form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/* @var $this View */
/* @var $model hipanel\modules\hosting\models\Db */
/* @var $type string */

use hipanel\base\View;
use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\modules\hosting\widgets\combo\AccountCombo;
use hipanel\modules\hosting\widgets\combo\DbServiceCombo;
use hipanel\modules\server\widgets\combo\ServerCombo;
use hipanel\widgets\PasswordInput;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;

?>
<div class="row">
<div class="col-md-4">
<div class="box box-danger">
<div class="box-body">
<div class="ticket-form" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html">
<?php $form = ActiveForm::begin([
'action' => $model->isNewRecord ? Url::to('create') : Url::toRoute([
'update',
'id' => $model->id
]),
]);
?>
<!-- Properties -->

<?php
print $form->field($model, 'client')->widget(ClientCombo::className());
print $form->field($model, 'server')->widget(ServerCombo::className());
print $form->field($model, 'account')->widget(AccountCombo::className());

print $form->field($model, 'domain');

?>

<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Create'), ['class' => 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>
</div>
</div>
</div>

<!-- ticket-_form -->
</div>
</div>
13 changes: 13 additions & 0 deletions views/hdomain/create.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/* @var $this yii\web\View */
/* @var $model hipanel\modules\ticket\models\Thread */
/* @var $type string */

$this->title = Yii::t('app', 'Create database');
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Domains'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="db-create">
<?= $this->render('_form', compact('model')) ?>
</div>
29 changes: 23 additions & 6 deletions views/hdomain/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,36 @@
*/

use hipanel\modules\hosting\grid\HdomainGridView;
use hipanel\widgets\ActionBox;
use hipanel\widgets\Pjax;
use yii\helpers\Html;

$this->title = Yii::t('app', 'Hdomains');
$this->title = Yii::t('app', 'Domains');
$this->params['breadcrumbs'][] = $this->title;
$this->params['subtitle'] = Yii::$app->request->queryParams ? 'filtered list' : 'full list';

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

<?= hdomainGridView::widget([
$box = ActionBox::begin(['options' => ['class' => 'box-info']]);
$box->beginActions();
echo Html::a(Yii::t('app', 'Create {modelClass}', ['modelClass' => 'domain']), ['create'], ['class' => 'btn btn-success']) . '&nbsp;';
$box->endActions();
$box::end();

echo HdomainGridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
'checkbox',
'seller_id','client_id',
'hdomain'
'seller_id',
'client_id',
'account',
'server',
'hdomain',
'ip',
'service',
'actions'
],
]) ?>
]);

Pjax::end();
5 changes: 3 additions & 2 deletions views/hdomain/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
<?= HdomainGridView::detailView([
'model' => $model,
'columns' => [
'seller_id','client_id',
['attribute' => 'hdomain'],
'seller_id',
'client_id',
['attribute' => 'domain']
],
]) ?>
</div>
Expand Down
22 changes: 22 additions & 0 deletions widgets/hdomain/State.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace hipanel\modules\hosting\widgets\hdomain;

use hipanel\base\Re;
use hipanel\widgets\Label;

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

public function run () {
$state = $this->model->state;
if ($state=='ok') $class = 'info';
elseif ($state=='blocked') $class = 'danger';
else $class = 'warning';

$this->zclass = $class;
$this->label = Re::l($this->model->state_label);
parent::run();
}
}

0 comments on commit a351075

Please sign in to comment.