Completed
Push — master ( bb044b...7af247 )
by Dmitry
03:54
created

src/views/server/index.php (1 issue)

Labels
Severity
1
<?php
2
3
use hipanel\models\IndexPageUiOptions;
4
use hipanel\modules\server\grid\ServerGridLegend;
5
use hipanel\modules\server\grid\ServerGridView;
6
use hipanel\modules\server\models\OsimageSearch;
7
use hipanel\widgets\AjaxModal;
8
use hipanel\widgets\AjaxModalWithTemplatedButton;
9
use hipanel\widgets\gridLegend\GridLegend;
10
use hipanel\widgets\IndexPage;
11
use hipanel\widgets\Pjax;
12
use yii\bootstrap\Dropdown;
13
use yii\bootstrap\Modal;
14
use yii\helpers\Html;
15
use yii\helpers\Json;
16
use yii\helpers\Url;
17
use yii\web\JsExpression;
18
19
/**
20
 * @var OsimageSearch
21
 * @var yii\web\View $this
22
 * @var IndexPageUiOptions $uiModel
23
 * @var \hiqdev\higrid\representations\RepresentationCollection $representationCollection
24
 * @var bool $orderIsAllowed
25
 */
26
$this->title = Yii::t('hipanel:server', 'Servers');
27
$this->params['subtitle'] = array_filter(Yii::$app->request->get($model->formName(), [])) ? Yii::t('hipanel', 'filtered list') : Yii::t('hipanel', 'full list');
28
$this->params['breadcrumbs'][] = $this->title;
29
$orderIsAllowed = $this->context->module->orderIsAllowed;
0 ignored issues
show
Accessing module on the interface yii\base\ViewContextInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
30
31
?>
32
33
<?php Pjax::begin(array_merge(Yii::$app->params['pjax'], ['enablePushState' => true])) ?>
34
<?php $page = IndexPage::begin(compact('model', 'dataProvider')) ?>
35
36
    <?php if (Yii::$app->user->can('support')) : ?>
37
        <?php $page->beginContent('legend') ?>
38
            <?= GridLegend::widget(['legendItem' => new ServerGridLegend($model)]) ?>
39
        <?php $page->endContent() ?>
40
    <?php endif ?>
41
42
    <?php $page->beginContent('main-actions') ?>
43
        <?php if (Yii::$app->user->can('server.create')) : ?>
44
            <?= Html::a(Yii::t('hipanel:server', 'Create server'), ['@server/create'], ['class' => 'btn btn-sm btn-success']) ?>
45
        <?php endif ?>
46
        <?php if (Yii::$app->user->can('server.pay') && $orderIsAllowed) : ?>
47
            <?= Html::a(Yii::t('hipanel:server:order', 'Buy server'), ['/server/order/index'], ['class' => 'btn btn-sm btn-primary']) ?>
48
        <?php endif ?>
49
    <?php $page->endContent() ?>
50
51
    <?php $page->beginContent('sorter-actions') ?>
52
        <?= $page->renderSorter([
53
            'attributes' => array_filter([
54
                'name', 'tariff', 'ip',
55
                Yii::$app->user->can('support') ? 'client' : null,
56
            ]),
57
        ]) ?>
58
    <?php $page->endContent() ?>
59
    <?php $page->beginContent('representation-actions') ?>
60
        <?= $page->renderRepresentations($representationCollection) ?>
61
    <?php $page->endContent() ?>
62
63
    <?php $page->beginContent('bulk-actions') ?>
64
        <?php if ($uiModel->representation === 'hardware'
65
            && Yii::getAlias('@part', false)
66
            && Yii::$app->user->can('part.read')
67
        ): ?>
68
            <?php
69
            $partsDetailsLink = Json::htmlEncode(Url::to(\hipanel\helpers\Url::toSearch('part')));
70
            echo Html::button(Yii::t('hipanel:server', 'View parts'), [
71
                    'class' => 'btn btn-sm btn-default',
72
                    'onClick' => new JsExpression(<<<JS
73
                        const selection = jQuery('div[role="grid"]').yiiGridView('getSelectedRows');
74
                        window.location.href = $partsDetailsLink + '?' + jQuery.param({PartSearch: {dst_id_in: selection}});
75
JS
76
            ), ]) ?>
77
        <?php endif ?>
78
        <?php if (Yii::$app->user->can('server.sell')): ?>
79
            <?= AjaxModal::widget([
80
                'id' => 'bulk-sale-modal',
81
                'bulkPage' => true,
82
                'header' => Html::tag('h4', Yii::t('hipanel:server', 'Sell servers'), ['class' => 'modal-title']),
83
                'scenario' => 'bulk-sale',
84
                'size' => Modal::SIZE_LARGE,
85
                'toggleButton' => ['label' => Yii::t('hipanel:server', 'Sell'), 'class' => 'btn btn-sm btn-default'],
86
            ]) ?>
