1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Server module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-server |
6
|
|
|
* @package hipanel-module-server |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\server\grid; |
12
|
|
|
|
13
|
|
|
use hipanel\grid\MainColumn; |
14
|
|
|
use hipanel\grid\RefColumn; |
15
|
|
|
use hipanel\grid\XEditableColumn; |
16
|
|
|
use hipanel\helpers\Url; |
17
|
|
|
use hipanel\modules\hosting\controllers\AccountController; |
|
|
|
|
18
|
|
|
use hipanel\modules\hosting\controllers\IpController; |
|
|
|
|
19
|
|
|
use hipanel\modules\server\menus\ServerActionsMenu; |
20
|
|
|
use hipanel\modules\server\widgets\DiscountFormatter; |
21
|
|
|
use hipanel\modules\server\widgets\Expires; |
22
|
|
|
use hipanel\modules\server\widgets\OSFormatter; |
23
|
|
|
use hipanel\modules\server\widgets\State; |
24
|
|
|
use hipanel\widgets\ArraySpoiler; |
25
|
|
|
use hipanel\widgets\gridLegend\ColorizeGrid; |
26
|
|
|
use hipanel\widgets\gridLegend\GridLegend; |
27
|
|
|
use hipanel\widgets\Label; |
28
|
|
|
use hiqdev\yii2\menus\grid\MenuColumn; |
29
|
|
|
use Yii; |
30
|
|
|
use yii\helpers\ArrayHelper; |
31
|
|
|
use yii\helpers\Html; |
32
|
|
|
|
33
|
|
|
class ServerGridView extends \hipanel\grid\BoxedGridView |
34
|
|
|
{ |
35
|
|
|
use ColorizeGrid; |
|
|
|
|
36
|
|
|
|
37
|
|
|
public $controllerUrl = '@server'; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
public $osImages; |
43
|
|
|
|
44
|
|
|
protected function formatTariff($model) |
45
|
|
|
{ |
46
|
|
|
if (Yii::$app->user->can('manage')) { |
|
|
|
|
47
|
|
|
if ($model->parent_tariff) { |
48
|
|
|
$title = Html::tag('abbr', $model->parent_tariff, ['title' => $model->tariff, 'data-toggle' => 'tooltip']); |
49
|
|
|
} else { |
50
|
|
|
$title = $model->tariff; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return Html::a($title, ['@tariff/view', 'id' => $model->tariff_id]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return !empty($model->parent_tariff) ? $model->parent_tariff : $model->tariff; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function columns() |
60
|
|
|
{ |
61
|
|
|
$canAdmin = Yii::$app->user->can('admin'); |
|
|
|
|
62
|
|
|
$canSupport = Yii::$app->user->can('support'); |
63
|
|
|
|
64
|
|
|
return array_merge(parent::columns(), [ |
65
|
|
|
'server' => [ |
66
|
|
|
'class' => MainColumn::class, |
67
|
|
|
'attribute' => 'name', |
68
|
|
|
'filterAttribute' => 'name_like', |
69
|
|
|
'note' => $canSupport ? 'label' : 'note', |
70
|
|
|
'noteOptions' => [ |
71
|
|
|
'url' => $canSupport ? Url::to('set-label') : Url::to('set-note'), |
72
|
|
|
], |
73
|
|
|
'badges' => function ($model) use ($canSupport) { |
74
|
|
|
$badges = ''; |
75
|
|
|
if ($canSupport) { |
76
|
|
|
if ($model->wizzarded) { |
77
|
|
|
$badges .= Label::widget(['label' => 'W', 'tag' => 'sup', 'color' => 'success']); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $badges; |
82
|
|
|
}, |
83
|
|
|
], |
84
|
|
|
'dc' => [ |
85
|
|
|
'attribute' => 'dc', |
86
|
|
|
'filter' => false, |
87
|
|
|
], |
88
|
|
|
'state' => [ |
89
|
|
|
'class' => RefColumn::class, |
90
|
|
|
'filterOptions' => ['class' => 'narrow-filter'], |
91
|
|
|
'i18nDictionary' => 'hipanel:server', |
92
|
|
|
'format' => 'raw', |
93
|
|
|
'gtype' => 'state,device', |
94
|
|
|
'value' => function ($model) { |
95
|
|
|
$html = State::widget(compact('model')); |
96
|
|
|
if ($model->status_time) { |
97
|
|
|
$html .= ' ' . Html::tag('nobr', Yii::t('hipanel:server', 'since {date}', ['date' => Yii::$app->formatter->asDate($model->status_time)])); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return $html; |
101
|
|
|
}, |
102
|
|
|
], |
103
|
|
|
'panel' => [ |
104
|
|
|
'attribute' => 'panel', |
105
|
|
|
'format' => 'html', |
106
|
|
|
'contentOptions' => ['class' => 'text-uppercase'], |
107
|
|
|
'value' => function ($model) use ($canSupport) { |
108
|
|
|
$value = $model->getPanel() ? Yii::t('hipanel:server:panel', $model->getPanel()) : Yii::t('hipanel:server:panel', 'No control panel'); |
109
|
|
|
if ($canSupport) { |
110
|
|
|
$value .= $model->wizzarded ? Label::widget(['label' => 'W', 'tag' => 'sup', 'color' => 'success']) : ''; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $value; |
114
|
|
|
}, |
115
|
|
|
], |
116
|
|
|
'os' => [ |
117
|
|
|
'attribute' => 'os', |
118
|
|
|
'format' => 'raw', |
119
|
|
|
'value' => function ($model) { |
120
|
|
|
return OSFormatter::widget([ |
121
|
|
|
'osimages' => $this->osImages, |
122
|
|
|
'imageName' => $model->osimage, |
123
|
|
|
]); |
124
|
|
|
}, |
125
|
|
|
], |
126
|
|
|
'os_and_panel' => [ |
127
|
|
|
'attribute' => 'os', |
128
|
|
|
'format' => 'raw', |
129
|
|
|
'value' => function ($model) { |
130
|
|
|
$html = OSFormatter::widget([ |
131
|
|
|
'osimages' => $this->osImages, |
132
|
|
|
'imageName' => $model->osimage, |
133
|
|
|
]); |
134
|
|
|
$html .= ' ' . ($model->panel ?: ''); |
135
|
|
|
|
136
|
|
|
return $html; |
137
|
|
|
}, |
138
|
|
|
], |
139
|
|
|
'discount' => [ |
140
|
|
|
'attribute' => 'discount', |
141
|
|
|
'label' => Yii::t('hipanel:server', 'Discount'), |
142
|
|
|
'format' => 'raw', |
143
|
|
|
'headerOptions' => ['style' => 'width: 1em'], |
144
|
|
|
'value' => function ($model) { |
145
|
|
|
return DiscountFormatter::widget([ |
146
|
|
|
'current' => $model->discounts['fee']['current'], |
147
|
|
|
'next' => $model->discounts['fee']['next'], |
148
|
|
|
]); |
149
|
|
|
}, |
150
|
|
|
], |
151
|
|
|
'expires' => [ |
152
|
|
|
'filter' => false, |
153
|
|
|
'format' => 'raw', |
154
|
|
|
'headerOptions' => ['style' => 'width: 1em'], |
155
|
|
|
'value' => function ($model) { |
156
|
|
|
return Expires::widget(compact('model')); |
157
|
|
|
}, |
158
|
|
|
], |
159
|
|
|
'tariff' => [ |
160
|
|
|
'format' => 'raw', |
161
|
|
|
'filterAttribute' => 'tariff_like', |
162
|
|
|
'value' => function ($model) { |
163
|
|
|
return $this->formatTariff($model); |
164
|
|
|
}, |
165
|
|
|
], |
166
|
|
|
'tariff_and_discount' => [ |
167
|
|
|
'attribute' => 'tariff', |
168
|
|
|
'filterAttribute' => 'tariff_like', |
169
|
|
|
'format' => 'raw', |
170
|
|
|
'value' => function ($model) { |
171
|
|
|
return $this->formatTariff($model) . ' ' . DiscountFormatter::widget([ |
172
|
|
|
'current' => $model->discounts['fee']['current'], |
173
|
|
|
'next' => $model->discounts['fee']['next'], |
174
|
|
|
]); |
175
|
|
|
}, |
176
|
|
|
], |
177
|
|
|
'ip' => [ |
178
|
|
|
'filter' => false, |
179
|
|
|
], |
180
|
|
|
'mac' => [ |
181
|
|
|
'filter' => false, |
182
|
|
|
], |
183
|
|
|
'ips' => [ |
184
|
|
|
'format' => 'raw', |
185
|
|
|
'attribute' => 'ips', |
186
|
|
|
'filter' => false, |
187
|
|
|
'value' => function ($model) { |
188
|
|
|
return ArraySpoiler::widget([ |
189
|
|
|
'data' => ArrayHelper::getColumn($model->ips, 'ip'), |
190
|
|
|
'delimiter' => '<br />', |
191
|
|
|
'visibleCount' => 3, |
192
|
|
|
'button' => ['popoverOptions' => ['html' => true]], |
193
|
|
|
]); |
194
|
|
|
}, |
195
|
|
|
], |
196
|
|
|
'sale_time' => [ |
197
|
|
|
'attribute' => 'sale_time', |
198
|
|
|
'format' => 'datetime', |
199
|
|
|
], |
200
|
|
|
'note' => [ |
201
|
|
|
'class' => XEditableColumn::class, |
202
|
|
|
'pluginOptions' => [ |
203
|
|
|
'url' => Url::to('set-note'), |
204
|
|
|
], |
205
|
|
|
'widgetOptions' => [ |
206
|
|
|
'linkOptions' => [ |
207
|
|
|
'data-type' => 'textarea', |
208
|
|
|
], |
209
|
|
|
], |
210
|
|
|
], |
211
|
|
|
'label' => [ |
212
|
|
|
'class' => XEditableColumn::class, |
213
|
|
|
'visible' => $canSupport, |
214
|
|
|
'pluginOptions' => [ |
215
|
|
|
'url' => Url::to('set-label'), |
216
|
|
|
], |
217
|
|
|
'widgetOptions' => [ |
218
|
|
|
'linkOptions' => [ |
219
|
|
|
'data-type' => 'textarea', |
220
|
|
|
], |
221
|
|
|
], |
222
|
|
|
], |
223
|
|
|
'type' => [ |
224
|
|
|
'format' => 'html', |
225
|
|
|
'filter' => false, |
226
|
|
|
'value' => function ($model) { |
227
|
|
|
return Html::tag('span', $model->type_label, ['class' => 'label label-default']); |
228
|
|
|
}, |
229
|
|
|
], |
230
|
|
|
'detailed_type' => [ |
231
|
|
|
'label' => Yii::t('hipanel', 'Type'), |
232
|
|
|
'format' => 'html', |
233
|
|
|
'filter' => false, |
234
|
|
|
'value' => function ($model) { |
235
|
|
|
return Html::tag('span', $model->type_label, ['class' => 'label label-default']); |
236
|
|
|
}, |
237
|
|
|
'contentOptions' => function ($model) { |
238
|
|
|
return GridLegend::create($this->findOrFailGridLegend($model))->gridColumnOptions('actions'); |
239
|
|
|
}, |
240
|
|
|
], |
241
|
|
|
'rack' => [ |
242
|
|
|
'class' => BindingColumn::class, |
243
|
|
|
], |
244
|
|
|
'net' => [ |
245
|
|
|
'class' => BindingColumn::class, |
246
|
|
|
], |
247
|
|
|
'kvm' => [ |
248
|
|
|
'class' => BindingColumn::class, |
249
|
|
|
], |
250
|
|
|
'pdu' => [ |
251
|
|
|
'class' => BindingColumn::class, |
252
|
|
|
], |
253
|
|
|
'ipmi' => [ |
254
|
|
|
'class' => BindingColumn::class, |
255
|
|
|
], |
256
|
|
|
'nums' => [ |
257
|
|
|
'label' => '', |
258
|
|
|
'format' => 'raw', |
259
|
|
|
'value' => function ($model) { |
260
|
|
|
$ips_num = $model->ips_num; |
261
|
|
|
$ips = $ips_num ? Html::a("$ips_num ips", IpController::getSearchUrl(['server' => $model->name])) : 'no ips'; |
262
|
|
|
$act_acs_num = $model->acs_num - $model->del_acs_num; |
263
|
|
|
$del_acs_num = $model->del_acs_num; |
264
|
|
|
$acs_num = $act_acs_num . ($del_acs_num ? "+$del_acs_num" : ''); |
265
|
|
|
$acs = $acs_num ? Html::a("$acs_num acc", AccountController::getSearchUrl(['server' => $model->name])) : 'no acc'; |
266
|
|
|
|
267
|
|
|
return Html::tag('nobr', $ips) . ' ' . Html::tag('nobr', $acs); |
268
|
|
|
}, |
269
|
|
|
], |
270
|
|
|
'actions' => [ |
271
|
|
|
'class' => MenuColumn::class, |
272
|
|
|
'menuClass' => ServerActionsMenu::class, |
273
|
|
|
], |
274
|
|
|
]); |
275
|
|
|
} |
276
|
|
|
} |
277
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths