Skip to content

Commit

Permalink
Sources moved to src directory
Browse files Browse the repository at this point in the history
  • Loading branch information
SilverFire committed Jul 31, 2015
1 parent bc3b774 commit 0d4e9de
Show file tree
Hide file tree
Showing 25 changed files with 131 additions and 46 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"autoload": {
"psr-4": {
"hipanel\\modules\\server\\": ""
"hipanel\\modules\\server\\": "src"
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class OsSelectionAsset extends AssetBundle
/**
* @var string
*/
public $sourcePath = '@hipanel/modules/server/assets';
public $sourcePath = '@hipanel/modules/server/src/assets';

/**
* @var array
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
52 changes: 34 additions & 18 deletions grid/ServerGridView.php → src/grid/ServerGridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

namespace hipanel\modules\server\grid;

use Yii;
use yii\helpers\Html;
use hipanel\grid\ActionColumn;
use hipanel\grid\MainColumn;
use hipanel\grid\RefColumn;
use hipanel\modules\server\widgets\DiscountFormatter;
use hipanel\modules\server\widgets\Expires;
use hipanel\modules\server\widgets\OSFormatter;
use hipanel\modules\server\widgets\State;
use Yii;
use yii\helpers\Html;

class ServerGridView extends \hipanel\grid\BoxedGridView
{
Expand All @@ -34,29 +34,33 @@ public static function defaultColumns()
$osImages = self::$osImages;

return [
'server' => [
'server' => [
'class' => MainColumn::className(),
'attribute' => 'name',
'filterAttribute' => 'name_like',
'note' => true
],
'state' => [
'class' => RefColumn::className(),
'format' => 'raw',
'gtype' => 'state,device',
'value' => function ($model) {
return State::widget(compact('model'));
}
'state' => [
'class' => RefColumn::className(),
'format' => 'raw',
'gtype' => 'state,device',
'value' => function ($model) {
$html = State::widget(compact('model'));
if ($model->status_time) {
$html .= ' ' . Yii::t('app', 'since') . ' ' . Yii::$app->formatter->asDate($model->status_time);
}
return $html;
},
],
'panel' => [
'panel' => [
'attribute' => 'panel',
'format' => 'text',
'contentOptions' => ['class' => 'text-uppercase'],
'value' => function ($model) {
return $model->panel ?: '';
}
],
'os' => [
'os' => [
'attribute' => 'os',
'format' => 'raw',
'value' => function ($model) use ($osImages) {
Expand All @@ -66,17 +70,29 @@ public static function defaultColumns()
]);
}
],
'discounts' => [
'attribute' => 'discounts',
'format' => 'raw',
'value' => function ($model) {
'os_and_panel' => [
'format' => 'raw',
'value' => function ($model) use ($osImages) {
$html = OSFormatter::widget([
'osimages' => $osImages,
'imageName' => $model->osimage
]);
$html .= ' ' . $model->panel ?: '';
return $html;
}
],
'discount' => [
'attribute' => 'discount',
'format' => 'raw',
'headerOptions' => ['style' => 'width: 1em'],
'value' => function ($model) {
return DiscountFormatter::widget([
'current' => $model->discounts['fee']['current'],
'next' => $model->discounts['fee']['next'],
]);
}
],
'actions' => [
'actions' => [
'class' => ActionColumn::className(),
'template' => '{view} {block} {delete} {update}', // {state}
'header' => Yii::t('app', 'Actions'),
Expand All @@ -86,7 +102,7 @@ public static function defaultColumns()
},
],
],
'expires' => [
'expires' => [
'filter' => false,
'format' => 'raw',
'headerOptions' => ['style' => 'width: 1em'],
Expand Down
File renamed without changes.
File renamed without changes.
65 changes: 43 additions & 22 deletions models/Server.php → src/models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class Server extends \hipanel\base\Model
/**
* @return array the list of attributes for this record
*/
public function attributes () {
public function attributes()
{
return [
'id',
'name',
Expand Down Expand Up @@ -52,18 +53,24 @@ public function attributes () {
'note',
];
}
public function rules () {

public function rules()
{
return [
[['state'], 'isOperable', 'on' => [
'reinstall',
'reboot',
'reset',
'shutdown',
'power-off',
'power-on',
'boot-live',
'regen-root-password'
]],
[
['state'],
'isOperable',
'on' => [
'reinstall',
'reboot',
'reset',
'shutdown',
'power-off',
'power-on',
'boot-live',
'regen-root-password'
]
],
[['id', 'note'], 'required', 'on' => ['set-note']],

];
Expand All @@ -80,47 +87,60 @@ public function rules () {
// 'regen-root-password' => ['id'],
// ];
// }
public function goodStates () {
public function goodStates()
{
return ['ok', 'disabled'];
}

/**
* @return bool
*/
public function isOperable () {
public function isOperable()
{
/// TODO: all is operable for admin
if ($this->running_task || !in_array($this->state, $this->goodStates())) {
return false;
}
return true;
}

/**
* Returns true, if server supports VNC
*
* @return bool
*/
public function isVNCSupported () {
public function isVNCSupported()
{
return $this->type != 'ovds';
}
public function isPwChangeSupported () {

public function isPwChangeSupported()
{
return $this->type == 'ovds';
}
public function isLiveCDSupported () {

public function isLiveCDSupported()
{
return $this->type != 'ovds';
}

/**
* @return bool
* @throws NotSupportedException
*/
public function checkOperable () {
if (!$this->isOperable()) throw new NotSupportedException(\Yii::t('app', 'Server already has a running task. Can not start new.'));
public function checkOperable()
{
if (!$this->isOperable()) {
throw new NotSupportedException(\Yii::t('app', 'Server already has a running task. Can not start new.'));
}
return true;
}

/**
* @inheritdoc
*/
public function scenarioCommands () {
public function scenarioCommands()
{
return [
'reinstall' => 'resetup'
];
Expand All @@ -129,10 +149,11 @@ public function scenarioCommands () {
/**
* @inheritdoc
*/
public function attributeLabels ()
public function attributeLabels()
{
return $this->mergeAttributeLabels([
'remoteid' => Yii::t('app', 'Remote ID'),
'remoteid' => Yii::t('app', 'Remote ID'),
'name_like' => Yii::t('app', 'Name'),
'name' => Yii::t('app', 'Name'),
'panel' => Yii::t('app', 'Panel'),
'parent_tariff' => Yii::t('app', 'Parent tariff'),
Expand Down
File renamed without changes.
38 changes: 38 additions & 0 deletions src/views/server/_search.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

use hipanel\modules\client\widgets\combo\ClientCombo;
use hipanel\widgets\AdvancedSearch;
use hiqdev\combo\StaticCombo;
use kartik\widgets\DatePicker;
use yii\helpers\Html;

?>

<?php $form = AdvancedSearch::begin(compact('model')) ?>
<div class="col-md-4">
<?= $form->field('name_like') ?>
<?= $form->field('note') ?>
</div>

<div class="col-md-4">
<?= $form->field('client_id')->widget(ClientCombo::classname()) ?>
<?= $form->field('seller_id')->widget(ClientCombo::classname()) ?>
</div>

<div class="col-md-4">
<?= $form->field('state')->widget(StaticCombo::classname(), [
'data' => $state_data,
'hasId' => true,
'pluginOptions' => [
'select2Options' => [
'multiple' => true,
]
],
]) ?>
</div>

<div class="col-md-12">
<?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
</div>

<?php $form::end() ?>
File renamed without changes.
14 changes: 12 additions & 2 deletions views/server/index.php → src/views/server/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use hipanel\widgets\ActionBox;
use hipanel\widgets\BulkButtons;
use hipanel\widgets\GridActionButton;
use hipanel\widgets\LinkSorter;
use hipanel\widgets\Pjax;
use hipanel\widgets\RequestState;
use yii\bootstrap\ButtonDropdown;
Expand All @@ -39,6 +40,14 @@
<?php $box = ActionBox::begin(['bulk' => true, 'options' => ['class' => 'box-info']]) ?>
<?php $box->beginActions() ?>
<?= Html::a(Yii::t('app', 'Advanced search'), '#', ['class' => 'btn btn-info search-button']) ?>
<?= LinkSorter::widget([
'show' => true,
'sort' => $dataProvider->getSort(),
'attributes' => [
'name', 'id', 'client', 'tariff',
'panel', 'ip', 'state', 'expires'
],
]) ?>
<?php $box->endActions() ?>

<?php $box->beginBulkActions() ?>
Expand Down Expand Up @@ -76,21 +85,22 @@
]) ?>

<?php $box->endBulkActions() ?>
<?//= $this->render('_search', compact('model')) ?>
<?= $this->render('_search', compact('model')) ?>
<?php $box::end() ?>

<?= ServerGridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $model,
'osImages' => $osimages,
'columns' => [
'checkbox',
'server',
'client_id',
'seller_id',
'state',
'expires',
'discount',
'actions',
'checkbox',
]
]); ?>
<?php
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions widgets/State.php → src/widgets/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class State extends \hipanel\widgets\Type
public $values = [];
public $defaultValues = [
'info' => ['ok'],
'danger' => ['blocked','expired'],
'warning' => [],
'danger' => ['expired'],
'warning' => ['blocked'],
];
public $field = 'state';
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 0d4e9de

Please sign in to comment.