87
        <?php endif ?>
88
        <div class="dropdown" style="display: inline-block">
89
            <?php if (
90
                    Yii::$app->user->can('server.update')
91
                ||  Yii::$app->user->can('server.set-note')
92
                ||  Yii::$app->user->can('server.enable-block')
93
                ||  Yii::$app->user->can('server.disable-block')
94
                || Yii::$app->user->can('manage')
95
            ) : ?>
96
                <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
97
                    <?= Yii::t('hipanel', 'Basic actions') ?>
98
                    <span class="caret"></span>
99
                </button>
100
                <?= Dropdown::widget([
101
                    'encodeLabels' => false,
102
                    'options' => ['class' => 'pull-right'],
103
                    'items' => array_filter([
104
                        [
105
                            'label' => '<i class="fa fa-plug"></i> ' . Yii::t('hipanel:server', 'Assign hubs'),
106
                            'url' => '#',
107
                            'linkOptions' => ['data-action' => 'assign-hubs'],
108
                            'visible' => Yii::$app->user->can('server.update'),
109
                        ],
110
                        Yii::$app->user->can('server.update') ? AjaxModalWithTemplatedButton::widget([
111
                            'ajaxModalOptions' => [
112
                                'id' => 'bulk-set-type-modal',
113
                                'bulkPage' => true,
114
                                'header' => Html::tag('h4', Yii::t('hipanel:server', 'Change type'), ['class' => 'modal-title']),
115
                                'scenario' => 'set-type',
116
                                'toggleButton' => [
117
                                    'tag' => 'a',
118
                                    'label' => '<i class="fa fa-pencil"></i> ' . Yii::t('hipanel:server', 'Change type'),
119
                                ],
120
                            ],
121
                            'toggleButtonTemplate' => '<li>{toggleButton}</li>',
122
                        ]) : null,
123
                        [
124
                            'label' => '<i class="fa fa-pencil"></i> ' . Yii::t('hipanel:server', 'Set one type to many servers'),
125
                            'url' => '#',
126
                            'linkOptions' => ['data-action' => 'set-one-type'],
127
                            'visible' => Yii::$app->user->can('server.update'),
128
                        ],
129
                        Yii::$app->user->can('server.update') ? [
130
                            'label' => '<i class="fa fa-cog"></i> ' . Yii::t('hipanel:server', 'Set units'),
131
                            'url' => '#',
132
                            'linkOptions' => ['data-action' => 'set-units'],
133
                            'visible' => Yii::$app->user->can('server.update'),
134
                        ] : null,
135
                        [
136
                            'label' => '<i class="fa fa-cog"></i> ' . Yii::t('hipanel:server', 'Set Rack No.'),
137
                            'url' => '#',
138
                            'linkOptions' => ['data-action' => 'set-rack-no'],
139
                            'visible' => Yii::$app->user->can('server.update'),
140
                        ],
141
                        Yii::$app->user->can('consumption.delete') ? AjaxModalWithTemplatedButton::widget([
142
                            'ajaxModalOptions' => [
143
                                'id' => 'clear-resources-modal',
144
                                'bulkPage' => true,
145
                                'header' => Html::tag('h4', Yii::t('hipanel:server', 'Clear resources'), ['class' => 'modal-title']),
146
                                'scenario' => 'clear-resources-modal',
147
                                'toggleButton' => [
148
                                    'tag' => 'a',
149
                                    'label' => '<i class="fa fa-history"></i> ' . Yii::t('hipanel:server', 'Clear resources'),
150
                                ],
151
                            ],
152
                            'toggleButtonTemplate' => '<li>{toggleButton}</li>',
153
                        ]) : null,
154
                        Yii::$app->user->can('consumption.delete') ? AjaxModalWithTemplatedButton::widget([
155
                            'ajaxModalOptions' => [
156
                                'id' => 'flush-modal',
157
                                'bulkPage' => true,
158
                                'header' => Html::tag('h4', Yii::t('hipanel:server', 'Flush switch graphs'), ['class' => 'modal-title']),
159
                                'scenario' => 'flush-switch-graphs-modal',
160
                                'toggleButton' => [
161
                                    'tag' => 'a',
162
                                    'label' => '<i class="fa fa-history"></i> ' . Yii::t('hipanel:server', 'Flush switch graphs'),
163
                                ],
164
                            ],
165
                            'toggleButtonTemplate' => '<li>{toggleButton}</li>',
166
                        ]) : null,
167
                        Yii::$app->user->can('server.disable-block') ? AjaxModalWithTemplatedButton::widget([
168
                            'ajaxModalOptions' => [
169
                                'bulkPage' => true,
170
                                'id' => 'bulk-enable-block-modal',
171
                                'scenario' => 'bulk-enable-block-modal',
172
                                'header' => Html::tag('h4', Yii::t('hipanel:server', 'Block servers'), ['class' => 'modal-title label-warning']),
173
                                'headerOptions' => ['class' => 'label-warning'],
174
                                'toggleButton' => [
175
                                    'tag' => 'a',
176
                                    'label' => '<i class="fa fa-toggle-on"></i> ' . Yii::t('hipanel', 'Enable block'),
177
                                ],
178
                            ],
179
                            'toggleButtonTemplate' => '<li>{toggleButton}</li>',
180
                        ]) : null,
181
                        Yii::$app->user->can('server.enable-block') ? AjaxModalWithTemplatedButton::widget([
182
                            'ajaxModalOptions' => [
183
                                'bulkPage' => true,
184
                                'id' => 'bulk-disable-block-modal',
185
                                'scenario' => 'bulk-disable-block-modal',
186
                                'header' => Html::tag('h4', Yii::t('hipanel:server', 'Unblock servers'), ['class' => 'modal-title']),
187
                                'headerOptions' => ['class' => 'label-warning'],
188
                                'toggleButton' => [
189
                                    'tag' => 'a',
190
                                    'label' => '<i class="fa fa-toggle-off"></i> ' . Yii::t('hipanel', 'Disable block'),
191
                                ],
192
                            ],
193
                            'toggleButtonTemplate' => '<li>{toggleButton}</li>',
194
                        ]) : null,
195
                        Yii::$app->user->can('server.set-note') ? AjaxModalWithTemplatedButton::widget([
196
                            'ajaxModalOptions' => [
197
                                'bulkPage' => true,
198
                                'id' => 'servers-set-note',
199
                                'scenario' => Yii::$app->user->can('support') ? 'set-label' : 'set-note',
200
                                'size' => Modal::SIZE_LARGE,
201
                                'header' => Html::tag('h4', Yii::t('hipanel:server', 'Set notes'), ['class' => 'modal-title']),
202
                                'toggleButton' => [
203
                                    'tag' => 'a',
204
                                    'label' => '<i class="fa fa-pencil"></i> ' . Yii::t('hipanel:server', 'Set notes'),
205
                                ],
206
                            ],
207
                            'toggleButtonTemplate' => '<li>{toggleButton}</li>',
208
                        ]) : null,
209
                        Yii::$app->user->can('server.delete') ? AjaxModalWithTemplatedButton::widget([
210
                            'ajaxModalOptions' => [
211
                                'id' => 'bulk-delete-modal',
212
                                'bulkPage' => true,
213
                                'scenario' => 'bulk-delete-modal',
214
                                'header' => Html::tag('h4', Yii::t('hipanel', 'Delete'), ['class' => 'modal-title label-danger']),
215
                                'headerOptions' => ['class' => 'label-danger'],
216
                                'toggleButton' => [
217
                                    'tag' => 'a',
218
                                    'label' => '<i class="fa fa-trash"></i> ' . Yii::t('hipanel', 'Delete'),
219
                                ],
220
                            ],
221
                            'toggleButtonTemplate' => '<li>{toggleButton}</li>',
222
                        ]) : null,
223
                        Yii::$app->user->can('server.control-power') ? [
224
                            'label' => '<i class="fa fw fa-power-off"></i>&nbsp;' . Yii::t('hipanel:server', 'Reboot'),
225
                            'url' => '#',
226
                            'linkOptions' => [
227
                                'data-action' => 'reboot',
228
                                'onclick' => new JsExpression(
229
                                    sprintf(
230
                                        'return confirm(\'%s %s\');',
231
                                        Yii::t('hipanel:server', 'This may cause data loose!'),
232
                                        Yii::t('hipanel:server', 'Reboot will interrupt all processes on the server. Are you sure you want to reset the server?')
233
                                    )
234
                                ),
235
                            ],
236
                        ] : null,
237
                    ]),
238
                ]) ?>
239
            <?php endif ?>
240
        </div>
241
    <?php $page->endContent() ?>
242
243
    <?php $page->beginContent('table') ?>
244
        <?php $page->beginBulkForm(); ?>
245
            <?= ServerGridView::widget([
246
                'dataProvider' => $dataProvider,
247
                'boxed' => false,
248
                'colorize' => true,
249
                'filterModel' => $model,
250
                'osImages' => $osimages,
251
                'columns' => $representationCollection->getByName($uiModel->representation)->getColumns(),
252
                'rowOptions' => function ($model) {
253
                    return GridLegend::create(new ServerGridLegend($model))->gridRowOptions();
254
                },
255
            ]) ?>
256
        <?php $page->endBulkForm(); ?>
257
    <?php $page->endContent() ?>
258
<?php $page->end() ?>
259
<?php Pjax::end() ?>
260