Skip to content
This repository has been archived by the owner on Nov 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #890 from dewrich/issue/859
Browse files Browse the repository at this point in the history
Solves #859 Traffic Ops hardware Tab fails to populate when there are too many rows returned
  • Loading branch information
dangogh committed Dec 23, 2015
2 parents 21061c7 + 2d9a7b6 commit 790f780
Show file tree
Hide file tree
Showing 10 changed files with 15,154 additions and 49 deletions.
78 changes: 78 additions & 0 deletions traffic_ops/app/lib/API/HwInfo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,82 @@ sub index {
$self->success( \@data, undef, $limit, undef );
}

sub data {
my $self = shift;
my $idisplay_start = $self->param("iDisplayStart");
my $sort_order = $self->param("sSortDir_0") || "asc";
my $search_field = $self->param("sSearch");
my $sort_column = $self->param("iSortCol_0");

# NOTE: If changes are made to send additional columns then this mapping has to be updated
# to match the Column Number coming from datatables to it's name
# Unfortunately, this is a short coming with the jquery datatables ui widget in that it expects
# an array arrays instead of an array of hashes
my $sort_direction = sprintf( "-%s", $sort_order );
my @column_number_to_name = qw{ serverid.host_name description val last_updated };
my $column_name = $column_number_to_name[ $sort_column - 1 ] || "serverid";

my $idisplay_length = $self->param("iDisplayLength");

my %data = ( "data" => [] );
my $rs;

my %condition;
my %attrs;
my %limit;

#if (search_field eq ''){
%condition = (
-or => {
'me.description' => { -like => '%' . $search_field . '%' },
'me.val' => { -like => '%' . $search_field . '%' },
'serverid.host_name' => { -like => '%' . $search_field . '%' }
}
);

#} else {
#}
%limit = ( order_by => { $sort_direction => $column_name }, page => $idisplay_start, rows => $idisplay_length );
%attrs = ( attrs => [ { 'serverid' => undef } ], join => 'serverid', %limit );

# Original
#$rs = $self->db->resultset('Hwinfo')->search( undef, { attrs => ['serverid'] } );
$rs = $self->db->resultset('Hwinfo')->search( \%condition, \%attrs );

while ( my $row = $rs->next ) {
my @line = [ $row->serverid->id, $row->serverid->host_name . "." . $row->serverid->domain_name, $row->description, $row->val, $row->last_updated ];
push( @{ $data{'data'} }, @line );
}
my $total_display_records = 0;
if ( defined( $data{"data"} ) ) {
$total_display_records = scalar keys $data{"data"};
}
my %itotals_display_records = ( iTotalRecords => $total_display_records );
%data = %{ merge( \%data, \%itotals_display_records ) };

# Count all records
if ( $search_field eq '' ) {
$rs = $self->db->resultset('Hwinfo')->search();
}
else {
$rs = $self->db->resultset('Hwinfo')->search(
{
-or => {
'me.description' => { -like => '%' . $search_field . '%' },
'me.val' => { -like => '%' . $search_field . '%' },
'serverid.host_name' => { -like => '%' . $search_field . '%' }
}
},
{ page => $idisplay_start, prefetch => [ { 'serverid' => undef } ], join => 'serverid' },
);

}

my $total_records = $rs->count;
my %itotal_records = ( iTotalDisplayRecords => $total_records );
%data = %{ merge( \%data, \%itotal_records ) };

$self->render( json => \%data );
}

1;
18 changes: 18 additions & 0 deletions traffic_ops/app/lib/Fixtures/Hwinfo.pm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ my %definition_for = (
val => 'Beetle',
},
},
hw6 => {
new => 'Hwinfo',
using => {
id => 6,
serverid => 3,
description => 'Manufacturer',
val => 'Ferrari',
},
},
hw6 => {
new => 'Hwinfo',
using => {
id => 7,
serverid => 3,
description => 'Model',
val => 'Spider',
},
},
);

