From e0b5cfef23a49bcc1c9659a22822f1ab700b0312 Mon Sep 17 00:00:00 2001 From: SilverFire - Dmitry Naumenko Date: Fri, 20 Nov 2015 14:00:57 +0200 Subject: [PATCH] Service - added gridview --- src/controllers/ServiceController.php | 8 +++++ src/grid/ServiceGridView.php | 46 +++++++++++++++++++++++++++ src/models/Service.php | 6 +++- src/views/service/index.php | 14 +++++--- src/views/service/view.php | 10 ++++-- 5 files changed, 76 insertions(+), 8 deletions(-) diff --git a/src/controllers/ServiceController.php b/src/controllers/ServiceController.php index e534d3de..fba21bfb 100644 --- a/src/controllers/ServiceController.php +++ b/src/controllers/ServiceController.php @@ -7,6 +7,8 @@ namespace hipanel\modules\hosting\controllers; +use yii\base\Event; + class ServiceController extends \hipanel\base\CrudController { public function actions() @@ -14,6 +16,12 @@ public function actions() return [ 'index' => [ 'class' => 'hipanel\actions\IndexAction', + 'on beforePerform' => function (Event $event) { + /** @var \hipanel\actions\SearchAction $action */ + $action = $event->sender; + $dataProvider = $action->getDataProvider(); + $dataProvider->query->joinWith('ips'); + } ], ]; } diff --git a/src/grid/ServiceGridView.php b/src/grid/ServiceGridView.php index b049b477..2f9d42ca 100644 --- a/src/grid/ServiceGridView.php +++ b/src/grid/ServiceGridView.php @@ -7,7 +7,11 @@ namespace hipanel\modules\hosting\grid; +use hipanel\grid\ActionColumn; use hipanel\grid\MainColumn; +use hipanel\modules\server\grid\ServerColumn; +use hipanel\widgets\ArraySpoiler; +use kartik\helpers\Html; class ServiceGridView extends \hipanel\grid\BoxedGridView { @@ -16,8 +20,50 @@ static public function defaultColumns() return [ 'service' => [ 'class' => MainColumn::className(), + 'attribute' => 'name', 'filterAttribute' => 'service_like', ], + 'server_id' => [ + 'class' => ServerColumn::className(), + ], + 'object' => [ + 'format' => 'raw', + 'value' => function ($model) { + + }, + ], + 'ip' => [ + 'format' => 'raw', + 'value' => function ($model) { + return ArraySpoiler::widget(['data' => $model->ips]); + }, + ], + 'bin' => [ + 'format' => 'html', + 'value' => function ($model) { + return $model->bin ? Html::tag('code', $model->bin) : ''; + } + ], + 'etc' => [ + 'format' => 'html', + 'value' => function ($model) { + return $model->etc ? Html::tag('code', $model->etc) : ''; + } + ], + 'soft' => [ + 'value' => function ($model) { + return $model->soft; + } + ], + 'state' => [ + 'value' => function ($model) { + return $model->state_label; + } + ], + 'actions' => [ + 'class' => ActionColumn::className(), + 'template' => '{view} {delete}', + ], ]; } } diff --git a/src/models/Service.php b/src/models/Service.php index e557de6e..64d5c7c0 100644 --- a/src/models/Service.php +++ b/src/models/Service.php @@ -19,7 +19,7 @@ public function rules () { return [ [['id', 'server_id', 'device_id', 'client_id', 'seller_id', 'soft_id'], 'integer'], [['name', 'server', 'device', 'client', 'seller', 'soft'], 'safe'], - [['ip', 'bin', 'etc'], 'safe'], + [['ips', 'bin', 'etc'], 'safe'], [['soft_type', 'soft_type_label', 'state', 'state_label'], 'safe'], ]; } @@ -31,4 +31,8 @@ public function attributeLabels () { 'soft_type_label' => Yii::t('app', 'Soft type label'), ]); } + + public function getIps() { + return $this->hasMany(Ip::className(), ['service_id', 'id']); + } } diff --git a/src/views/service/index.php b/src/views/service/index.php index 918da43c..a2e627d2 100644 --- a/src/views/service/index.php +++ b/src/views/service/index.php @@ -7,7 +7,7 @@ use hipanel\modules\hosting\grid\ServiceGridView; -$this->title = Yii::t('app', 'Services'); +$this->title = Yii::t('hipanel/hosting', 'Services'); $this->params['breadcrumbs'][] = $this->title; $this->params['subtitle'] = array_filter(Yii::$app->request->get($model->formName(), [])) ? 'filtered list' : 'full list'; @@ -17,9 +17,13 @@ 'dataProvider' => $dataProvider, 'filterModel' => $model, 'columns' => [ - 'checkbox', - 'seller', - 'client', - 'service' + 'seller_id', + 'client_id', + 'service', + 'ip', + 'bin', + 'etc', + 'soft', + 'state', ], ]) ?> diff --git a/src/views/service/view.php b/src/views/service/view.php index 1041814b..32c821de 100644 --- a/src/views/service/view.php +++ b/src/views/service/view.php @@ -22,8 +22,14 @@ $model, 'columns' => [ - 'seller_id','client_id', - ['attribute' => 'service'], + 'seller_id', + 'client_id', + 'service', + 'ip', + 'bin', + 'etc', + 'soft', + 'state', ], ]) ?>