diff --git a/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm b/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm index 2df25bb3..7356c4b0 100644 --- a/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm +++ b/Netdisco/lib/Netdisco/DB/Result/DevicePort.pm @@ -137,6 +137,17 @@ __PACKAGE__->belongs_to( neighbor_alias => 'Netdisco::DB::Result::DeviceIp', { join_type => 'LEFT' }, ); +=head2 power + +Returns a row from the C table if one refers to this +device port. + +=cut + +__PACKAGE__->might_have( power => 'Netdisco::DB::Result::DevicePortPower', { + 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port', +}); + =head2 port_vlans_tagged Returns a set of rows from the C table relating to this diff --git a/Netdisco/lib/Netdisco/DB/Result/DevicePortPower.pm b/Netdisco/lib/Netdisco/DB/Result/DevicePortPower.pm index 68a81758..7cad712f 100644 --- a/Netdisco/lib/Netdisco/DB/Result/DevicePortPower.pm +++ b/Netdisco/lib/Netdisco/DB/Result/DevicePortPower.pm @@ -31,6 +31,16 @@ __PACKAGE__->set_primary_key("port", "ip"); # Created by DBIx::Class::Schema::Loader v0.07015 @ 2012-01-07 14:20:02 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:sHcdItRUFUOAtIZQjdWbcg +=head1 RELATIONSHIPS + +=head2 port + +Returns the entry from the C table for which this Power entry applies. + +=cut + +__PACKAGE__->belongs_to( port => 'Netdisco::DB::Result::DevicePort', { + 'foreign.ip' => 'self.ip', 'foreign.port' => 'self.port', +}); -# You can replace this text with custom code or comments, and it will be preserved on regeneration 1; diff --git a/Netdisco/lib/Netdisco/Web/Device.pm b/Netdisco/lib/Netdisco/Web/Device.pm index 6e0c1f4f..3716da23 100644 --- a/Netdisco/lib/Netdisco/Web/Device.pm +++ b/Netdisco/lib/Netdisco/Web/Device.pm @@ -21,7 +21,8 @@ hook 'before' => sub { { name => 'c_mac', label => 'Port MAC', default => '' }, { name => 'c_mtu', label => 'MTU', default => '' }, { name => 'c_vlan', label => 'Native VLAN', default => 'on' }, - { name => 'c_vmember', label => 'VLAN Membership', default => 'on' }, + { name => 'c_vmember', label => 'Tagged VLANs', default => 'on' }, + { name => 'c_power', label => 'PoE', default => '' }, { name => 'c_nodes', label => 'Connected Nodes', default => '' }, { name => 'c_neighbors', label => 'Connected Devices', default => 'on' }, { name => 'c_stp', label => 'Spanning Tree', default => '' }, diff --git a/Netdisco/lib/Netdisco/Web/PortControl.pm b/Netdisco/lib/Netdisco/Web/PortControl.pm index 24dc4d74..f00c1b59 100644 --- a/Netdisco/lib/Netdisco/Web/PortControl.pm +++ b/Netdisco/lib/Netdisco/Web/PortControl.pm @@ -17,10 +17,11 @@ ajax '/ajax/portcontrol' => sub { 'c_port' => 'portcontrol', 'c_name' => 'portname', 'c_vlan' => 'vlan', + 'c_power' => 'power', ); my $action = $action_map{ param('field') }; - my $subaction = ($action eq 'portcontrol' + my $subaction = ($action =~ m/^(?:power|portcontrol)/ ? (param('action') ."-other") : param('value')); diff --git a/Netdisco/public/css/netdisco.css b/Netdisco/public/css/netdisco.css index f3535691..654ddf30 100644 --- a/Netdisco/public/css/netdisco.css +++ b/Netdisco/public/css/netdisco.css @@ -100,6 +100,19 @@ body { display: none; } +.nd_power_icon { + cursor: pointer; +} + +.icon-off { + vertical-align: middle; + color: darkRed; +} + +.nd_power_on { + color: darkGreen; +} + /* placement of port link when port admin hint is enabled */ .nd_editable_cell > .nd_this_port_only { margin-left: 18px; diff --git a/Netdisco/public/javascripts/netdisco_portcontrol.js b/Netdisco/public/javascripts/netdisco_portcontrol.js index 145db5fc..f4ffb062 100644 --- a/Netdisco/public/javascripts/netdisco_portcontrol.js +++ b/Netdisco/public/javascripts/netdisco_portcontrol.js @@ -1,6 +1,6 @@ // user clicked or asked for port changes to be submitted via ajax function port_control (e) { - var td = $(e).closest('.nd_editable_cell'); + var td = $(e).closest('td'); $.ajax({ type: 'POST' @@ -30,6 +30,17 @@ function port_control (e) { $(e).data('tooltip').options.title = 'Click to Disable'; td.attr('data-action', 'down'); } + else if ($.trim(td.attr('data-action')) == 'false') { + $(e).next('span').text(''); + $(e).toggleClass('nd_power_on'); + $(e).data('tooltip').options.title = 'Click to Enable'; + td.attr('data-action', 'true'); + } + else if ($.trim(td.attr('data-action')) == 'true') { + $(e).toggleClass('nd_power_on'); + $(e).data('tooltip').options.title = 'Click to Disable'; + td.attr('data-action', 'false'); + } } ,error: function() { toastr.error('Failed to submit change request'); diff --git a/Netdisco/views/ajax/device/ports.tt b/Netdisco/views/ajax/device/ports.tt index a4dd534f..3e407d53 100644 --- a/Netdisco/views/ajax/device/ports.tt +++ b/Netdisco/views/ajax/device/ports.tt @@ -71,11 +71,11 @@ [% IF params.c_name %] [% IF vars.user.port_control AND params.c_admin %] - [% ELSE %] - + [% END %]
[% row.name | html_entity %] @@ -135,6 +135,48 @@ [% END %] + [% IF params.c_power %] + [% IF row.power %] + [% IF row.power.admin == 'true' %] + [% IF vars.user.port_control AND params.c_admin %] + + + + [% ELSE %] + + + [% END %] + + [% IF row.power.power > 0 %] + [% row.power.power %] mW + [% ELSE %] + ([% row.power.status %]) + [% END %] + + [% ELSE %] + [% IF vars.user.port_control AND params.c_admin %] + + + + [% ELSE %] + + + [% END %] + [% END %] + + [% ELSE %] + + [% END %] + [% END %] + [% IF params.c_nodes OR params.c_neighbors %] [% IF params.c_neighbors AND row.remote_ip %] diff --git a/Netdisco/views/js/device.js b/Netdisco/views/js/device.js index 174abdd9..354a6d1f 100644 --- a/Netdisco/views/js/device.js +++ b/Netdisco/views/js/device.js @@ -52,6 +52,11 @@ port_control(this); // save }); + // activity for power enable/disable control + $('.nd_power_icon').click(function() { + port_control(this); // save + }); + var dirty = false; // activity for contenteditable control