new device module plugin
This commit is contained in:
@@ -116,4 +116,43 @@ sub sort_port {
|
||||
return $val;
|
||||
}
|
||||
|
||||
=head2 sort_modules( $modules )
|
||||
|
||||
Sort devices modules into tree hierarchy based upon position and parent -
|
||||
input arg is module list.
|
||||
|
||||
=cut
|
||||
|
||||
sub sort_modules {
|
||||
my $input = shift;
|
||||
|
||||
my %modules;
|
||||
|
||||
foreach my $module (@$input) {
|
||||
$modules{$module->index}{module} = $module;
|
||||
if ($module->parent) {
|
||||
# Next wrong: some things have weird pos'
|
||||
# index | description | type | parent | class | pos
|
||||
#-------+----------------------------------------+---------------------+--------+---------+-----
|
||||
# 1 | Cisco Aironet 1200 Series Access Point | cevChassisAIRAP1210 | 0 | chassis | -1
|
||||
# 3 | PowerPC405GP Ethernet | cevPortFEIP | 1 | port | -1
|
||||
# 2 | 802.11G Radio | cevPortUnknown | 1 | port | 0
|
||||
$module->pos = 0 if ($module->pos < 0);
|
||||
|
||||
# this is wrong. a given parent can
|
||||
# have multiple items at a single pos value.
|
||||
# (HP may have gotten this wrong, but that's
|
||||
# reality...)
|
||||
if ($module->pos) {
|
||||
${$modules{$module->parent}{children}{$module->class}}[$module->pos] = $module->index;
|
||||
} else {
|
||||
push(@{$modules{$module->parent}{children}{$module->class}}, $module->index);
|
||||
}
|
||||
} else {
|
||||
push(@{$modules{root}}, $module->index);
|
||||
}
|
||||
}
|
||||
return \%modules;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
@@ -2,14 +2,29 @@ package App::Netdisco::Web::Plugin::Device::Modules;
|
||||
|
||||
use Dancer ':syntax';
|
||||
use Dancer::Plugin::Ajax;
|
||||
use Dancer::Plugin::DBIC;
|
||||
use Dancer::Plugin::Auth::Extensible;
|
||||
|
||||
use App::Netdisco::Util::Web (); # for sort_module
|
||||
use App::Netdisco::Web::Plugin;
|
||||
|
||||
register_device_tab({ tag => 'modules', label => 'Modules' });
|
||||
|
||||
ajax '/ajax/content/device/:thing' => require_login sub {
|
||||
return "<p>Hello, this is where the ". param('thing') ." content goes.</p>";
|
||||
ajax '/ajax/content/device/modules' => require_login sub {
|
||||
my $q = param('q');
|
||||
|
||||
my $device = schema('netdisco')->resultset('Device')
|
||||
->search_for_device($q) or send_error('Bad device', 400);
|
||||
my @set = $device->modules->search({}, {order_by => { -asc => [qw/parent pos index/] }});
|
||||
|
||||
# sort modules (empty set would be a 'no records' msg)
|
||||
my $results = &App::Netdisco::Util::Web::sort_modules( \@set );
|
||||
return unless scalar %$results;
|
||||
|
||||
content_type('text/html');
|
||||
template 'ajax/device/modules.tt', {
|
||||
nodes => $results,
|
||||
}, { layout => undef };
|
||||
};
|
||||
|
||||
true;
|
||||
|
||||
@@ -45,7 +45,7 @@ web_plugins:
|
||||
- Search::Port
|
||||
- Device::Details
|
||||
- Device::Ports
|
||||
# - Device::Modules
|
||||
- Device::Modules
|
||||
- Device::Neighbors
|
||||
- Device::Addresses
|
||||
web_plugins_extra: []
|
||||
|
||||
63
Netdisco/share/public/css/bootstrap-tree.css
vendored
Normal file
63
Netdisco/share/public/css/bootstrap-tree.css
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
/* style for collapsable tree */
|
||||
|
||||
.tree {
|
||||
min-height:20px;
|
||||
padding:19px;
|
||||
margin-bottom:20px;
|
||||
background-color:#fbfbfb;
|
||||
border:1px solid #999;
|
||||
-webkit-border-radius:4px;
|
||||
-moz-border-radius:4px;
|
||||
border-radius:4px;
|
||||
-webkit-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05);
|
||||
-moz-box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05);
|
||||
box-shadow:inset 0 1px 1px rgba(0, 0, 0, 0.05)
|
||||
}
|
||||
.tree li {
|
||||
list-style-type:none;
|
||||
margin:0;
|
||||
padding:10px 5px 0 5px;
|
||||
position:relative
|
||||
}
|
||||
.tree li::before, .tree li::after {
|
||||
content:'';
|
||||
left:-20px;
|
||||
position:absolute;
|
||||
right:auto
|
||||
}
|
||||
.tree li::before {
|
||||
border-left:1px solid #999;
|
||||
bottom:50px;
|
||||
height:100%;
|
||||
top:0;
|
||||
width:1px
|
||||
}
|
||||
.tree li::after {
|
||||
border-top:1px solid #999;
|
||||
height:20px;
|
||||
top:25px;
|
||||
width:25px
|
||||
}
|
||||
.tree li span {
|
||||
-moz-border-radius:5px;
|
||||
-webkit-border-radius:5px;
|
||||
border:1px solid #999;
|
||||
border-radius:5px;
|
||||
display:inline-block;
|
||||
padding:3px 8px;
|
||||
text-decoration:none
|
||||
}
|
||||
.tree li.parent_li>span {
|
||||
cursor:pointer
|
||||
}
|
||||
.tree>ul>li::before, .tree>ul>li::after {
|
||||
border:0
|
||||
}
|
||||
.tree li:last-child::before {
|
||||
height:30px
|
||||
}
|
||||
.tree li.parent_li>span:hover, .tree li.parent_li>span:hover+ul li span {
|
||||
background:#eee;
|
||||
border:1px solid #94a0b4;
|
||||
color:#000
|
||||
}
|
||||
60
Netdisco/share/views/ajax/device/modules.tt
Normal file
60
Netdisco/share/views/ajax/device/modules.tt
Normal file
@@ -0,0 +1,60 @@
|
||||
[% BLOCK recurse -%]
|
||||
[% INCLUDE print_line item=item %]
|
||||
[% IF nodes.$item.children.defined -%]
|
||||
<ul>
|
||||
[% FOREACH kidtype IN nodes.$item.children.keys -%]
|
||||
[%- FOREACH kid IN nodes.$item.children.$kidtype -%]
|
||||
[%- IF kid -%]
|
||||
[% INCLUDE recurse item=kid %]
|
||||
[%- END -%]
|
||||
[%- END -%]
|
||||
[%- END -%]
|
||||
</ul>
|
||||
[% END -%]
|
||||
</li>
|
||||
[%- END -%]
|
||||
[% BLOCK print_line -%]
|
||||
<li>
|
||||
[% IF nodes.$item.children.defined -%]
|
||||
<span><i class="icon-minus-sign text-info"></i>
|
||||
[%- ELSE -%]
|
||||
<span><i class="icon-leaf"></i>
|
||||
[%- END -%]
|
||||
[% nodes.$item.module.description -%]
|
||||
[%- IF nodes.$item.module.name -%]
|
||||
([% nodes.$item.module.name %])
|
||||
[%- END -%]
|
||||
[%- IF nodes.$item.module.fw_ver -%]
|
||||
fw: [% nodes.$item.module.fw_ver %]
|
||||
[%- END -%]
|
||||
[%- IF nodes.$item.module.hw_ver -%]
|
||||
hw: [% nodes.$item.module.fw_ver %]
|
||||
[%- END -%]
|
||||
[%- IF nodes.$item.module.sw_ver -%]
|
||||
sw: [% nodes.$item.module.sw_ver %]
|
||||
[%- END -%]
|
||||
[%- IF nodes.$item.module.serial -%]
|
||||
[serial: [% nodes.$item.module.serial %]]
|
||||
[%- END -%]
|
||||
[%- IF nodes.$item.module.type -%]
|
||||
/ [% nodes.$item.module.type %]
|
||||
[%- END -%]
|
||||
[%- IF nodes.$item.module.model -%]
|
||||
/ [% nodes.$item.module.model %]
|
||||
[%- END -%]
|
||||
[%- IF nodes.$item.module.fru -%]
|
||||
<b>[FRU]</b>
|
||||
[%- END -%]
|
||||
</span>
|
||||
[%- END -%]
|
||||
<div class="tree">
|
||||
<ul>
|
||||
[% FOREACH module IN nodes.root %]
|
||||
[% INCLUDE recurse item=module %]
|
||||
[%- END -%]
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
[%+ INCLUDE 'js/bootstrap-tree.js' -%]
|
||||
</script>
|
||||
15
Netdisco/share/views/js/bootstrap-tree.js
vendored
Normal file
15
Netdisco/share/views/js/bootstrap-tree.js
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
$(document).ready(function() {
|
||||
$('.tree > ul').attr('role', 'tree').find('ul').attr('role', 'group');
|
||||
$('.tree').find('li:has(ul)').addClass('parent_li').attr('role', 'treeitem').find(' > span').attr('title', 'Collapse this branch').on('click', function (e) {
|
||||
var children = $(this).parent('li.parent_li').find(' > ul > li');
|
||||
if (children.is(':visible')) {
|
||||
children.hide('fast');
|
||||
$(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
|
||||
}
|
||||
else {
|
||||
children.show('fast');
|
||||
$(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
|
||||
}
|
||||
e.stopPropagation();
|
||||
});
|
||||
});
|
||||
@@ -43,6 +43,7 @@
|
||||
<link rel="stylesheet" href="[% uri_base %]/css/font-awesome.min.css"/>
|
||||
<link rel="stylesheet" href="[% uri_base %]/css/toastr.css"/>
|
||||
<link rel="stylesheet" href="[% uri_base %]/css/netdisco.css"/>
|
||||
<link rel="stylesheet" href="[% uri_base %]/css/bootstrap-tree.css"/>
|
||||
<link rel="stylesheet" href="[% uri_base %]/css/nd_print.css" media="print"/>
|
||||
|
||||
[% FOREACH add_css IN settings._additional_css %]
|
||||
|
||||
Reference in New Issue
Block a user