Skip to content

Commit

Permalink
Server view - added IP addresses table
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Mar 7, 2016
1 parent 12eb52e commit eb8296c
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/controllers/ServerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ public function actions()
$action = $event->sender;
$dataProvider = $action->getDataProvider();
$dataProvider->query->joinWith('uses');
$dataProvider->query->joinWith('ips');

// TODO: ipModule is not wise yet. Redo
$dataProvider->query
->andWhere(['with_requests' => 1])
->andWhere(['show_deleted' => 1])
->andWhere(['with_discounts' => 1])
->andWhere(['with_uses' => 1])
->andWhere(['with_ips' => 1])
->select(['*']);
},
'data' => function ($action) {
Expand Down
7 changes: 6 additions & 1 deletion src/models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace hipanel\modules\server\models;

use hipanel\modules\hosting\models\Ip;
use hipanel\modules\server\helpers\ServerHelper;
use hipanel\validators\EidValidator;
use hipanel\validators\RefValidator;
Expand Down Expand Up @@ -56,7 +57,6 @@ public function rules()
'type',
'block_reason_label',
'ip',
'ips',
'os',
'rcp',
'vnc',
Expand Down Expand Up @@ -195,6 +195,11 @@ public function getUses()
return $this->hasMany(ServerUse::class, ['object_id' => 'id']);
}

public function getIps()
{
return $this->hasMany(Ip::class, ['some_id' => 'id'])->join('links');
}

/**
* @inheritdoc
*/
Expand Down
76 changes: 75 additions & 1 deletion src/views/server/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
'columns' => [
'client_id', 'seller_id', 'note', 'label',
['attribute' => 'name'],
'state', 'ips', 'os', 'panel'
'state', 'os', 'panel'
],
]);
$box->endBody();
Expand Down Expand Up @@ -204,6 +204,80 @@
<?php Pjax::end() ?>
</div>
<?php } ?>
<?php if (Yii::getAlias('@ip', false)) { ?>
<div class="row">
<div class="col-md-12">
<?php
$ipsDataProvider = new \yii\data\ArrayDataProvider([
'allModels' => $model->ips,
'pagination' => false,
'sort' => false,
]);

$box = Box::begin(['renderBody' => false]);
$box->beginHeader();
echo $box->renderTitle(Yii::t('hipanel/server', 'IP addresses'));
$box->endHeader();
$box->beginBody();
echo \hipanel\grid\GridView::widget([
'dataProvider' => $ipsDataProvider,
'columns' => [
[
'attribute' => 'ip',
'format' => 'html',
'label' => Yii::t('hipanel', 'IP address'),
'options' => [
'style' => 'width: 20%',
],
'value' => function ($model) {
if (Yii::$app->user->can('support') && Yii::getAlias('@ip', false)) {
return Html::a($model->ip, ['@ip/view', 'id' => $model->id]);
}

return $model->ip;
}
],
[
'attribute' => 'ptr',
'format' => 'html',
'label' => Yii::t('hipanel', 'PTR'),
'options' => [
'style' => 'width: 40%',
],
'value' => function ($model) {
return \hipanel\widgets\XEditable::widget([
'model' => $model,
'attribute' => 'ptr',
'scenario' => 'set-ptr',
'value' => 'my.domain.ptr.com'
]);
}
],
[
'attribute' => 'links',
'format' => 'html',
'label' => Yii::t('hipanel', 'Services'),
'value' => function ($model) {
return \hipanel\widgets\ArraySpoiler::widget([
'data' => $model->links,
'formatter' => function ($link) {
if (Yii::$app->user->can('support') && Yii::getAlias('@service', false)) {
return Html::a($link->service, ['@service/view', 'id' => $link->service_id]);
}

return $link->service;
}
]);
}
]
]
]);
$box->endBody();
$box->end();
?>
</div>
</div>
<?php } ?>
</div>
<div class="col-md-5">
<?php if (isset($chartsData['server_traf'])) { ?>
Expand Down

0 comments on commit eb8296c

Please sign in to comment.