lib/CrashTest/Controller/CrashGroups.pm
author Vincent Tondellier <tonton+hg@team1664.org>
Sun, 18 Dec 2016 21:11:27 +0100
changeset 122 8692800ec9ba
parent 121 5a99941ed0ca
permissions -rw-r--r--
Use Dzil PkgVersion Add a newline after each package to make Dist::Zilla happy

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

package CrashTest::Controller::CrashGroups;

use Mojo::Base 'Mojolicious::Controller';
use Mojo::Util qw/dumper/;

sub index {
    my $self = shift;

    my $page = 1;
    my $crashs_per_page = 25;

    $self->validation->required('page')->like(qr/^[0-9]+$/);
    $page = scalar $self->validation->param("page") if $self->validation->is_valid('page');

    my ($results, $pager, $err) = $self->crash_groups->index($page, $crashs_per_page, $self->req->param('search'));

    if($err) {
        $self->app->log->info($err);
        $self->stash(error => "Syntax error in search string: $err");
    }


    #$self->app->log->debug(dumper $results);

    $self->stash(crashs => $results);
    $self->stash(pager => $pager);
    $self->stash(extra_columns => $self->app->config->{WebInterface}->{ExtraColumns}->{GroupIndex});

    $self->render("groups/index");
}

sub show {
    my $self = shift;

    my $uuid = $self->param('uuid');

    my $group = $self->app->crash_groups->get($uuid);
    $self->stash(group => $self->app->crash_groups->get($uuid));
    $self->stash(stats_by_product_and_version => $self->app->crash_groups->stats_by_product_and_version($uuid));

    my $page = 1;
    my $crashs_per_page = 20;
    $self->validation->required('page')->like(qr/^[0-9]+$/);
    $page = scalar $self->validation->param("page") if $self->validation->is_valid('page');

    my $search = $self->req->param('search');
    if(defined($search) && $search ne "") {
        $search = "(" . $search . ") AND " . "group_id=$group->{id}";
    } else {
        $search = "group_id=$group->{id}";
    }

    my ($results, $pager, $err) = $self->crash_reports->index($page, $crashs_per_page, $search);

    if($err) {
        $self->app->log->info($err);
        $self->stash(warning => "Syntax error in search string: $err");
    }

    #$self->app->log->debug(dumper $results);

    $self->stash(crashs => $results);
    $self->stash(pager => $pager);
    $self->stash(extra_columns => $self->app->config->{WebInterface}->{ExtraColumns}->{Index});

    $self->render("group/show");
}

1;