BootLive   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 4
eloc 31
c 3
b 0
f 0
dl 0
loc 55
ccs 0
cts 39
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generatOSItemList() 0 15 2
A init() 0 27 2
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-2019, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hipanel\modules\server\widgets;
12
13
use hipanel\widgets\ModalButton;
14
use hipanel\widgets\SimpleOperation;
15
use Yii;
16
use yii\base\InvalidConfigException;
17
use yii\helpers\Html;
18
19
class BootLive extends SimpleOperation
20
{
21
    /**
22
     * @var string
23
     */
24
    public $scenario = 'boot-live';
25
26
    public $osimageslivecd;
27
28
    protected $osItems;
29
30
    public function init()
31
    {
32
        $this->scenario = 'boot-live';
33
34
        parent::init();
35
36
        if ($this->model === null) {
37
            throw new InvalidConfigException('Please specify the "model" property.');
38
        }
39
40
        $this->buttonLabel = Yii::t('hipanel:server', 'Boot LiveCD');
41
        $this->buttonPosition = ModalButton::BUTTON_IN_MODAL;
42
        $this->buttonVisible = $this->model->isLiveCDSupported();
43
        $this->modalHeaderLabel = Yii::t('hipanel:server', 'Confirm booting from Live CD');
44
        $this->modalHeaderOptions = ['class' => 'label-info'];
45
        $this->modalFooter = \yii\bootstrap\ButtonDropdown::widget([
46
            'label' => Yii::t('hipanel:server', 'Boot LiveCD'),
47
            'dropdown' => [
48
                'items' => $this->generatOSItemList(),
49
            ],
50
            'options' => [
51
                'class' => 'btn btn-info',
52
                'data-loading-text' => '<i class="fa fa-circle-o-notch fa-spin"></i> ' . Yii::t('hipanel','loading'),
53
            ],
54
        ]);
55
        $this->body = Html::hiddenInput('osimage', null, ['class' => 'livecd-osimage']) .
56
            Yii::t('hipanel:server', 'This action will shutdown the server and boot live cd image');
57
    }
58
59
    protected function generatOSItemList()
60
    {
61
        $osItems = [];
62
        foreach ($this->osimageslivecd as $item) {
63
            $js = "$(this).closest('form').find('.livecd-osimage').val('{$item['osimage']}').end().submit(); $(this).closest('button').button('loading');";
64
            $osItems[] = [
65
                'label' => $item['os'] . ' ' . $item['bitwise'],
66
                'url' => '#',
67
                'options' => [
68
                    'onclick' => new \yii\web\JsExpression($js),
69
                ],
70
            ];
71
        }
72
73
        return $osItems;
74
    }
75
}
76