1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Hosting Plugin for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-hosting |
6
|
|
|
* @package hipanel-module-hosting |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\hosting\grid; |
12
|
|
|
|
13
|
|
|
use hipanel\grid\ActionColumn; |
14
|
|
|
use hipanel\grid\BoxedGridView; |
15
|
|
|
use hipanel\grid\MainColumn; |
16
|
|
|
use hipanel\grid\RefColumn; |
17
|
|
|
use hipanel\grid\XEditableColumn; |
18
|
|
|
use hipanel\modules\hosting\models\Db; |
19
|
|
|
use hipanel\modules\hosting\widgets\backup\BackupGridRow; |
20
|
|
|
use hipanel\modules\hosting\widgets\db\State; |
21
|
|
|
use hipanel\modules\server\grid\ServerColumn; |
22
|
|
|
use Yii; |
23
|
|
|
use yii\helpers\Html; |
24
|
|
|
|
25
|
|
|
class DbGridView extends BoxedGridView |
26
|
|
|
{ |
27
|
|
|
public function columns() |
28
|
|
|
{ |
29
|
|
|
return array_merge(parent::columns(), [ |
30
|
|
|
'name' => [ |
31
|
|
|
'class' => MainColumn::class, |
32
|
|
|
'format' => 'html', |
33
|
|
|
'attribute' => 'name', |
34
|
|
|
'filterAttribute' => 'name_like', |
35
|
|
|
], |
36
|
|
|
'state' => [ |
37
|
|
|
'class' => RefColumn::class, |
38
|
|
|
'i18nDictionary' => 'hipanel:hosting', |
39
|
|
|
'format' => 'raw', |
40
|
|
|
'value' => function ($model) { |
41
|
|
|
return State::widget(compact('model')); |
42
|
|
|
}, |
43
|
|
|
'gtype' => 'state,db', |
44
|
|
|
], |
45
|
|
|
'account' => [ |
46
|
|
|
'class' => AccountColumn::class, |
47
|
|
|
], |
48
|
|
|
'server' => [ |
49
|
|
|
'class' => ServerColumn::class, |
50
|
|
|
], |
51
|
|
|
'service_ip' => [ |
52
|
|
|
'filter' => false, |
53
|
|
|
], |
54
|
|
|
'description' => [ |
55
|
|
|
'class' => XEditableColumn::class, |
56
|
|
|
'pluginOptions' => [ |
57
|
|
|
'url' => 'set-description', |
58
|
|
|
], |
59
|
|
|
'filter' => true, |
60
|
|
|
'popover' => Yii::t('hipanel', 'Make any notes for your convenience'), |
61
|
|
|
], |
62
|
|
|
'password' => [ |
63
|
|
|
'class' => XEditableColumn::class, |
64
|
|
|
'pluginOptions' => [ |
65
|
|
|
'url' => 'set-password', |
66
|
|
|
], |
67
|
|
|
'filter' => true, |
68
|
|
|
'popover' => Yii::t('hipanel', 'Change password'), |
69
|
|
|
'value' => function () { |
70
|
|
|
return Yii::t('hipanel', 'Change password'); |
71
|
|
|
}, |
72
|
|
|
], |
73
|
|
|
'backups_widget' => [ |
74
|
|
|
'label' => Yii::t('hipanel:hosting', 'Backups'), |
75
|
|
|
'format' => 'raw', |
76
|
|
|
'value' => function ($model) { |
77
|
|
|
return BackupGridRow::widget(['model' => $model]); |
78
|
|
|
}, |
79
|
|
|
], |
80
|
|
|
'info_server' => [ |
81
|
|
|
'label' => Yii::t('hipanel:hosting', 'Server'), |
82
|
|
|
'format' => 'raw', |
83
|
|
View Code Duplication |
'value' => function (Db $model): string { |
|
|
|
|
84
|
|
|
return Yii::t('hipanel:hosting', '{host_label} {host} {dbms_label} {dbms}', [ |
85
|
|
|
'host_label' => Html::tag('b', Yii::t('hipanel:hosting', 'Host:')), |
86
|
|
|
'host' => $model->service_ip, |
|
|
|
|
87
|
|
|
'dbms_label' => Html::tag('b', Yii::t('hipanel:hosting', 'DBMS:')), |
88
|
|
|
'dbms' => $model->service, |
|
|
|
|
89
|
|
|
]); |
90
|
|
|
}, |
91
|
|
|
], |
92
|
|
|
'access' => [ |
93
|
|
|
'label' => Yii::t('hipanel:hosting', 'Access credentials'), |
94
|
|
|
'format' => 'raw', |
95
|
|
|
'value' => function (DB $model): string { |
96
|
|
|
return Yii::t('hipanel:hosting', '{login_label} {login}', [ |
97
|
|
|
'login_label' => Html::tag('b', Yii::t('hipanel:hosting', 'Login:')), |
98
|
|
|
'login' => $model->name, |
|
|
|
|
99
|
|
|
]); |
100
|
|
|
}, |
101
|
|
|
], |
102
|
|
|
'actions' => [ |
103
|
|
|
'class' => ActionColumn::class, |
104
|
|
|
'template' => '{view} {delete}', |
105
|
|
|
], |
106
|
|
|
]); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.