diff --git a/Netdisco/Changes b/Netdisco/Changes index 8446a7e8..5f31ea11 100644 --- a/Netdisco/Changes +++ b/Netdisco/Changes @@ -8,6 +8,7 @@ * [#31] get_community now supported * [#19] Ask for Reason when changing Port up/down Status, or VLAN * [#30] Support for expire_devices, expire_nodes, and expire_nodes_archive + * Port Log viewable via an icon by device port name (Port Control rights req'd) [ENHANCEMENTS] diff --git a/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod b/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod index 4fe1723a..5fa90d92 100644 --- a/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod +++ b/Netdisco/lib/App/Netdisco/Manual/WritingPlugins.pod @@ -218,6 +218,16 @@ Note that this won't work for any target link - the path must be an App::Netdisco Dancer route handler. Please bug the App::Netdisco devs if you want arbitrary links supported. +An additional feature allows you to create Admin Tasks which do not appear in +the Navbar menu. This is useful if the page is only linked directly from +another (for example Port Log). To enable this feature add the C key: + + register_admin_task({ + tag => 'newfeature', + label => 'My New Feature', + hidden => true, + }); + =head1 Device Port Columns You can also add columns to the Device Ports page. The canonical example of diff --git a/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PortLog.pm b/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PortLog.pm new file mode 100644 index 00000000..b95b9732 --- /dev/null +++ b/Netdisco/lib/App/Netdisco/Web/Plugin/AdminTask/PortLog.pm @@ -0,0 +1,39 @@ +package App::Netdisco::Web::Plugin::AdminTask::PortLog; + +use Dancer ':syntax'; +use Dancer::Plugin::Ajax; +use Dancer::Plugin::DBIC; +use Dancer::Plugin::Auth::Extensible; + +use App::Netdisco::Web::Plugin; + +register_admin_task({ + tag => 'portlog', + label => 'Port Control Log', + hidden => true, +}); + +ajax '/ajax/content/admin/portlog' => require_role admin => sub { + my $device = param('q'); + my $port = param('f'); + send_error('Bad Request', 400) unless $device and $port; + + $device = schema('netdisco')->resultset('Device') + ->search_for_device($device); + return unless $device; + + my $set = schema('netdisco')->resultset('DevicePortLog')->search({ + ip => $device->ip, + port => $port, + }, { + order_by => { -desc => [qw/creation/] }, + rows => 200, + }); + + content_type('text/html'); + template 'ajax/admintask/portlog.tt', { + results => $set, + }, { layout => undef }; +}; + +true; diff --git a/Netdisco/share/public/css/netdisco.css b/Netdisco/share/public/css/netdisco.css index 8a74ab41..82d42b1f 100644 --- a/Netdisco/share/public/css/netdisco.css +++ b/Netdisco/share/public/css/netdisco.css @@ -251,10 +251,23 @@ td > form.nd_inline-form { /* port admin up/down control */ .nd_edit-icon, .nd_hand-icon { cursor: pointer; + float: right; + display: none; + margin-top: 3px; +} + +/* port admin log view */ +.nd_log-icon { + cursor: pointer; + color: black; float: left; display: none; margin-top: 3px; } +.nd_log-icon:hover, .nd_log-icon:focus { + text-decoration: none; + color: black; +} /* port power control */ .nd_power-icon { diff --git a/Netdisco/share/public/javascripts/netdisco_portcontrol.js b/Netdisco/share/public/javascripts/netdisco_portcontrol.js index eeab2485..5e8a60db 100644 --- a/Netdisco/share/public/javascripts/netdisco_portcontrol.js +++ b/Netdisco/share/public/javascripts/netdisco_portcontrol.js @@ -92,14 +92,14 @@ $(document).ready(function() { // toggle visibility of port up/down and edit controls $('.tab-content').on('mouseenter', '.nd_editable-cell', function() { - $(this).children('.nd_hand-icon').show(); + $(this).children('.nd_hand-icon,.nd_log-icon').show(); if (! $(this).is(':focus')) { $(this).children('.nd_edit-icon').show(); // ports $(this).siblings('td').find('.nd_device-details-edit').show(); // details } }); $('.tab-content').on('mouseleave', '.nd_editable-cell', function() { - $(this).children('.nd_hand-icon').hide(); + $(this).children('.nd_hand-icon,.nd_log-icon').hide(); if (! $(this).is(':focus')) { $(this).children('.nd_edit-icon').hide(); // ports $(this).siblings('td').find('.nd_device-details-edit').hide(); // details diff --git a/Netdisco/share/views/admintask.tt b/Netdisco/share/views/admintask.tt index a7e447e9..d6eb0ae9 100644 --- a/Netdisco/share/views/admintask.tt +++ b/Netdisco/share/views/admintask.tt @@ -13,8 +13,8 @@
[% TRY %] - [% INCLUDE "sidebar/admintask/${task.tag}.tt" %] + [% INCLUDE "sidebar/admintask/${task.tag}.tt" %] [% CATCH %] [% END %] @@ -40,6 +40,12 @@ + [% ELSIF task.tag == 'portlog' %] + + [% params.q %] + - + [% params.f %] + [% ELSIF task.provides_csv %] diff --git a/Netdisco/share/views/ajax/admintask/performance.tt b/Netdisco/share/views/ajax/admintask/performance.tt index 6abdb8e4..675d62cd 100644 --- a/Netdisco/share/views/ajax/admintask/performance.tt +++ b/Netdisco/share/views/ajax/admintask/performance.tt @@ -1,5 +1,5 @@ [% IF results.count == 0 %] -
The aren't enough jobs to report.
+
The aren't enough jobs to report.
[% ELSE %] diff --git a/Netdisco/share/views/ajax/admintask/portlog.tt b/Netdisco/share/views/ajax/admintask/portlog.tt new file mode 100644 index 00000000..618e9622 --- /dev/null +++ b/Netdisco/share/views/ajax/admintask/portlog.tt @@ -0,0 +1,29 @@ +[% IF results.count == 0 %] +
This port's log is empty.
+[% ELSE %] +
+ + + + + + + + + + + + [% WHILE (row = results.next) %] + + + + + + + + + [% END %] + +
CreationUserUser IPActionReasonLog
[% row.creation | html_entity %][% row.username | html_entity %][% row.userip | html_entity %][% row.action | html_entity %][% settings.port_control_reasons.item(row.reason) || row.reason | html_entity %][% row.log || '-' | html_entity %]
+[% END %] + diff --git a/Netdisco/share/views/ajax/device/ports.tt b/Netdisco/share/views/ajax/device/ports.tt index f4075bb5..47294d7e 100644 --- a/Netdisco/share/views/ajax/device/ports.tt +++ b/Netdisco/share/views/ajax/device/ports.tt @@ -57,6 +57,12 @@ rel="tooltip" data-placement="top" data-offset="3" data-animation="" data-title="Click to Enable"> [% END %] +
+ + [% ELSE %] [% END %] diff --git a/Netdisco/share/views/layouts/main.tt b/Netdisco/share/views/layouts/main.tt index 0dd95f64..6dee8dca 100644 --- a/Netdisco/share/views/layouts/main.tt +++ b/Netdisco/share/views/layouts/main.tt @@ -105,6 +105,7 @@ [% IF settings._admin_tasks.size %]
  • [% FOREACH ai IN settings._admin_tasks.keys.sort %] + [% NEXT IF settings._admin_tasks.$ai.hidden %]
  • [% settings._admin_tasks.$ai.label | html_entity %]
  • [% END %] [% END %] diff --git a/Netdisco/share/views/sidebar/admintask/portlog.tt b/Netdisco/share/views/sidebar/admintask/portlog.tt new file mode 100644 index 00000000..bbc2f661 --- /dev/null +++ b/Netdisco/share/views/sidebar/admintask/portlog.tt @@ -0,0 +1,5 @@ + + + + +