Port Log now viewable via an icon by device port name

This commit is contained in:
Oliver Gorwits
2013-12-29 21:28:48 +00:00
parent 7749082dfd
commit a2cc3f989e
11 changed files with 114 additions and 4 deletions

View File

@@ -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]

View File

@@ -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<hidden> 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

View File

@@ -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;

View File

@@ -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 {

View File

@@ -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

View File

@@ -13,8 +13,8 @@
<form id="[% task.tag %]_form" class="nd_sidebar-form form-stacked"
method="get" action="[% uri_for('/admin') %]">
[% TRY %]
[% INCLUDE "sidebar/admintask/${task.tag}.tt" %]
<script type="text/javascript">has_sidebar["[% task.tag %]"] = 1;</script>
[% INCLUDE "sidebar/admintask/${task.tag}.tt" %]
[% CATCH %]
<script type="text/javascript">has_sidebar["[% task.tag %]"] = 0;</script>
[% END %]
@@ -40,6 +40,12 @@
<span id="nd_device-name">
<a class="nd_adminbutton" name="delall" href="#"><i class="icon-trash text-error"></i></a>
</span>
[% ELSIF task.tag == 'portlog' %]
<span id="nd_device-name">
<a href="[% device_ports %]&q=[% params.q | uri %]&c_admin=on">[% params.q %]</a>
-
<a href="[% device_ports %]&q=[% params.q | uri %]&f=[% params.f | uri %]&c_admin=on">[% params.f %]</a>
</span>
[% ELSIF task.provides_csv %]
<span id="nd_device-name">
<a id="nd_csv-download" href="#" download="netdisco.csv">

View File

@@ -1,5 +1,5 @@
[% IF results.count == 0 %]
<div class="span2 alert alert-info">The aren't enough jobs to report.</div>
<div class="span3 alert alert-info">The aren't enough jobs to report.</div>
[% ELSE %]
<table class="table table-bordered table-condensed table-hover nd_floatinghead">
<thead>

View File

@@ -0,0 +1,29 @@
[% IF results.count == 0 %]
<div class="span2 alert alert-info">This port's log is empty.</div>
[% ELSE %]
<table class="table table-bordered table-condensed table-hover nd_floatinghead">
<thead>
<tr>
<th class="nd_center-cell">Creation</th>
<th class="nd_center-cell">User</th>
<th class="nd_center-cell">User IP</th>
<th class="nd_center-cell">Action</th>
<th class="nd_center-cell">Reason</th>
<th class="nd_center-cell">Log</th>
</tr>
</thead>
</tbody>
[% WHILE (row = results.next) %]
<tr>
<td class="nd_center-cell">[% row.creation | html_entity %]</td>
<td class="nd_center-cell">[% row.username | html_entity %]</td>
<td class="nd_center-cell">[% row.userip | html_entity %]</td>
<td class="nd_center-cell">[% row.action | html_entity %]</td>
<td class="nd_center-cell">[% settings.port_control_reasons.item(row.reason) || row.reason | html_entity %]</td>
<td class="nd_center-cell">[% row.log || '-' | html_entity %]</td>
</tr>
[% END %]
</tbody>
</table>
[% END %]

View File

@@ -57,6 +57,12 @@
rel="tooltip" data-placement="top" data-offset="3"
data-animation="" data-title="Click to Enable"></i>
[% END %]
<a class="nd_log-icon"
href="[% uri_for('/admin/portlog') %]?q=[% device.dns || device.ip | uri %]&f=[% row.port | uri %]">
<i class="icon-file-text-alt"
rel="tooltip" data-placement="top" data-offset="3"
data-animation="" data-title="View Port Log"></i>
</a>
[% ELSE %]
<td nowrap>
[% END %]

View File

@@ -105,6 +105,7 @@
[% IF settings._admin_tasks.size %]
<li class="divider"></li>
[% FOREACH ai IN settings._admin_tasks.keys.sort %]
[% NEXT IF settings._admin_tasks.$ai.hidden %]
<li><a href="[% uri_for('/admin/' _ ai) %]">[% settings._admin_tasks.$ai.label | html_entity %]</a></li>
[% END %]
[% END %]

View File

@@ -0,0 +1,5 @@
<input name="q" value="[% params.q | html_entity %]" type="hidden"/>
<input name="f" value="[% params.f | html_entity %]" type="hidden"/>
<script type="text/javascript">has_sidebar["portlog"] = 0;</script>