remove device/details
This commit is contained in:
		@@ -3,6 +3,8 @@ package App::Netdisco::Web::Plugin;
 | 
				
			|||||||
use Dancer ':syntax';
 | 
					use Dancer ':syntax';
 | 
				
			||||||
use Dancer::Plugin;
 | 
					use Dancer::Plugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					use App::Netdisco::Util::Web 'request_is_api';
 | 
				
			||||||
 | 
					use Dancer::Plugin::REST 'status_bad_request';
 | 
				
			||||||
use Path::Class 'dir';
 | 
					use Path::Class 'dir';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
set(
 | 
					set(
 | 
				
			||||||
@@ -23,6 +25,14 @@ set(
 | 
				
			|||||||
# this is what Dancer::Template::TemplateToolkit does by default
 | 
					# this is what Dancer::Template::TemplateToolkit does by default
 | 
				
			||||||
config->{engines}->{netdisco_template_toolkit}->{INCLUDE_PATH} ||= [ setting('views') ];
 | 
					config->{engines}->{netdisco_template_toolkit}->{INCLUDE_PATH} ||= [ setting('views') ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					register 'bang' => sub {
 | 
				
			||||||
 | 
					  if (request_is_api()) {
 | 
				
			||||||
 | 
					      content_type('application/json');
 | 
				
			||||||
 | 
					      status_bad_request(@_);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  else { send_error(@_)  }
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
register 'register_template_path' => sub {
 | 
					register 'register_template_path' => sub {
 | 
				
			||||||
  my ($self, $path) = plugin_args(@_);
 | 
					  my ($self, $path) = plugin_args(@_);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,6 @@
 | 
				
			|||||||
package App::Netdisco::Web::Plugin::Device::Details;
 | 
					package App::Netdisco::Web::Plugin::Device::Details;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
use Dancer ':syntax';
 | 
					use Dancer ':syntax';
 | 
				
			||||||
use Dancer::Plugin::Ajax;
 | 
					 | 
				
			||||||
use Dancer::Plugin::DBIC;
 | 
					use Dancer::Plugin::DBIC;
 | 
				
			||||||
use Dancer::Plugin::Auth::Extensible;
 | 
					use Dancer::Plugin::Auth::Extensible;
 | 
				
			||||||
use Dancer::Plugin::Swagger;
 | 
					use Dancer::Plugin::Swagger;
 | 
				
			||||||
@@ -10,23 +9,29 @@ use App::Netdisco::Web::Plugin;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
register_device_tab({ tag => 'details', label => 'Details' });
 | 
					register_device_tab({ tag => 'details', label => 'Details' });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# device details table
 | 
					# forward API call to AJAX route handler
 | 
				
			||||||
swagger_path {
 | 
					swagger_path {
 | 
				
			||||||
    description => 'Get properties and power details for a device.',
 | 
					    description => 'Get properties and power details for a device.',
 | 
				
			||||||
    path => '/api/device/{identifier}/details',
 | 
					 | 
				
			||||||
    tags => ['Devices'],
 | 
					    tags => ['Devices'],
 | 
				
			||||||
    parameters => [
 | 
					    parameters => [
 | 
				
			||||||
        { name => 'identifier', in => 'path', required => 1, type => 'string' },
 | 
					        identifier => {in => 'path', required => 1, type => 'string' },
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    responses => { default => { examples => {
 | 
					    responses => { default => { examples => {
 | 
				
			||||||
        # TODO document fields returned
 | 
					        # TODO document fields returned
 | 
				
			||||||
        'application/json' => { device => {}, power => {} },
 | 
					        'application/json' => { device => {} },
 | 
				
			||||||
    } } },
 | 
					    } } },
 | 
				
			||||||
},
 | 
					},
 | 
				
			||||||
 | 
					get '/api/device/:identifier' => require_login sub {
 | 
				
			||||||
 | 
					    vars->{'is_api'} = 1;
 | 
				
			||||||
 | 
					    forward '/ajax/content/device/details',
 | 
				
			||||||
 | 
					      { tab => 'details', q => params->{'identifier'} };
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# device details table
 | 
				
			||||||
get '/ajax/content/device/details' => require_login sub {
 | 
					get '/ajax/content/device/details' => require_login sub {
 | 
				
			||||||
    my $q = param('q');
 | 
					    my $q = param('q');
 | 
				
			||||||
    my $device = schema('netdisco')->resultset('Device')
 | 
					    my $device = schema('netdisco')->resultset('Device')
 | 
				
			||||||
      ->search_for_device($q) or send_error('Bad device', 400);
 | 
					      ->search_for_device($q) or return bang('Bad device', 400);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    my @results
 | 
					    my @results
 | 
				
			||||||
        = schema('netdisco')->resultset('Device')
 | 
					        = schema('netdisco')->resultset('Device')
 | 
				
			||||||
@@ -37,11 +42,12 @@ get '/ajax/content/device/details' => require_login sub {
 | 
				
			|||||||
        = schema('netdisco')->resultset('DevicePower')
 | 
					        = schema('netdisco')->resultset('DevicePower')
 | 
				
			||||||
        ->search( { 'me.ip' => $device->ip } )->with_poestats->hri->all;
 | 
					        ->search( { 'me.ip' => $device->ip } )->with_poestats->hri->all;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    delete $results[0]->{'snmp_comm'};
 | 
				
			||||||
 | 
					    $results[0]->{'power'} = \@power;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (vars->{'is_api'}) {
 | 
					    if (vars->{'is_api'}) {
 | 
				
			||||||
        content_type('application/json');
 | 
					        content_type('application/json');
 | 
				
			||||||
        # TODO merge power into device details
 | 
					        to_json { device => $results[0] };
 | 
				
			||||||
        # TODO remove sensitive data (community)
 | 
					 | 
				
			||||||
        to_json { device => $results[0], power => \@power };
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else {
 | 
					    else {
 | 
				
			||||||
        content_type('text/html');
 | 
					        content_type('text/html');
 | 
				
			||||||
@@ -51,4 +57,4 @@ get '/ajax/content/device/details' => require_login sub {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
1;
 | 
					true;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -92,10 +92,10 @@ web_plugins:
 | 
				
			|||||||
extra_web_plugins: []
 | 
					extra_web_plugins: []
 | 
				
			||||||
api_enabled:
 | 
					api_enabled:
 | 
				
			||||||
  device:
 | 
					  device:
 | 
				
			||||||
    details: true
 | 
					 | 
				
			||||||
    port: false
 | 
					    port: false
 | 
				
			||||||
    ports: false
 | 
					    ports: false
 | 
				
			||||||
    modules: false
 | 
					    modules: false
 | 
				
			||||||
 | 
					    neighbors: false
 | 
				
			||||||
    addresses: false
 | 
					    addresses: false
 | 
				
			||||||
    vlans: false
 | 
					    vlans: false
 | 
				
			||||||
  node: false
 | 
					  node: false
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user