Skip to content

Commit

Permalink
Service - added gridview
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Nov 20, 2015
1 parent 9adcd1f commit e0b5cfe
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 8 deletions.
8 changes: 8 additions & 0 deletions src/controllers/ServiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@

namespace hipanel\modules\hosting\controllers;

use yii\base\Event;

class ServiceController extends \hipanel\base\CrudController
{
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');
}
],
];
}
Expand Down
46 changes: 46 additions & 0 deletions src/grid/ServiceGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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}',
],
];
}
}
6 changes: 5 additions & 1 deletion src/models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
];
}
Expand All @@ -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']);
}
}
14 changes: 9 additions & 5 deletions src/views/service/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -17,9 +17,13 @@
'dataProvider' => $dataProvider,
'filterModel' => $model,
'columns' => [
'checkbox',
'seller',
'client',
'service'
'seller_id',
'client_id',
'service',
'ip',
'bin',
'etc',
'soft',
'state',
],
]) ?>
10 changes: 8 additions & 2 deletions src/views/service/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@
<?= ServiceGridView::detailView([
'model' => $model,
'columns' => [
'seller_id','client_id',
['attribute' => 'service'],
'seller_id',
'client_id',
'service',
'ip',
'bin',
'etc',
'soft',
'state',
],
]) ?>
</div>
Expand Down

0 comments on commit e0b5cfe

Please sign in to comment.