lib/CrashTest/Controller/CrashReports.pm
author Vincent Tondellier <tonton+hg@team1664.org>
Mon, 17 Jul 2023 22:52:42 +0200
changeset 134 26ba2717da6e
parent 122 8692800ec9ba
permissions -rw-r--r--
Allow matching filelink on partial url paths

# 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::CrashReports;

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

use CrashTest::Model::Thread;

sub index {
    my $self = shift;

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

    if($self->req->url =~ qr{.*\.atom$}) {
        $crashs_per_page = 100;
    }

    $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_reports->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}->{Index});

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

sub show {
    my $self = shift;

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

    my $data = $self->app->crash_reports->get_processed_data($uuid);
    $self->stash(processed_data => $data);

    my $crashing_thread = CrashTest::Model::Thread->new($data->{crashing_thread});
    $crashing_thread = $self->app->stackfilter->apply($crashing_thread);
    $self->stash(crashing_thread => $crashing_thread);

    my @threads = ();
    foreach my $raw_thread(@{$data->{threads}}) {
        my $thread = CrashTest::Model::Thread->new($raw_thread);
        $thread = $self->app->stackfilter->apply($thread);
        push @threads, $thread;
    }
    $self->stash(threads => \@threads);

    my $report = $self->app->crash_reports->get($uuid);
    $self->stash(crash => $report);

    my $bugs_status = {};
    if(defined($report) && defined($report->{bug_links})) {
        $bugs_status = $self->app->bug_link->get_statuses($report->{bug_links});
    }
    $self->stash(bugs_status => $bugs_status);
    my $group = $self->app->crash_groups->get($uuid);
    $self->stash(crash_group => $group);
    $self->stash(extra_columns => $self->app->config->{WebInterface}->{ExtraColumns}->{Index});

    $self->render("report/crash");
}

1;