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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
88
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     1
# This program is free software: you can redistribute it and/or modify
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     2
# it under the terms of the GNU General Public License as published by
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     3
# the Free Software Foundation, either version 3 of the License, or
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     4
# (at your option) any later version.
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     5
#
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     6
# This program is distributed in the hope that it will be useful,
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     7
# but WITHOUT ANY WARRANTY; without even the implied warranty of
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
     9
# GNU General Public License for more details.
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    10
#
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    11
# You should have received a copy of the GNU General Public License
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    12
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    13
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    14
package CrashTest::Controller::CrashGroups;
122
8692800ec9ba Use Dzil PkgVersion
Vincent Tondellier <tonton+hg@team1664.org>
parents: 121
diff changeset
    15
88
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    16
use Mojo::Base 'Mojolicious::Controller';
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    17
use Mojo::Util qw/dumper/;
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    18
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    19
sub index {
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    20
    my $self = shift;
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    21
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    22
    my $page = 1;
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    23
    my $crashs_per_page = 25;
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    24
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    25
    $self->validation->required('page')->like(qr/^[0-9]+$/);
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    26
    $page = scalar $self->validation->param("page") if $self->validation->is_valid('page');
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    27
121
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    28
    my ($results, $pager, $err) = $self->crash_groups->index($page, $crashs_per_page, $self->req->param('search'));
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    29
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    30
    if($err) {
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    31
        $self->app->log->info($err);
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    32
        $self->stash(error => "Syntax error in search string: $err");
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    33
    }
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    34
88
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    35
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    36
    #$self->app->log->debug(dumper $results);
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    37
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    38
    $self->stash(crashs => $results);
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    39
    $self->stash(pager => $pager);
100
4dae01f2beee Allow extra columns in group index, and split search columns
Vincent Tondellier <tonton+hg@team1664.org>
parents: 88
diff changeset
    40
    $self->stash(extra_columns => $self->app->config->{WebInterface}->{ExtraColumns}->{GroupIndex});
88
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    41
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    42
    $self->render("groups/index");
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    43
}
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    44
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    45
sub show {
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    46
    my $self = shift;
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    47
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    48
    my $uuid = $self->param('uuid');
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    49
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    50
    my $group = $self->app->crash_groups->get($uuid);
102
396528bdb9ad Allow showing a group by the uuid of any of it's individual crash
Vincent Tondellier <tonton+hg@team1664.org>
parents: 100
diff changeset
    51
    $self->stash(group => $self->app->crash_groups->get($uuid));
396528bdb9ad Allow showing a group by the uuid of any of it's individual crash
Vincent Tondellier <tonton+hg@team1664.org>
parents: 100
diff changeset
    52
    $self->stash(stats_by_product_and_version => $self->app->crash_groups->stats_by_product_and_version($uuid));
88
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    53
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    54
    my $page = 1;
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    55
    my $crashs_per_page = 20;
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    56
    $self->validation->required('page')->like(qr/^[0-9]+$/);
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    57
    $page = scalar $self->validation->param("page") if $self->validation->is_valid('page');
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    58
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    59
    my $search = $self->req->param('search');
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    60
    if(defined($search) && $search ne "") {
121
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    61
        $search = "(" . $search . ") AND " . "group_id=$group->{id}";
88
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    62
    } else {
102
396528bdb9ad Allow showing a group by the uuid of any of it's individual crash
Vincent Tondellier <tonton+hg@team1664.org>
parents: 100
diff changeset
    63
        $search = "group_id=$group->{id}";
88
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    64
    }
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    65
121
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    66
    my ($results, $pager, $err) = $self->crash_reports->index($page, $crashs_per_page, $search);
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    67
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    68
    if($err) {
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    69
        $self->app->log->info($err);
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    70
        $self->stash(warning => "Syntax error in search string: $err");
5a99941ed0ca Display an error message instead of a 500 page when the search string is invalid
Vincent Tondellier <tonton+hg@team1664.org>
parents: 102
diff changeset
    71
    }
88
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    72
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    73
    #$self->app->log->debug(dumper $results);
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    74
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    75
    $self->stash(crashs => $results);
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    76
    $self->stash(pager => $pager);
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    77
    $self->stash(extra_columns => $self->app->config->{WebInterface}->{ExtraColumns}->{Index});
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    78
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    79
    $self->render("group/show");
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    80
}
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    81
c82f5589db11 Add first cut of the crash grouping feature
Vincent Tondellier <tonton+hg@team1664.org>
parents:
diff changeset
    82
1;