sub get_definition {
Expand Down
1 change: 1 addition & 0 deletions traffic_ops/app/lib/TrafficOpsRoutes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ sub api_routes {

# -- HWINFO - #NEW
# Supports: ?orderby=key
$r->get( "/api/$version/hwinfo/dtdata" => [ format => [qw(json)] ] )->over( authenticated => 1 )->to( 'HwInfo#data', namespace => $namespace );
$r->get("/api/$version/hwinfo")->over( authenticated => 1 )->to( 'HwInfo#index', namespace => $namespace );

# -- KEYS
Expand Down
91 changes: 67 additions & 24 deletions traffic_ops/app/lib/UI/Cdn.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use Data::Dumper;
use UI::ConfigFiles;
use Date::Manip;
use JSON;
use Hash::Merge qw(merge);
use String::CamelCase qw(decamelize);

# Yes or no
Expand Down Expand Up @@ -438,30 +439,72 @@ sub adeliveryservice {
$self->render( json => \%data );
}

sub ahwinfo {
my $self = shift;
my $limit = $self->param("limit");
my $orderby = $self->param('orderby') || "hostName";
my $orderby_snakecase = lcfirst( decamelize($orderby) );
my %data = ( "aaData" => undef );
<<<< <<< HEAD
sub hwinfo {
my $self = shift;
my $idisplay_start = $self->param("iDisplayStart") || 0;
my $sort_order = $self->param("sSortDir_0") || "asc";
my $search_field = $self->param("sSearch") || '';
my $sort_column = $self->param("iSortCol_0") || "id";
my $echo = $self->param("sEcho");
# NOTE: If changes are made to send additional columns then this mapping has to be updated
# to match the Column Number coming from datatables to it's name
# Unfortunately, this is a short coming with the jquery datatables ui widget in that it expects
# an array arrays instead of an array of hashes
my $sort_direction = sprintf( "-%s", $sort_order );
my @column_number_to_name = qw{ serverid.host_name description val last_updated };
my $column_name = $column_number_to_name[ $sort_column - 1 ] || "serverid";
my $idisplay_length = $self->param("iDisplayLength") || 10;
my %data = ( "data" => [] );
my %condition;
my %attrs;
my %nolimit;
my %nolimit_attrs;
%condition = (
-or => {
'me.description' => { -like => '%' . $search_field . '%' },
'me.val' => { -like => '%' . $search_field . '%' },
'serverid.host_name' => { -like => '%' . $search_field . '%' }
}
);
my $total_count = $self->db->resultset('Hwinfo')->search()->count();
my $filtered_count;
my $dbh;
if ( $search_field eq '' ) {
# if no filtering has occurred obviouslly these would be equal
$filtered_count = $total_count;
}
else {
# Now count the filtered records
my %filtered_attrs = ( attrs => [ { 'serverid' => undef } ], join => 'serverid', undef );
my $filtered = $self->db->resultset('Hwinfo')->search( \%condition, \%filtered_attrs );
$filtered_count = $filtered->count();
}
my $page = $idisplay_start + 1;
my $rs;
if ( defined( $self->param('filter') )
&& defined( $self->param('value') )
&& $self->param('value') ne "all" )
{
my $col = $self->param('filter');
my $val = $self->param('value');
$rs = $self->db->resultset('Hwinfo')->search( { $col => $val }, { prefetch => ['serverid'], order_by => 'me.' . $orderby_snakecase } );
}
else {
$rs = $self->db->resultset('Hwinfo')->search( undef, { prefetch => ['serverid'] } );
}
while ( my $row = $rs->next ) {
my @line = [ $row->serverid->id, $row->serverid->host_name . "." . $row->serverid->domain_name, $row->description, $row->val, $row->last_updated ];
push( @{ $data{'aaData'} }, @line );
}
$self->render( json => \%data );
#my %limit = ( page => 100, rows => 100, order_by => { $sort_direction => $column_name } );
my %limit = ( offset => $idisplay_start, rows => $idisplay_length, order_by => { $sort_direction => $column_name } );
%attrs = ( attrs => [ { 'serverid' => undef } ], join => 'serverid', %limit );
$dbh = $self->db->resultset('Hwinfo')->search( \%condition, \%attrs );
# Now load up the rows
while ( my $row = $dbh->next ) {
my @line = [ $row->serverid->id, $row->serverid->host_name . "." . $row->serverid->domain_name, $row->description, $row->val, $row->last_updated ];
push( @{ $data{'data'} }, @line );
}
%data = %{ merge( \%data, { recordsTotal => $total_count } ) };
%data = %{ merge( \%data, { recordsFiltered => $filtered_count } ) };
$self->render( json => \%data );
}
sub ajob {
Expand Down Expand Up @@ -691,7 +734,7 @@ sub aadata {
&adeliveryservice($self);
}
elsif ( $table eq 'Hwinfo' ) {
&ahwinfo($self);
&hwinfo($self);
}
elsif ( $table eq 'Federation' ) {
&afederation($self);
Expand Down
126 changes: 126 additions & 0 deletions traffic_ops/app/public/css/datatables.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
.dataTables_wrapper .dataTables_paginate {
float: right;
text-align: right;
padding-top: 0.25em;
padding-bottom: 0.25em;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
box-sizing: border-box;
display: inline-block;
min-width: 1.5em;
padding: 0.5em 1em;
margin-left: 2px;
text-align: center;
text-decoration: none !important;
cursor: pointer;
*cursor: hand;
color: #333 !important;
border: 1px solid transparent;
border-radius: 2px
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
color: #333 !important;
border: 1px solid #979797;
background-color: white;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #fff), color-stop(100%, #dcdcdc));
background: -webkit-linear-gradient(top, #fff 0%, #dcdcdc 100%);
background: -moz-linear-gradient(top, #fff 0%, #dcdcdc 100%);
background: -ms-linear-gradient(top, #fff 0%, #dcdcdc 100%);
background: -o-linear-gradient(top, #fff 0%, #dcdcdc 100%);
background: linear-gradient(to bottom, #fff 0%, #dcdcdc 100%)
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:active {
cursor: default;
color: #666 !important;
border: 1px solid transparent;
background: transparent;
box-shadow: none
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover {
color: white !important;
border: 1px solid #111;
background-color: #585858;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #585858), color-stop(100%, #111));
background: -webkit-linear-gradient(top, #585858 0%, #111 100%);
background: -moz-linear-gradient(top, #585858 0%, #111 100%);
background: -ms-linear-gradient(top, #585858 0%, #111 100%);
background: -o-linear-gradient(top, #585858 0%, #111 100%);
background: linear-gradient(to bottom, #585858 0%, #111 100%)
}
.dataTables_wrapper .dataTables_paginate .paginate_button:active {
outline: none;
background-color: #2b2b2b;
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%, #2b2b2b), color-stop(100%, #0c0c0c));
background: -webkit-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%);
background: -moz-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%);
background: -ms-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%);
background: -o-linear-gradient(top, #2b2b2b 0%, #0c0c0c 100%);
background: linear-gradient(to bottom, #2b2b2b 0%, #0c0c0c 100%);
box-shadow: inset 0 0 3px #111
}
.dataTables_wrapper .dataTables_paginate {
color: white;
}
.dataTables_wrapper .dataTables_processing {
position: absolute;
top: 50%;
left: 50%;
width: 100%;
height: 40px;
margin-left: -50%;
margin-top: -25px;
padding-top: 20px;
text-align: center;
font-size: 1.2em;
background-color: white;
background: -webkit-gradient(linear, left top, right top, color-stop(0%, rgba(255, 255, 255, 0)), color-stop(25%, rgba(255, 255, 255, 0.9)), color-stop(75%, rgba(255, 255, 255, 0.9)), color-stop(100%, rgba(255, 255, 255, 0)));
background: -webkit-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%);
background: -moz-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%);
background: -ms-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%);
background: -o-linear-gradient(left, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%);
background: linear-gradient(to right, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.9) 25%, rgba(255, 255, 255, 0.9) 75%, rgba(255, 255, 255, 0) 100%)
}
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_processing{
margin-top: 10px;
}
.dataTables_wrapper:after {
visibility: hidden;
display: block;
content: "";
clear: both;
height: 0
}
@media screen and (max-width: 767px) {
.dataTables_wrapper .dataTables_paginate {
float: none;
text-align: center
}
.dataTables_wrapper .dataTables_paginate {
margin-top: 0.5em
}
}
@media screen and (max-width: 640px) {
.dataTables_wrapper .dataTables_filter {
float: none;
text-align: center
}
.dataTables_wrapper .dataTables_filter {
margin-top: 0.5em
}
}

.dataTables_paginate .fg-button {
padding: 1em;
margin: 2px;
border-radius: 5px
}

.dataTables_info {
margin-left: 10px;
margin-top: 10px;
float:left;
}
Loading

0 comments on commit 790f780

Please sign in to comment.