ccooper%deadsquid.com 0adafdc46e b=464036
- add admin option to sort by date vetted

Misc.
- fix date display in comment popups


git-svn-id: svn://10.0.0.236/trunk@255258 18797224-902f-48f8-a5cc-f745e15eee43
2008-11-28 17:06:17 +00:00

429 lines
13 KiB
Perl
Executable File

# -*- mode: cperl; c-basic-offset: 8; indent-tabs-mode: nil; -*-
=head1 COPYRIGHT
# ***** 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 *****
=cut
package Litmus::FormWidget;
use strict;
#use Encode qw( encode_utf8 decode_utf8 );
use utf8;
use diagnostics;
BEGIN {
use Exporter ();
use vars qw ($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
$VERSION = 0.01;
@ISA = qw (Exporter);
#Give a hoot don't pollute, do not export more than needed by default
@EXPORT = qw ();
@EXPORT_OK = qw ();
%EXPORT_TAGS = ();
}
use DBI;
use Litmus::DBI;
use Litmus::DB::TestDay;
our $_dbh = Litmus::DBI->db_Main();
#########################################################################
=head1 NAME
Litmus::FormWidget - Create value lists to be used in HTML forms
=head1 SYNOPSIS
use Litmus::FormWidget
=head1 DESCRIPTION
Litmus::FormWidget creates value lists to be used in HTML forms.
=head1 USAGE
=head1 BUGS
=head1 SUPPORT
=head1 AUTHOR
Chris Cooper
CPAN ID: CCOOPER
Mozilla Corporation
ccooper@deadsquid.com
http://litmus.mozilla.org/
=head1 SEE ALSO
perl(1).
=cut
#########################################################################
sub getProducts()
{
my ($self, $enabled) = @_;
my $sql = "SELECT name, product_id FROM products";
if ($enabled) {
$sql .= " WHERE enabled=1";
}
$sql .= " ORDER BY name ASC";
return _getValues($sql);
}
#########################################################################
sub getUniquePlatforms()
{
my $sql = "SELECT DISTINCT(name), platform_id FROM platforms ORDER BY name";
return _getValues($sql);
}
#########################################################################
sub getPlatforms()
{
my $sql = "SELECT platform_id, name from platforms ORDER BY name ASC";
return _getValues($sql);
}
#########################################################################
sub getBranches()
{
my ($self, $enabled) = @_;
my $sql = "SELECT b.name, b.branch_id, b.product_id, p.name AS product_name FROM branches b, products p WHERE b.product_id=p.product_id";
if ($enabled) {
$sql .= " AND b.enabled=1";
}
$sql .= " ORDER BY b.name ASC";
return _getValues($sql);
}
#########################################################################
sub getUniqueBranches()
{
my ($self, $enabled) = @_;
my $sql = "SELECT DISTINCT(name) FROM branches";
if ($enabled) {
$sql .= " WHERE enabled=1";
}
$sql .= " ORDER BY name ASC";
return _getValues($sql);
}
#########################################################################
sub getOpsyses()
{
my $sql = "SELECT o.name, o.opsys_id, o.platform_id, pl.name AS platform_name FROM opsyses o, platforms pl WHERE o.platform_id=pl.platform_id ORDER BY o.name ASC";
return _getValues($sql);
}
#########################################################################
sub getUniqueOpsyses()
{
my $sql = "SELECT DISTINCT(name), opsys_id, platform_id FROM opsyses ORDER BY name ASC";
return _getValues($sql);
}
#########################################################################
sub getLogTypes()
{
my $sql = "SELECT DISTINCT(name) FROM log_type_lookup ORDER BY name";
return _getValues($sql);
}
#########################################################################
sub getTestStatuses()
{
my @TestStatuses = ({name => 'Enabled'},
{name => 'Disabled'});
return \@TestStatuses;
}
#########################################################################
sub getResultStatuses()
{
my $sql = "SELECT result_status_id,name,class_name FROM test_result_status_lookup ORDER BY result_status_id";
return _getValues($sql);
}
#########################################################################
sub getTestcaseIDs()
{
my ($self, $enabled, $community_enabled) = @_;
my $sql = "SELECT testcase_id,summary FROM testcases";
if ($enabled) {
$sql .= " WHERE enabled=1";
}
if ($community_enabled) {
if ($sql =~ /WHERE/) {
$sql .= " AND community_enabled=1";
} else {
$sql .= " WHERE community_enabled=1";
}
}
$sql .= " ORDER BY testcase_id";
return _getValues($sql);
}
#########################################################################
sub getTestcases()
{
my ($self, $enabled, $sort_by) = @_;
my $sql = "SELECT testcase_id, summary, product_id, branch_id FROM testcases";
if ($enabled) {
$sql .= " WHERE enabled=1";
}
if (!$sort_by) {
$sort_by='id';
}
if ($sort_by eq 'name') {
$sql .= " ORDER BY summary ASC, testcase_id ASC";
} elsif ($sort_by eq 'id') {
$sql .= " ORDER BY testcase_id ASC";
} else {
Litmus::Error::logError("Unknown sort_by type: $sort_by", caller(0));
}
return _getValues($sql);
}
#########################################################################
sub getDistinctSubgroups()
{
my ($self, $enabled) = @_;
my $sql = "SELECT DISTINCT(sg.subgroup_id), sg.name, sg.product_id, sg.branch_id, sgtg.testgroup_id FROM subgroups sg LEFT JOIN subgroup_testgroups sgtg ON (sg.subgroup_id=sgtg.subgroup_id)";
if ($enabled) {
$sql .= " AND sg.enabled=1";
}
$sql .= " ORDER BY sgtg.sort_order ASC, sg.name ASC, sg.subgroup_id ASC";
return _getValues($sql);
}
#########################################################################
sub getSubgroups()
{
my ($self, $enabled, $sort_by) = @_;
my $sql = "SELECT sg.subgroup_id, sg.name, sg.product_id, sg.branch_id, sgtg.testgroup_id FROM subgroups sg LEFT JOIN subgroup_testgroups sgtg ON (sg.subgroup_id=sgtg.subgroup_id)";
if ($enabled) {
$sql .= " AND sg.enabled=1";
}
if (!$sort_by) {
$sort_by='id';
}
if ($sort_by eq 'name') {
$sql .= " ORDER BY sg.name ASC, sg.subgroup_id ASC";
} elsif ($sort_by eq 'id') {
$sql .= " ORDER BY sg.subgroup_id ASC";
} elsif ($sort_by eq 'sort_order') {
$sql .= " ORDER BY sgtg.sort_order ASC, sg.name ASC, sg.subgroup_id ASC";
} else {
Litmus::Error::logError("Unknown sort_by type: $sort_by",
caller(0));
}
return _getValues($sql);
}
#########################################################################
sub getTestgroups()
{
my ($self, $enabled) = @_;
my $sql = "SELECT tg.testgroup_id, tg.name, tg.product_id, tg.branch_id FROM testgroups tg";
if ($enabled) {
$sql .= " WHERE tg.enabled=1";
}
$sql .= " ORDER BY tg.name, tg.testgroup_id";
return _getValues($sql);
}
#########################################################################
sub getLocales()
{
my @locales = Litmus::DB::Locale->retrieve_all();
# Append an extra copy of 'en-US' at the start of the list.
foreach my $locale (@locales) {
if ($locale->locale_abbrev eq 'en-US') {
unshift @locales, $locale;
last;
}
}
return \@locales;
}
#########################################################################
sub getUsers()
{
my @users = Litmus::DB::User->retrieve_all();
return \@users;
}
#########################################################################
sub getTestdays()
{
my @testdays = Litmus::DB::TestDay->retrieve_all_sorted_by("finish_timestamp DESC, product_id ASC, branch_id ASC, testday_id ASC" );
return \@testdays;
}
#########################################################################
sub getAuthors()
{
my $sql = "SELECT users.user_id, users.email FROM users, user_group_map, security_groups
WHERE
users.user_id=user_group_map.user_id AND
user_group_map.group_id=security_groups.group_id AND
(security_groups.grouptype=1 OR security_groups.grouptype=2
OR security_groups.grouptype=3)
ORDER BY users.email";
return _getValues($sql);
}
#########################################################################
sub getTestRuns() {
my ($self, $enabled) = @_;
my $sql = "SELECT test_run_id, name, product_id, start_timestamp, finish_timestamp FROM test_runs";
if ($enabled) {
$sql .= " WHERE enabled=1";
}
$sql .= " ORDER BY finish_timestamp DESC, name DESC";
return _getValues($sql);
}
#########################################################################
sub getFields()
{
my @fields = (
{ name => 'build_id',
display_string => "Build ID", },
{ name => 'comment',
display_string => "Comments", },
{ name => 'locale',
display_string => "Locale", },
{ name => 'opsys',
display_string => "Operating System", },
{ name => 'platform',
display_string => "Platform", },
{ name => 'product',
display_string => "Product", },
{ name => 'result_status',
display_string => "Result Status", },
{ name => 'subgroup',
display_string => "Subgroup", },
{ name => 'email',
display_string => "Submitted By", },
{ name => 'summary',
display_string => "Summary", },
{ name => 'testgroup',
display_string => "Testgroup", },
{ name => 'user_agent',
display_string => "User Agent", },
);
return \@fields;
}
#########################################################################
sub getMatchCriteria()
{
my @match_criteria = (
{ name => "contains_all",
display_string => "contains all of the words/strings" },
{ name => "contains_any",
display_string => "contains any of the words/strings" },
{ name => "contains",
display_string => "contains the word/string" },
{ name => "contains_case",
display_string => "contains the word/string (exact case)" },
{ name => "not_contain",
display_string => "does not contain the word/string" },
{ name => "not_contain_any",
display_string => "does not contain any of the words/strings" },
{ name => "regexp",
display_string => "matches the regexp" },
{ name => "not_regexp",
display_string => "does not match the regexp" },
);
return \@match_criteria;
}
#########################################################################
sub getSortFields()
{
my @sort_fields = (
{ name => "branch",
display_string => "Branch"},
{ name => "created",
display_string => "Date"},
{ name => "locale",
display_string => "Locale"},
{ name => "platform",
display_string => "Platform"},
{ name => "product",
display_string => "Product"},
{ name => "email",
display_string => "Submitted By"},
{ name => "summary",
display_string => "Summary"},
{ name => "result_status",
display_string => "Status"},
{ name => "testcase_id",
display_string => "Testcase ID#"},
{ name => "testgroup",
display_string => "Testgroup"},
{ name => "vetted_date",
display_string => "Vetted Date"},
);
return \@sort_fields;
}
#########################################################################
sub _getValues($)
{
my ($sql) = @_;
my $sth = $_dbh->prepare($sql);
$sth->execute();
my @rows;
while (my $data = $sth->fetchrow_hashref) {
foreach my $key (keys %$data) {
Encode::_utf8_on($data->{$key});
utf8::decode($data->{$key});
}
push @rows, $data;
}
$sth->finish();
return \@rows;
}
1;