Skip to content

Commit

Permalink
Merge branch 'development' into generic_attrs_editable
Browse files Browse the repository at this point in the history
  • Loading branch information
lomky committed Jan 10, 2018
2 parents 1c54929 + 696617c commit 9f7cdb5
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 75 deletions.
1 change: 1 addition & 0 deletions lib/Tuba/Controller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1538,6 +1538,7 @@ sub page {
sub per_page {
my $c = shift;
return undef if $c->param('all');
return $c->param('per_page') if $c->param('per_page');
return 24 if $c->param('thumbs');
return 20;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Tuba/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use Tuba::DB::Objects qw/-nicknames/;
sub list {
my $c = shift;
return $c->reply->not_found;
$c->stash(objects => Files->get_objects(with_objects => 'publications', page => $c->page));
$c->stash(objects => Files->get_objects(with_objects => 'publications', page => $c->page, per_page => $c->per_page));
my $count = Files->get_objects_count;
$c->set_pages($count);
$c->SUPER::list(@_);
Expand Down
2 changes: 1 addition & 1 deletion lib/Tuba/Finding.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ sub list {
my $meta = Finding->meta;
my $report_identifier = $c->stash('report_identifier');
my $all = $c->param('all');
my @page = $all ? () : (page => $c->page);
my @page = $all ? () : (page => $c->page, per_page => $c->per_page);

if (my $chapter = $c->stash('chapter')) {
$objects = Findings->get_objects(
Expand Down
2 changes: 1 addition & 1 deletion lib/Tuba/GcmdKeyword.pm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use Tuba::DB::Objects qw/-nicknames/;

sub list {
my $c = shift;
$c->stash(objects => GcmdKeywords->get_objects(with_objects => 'publications', page => $c->page));
$c->stash(objects => GcmdKeywords->get_objects(with_objects => 'publications', page => $c->page, per_page => $c->per_page));
my $count = GcmdKeywords->get_objects_count;
$c->stash(extra_cols => [qw/label/]);
$c->set_pages($count);
Expand Down
2 changes: 1 addition & 1 deletion lib/Tuba/Organization.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ sub list {
if ($c->param('all')) {
$c->stash(objects => Organizations->get_objects(@q));
} else {
$c->stash(objects => scalar Organizations->get_objects(@q, sort_by => 'name', page => $c->page));
$c->stash(objects => scalar Organizations->get_objects(@q, sort_by => 'name', page => $c->page, per_page => $c->per_page));
$c->set_pages(Organizations->get_objects_count(@q));
}
$c->SUPER::list(@_);
Expand Down
2 changes: 1 addition & 1 deletion lib/Tuba/Person.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ sub list {
if ($c->param('all')) {
$c->stash(objects => Persons->get_objects(@q));
} else {
$c->stash(objects => scalar Persons->get_objects(@q, sort_by => 'last_name, first_name', page => $c->page));
$c->stash(objects => scalar Persons->get_objects(@q, sort_by => 'last_name, first_name', page => $c->page, per_page => $c->per_page));
$c->set_pages(Persons->get_objects_count(@q));
}
$c->SUPER::list(@_);
Expand Down
9 changes: 7 additions & 2 deletions lib/Tuba/Region.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@ sub list {
$objects = Regions->get_objects(
query => [ publication_id => $publication->id ],
with_objects => [qw/publications/],
page => $c->page
page => $c->page,
per_page => $c->per_page
);
$count = Regions->get_objects_count(
query => [ publication_id => $publication->id ],
with_objects => [qw/publications/],
);
}
else {
$objects = Regions->get_objects(with_objects => 'publications', page => $c->page);
$objects = Regions->get_objects(
with_objects => 'publications',
page => $c->page,
per_page => $c->per_page
);
$count = Regions->get_objects_count;
}
$c->stash(objects => $objects);
Expand Down
2 changes: 1 addition & 1 deletion lib/Tuba/Table.pm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sub list {
my $tables;
my $report_identifier = $c->stash('report_identifier');
my $all = $c->param('all');
my @page = $all ? () : (page => $c->page);
my @page = $all ? () : (page => $c->page, per_page => $c->per_page);
if (my $ch = $c->stash('chapter')) {
$tables = Tables->get_objects(
query => [chapter_identifier => $ch->identifier, report_identifier => $report_identifier], with_objects => ['chapter'],
Expand Down
154 changes: 88 additions & 66 deletions lib/Tuba/files/templates/pager.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -7,81 +7,103 @@
% my $per_page = stash 'per_page';

<div class='row pagers'>
<form class="form-inline" action="#">
<div class="row">
% if ($page && $pages > 1) {
<div class="btn-group <%= (stash 'bottom') ? ' dropup' : '' %>">
<form class="form-inline" action="#">
%# Whole Row
<div class="row">
%# Page selector button group Start
% if ($page && $pages > 1) {
<div class="btn-group <%= (stash 'bottom') ? ' dropup' : '' %>">

% if ($page==1) {
<span class='btn btn-default btn-sm disabled'><i class='glyphicon glyphicon-backward'></i></span>
% } else {
<%= link_to url_with->query([page => ( $page - 1)]) => class => 'btn btn-default btn-sm' => begin %><i class='glyphicon glyphicon-backward'></i><%= end %>
% }
%# Back button
% if ($page==1) {
<span class='btn btn-default btn-sm disabled'><i class='glyphicon glyphicon-backward'></i></span>
% } else {
<%= link_to url_with->query([page => ( $page - 1)]) => class => 'btn btn-default btn-sm' => begin %><i class='glyphicon glyphicon-backward'></i><%= end %>
% }

<button class='btn btn-default btn-sm dropdown-toggle' data-toggle='dropdown'>
<small>page <%= $page %></small> <span class='caret'></span>
</button>
% if ($page==$pages) {
<span class='btn btn-default btn-sm disabled'><i class='glyphicon glyphicon-forward'></i></span>
% } else {
<%= link_to url_with->query([page => ( $page + 1)]) => class => 'btn btn-default btn-sm' => begin %><i class='glyphicon glyphicon-forward'></i><%= end %>
% }
<span class="btn btn-default btn-sm">
<%= ( $page - 1) * $per_page + 1 %> to <%= min($page * $per_page,$count) %> of <%= $count %>
</span>
<ul class='dropdown-menu' role='menu' aria-labelledby='dLabel'>
% if (stash 'favorite_ok') {
<li><%= link_to url_with->query([page => '♥']) => begin %><i class='glyphicon glyphicon-heart'></i><%= end %></li>
% }
% my $i = 1;
% while ($i <= $pages) {
<li><%= link_to url_with->query([page => $i]) => begin %>page <%= $i %><%= end %></li>
% $i++;
% if (($i > 10) && ($i < ($pages - 10)) && ($pages > 20)) {
<li><%= link_to url_with->query([page => int($pages/2)]) => begin %>...<%= end %></li>
% $i = $pages - 10;
% }
% }
</ul>
%# Page display & select button
<button class='btn btn-default btn-sm dropdown-toggle' data-toggle='dropdown'>
<small>page <%= $page %></small> <span class='caret'></span>
</button>

</div>
%# Forward button
% if ($page==$pages) {
<span class='btn btn-default btn-sm disabled'><i class='glyphicon glyphicon-forward'></i></span>
% } else {
<%= link_to url_with->query([page => ( $page + 1)]) => class => 'btn btn-default btn-sm' => begin %><i class='glyphicon glyphicon-forward'></i><%= end %>
% }
% if ($show_search_box) {
<%= text_field 'search_obj', autocomplete => 'off', id => 'search_obj', class => 'form-control input-sm', placeholder => 'search', style => "width:50%;"; %>

%# X to Y of Z "button"
<span class="btn btn-default btn-sm">
<%= ( $page - 1) * $per_page + 1 %> to <%= min($page * $per_page,$count) %> of <%= $count %>
</span>

%# Per page selection
<span class="btn btn-default btn-sm">Per page:</span>
<%= link_to url_with->query([per_page => 25]) => class => 'btn btn-default btn-sm' => begin %>20<%= end %>
<%= link_to url_with->query([per_page => 50]) => class => 'btn btn-default btn-sm' => begin %>50<%= end %>
<%= link_to url_with->query([per_page => 100]) => class => 'btn btn-default btn-sm' => begin %>100<%= end %>

%# Dropdown list page selection
<ul class='dropdown-menu' role='menu' aria-labelledby='dLabel'>
% if (stash 'favorite_ok') {
<li><%= link_to url_with->query([page => '♥']) => begin %><i class='glyphicon glyphicon-heart'></i><%= end %></li>
% }
% my $i = 1;
% while ($i <= $pages) {
<li><%= link_to url_with->query([page => $i]) => begin %>page <%= $i %><%= end %></li>
% $i++;
% if (($i > 10) && ($i < ($pages - 10)) && ($pages > 20)) {
<li><%= link_to url_with->query([page => int($pages/2)]) => begin %>...<%= end %></li>
% $i = $pages - 10;
% }
% }
</ul>

</div>
% }
%# Page selector button group End
%# Search Box Start
% if ($show_search_box) {
<%= text_field 'search_obj', autocomplete => 'off', id => 'search_obj', class => 'form-control input-sm', placeholder => 'search', style => "width:50%;"; %>
% }
%# Search Box End
%# List/Thumbs Section Start
<div class='pull-right text-right'>
<div class='btn-group'>
% if (param 'thumbs') {
%# List selection, thumb display
<%= link_to url_with->query([thumbs => 0]) => class => 'btn btn-default btn-sm' => begin %><i class='glyphicon glyphicon-th-list'></i><%= end %>
<div class='btn btn-default btn-sm active'><i class='glyphicon glyphicon-th'></i></div>
% } else {
%# List display, thumb selector
<div class='btn btn-default btn-sm active'><i class='glyphicon glyphicon-th-list'></i></div>
<%= link_to url_with->query([thumbs => 1]) => class => 'btn btn-default btn-sm' => begin %><i class='glyphicon glyphicon-th'></i><%= end %>
% }
<div class='pull-right text-right'>
<div class='btn-group'>
% if (param 'thumbs') {
<%= link_to url_with->query([thumbs => 0]) => class => 'btn btn-default btn-sm' => begin %><i class='glyphicon glyphicon-th-list'></i><%= end %>
<div class='btn btn-default btn-sm active'><i class='glyphicon glyphicon-th'></i></div>
% } else {
<div class='btn btn-default btn-sm active'><i class='glyphicon glyphicon-th-list'></i></div>
<%= link_to url_with->query([thumbs => 1]) => class => 'btn btn-default btn-sm' => begin %><i class='glyphicon glyphicon-th'></i><%= end %>
% }
</div>
</div>
</div>
</div>
</div>
</div>
%# List/Thumbs Section End
</div>
</div>
</form>
<br>


% if ($show_search_box) {
%= javascript begin
% my $restrict = ( (stash 'report_identifier') ? "report_identifier:".(stash 'report_identifier') : "");
$('#search_obj').typeahead({
minLength : 1,
items : 30,
updater: function(str) {
var pieces = str.split(' ');
window.location.href = pieces[0];
},
source : function(query,process) {
return $.get('/autocomplete', { q : query, items : 30, type : '<%= $search_table %>', restrict : '<%= $restrict %>', gcids : 1 }, function(data) {
return process(data);
%= javascript begin
% my $restrict = ( (stash 'report_identifier') ? "report_identifier:".(stash 'report_identifier') : "");
$('#search_obj').typeahead({
minLength : 1,
items : 30,
updater: function(str) {
var pieces = str.split(' ');
window.location.href = pieces[0];
},
source : function(query,process) {
return $.get('/autocomplete', { q : query, items : 30, type : '<%= $search_table %>', restrict : '<%= $restrict %>', gcids : 1 }, function(data) {
return process(data);
});
}
});
%= end
}
});
%= end
% }

15 changes: 14 additions & 1 deletion t/003_lists.t
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ my @reports = map +{
in_library => 1,
contact_note => "notey note",
contact_email => "note\@note.com"
}, 1..2;
}, 1..5;

$t->post_ok("/report" => json => $_)->status_is(200) for @reports;

Expand All @@ -47,9 +47,22 @@ my $expect = <<"CSV";
uri,href,identifier,_public,contact_email,contact_note,doi,frequency,in_library,publication_year,report_type_identifier,summary,title,topic,url
/report/report-number-1,$base/report/report-number-1,report-number-1,1,note\@note.com,"notey note",10.123/91023-1,"1 year",1,2001,report,"This is a really interesting report about 1. Temperature is 1°F (± 12½).","This is report number 1",nothing,http://example.com/report/1
/report/report-number-2,$base/report/report-number-2,report-number-2,1,note\@note.com,"notey note",10.123/91023-2,"1 year",1,2002,report,"This is a really interesting report about 2. Temperature is 2°F (± 12½).","This is report number 2",nothing,http://example.com/report/2
/report/report-number-3,$base/report/report-number-3,report-number-3,1,note\@note.com,"notey note",10.123/91023-3,"1 year",1,2003,report,"This is a really interesting report about 3. Temperature is 3°F (± 12½).","This is report number 3",nothing,http://example.com/report/3
/report/report-number-4,$base/report/report-number-4,report-number-4,1,note\@note.com,"notey note",10.123/91023-4,"1 year",1,2004,report,"This is a really interesting report about 4. Temperature is 4°F (± 12½).","This is report number 4",nothing,http://example.com/report/4
/report/report-number-5,$base/report/report-number-5,report-number-5,1,note\@note.com,"notey note",10.123/91023-5,"1 year",1,2005,report,"This is a really interesting report about 5. Temperature is 5°F (± 12½).","This is report number 5",nothing,http://example.com/report/5
CSV

$t->get_ok("/report.csv")->status_is(200)->content_is($expect);
#$t->get_ok("/report.json?per_page=2")->status_is(200)->content_is('report-number-3');


my $expect2 = <<"CSV";
uri,href,identifier,_public,contact_email,contact_note,doi,frequency,in_library,publication_year,report_type_identifier,summary,title,topic,url
/report/report-number-1,$base/report/report-number-1,report-number-1,1,note\@note.com,"notey note",10.123/91023-1,"1 year",1,2001,report,"This is a really interesting report about 1. Temperature is 1°F (± 12½).","This is report number 1",nothing,http://example.com/report/1
/report/report-number-2,$base/report/report-number-2,report-number-2,1,note\@note.com,"notey note",10.123/91023-2,"1 year",1,2002,report,"This is a really interesting report about 2. Temperature is 2°F (± 12½).","This is report number 2",nothing,http://example.com/report/2
CSV

$t->get_ok("/report.csv?per_page=2")->status_is(200)->content_is($expect2);

$t->get_ok('/image')->status_is(200);
$t->get_ok('/image.json')->status_is(200)->json_is([]);
Expand Down

0 comments on commit 9f7cdb5

Please sign in to comment.