implement port control
This commit is contained in:
3
Changes
3
Changes
@@ -1,7 +1,8 @@
|
|||||||
0.7 -
|
0.7 - 2012-11-25
|
||||||
|
|
||||||
[NEW FEATURES]
|
[NEW FEATURES]
|
||||||
|
|
||||||
|
* Add Port Control (admin table) features
|
||||||
* Implement DBIx::Class::Schema::Versioned support - DB schema is now versioned
|
* Implement DBIx::Class::Schema::Versioned support - DB schema is now versioned
|
||||||
* Navbar query for device with single hit redirects to Device details page
|
* Navbar query for device with single hit redirects to Device details page
|
||||||
* Show device name on device details views (closes #30)
|
* Show device name on device details views (closes #30)
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ use URI::QueryParam (); # part of URI, to add helper methods
|
|||||||
use Netdisco::Web::AuthN;
|
use Netdisco::Web::AuthN;
|
||||||
use Netdisco::Web::Search;
|
use Netdisco::Web::Search;
|
||||||
use Netdisco::Web::Device;
|
use Netdisco::Web::Device;
|
||||||
|
use Netdisco::Web::PortControl;
|
||||||
use Netdisco::Web::Inventory;
|
use Netdisco::Web::Inventory;
|
||||||
|
|
||||||
hook 'before_template' => sub {
|
hook 'before_template' => sub {
|
||||||
|
|||||||
65
Netdisco/lib/Netdisco/Web/PortControl.pm
Normal file
65
Netdisco/lib/Netdisco/Web/PortControl.pm
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package Netdisco::Web::PortControl;
|
||||||
|
|
||||||
|
use Dancer ':syntax';
|
||||||
|
use Dancer::Plugin::Ajax;
|
||||||
|
use Dancer::Plugin::DBIC;
|
||||||
|
use Try::Tiny;
|
||||||
|
|
||||||
|
ajax '/ajax/portcontrol' => sub {
|
||||||
|
try {
|
||||||
|
my $log = sprintf 'd:[%s] p:[%s] f:[%s]. a:[%s] v[%s]',
|
||||||
|
param('device'), (param('port') || ''), param('field'),
|
||||||
|
(param('action') || ''), (param('value') || '');
|
||||||
|
|
||||||
|
my %action_map = (
|
||||||
|
'location' => 'location',
|
||||||
|
'contact' => 'contact',
|
||||||
|
'c_port' => 'portcontrol',
|
||||||
|
'c_name' => 'portname',
|
||||||
|
'c_vlan' => 'vlan',
|
||||||
|
);
|
||||||
|
|
||||||
|
my $action = $action_map{ param('field') };
|
||||||
|
my $subaction = ($action eq 'portcontrol'
|
||||||
|
? (param('action') ."-other")
|
||||||
|
: param('value'));
|
||||||
|
|
||||||
|
schema('netdisco')->resultset('Admin')->create({
|
||||||
|
device => param('device'),
|
||||||
|
port => param('port'),
|
||||||
|
action => $action,
|
||||||
|
subaction => $subaction,
|
||||||
|
status => 'queued',
|
||||||
|
username => session('user'),
|
||||||
|
userip => request->remote_address,
|
||||||
|
log => $log,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
send_error('Failed to parse params or add DB record');
|
||||||
|
};
|
||||||
|
|
||||||
|
content_type('application/json');
|
||||||
|
to_json({});
|
||||||
|
};
|
||||||
|
|
||||||
|
ajax '/ajax/userlog' => sub {
|
||||||
|
my $user = session('user');
|
||||||
|
send_error('No username') unless $user;
|
||||||
|
|
||||||
|
my $rs = schema('netdisco')->resultset('Admin')->search({
|
||||||
|
username => $user,
|
||||||
|
action => [qw/portcontrol vlan location/],
|
||||||
|
finished => { '>' => \"(now() - interval '5 seconds')" },
|
||||||
|
});
|
||||||
|
|
||||||
|
my %status = (
|
||||||
|
'done' => $rs->search({status => 'done'})->count(),
|
||||||
|
'error' => $rs->search({status => 'error'})->count(),
|
||||||
|
);
|
||||||
|
|
||||||
|
content_type('application/json');
|
||||||
|
to_json(\%status);
|
||||||
|
};
|
||||||
|
|
||||||
|
true;
|
||||||
@@ -16,7 +16,9 @@ function port_control (e) {
|
|||||||
toastr.info('Submitted change request');
|
toastr.info('Submitted change request');
|
||||||
}
|
}
|
||||||
,error: function() {
|
,error: function() {
|
||||||
toastr.error('Failed to submit change request')
|
toastr.error('Failed to submit change request');
|
||||||
|
document.execCommand('undo');
|
||||||
|
$(e).blur();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -26,6 +28,22 @@ function port_control (e) {
|
|||||||
$.ajax({
|
$.ajax({
|
||||||
url: uri_base + '/ajax/userlog'
|
url: uri_base + '/ajax/userlog'
|
||||||
,success: function(data) {
|
,success: function(data) {
|
||||||
|
// console.log(data);
|
||||||
|
|
||||||
|
if (data['error'] == 1 ) {
|
||||||
|
toastr.error('1 recent failed change request');
|
||||||
|
}
|
||||||
|
else if (data['error'] > 1) {
|
||||||
|
toastr.error(data['error'] + ' recent failed change requests');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data['done'] == 1 ) {
|
||||||
|
toastr.success('1 recent successful change request');
|
||||||
|
}
|
||||||
|
else if (data['done'] > 1) {
|
||||||
|
toastr.success(data['done'] + ' recent successful change requests');
|
||||||
|
}
|
||||||
|
|
||||||
// Schedule next request when the current one's complete
|
// Schedule next request when the current one's complete
|
||||||
setTimeout(worker, 5000);
|
setTimeout(worker, 5000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,8 +62,8 @@
|
|||||||
|
|
||||||
}
|
}
|
||||||
else if (nl) {
|
else if (nl) {
|
||||||
event.preventDefault();
|
|
||||||
$(this).blur();
|
$(this).blur();
|
||||||
|
event.preventDefault();
|
||||||
dirty = false;
|
dirty = false;
|
||||||
port_control(this); // save
|
port_control(this); // save
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user