Skip to content

Commit

Permalink
Add web UI controls to select more builds in group_overview
Browse files Browse the repository at this point in the history
The query parameter 'limit_builds' allows to show more than the default 10
builds on demand. Just like we have for configuring previous results, the
current commit adds web UI selections to reload the same page with
higher number of builds on demand. For this, the limit of days is increased
to show more builds but still limited by the selected number.
  • Loading branch information
okurz committed Aug 7, 2016
1 parent d3dc0bc commit 3d3f6f3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/OpenQA/WebAPI/Controller/Main.pm
Expand Up @@ -159,9 +159,10 @@ sub group_overview {
$res->{$build}->{tag} = {type => $tag[1], description => $tag[2]};
}
}
$self->stash('result', $res);
$self->stash('group', $group);
$self->stash('comments', \@comments);
$self->stash('result', $res);
$self->stash('group', $group);
$self->stash('limit_builds', $limit_builds);
$self->stash('comments', \@comments);
}

sub add_comment {
Expand Down
14 changes: 14 additions & 0 deletions lib/OpenQA/WebAPI/Plugin/Helpers.pm
Expand Up @@ -242,6 +242,20 @@ sub register {

return $c->tag('span', title => $text, sub { substr($text, 0, $length - 4) . " ..." });
});

$app->helper(
#%= b join(' / ', map { link_to($_ == $limit_builds ? "<b>$_</b>" : $_ => url_with->query(time_limit_days => 1000, limit_builds => $_)) } (10, 20, 50, 100, 400))
#%= b join(' / ', map { $_ == $limit_previous ? "<b>$_</b>" : link_to($_ => url_with->query(limit_previous => $_) . '#previous') } (10, 20, 50, 100, 400))
limit_choices => sub {
my ($c, $args) = @_;
$args->{choices} //= [10, 20, 50, 100, 400];
my $key = $args->{limit_key};
my $limit = int($args->{$key});
my $b = join(' / ', map { $_ == int($limit) ? "<b>$_</b>" : $c->link_to($_ => $c->url_with->query($key => $_, $args->{query_args}) . $args->{url_suffix}) } $args->{choices});
return Mojo::ByteStream->new($b);
});


}

sub _step_thumbnail {
Expand Down
7 changes: 7 additions & 0 deletions t/ui/14-dashboard.t
Expand Up @@ -56,6 +56,13 @@ $driver->find_element('opensuse', 'link_text')->click();
is(scalar @{$driver->find_elements('h4', 'css')}, 4, 'number of builds for opensuse');
is($driver->get($baseurl . '?limit_builds=2'), 1, 'group overview page accepts query parameter, too');

my $more_builds = $t->get_ok($baseurl . 'group_overview/1001')->tx->res->dom->at('#more_builds');
my $res = OpenQA::Test::Case::trim_whitespace($more_builds->all_text);
is($res, q{Limit to 10 / 20 / 50 / 100 / 400 builds}, 'more builds can be requested');
my $get = $t->get_ok($more_builds->find('a[href]')->last->{href})->status_is(200);
$res = OpenQA::Test::Case::trim_whitespace($t->tx->res->dom->at('#more_builds b')->all_text);
like($res, qr/400/, 'limited to the selected number');

#t::ui::PhantomTest::make_screenshot('mojoResults.png');

t::ui::PhantomTest::kill_phantom();
Expand Down
7 changes: 7 additions & 0 deletions templates/main/group_overview.html.ep
Expand Up @@ -10,6 +10,13 @@
<h2>Last Builds for Group <%= $group->name %></h2>
%= include 'main/group_builds', result => $result

<div id="more_builds">
Limit to
%= b join(' / ', map { $_ == $limit_builds ? "<b>$_</b>" : link_to($_ => url_with->query(time_limit_days => 1000, limit_builds => $_)) } (10, 20, 50, 100, 400));
<!--%= limit_choices {limit_key => 'limit_builds', limit_builds => $limit_builds, query_args => {time_limit_days => 1000}}-->
builds
</div>

<h2>Comments</h2>
% for my $comment (reverse @$comments) {
%= include 'comments/comment_row', comment_id => $comment->id, comment => $comment, user => $comment->user, context => {type => 'group', id => $group->id}, put_action => 'apiv1_put_group_comment', delete_action => 'apiv1_delete_group_comment'
Expand Down

0 comments on commit 3d3f6f3

Please sign in to comment.