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
|
|
|
/** |
12
|
|
|
* @see http://hiqdev.com/hipanel-module-hosting |
13
|
|
|
* @license http://hiqdev.com/hipanel-module-hosting/license |
14
|
|
|
* @copyright Copyright (c) 2015 HiQDev |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace hipanel\modules\hosting\grid; |
18
|
|
|
|
19
|
|
|
use hipanel\grid\MainColumn; |
20
|
|
|
use hipanel\helpers\Url; |
21
|
|
|
use hipanel\modules\server\grid\ServerColumn; |
22
|
|
|
use hipanel\widgets\obj\ObjLabelWidget; |
23
|
|
|
use hipanel\widgets\obj\ObjLinkWidget; |
24
|
|
|
use hiqdev\xeditable\widgets\XEditable; |
25
|
|
|
use Yii; |
26
|
|
|
use yii\helpers\Html; |
27
|
|
|
|
28
|
|
|
class BackupingGridView extends \hipanel\grid\BoxedGridView |
29
|
|
|
{ |
30
|
|
|
public $typeOptions = []; |
31
|
|
|
|
32
|
|
|
public function init() |
33
|
|
|
{ |
34
|
|
|
parent::init(); |
35
|
|
|
$controller = Yii::$app->controller; |
36
|
|
|
if (empty($this->typeOptions) && method_exists($controller, 'getTypeOptions')) { |
37
|
|
|
$this->typeOptions = (array) $controller->getTypeOptions(); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function getTypeOptions() |
42
|
|
|
{ |
43
|
|
|
$result = []; |
44
|
|
|
foreach ($this->typeOptions as $key => $value) { |
45
|
|
|
$result[$key] = Yii::t('hipanel.hosting.backuping.periodicity', $value); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
return $result; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function columns() |
52
|
|
|
{ |
53
|
|
|
$typeOptions = $this->getTypeOptions(); |
54
|
|
|
|
55
|
|
|
return array_merge(parent::columns(), [ |
56
|
|
|
'name' => [ |
57
|
|
|
'class' => MainColumn::class, |
58
|
|
|
'filterAttribute' => 'name_like', |
59
|
|
|
'format' => 'html', |
60
|
|
|
'value' => function ($model) { |
61
|
|
|
return Html::a($model->name, ['@' . $model->object . '/view', 'id' => $model->id], ['class' => 'bold']); |
62
|
|
|
}, |
63
|
|
|
], |
64
|
|
|
'main' => [ |
65
|
|
|
'attribute' => 'name', |
66
|
|
|
'filterAttribute' => 'name_like', |
67
|
|
|
'format' => 'raw', |
68
|
|
|
'value' => function ($model) { |
69
|
|
|
return Html::tag('span', Html::a($model->name, ['@backuping/view', 'id' => $model->id], ['class' => 'bold']) . ' ' . |
70
|
|
|
ObjLinkWidget::widget(['model' => $model->getObj()]), ['style' => 'display: flex; justify-content: space-between;']); |
71
|
|
|
}, |
72
|
|
|
], |
73
|
|
|
'account' => [ |
74
|
|
|
'attribute' => 'account_id', |
75
|
|
|
'class' => AccountColumn::class, |
76
|
|
|
], |
77
|
|
|
'server' => [ |
78
|
|
|
'attribute' => 'server_id', |
79
|
|
|
'class' => ServerColumn::class, |
80
|
|
|
], |
81
|
|
|
'object' => [ |
82
|
|
|
'filter' => false, |
83
|
|
|
'format' => 'raw', |
84
|
|
|
'value' => function ($model) { |
85
|
|
|
return ObjLabelWidget::widget(['model' => $model->getObj()]); |
86
|
|
|
}, |
87
|
|
|
], |
88
|
|
|
'backup_count' => [ |
89
|
|
|
'filter' => false, |
90
|
|
|
], |
91
|
|
|
'type' => [ |
92
|
|
|
'attribute' => 'type', |
93
|
|
|
'format' => 'raw', |
94
|
|
|
'filter' => false, |
95
|
|
|
'enableSorting' => false, |
96
|
|
|
'value' => function ($model) use ($typeOptions) { |
97
|
|
|
return XEditable::widget([ |
98
|
|
|
'model' => $model, |
99
|
|
|
'attribute' => 'type', |
100
|
|
|
'pluginOptions' => [ |
101
|
|
|
'type' => 'select', |
102
|
|
|
'source' => $typeOptions, |
103
|
|
|
'url' => Url::to('update'), |
104
|
|
|
'data-display-value' => Yii::t('hipanel.hosting.backuping.periodicity', $model->type), |
105
|
|
|
], |
106
|
|
|
]); |
107
|
|
|
}, |
108
|
|
|
], |
109
|
|
|
'state_label' => [ |
110
|
|
|
'filter' => false, |
111
|
|
|
'enableSorting' => false, |
112
|
|
|
], |
113
|
|
|
'backup_last' => [ |
114
|
|
|
'filter' => false, |
115
|
|
|
'format' => 'raw', |
116
|
|
|
'value' => function ($model) { |
117
|
|
|
return Html::tag('nobr', Yii::$app->formatter->asDate($model->backup_last)) . ' ' . |
118
|
|
|
Html::tag('nobr', Yii::$app->formatter->asTime($model->backup_last)); |
119
|
|
|
}, |
120
|
|
|
], |
121
|
|
|
'total_du' => [ |
122
|
|
|
'filter' => false, |
123
|
|
|
'format' => 'html', |
124
|
|
|
'value' => function ($model) { |
125
|
|
|
return Yii::$app->formatter->asShortSize($model->total_du, 2); |
126
|
|
|
}, |
127
|
|
|
], |
128
|
|
|
]); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|