Skip to content

Commit

Permalink
Added site_id to IPAM stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
tafid committed Aug 28, 2020
1 parent 43c17e8 commit 3bd96ac
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 29 deletions.
14 changes: 14 additions & 0 deletions src/grid/PrefixGridView.php
Expand Up @@ -19,6 +19,7 @@
use hiqdev\yii2\menus\grid\MenuColumn;
use Yii;
use yii\helpers\Html;
use yii\helpers\IpHelper;

class PrefixGridView extends BoxedGridView
{
Expand Down Expand Up @@ -55,6 +56,19 @@ public function columns()
'format' => 'raw',
'gtype' => 'type,ip_prefix_role',
],
'site' => [
'class' => RefColumn::class,
'i18nDictionary' => 'hipanel.hosting.ipam',
'format' => 'raw',
'gtype' => 'type,location',
],
'family' => [
'class' => DataColumn::class,
'label' => Yii::t('hipanel.hosting.ipam', 'Family'),
'value' => static function ($model) {
return sprintf('IPv%d', IpHelper::getIpVersion($model->ip));
}
],
'utilization' => [
'class' => UtilizationColumn::class,
],
Expand Down
1 change: 1 addition & 0 deletions src/grid/PrefixRepresentations.php
Expand Up @@ -26,6 +26,7 @@ protected function fillRepresentations()
'state',
'vrf',
'role',
'site',
'utilization',
'note',
],
Expand Down
15 changes: 13 additions & 2 deletions src/grid/UtilizationColumn.php
Expand Up @@ -26,12 +26,23 @@ public function init()

