Skip to content

Commit

Permalink
Domains deep coding
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Jun 10, 2015
1 parent a351075 commit 41a1875
Show file tree
Hide file tree
Showing 8 changed files with 330 additions and 21 deletions.
8 changes: 4 additions & 4 deletions models/Account.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Account extends \hipanel\base\Model

public function init()
{
$this->on(static::EVENT_BEFORE_INSERT, [$this, 'onBeforeInsert']);
$this->on(static::EVENT_BEFORE_VALIDATE, [$this, 'onBeforeValidate']);
}

public function rules()
Expand All @@ -35,7 +35,7 @@ public function rules()
[
[
'login',
'server_id',
'server',
'password',
'sshftp_ips',
'type',
Expand All @@ -46,7 +46,7 @@ public function rules()
[
[
'login',
'server_id',
'server',
'password',
'sshftp_ips',
'type',
Expand Down Expand Up @@ -147,7 +147,7 @@ public function scenarioCommands()
];
}

public function onBeforeInsert()
public function onBeforeValidate()
{
if ($this->scenario == 'create-user') {
$this->type = 'user';
Expand Down
27 changes: 25 additions & 2 deletions models/Hdomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,32 @@ class Hdomain extends \hipanel\base\Model
public function rules () {
return [
[
['id', 'server_id', 'client_id', 'seller_id', 'account_id', 'hdomain_id', 'state_id', 'type_id', 'vhost_id', 'device_id'],
[
'id', 'server_id', 'client_id', 'seller_id',
'account_id', 'hdomain_id', 'state_id', 'type_id',
'vhost_id', 'device_id'
],
'integer'
],
[['server', 'vhost', 'device', 'client', 'seller', 'account', 'domain', 'state', 'type', 'ip', 'alias'], 'safe'],
[
[
'server', 'vhost', 'device', 'client', 'seller',
'account', 'domain', 'state', 'type', 'ip', 'alias',
'backend_ip', 'backuping_type'
],
'safe'
],
[
[
'server', 'account', 'domain',
'with_www', 'path', 'ip',
],
'required', 'on' => 'create'
],
[
['proxy_enable'], 'safe', 'on' => 'create'
]

];
}

Expand All @@ -32,6 +54,7 @@ function getIsProxied() {
public function attributeLabels () {
return $this->mergeAttributeLabels([
'domain' => Yii::t('app', 'Domain Name'),
'backend_ip' => Yii::t('app', 'Backend IP'),
]);
}
}
23 changes: 22 additions & 1 deletion models/IpSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,27 @@

namespace hipanel\modules\hosting\models;

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

class IpSearch extends Ip{
use \hipanel\base\SearchModelTrait;
use SearchModelTrait {
searchAttributes as defaultSearchAttributes;
}

/**
* @inheritdoc
*/
public function searchAttributes()
{
return ArrayHelper::merge($this->defaultSearchAttributes(), [
'with_expanded_ips',
'show_only_device_link',
'with_links',
'not_tags',
'soft_type',
'server',
'device',
]);
}
}
131 changes: 126 additions & 5 deletions views/hdomain/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,160 @@
/* @var $type string */

use hipanel\base\View;
use hipanel\models\Ref;
use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\modules\hosting\widgets\combo\AccountCombo;
use hipanel\modules\hosting\widgets\combo\DbServiceCombo;
use hipanel\modules\hosting\widgets\ip\BackIpCombo;
use hipanel\modules\hosting\widgets\ip\FrontIpCombo;
use hipanel\modules\hosting\widgets\ip\HdomainIpCombo;
use hipanel\modules\server\widgets\combo\ServerCombo;
use hipanel\widgets\PasswordInput;
use hiqdev\combo\StaticCombo;
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use yii\helpers\Url;

$this->registerJs(<<<'JS'
$('.hdomain-create').on('change', '#hdomain-proxy_enable', function () {
var $checkbox = $(this);
var $scope = $(this).closest('form');
var $proxied = $scope.find('.field-hdomain-frontend_ip, .field-hdomain-backend_ip');
var $not_proxied = $scope.find('.field-hdomain-not-proxied_ip');
if ($checkbox.prop('checked')) {
$proxied.removeClass('hidden');
if ($scope.find('#hdomain-account').select2('data')) {
$proxied.find('input').select2('enable', true);
} else {
$proxied.find('input').select2('enable', false);
}
$not_proxied.addClass('hidden').find('input').prop({'required': false}).select2('enable', false);
} else {
$proxied.addClass('hidden').find('input').select2('enable', false);
$not_proxied.removeClass('hidden');
if ($scope.find('#hdomain-account').select2('data')) {
$not_proxied.find('input').select2('enable', true);
} else {
$not_proxied.find('input').select2('enable', false);
}
}
});
JS
);

$this->registerJs(<<<'JS'
/*
TODO: after ABAC - for admin
$('.hdomain-create').find('.field-hdomain-path').on('updatePath', function (e, update) {
var $path = $(this);
var s_path = $path.val().split('/');
if (s_path.length < 2 || s_path[1] != 'home') {
s_path = ['', 'home', ''];
}
// 0 - /
// 1 - home
// 2 - user
// 3 - domain
if (update.account) {
if (s_path.length > 1) {
s_path[2] = update.account;
if (!s_path[3]) s_path[3] = '';
}
} else if (update.domain) {
s_path[s_path.length - 1] = update.domain.replace(/\\//g, ''); /// удаляем слеши, чтобы не собрать паровоз из пути
} else if (update.clear) {
s_path = [];
}
$path.val(s_path.join('/'));
});
*/
$('.hdomain-create').find('.field-hdomain-path').on('updatePath', function (e, update) {
var $group = $(this);
var $input = $group.find('input');
var $span = $group.find('span');
if (update.account) $span.text('/home/' + update.account + '/');
if (update.domain !== undefined) $input.val(update.domain);
if (update.clear) $span.val('');
});
$('.hdomain-create').on('keyup keypress blur change', '.field-hdomain-domain input', function () {
var $scope = $(this).closest('form');
$scope.find('.field-hdomain-path').trigger('updatePath', {domain: $(this).val()});
});
JS
);
?>
<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([
'action' => $model->isNewRecord ? Url::to('create') : Url::toRoute([
'update',
'id' => $model->id
]),
'options' => ['class' => 'hdomain-create']
]);
?>
<!-- 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, 'account')->widget(AccountCombo::className(), [
'pluginOptions' => [
'onChange' => new \yii\web\JsExpression(<<<'JS'
function (event) {
var $form = event.element.closest('form');
var data;
if (event.added) {
data = {account: event.added.text};
} else {
data = {clear: true};
}
$form.find('.field-hdomain-path').trigger('updatePath', data);
return true;
}
JS
)
]
]);
print $form->field($model, 'domain');

print $form->field($model, 'path', [
'template' => '
{label}
<div class="input-group">
<span class="input-group-addon">/home/</span>
{input}
{hint}
{error}
</div>
'
]);
print $form->field($model, 'with_www')->checkbox();
print $form->field($model, 'proxy_enable')->checkbox();
print $form->field($model, 'ip', ['options' => ['class' => 'field-hdomain-not-proxied_ip']])
->widget(HdomainIpCombo::className());
print $form->field($model, 'ip', ['options' => ['class' => 'field-hdomain-frontend_ip hidden']])
->widget(FrontIpCombo::className(), ['inputOptions' => ['id' => 'hdomain-frontend_ip']])
->label('Frontend IP');
print $form->field($model, 'backend_ip', ['options' => ['class' => 'field-hdomain-frontend_ip hidden']])
->widget(BackIpCombo::className());
print $form->field($model, 'backuping_type')->widget(StaticCombo::className(), [
'hasId' => true,
'data' => Ref::getList('type,backuping')
]);
?>

<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Create'), ['class' => 'btn btn-primary']) ?>
</div>
Expand Down
19 changes: 10 additions & 9 deletions widgets/combo/AccountCombo.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ class AccountCombo extends Combo
'server' => 'server/server',
];

/** @inheritdoc */
public $_pluginOptions = [
'clearWhen' => ['client/client', 'server/server'],
'affects' => [
'client/seller' => 'seller',
'client/client' => 'client',
'server/server' => 'device',
]
];
public function getPluginOptions($config) {
return parent::getPluginOptions([
'clearWhen' => ['client/client', 'server/server'],
'affects' => [
'client/seller' => 'seller',
'client/client' => 'client',
'server/server' => 'device',
]
]);
}
}
27 changes: 27 additions & 0 deletions widgets/ip/BackIpCombo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace hipanel\modules\hosting\widgets\ip;

use hiqdev\combo\Combo;
use yii\helpers\ArrayHelper;


/**
* Class BackIpCombo
*/
class BackIpCombo extends HdomainIpCombo
{
/** @inheritdoc */
public $type = 'hosting/hdomain-backend-ip';

/** @inheritdoc */
public $name = 'hdomain-backend-ip';

/** @inheritdoc */
public function getFilter()
{
return ArrayHelper::merge(parent::getFilter(), [
'soft_in' => ['format' => ['apache','apache2']],
]);
}
}
27 changes: 27 additions & 0 deletions widgets/ip/FrontIpCombo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace hipanel\modules\hosting\widgets\ip;

use hiqdev\combo\Combo;
use yii\helpers\ArrayHelper;


/**
* Class FrontIpCombo
*/
class FrontIpCombo extends HdomainIpCombo
{
/** @inheritdoc */
public $type = 'hosting/hdomain-frontend-ip';

/** @inheritdoc */
public $name = 'hdomain-frontend-ip';

/** @inheritdoc */
public function getFilter()
{
return ArrayHelper::merge(parent::getFilter(), [
'soft_in' => ['format' => ['nginx']],
]);
}
}
Loading

0 comments on commit 41a1875

Please sign in to comment.