DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d5c3254b3e56)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
#!/usr/bin/perl -w
# -*- mode: cperl; c-basic-offset: 8; indent-tabs-mode: nil; -*-

# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Litmus.
#
# The Initial Developer of the Original Code is
# the Mozilla Corporation.
# Portions created by the Initial Developer are Copyright (C) 2006
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#   Chris Cooper <ccooper@deadsquid.com>
#   Zach Lipton <zach@zachlipton.com>
#
# ***** END LICENSE BLOCK *****

use strict;

use Litmus;
use Litmus::Auth;
use Litmus::Error;
use Litmus::DB::Testresult;
use Litmus::FormWidget;

use CGI;
use JSON -convert_blessed_universally;

Litmus->init();
my $c = Litmus->cgi(); 
print $c->header();

my $criteria = "Custom<br/>";
my ($results, $pager);
my @where;
my @order_by;
my $limit = $Litmus::DB::Testresult::_num_results_default;
my $where_criteria = "";
my $order_by_criteria = "";
my $limit_criteria = "";
my $page = 1;
if ($c->param) {    
    foreach my $param ($c->param) {
        next if (!$c->param($param) || $c->param($param) eq '');
        my $value = quotemeta($c->param($param));
        if ($param eq 'page') {
            $page = $value;
            if ($page !~ /^\d+$/) {
                $page = 1;
            }
            next;
        }
        if ($param =~ /^order_by_(.*)$/) {
            my $order_by_proto = quotemeta($1);
            next if ($value ne 'ASC' and
                     $value ne 'DESC');
            my $order_by_direction = $value;
            push @order_by, {field => $order_by_proto,
                             direction => $order_by_direction};
            $order_by_criteria .= "Order by $order_by_proto $order_by_direction<br/>";
        } elsif ($param eq 'branch') {
           if ($value =~ /^\d+$/) {
                push @where, {field => $param,
                              value => $value};
                my $branch = Litmus::DB::Branch->retrieve($value);
                $where_criteria .= "Branch is \'".$branch->{'name'}."\'<br/>";
           } else {
                push @where, {field => 'branch_name',
                              value => $value};
                $where_criteria .= "Branch is \'".$value."\'<br/>";
           }
        } elsif ($param eq 'locale') {
            push @where, {field => 'locale',
                          value => $value};
            $where_criteria .= "Locale is \'".$value."\'<br/>";
        } elsif ($param eq 'product') {
            if ($value =~ /^\d+$/) {
                push @where, {field => $param,
                              value => $value};
                my $product = Litmus::DB::Product->retrieve($value);
                $where_criteria .= "Product is \'".$product->{'name'}."\'<br/>";
            } else {
                push @where, {field => 'product_name',
                              value => $value};
                $where_criteria .= "Product is \'".$value."\'<br/>";
            }
        } elsif ($param eq 'platform') {
            if ($value =~ /^\d+$/) {
                push @where, {field => $param,
                              value => $value};
                my $platform = Litmus::DB::Platform->retrieve($value);
                $where_criteria .= "Platform is \'".$platform->{'name'}."\'<br/>";
            } else {
                push @where, {field => 'platform_name',
                              value => $value};
                $where_criteria .= "Platform is \'".$value."\'<br/>";
            }
        } elsif ($param =~ /^test_run/) {
            push @where, {field => 'test_run',
                          value => $value};
            $where_criteria .= "Test Run ID# is \'".$value."\'<br/>";
        } elsif ($param eq 'testgroup' or $param eq 'test_group') {
            push @where, {field => $param,
                          value => $value};
            $where_criteria .= "Testgroup is \'".$value."\'<br/>";
        } elsif ($param eq 'subgroup') {
            push @where, {field => $param,
                          value => $value};
            $where_criteria .= "Subgroup is \'".$value."\'<br/>";
        } elsif ($param eq 'testcase_id') {
            if ($value =~ /^\d+$/) {
                push @where, {field => $param,
                              value => $value};
                $where_criteria .= "Testcase ID# is \'".$value."\'<br/>";
            }
        } elsif ($param eq 'summary') {
            my $display_value = $value;
            # Upgrade to utf8 prior to search. 
            utf8::upgrade($value);
            push @where, {field => $param,
                          value => $value};
            utf8::decode($display_value);
            $where_criteria .= "Summary like \'".$display_value."\'<br/>";
        } elsif ($param eq 'email') {
            my $display_value = $value;
            # Upgrade to utf8 prior to search.
            utf8::upgrade($value);
            push @where, {field => $param,
                          value => $value};
            utf8::decode($display_value);
            $where_criteria .= "Submitted By like \'".$display_value."\'<br/>";
        } elsif ($param eq 'result_status') {
            push @where, {field => $param,
                          value => $value};
            $where_criteria .= "Status is \'".$value."\'<br/>";
        } elsif ($param eq 'timespan') {
            if ($value ne 'all') {
                $value =~ s/[^\-0-9]//g;
                push @where, {field => $param,
                              value => $value};
                $value =~ s/\-//g;
                if ($value == 1) {
                    $where_criteria .= "Submitted in the last day<br/>";
                } else {
                    $where_criteria .= "Submitted in the last $value days<br/>";
                }
            } else {
                $where_criteria .= "All Results<br/>";
            }
        } elsif ($param eq "limit") {
            next if ($value !~ /^\d+$/);
            next if ($value > $Litmus::DB::Testresult::_max_results_default);
            $limit = $value;
            $limit_criteria .= "Limit to $limit results per page";
        } elsif ($param eq "has_comments") {
          push @where, {field => $param,
                        value => $value};
          $where_criteria .= "Has comments<br/>";          
        } else {
            # Skip unknown field
        }
    }
    if ($where_criteria eq '' and 
        $order_by_criteria eq '' and
        $limit_criteria eq '') {
        $criteria = "No criteria specified";
    } else {
        $criteria .= $where_criteria . $order_by_criteria . $limit_criteria;
        $criteria =~ s/_/ /g;
        ($results,$pager) = Litmus::DB::Testresult->getTestResults(\@where,
                                                                   \@order_by,
                                                                   $limit,
                                                                   $page);
    }
} else {
    $criteria = "No criteria specified";
}

# Populate each of our form widgets for select/input.
# Set a default value as appropriate.
my $products = Litmus::FormWidget->getProducts;
my $platforms = Litmus::FormWidget->getUniquePlatforms;
my $test_groups = Litmus::FormWidget->getTestgroups;
my $result_statuses = Litmus::FormWidget->getResultStatuses;
my $branches = Litmus::FormWidget->getBranches;
my $locales = Litmus::FormWidget->getLocales;

my $json = new JSON;
my $products_js = $json->allow_unknown->convert_blessed->encode($products);
my $branches_js = $json->allow_unknown->convert_blessed->encode($branches);

my $title = 'Search Test Results';

my $vars = {
    title => $title,
    criteria => $criteria,
    products => $products,
    branches => $branches,
    products_js => $products_js,
    branches_js => $branches_js,
    platforms => $platforms,
    test_groups => $test_groups,
    result_statuses => $result_statuses,
    branches => $branches,
    locales => $locales,
    limit => $limit,
};

# Only include results if we have them.
if ($results and scalar @$results > 0) {
    $vars->{results} = $results;
}

if ($pager) {
    $vars->{pager} = $pager;
}

my $cookie =  Litmus::Auth::getCookie();
$vars->{"defaultemail"} = $cookie;
$vars->{"show_admin"} = Litmus::Auth::istrusted($cookie);

Litmus->template()->process("reporting/search_results.tmpl", $vars) || 
    internalError(Litmus->template()->error());

exit 0;