public function getDataCellValue($model, $key, $index)
{
$prc = mt_rand(1, 84);
$prc = mt_rand(1, 100);
switch ($prc) {
case $prc >= 0 && $prc <= 40:
$level = 'progress-bar-success';
break;
case $prc >= 41 && $prc <= 70:
$level = 'progress-bar-warning';
break;
case $prc >= 71 && $prc <= 100:
$level = 'progress-bar-danger';
break;
}

return Progress::widget([
'percent' => $prc,
'label' => $prc . '%',
'barOptions' => ['class' => 'progress-bar-success'],
'barOptions' => ['class' => $level],
'options' => ['style' => 'background-color: grey;'],
]);
}
Expand Down
1 change: 1 addition & 0 deletions src/models/Prefix.php
Expand Up @@ -37,6 +37,7 @@ public function attributeLabels()
return $this->mergeAttributeLabels([
'ip' => Yii::t('hipanel.hosting.ipam', 'Prefix'),
'vrf' => Yii::t('hipanel.hosting.ipam', 'VRF'),
'site' => Yii::t('hipanel.hosting.ipam', 'Site'),
'note' => Yii::t('hipanel.hosting.ipam', 'Description'),
'vlan' => Yii::t('hipanel.hosting.ipam', 'VLAN'),
'vlan_group' => Yii::t('hipanel.hosting.ipam', 'VLAN group'),
Expand Down
11 changes: 4 additions & 7 deletions src/views/aggregate/_form.php
Expand Up @@ -4,7 +4,6 @@

/* @var $model hipanel\modules\hosting\models\Aggregate */

use hiqdev\combo\StaticCombo;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
Expand All @@ -23,17 +22,15 @@
<div class="box-body">
<?= Html::activeHiddenInput($model, 'id') ?>
<?= $form->field($model, 'ip')->hint(Yii::t('hipanel.hosting.ipam', 'IPv4 or IPv6 network')) ?>
<?= $form->field($model, 'rir')->widget(StaticCombo::class, [
'data' => $this->context->getRefs('type,ip_rir', 'hipanel.hosting.ipam'),
'hasId' => true,
'multiple' => false,
])->hint(Yii::t('hipanel.hosting.ipam', 'Regional Internet Registry responsible for this prefix')) ?>
<?= $form->field($model, 'rir')
->dropDownList($this->context->getRefs('type,ip_rir', 'hipanel.hosting.ipam'), ['prompt' => '---'])
->hint(Yii::t('hipanel.hosting.ipam', 'Regional Internet Registry responsible for this prefix')) ?>
<?= $form->field($model, 'note')->textarea(['rows' => 3]) ?>
</div>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<?= Html::submitButton(Yii::t('hipanel', 'Create'), ['class' => 'btn btn-success']) ?>
<?= Html::submitButton(Yii::t('hipanel', $model->isNewRecord ? 'Create' : 'Save'), ['class' => 'btn btn-success']) ?>
</div>
</div>

Expand Down
33 changes: 13 additions & 20 deletions src/views/prefix/_form.php
Expand Up @@ -4,7 +4,6 @@

/* @var $model hipanel\modules\hosting\models\Aggregate */

use hiqdev\combo\StaticCombo;
use yii\helpers\Html;
use yii\helpers\Url;
use yii\widgets\ActiveForm;
Expand All @@ -26,21 +25,15 @@
<div class="box-body">
<?= Html::activeHiddenInput($model, 'id') ?>
<?= $form->field($model, 'ip')->hint(Yii::t('hipanel.hosting.ipam', 'IPv4 or IPv6 network with mask')) ?>
<?= $form->field($model, 'state')->widget(StaticCombo::class, [
'data' => $this->context->getRefs('state,ip', 'hipanel.hosting.ipam'),
'hasId' => true,
'multiple' => false,
])->hint(Yii::t('hipanel.hosting.ipam', 'Operational status of this prefix')) ?>
<?= $form->field($model, 'vrf')->widget(StaticCombo::class, [
'data' => $this->context->getRefs('type,ip_vrf', 'hipanel.hosting.ipam'),
'hasId' => true,
'multiple' => false,
])->hint(Yii::t('hipanel.hosting.ipam', 'Virtual Routing and Forwarding')) ?>
<?= $form->field($model, 'role')->widget(StaticCombo::class, [
'data' => $this->context->getRefs('type,ip_prefix_role', 'hipanel.hosting.ipam'),
'hasId' => true,
'multiple' => false,
])->hint(Yii::t('hipanel.hosting.ipam', 'The primary function of this prefix')) ?>
<?= $form->field($model, 'state')
->dropDownList($this->context->getRefs('state,ip', 'hipanel.hosting.ipam'))
->hint(Yii::t('hipanel.hosting.ipam', 'Operational status of this prefix')) ?>
<?= $form->field($model, 'vrf')
->dropDownList($this->context->getRefs('type,ip_vrf', 'hipanel.hosting.ipam'))
->hint(Yii::t('hipanel.hosting.ipam', 'Virtual Routing and Forwarding')) ?>
<?= $form->field($model, 'role')
->dropDownList($this->context->getRefs('type,ip_prefix_role', 'hipanel.hosting.ipam'), ['prompt' => '---'])
->hint(Yii::t('hipanel.hosting.ipam', 'The primary function of this prefix')) ?>
<?= $form->field($model, 'note')->textarea(['rows' => 2]) ?>
</div>
</div>
Expand All @@ -51,14 +44,14 @@
<h3 class="box-title"><?= Yii::t('hipanel.hosting.ipam', 'Site/VLAN Assignment') ?></h3>
</div>
<div class="box-body">
<?= $form->field($model, 'site')->dropDownList([]) ?>
<?= $form->field($model, 'vlan_group')->dropDownList([]) ?>
<?= $form->field($model, 'vlan')->dropDownList([]) ?>
<?= $form->field($model, 'site')->dropDownList($this->context->getRefs('type,location'), ['prompt' => '---']) ?>
<?= $form->field($model, 'vlan_group')->dropDownList([], ['prompt' => '---']) // todo: clarify the need ?>
<?= $form->field($model, 'vlan')->dropDownList([], ['prompt' => '---']) // todo: clarify the need ?>
</div>
</div>
</div>
<div class="col-md-12 col-sm-12 col-xs-12">
<?= Html::submitButton(Yii::t('hipanel', 'Create'), ['class' => 'btn btn-success']) ?>
<?= Html::submitButton(Yii::t('hipanel', $model->isNewRecord ? 'Create' : 'Save'), ['class' => 'btn btn-success']) ?>
</div>
</div>

Expand Down
3 changes: 3 additions & 0 deletions src/views/prefix/view.php
Expand Up @@ -38,9 +38,11 @@
'boxed' => false,
'model' => $model,
'columns' => [
'family',
'state',
'vrf',
'role',
'site',
'utilization',
'note',
],
Expand Down Expand Up @@ -78,6 +80,7 @@
'state',
'vrf',
'role',
'site',
'note'
],
]) ?>
Expand Down

0 comments on commit 3bd96ac

Please sign in to comment.