From 7ce67eec4fb2c17ee3621b1aad2f99295ed4649f Mon Sep 17 00:00:00 2001 From: "lpsolit%gmail.com" <> Date: Fri, 2 Sep 2005 04:33:06 +0000 Subject: Bug 302370: Remove the EmitFormElements() routine from editproducts.cgi and templatize that code - Patch by Gabriel Sales de Oliveira r=LpSolit a=myk --- editproducts.cgi | 301 +++++---------------- .../en/default/admin/products/create.html.tmpl | 64 +++++ .../default/admin/products/edit-common.html.tmpl | 89 ++++++ template/en/default/admin/products/edit.html.tmpl | 152 +++++++++++ 4 files changed, 377 insertions(+), 229 deletions(-) create mode 100644 template/en/default/admin/products/create.html.tmpl create mode 100644 template/en/default/admin/products/edit-common.html.tmpl create mode 100644 template/en/default/admin/products/edit.html.tmpl diff --git a/editproducts.cgi b/editproducts.cgi index 5f6c32614..ba8337189 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -44,13 +44,6 @@ use Bugzilla::Config qw(:DEFAULT $datadir); # doesn't work for me. use vars qw(@legal_bug_status @legal_resolution); -my %ctl = ( - &::CONTROLMAPNA => 'NA', - &::CONTROLMAPSHOWN => 'Shown', - &::CONTROLMAPDEFAULT => 'Default', - &::CONTROLMAPMANDATORY => 'Mandatory' -); - # TestProduct: just returns if the specified product does exists # CheckProduct: same check, optionally emit an error text @@ -186,67 +179,6 @@ sub CheckClassificationProductNew } } -# -# Displays the form to edit a products parameters -# - -sub EmitFormElements -{ - my ($classification, $product, $description, $milestoneurl, $disallownew, - $votesperuser, $maxvotesperbug, $votestoconfirm, $defaultmilestone) - = @_; - - $product = value_quote($product); - $description = value_quote($description); - - if (Param('useclassification')) { - print " Classification:\n"; - print " ",html_quote($classification),"\n"; - print "\n"; - } - - print " Product:\n"; - print " \n"; - print "\n"; - - print " Description:\n"; - print " \n"; - - $defaultmilestone = value_quote($defaultmilestone); - if (Param('usetargetmilestone')) { - $milestoneurl = value_quote($milestoneurl); - print "\n"; - print " URL describing milestones for this product:\n"; - print " \n"; - - print "\n"; - print " Default milestone:\n"; - - print " \n"; - } else { - print qq{\n}; - } - - - print "\n"; - print " Closed for bug entry:\n"; - my $closed = $disallownew ? "CHECKED" : ""; - print " \n"; - - print "\n"; - print " Maximum votes per person:\n"; - print " \n"; - - print "\n"; - print " Maximum votes a person can put on a single bug:\n"; - print " \n"; - - print "\n"; - print " Number of votes a bug in this product needs to automatically get out of the UNCONFIRMED state:\n"; - print " \n"; -} - - # # Displays a text like "a.", "a or b.", "a, b or c.", "a, b, c or d." # @@ -408,42 +340,18 @@ if (!$action && !$product) { # if ($action eq 'add') { - $template->put_header("Add product"); if (Param('useclassification')) { CheckClassification($classification); } - #print "This page lets you add a new product to bugzilla.\n"; - - print "
\n"; - print "\n"; - - EmitFormElements($classification,'', '', '', 0, 0, 10000, 0, "---"); - - print "\n"; - print " \n"; - print " \n"; - print "\n"; - print " \n"; - print " "; - print "\n"; - - print "
Version:
Create chart datasets for this product:
\n
\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "
"; - - my $other = $localtrailer; - $other =~ s/more/other/; - PutTrailer($other); + $vars->{'classification'} = $classification; + $template->process("admin/products/create.html.tmpl", $vars) + || ThrowTemplateError($template->error()); + exit; } - # # action='new' -> add product entered in the 'action=add' screen # @@ -781,8 +689,9 @@ if ($action eq 'delete') { # if ($action eq 'edit' || (!$action && $product)) { - $template->put_header("Edit product"); CheckProduct($product); + trick_taint($product); + my $product_id = get_product_id($product); my $classification_id=1; if (Param('useclassification')) { # If a product has been given with no classification associated @@ -790,7 +699,6 @@ if ($action eq 'edit' || (!$action && $product)) { if ($classification) { CheckClassificationProduct($classification, $product); } else { - trick_taint($product); $classification = $dbh->selectrow_array("SELECT classifications.name FROM products, classifications @@ -800,144 +708,79 @@ if ($action eq 'edit' || (!$action && $product)) { } $classification_id = get_classification_id($classification); } + + $vars->{'classification'} = $classification; # get data of product - SendSQL("SELECT classifications.description, - products.id,products.description,milestoneurl,disallownew, - votesperuser,maxvotesperbug,votestoconfirm,defaultmilestone - FROM products,classifications - WHERE products.name=" . SqlQuote($product) . - " AND classifications.id=" . SqlQuote($classification_id)); - my ($class_description, $product_id,$prod_description, $milestoneurl, $disallownew, - $votesperuser, $maxvotesperbug, $votestoconfirm, $defaultmilestone) = - FetchSQLData(); - - print "
\n"; - print "\n"; - - EmitFormElements($classification, $product, $prod_description, $milestoneurl, - $disallownew, $votesperuser, $maxvotesperbug, - $votestoconfirm, $defaultmilestone); + $vars->{'product'} = $dbh->selectrow_hashref(qq{ + SELECT id, name, classification_id, description, + milestoneurl, disallownew, votesperuser, + maxvotesperbug, votestoconfirm, defaultmilestone + FROM products + WHERE id = ?}, undef, $product_id); - print "\n"; - print " \n"; - print " \n\n"; - print " \n"; - print " \n\n"; - print " \n"; - print " \n\n"; - print " \n"; - print "\n\n"; - print " \n"; - print " \n
Edit components:"; - SendSQL("SELECT name,description - FROM components - WHERE product_id=$product_id"); - if (MoreSQLData()) { - print ""; - while ( MoreSQLData() ) { - my ($component, $description) = FetchSQLData(); - $description ||= "description missing"; - print ""; - print "\n"; - } - print "
$component:$description
\n"; - } else { - print "missing"; - } - - - print "
Edit versions:"; - SendSQL("SELECT value - FROM versions - WHERE product_id=$product_id - ORDER BY value"); - if (MoreSQLData()) { - my $br = 0; - while ( MoreSQLData() ) { - my ($version) = FetchSQLData(); - print "
" if $br; - print $version; - $br = 1; - } - } else { - print "missing"; - } + + $vars->{'components'} = $dbh->selectall_arrayref(qq{ + SELECT name, description + FROM components + WHERE product_id = ? + ORDER BY name}, {'Slice' => {}},$product_id); + + + $vars->{'versions'} = $dbh->selectcol_arrayref(q{ + SELECT value FROM versions + WHERE product_id = ? + ORDER BY value}, undef, $product_id); - # - # Adding listing for associated target milestones - matthew@zeroknowledge.com - # if (Param('usetargetmilestone')) { - print "
Edit milestones:"; - SendSQL("SELECT value - FROM milestones - WHERE product_id=$product_id - ORDER BY sortkey,value"); - if(MoreSQLData()) { - my $br = 0; - while ( MoreSQLData() ) { - my ($milestone) = FetchSQLData(); - print "
" if $br; - print $milestone; - $br = 1; - } - } else { - print "missing"; - } + $vars->{'milestones'} = $dbh->selectcol_arrayref(q{ + SELECT value + FROM milestones + WHERE product_id = ? + ORDER BY sortkey, value}, + undef, $product_id); } - - print "
Edit Group Access Controls\n"; - SendSQL("SELECT id, name, isactive, entry, membercontrol, othercontrol, canedit " . - "FROM groups, " . - "group_control_map " . - "WHERE group_control_map.group_id = id AND product_id = $product_id " . - "AND isbuggroup != 0 ORDER BY name"); - while (MoreSQLData()) { - my ($id, $name, $isactive, $entry, $membercontrol, $othercontrol, $canedit) - = FetchSQLData(); - print "" . html_quote($name) . ": "; - if ($isactive) { - print $ctl{$membercontrol} . "/" . $ctl{$othercontrol}; - print ", ENTRY" if $entry; - print ", CANEDIT" if $canedit; - } else { - print "DISABLED"; - } - print "
\n"; + + my $query = qq{SELECT + groups.id, groups.name, groups.isactive, + group_control_map.entry, + group_control_map.membercontrol, + group_control_map.othercontrol, + group_control_map.canedit + FROM groups + INNER JOIN group_control_map + ON groups.id = group_control_map.group_id + WHERE group_control_map.product_id = ? + AND groups.isbuggroup != 0 + ORDER BY groups.name}; + my $groups = $dbh->selectall_arrayref($query, {'Slice' => {}}, + $product_id); + + # Convert Group Controls(membercontrol and othercontrol) from + # integer to string to display Membercontrol/Othercontrol names + # at the template. + my $constants = { + (CONTROLMAPNA) => 'NA', + (CONTROLMAPSHOWN) => 'Shown', + (CONTROLMAPDEFAULT) => 'Default', + (CONTROLMAPMANDATORY) => 'Mandatory'}; + + foreach my $group (@$groups) { + $group->{'membercontrol'} = + $constants->{$group->{'membercontrol'}}; + $group->{'othercontrol'} = + $constants->{$group->{'othercontrol'}}; } - print "
Bugs:"; - SendSQL("SELECT count(bug_id), product_id - FROM bugs " . - $dbh->sql_group_by('product_id') . " - HAVING product_id = $product_id"); - my $bugs = ''; - $bugs = FetchOneColumn() if MoreSQLData(); - print $bugs || 'none'; - - print "
\n"; - - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - $defaultmilestone = value_quote($defaultmilestone); - print "\n"; - print "\n"; - print "\n"; - - print "
"; - - my $x = $localtrailer; - $x =~ s/more/other/; - PutTrailer($x); + + $vars->{'groups'} = $groups; + + $vars->{'bug_count'} = $dbh->selectrow_array(qq{ + SELECT COUNT(*) FROM bugs + WHERE product_id = ?}, undef, $product_id); + + $template->process("admin/products/edit.html.tmpl", $vars) + || ThrowTemplateError($template->error()); + exit; } diff --git a/template/en/default/admin/products/create.html.tmpl b/template/en/default/admin/products/create.html.tmpl new file mode 100644 index 000000000..8dc6615b4 --- /dev/null +++ b/template/en/default/admin/products/create.html.tmpl @@ -0,0 +1,64 @@ +[%# 1.0@bugzilla.org %] +[%# 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 the Bugzilla Bug Tracking System. + # + # Contributor(s): Gabriel S. Oliveira + #%] + +[%# INTERFACE: + # classification: string; name of the classification in which the new + # product is created. + # + #%] + +[% title = BLOCK %]Add Product[% END %] + +[% PROCESS global/header.html.tmpl + title = title +%] + +[% DEFAULT + product.votesperuser = "0", + product.maxvotesperbug = "10000", + product.votestoconfirm = "0", + version = "unspecified", + product.defaultmilestone = "---" +%] + +
+ + + [% PROCESS "admin/products/edit-common.html.tmpl" %] + + + + + + + + + +
Version: +
Create chart datasets for this product:
+ + + + + + +
+ +[% PROCESS "admin/products/footer.html.tmpl" no_add_product_link = 1 %] + +[% PROCESS global/footer.html.tmpl %] diff --git a/template/en/default/admin/products/edit-common.html.tmpl b/template/en/default/admin/products/edit-common.html.tmpl new file mode 100644 index 000000000..cbbbd8232 --- /dev/null +++ b/template/en/default/admin/products/edit-common.html.tmpl @@ -0,0 +1,89 @@ +[%# 1.0@bugzilla.org %] +[%# 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 the Bugzilla Bug Tracking System. + # + # Contributor(s): Jack Nerad + # Tiago R. Mello + # Gabriel S. Oliveira + #%] + +[%# INTERFACE: + # classification: string; name of classification product is in. + # product: array; an array of product objects. + #%] + +[% IF Param('useclassification') %] + + Classification: + [% classification FILTER html %] + +[% END %] + + + Product: + + + + + Description: + + + + +[% IF Param('usetargetmilestone') -%] + + URL describing milestones for this product: + + + + + Default milestone: + + + +[% END %] + + + Closed for [% terms.bug %] entry: + + + + + Maximum votes per person: + + + + + + Maximum votes a person can put on a single [% terms.bug %]: + + + + + + + Number of votes [% terms.abug %] in this product needs to + automatically get out of the + UNCONFIRMED state: + + + + diff --git a/template/en/default/admin/products/edit.html.tmpl b/template/en/default/admin/products/edit.html.tmpl new file mode 100644 index 000000000..da58e6722 --- /dev/null +++ b/template/en/default/admin/products/edit.html.tmpl @@ -0,0 +1,152 @@ +[%# 1.0@bugzilla.org %] +[%# 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 the Bugzilla Bug Tracking System. + # + # Contributor(s): Jack Nerad + # Tiago R. Mello + # Gabriel S. Oliveira + #%] + +[%# INTERFACE: + # classification: string; name of classification product is in. + # product: an array of product objects. + # components: an array of component object(s) related to the product. + # groups: an array of group objects related to the product. + # versions: an array of version objects related to product. + # milestones: an array of milestones objects related to product. + # bug_count: integer; number of bugs in this product. + #%] + +[% title = BLOCK %]Edit Product[% END %] + +[% PROCESS global/header.html.tmpl + title = title +%] + +
+ + + [% PROCESS "admin/products/edit-common.html.tmpl" %] + + + + + + + + + + [% IF Param('usetargetmilestone') %] + + + + + [% END %] + + + + + + + + +
+ + Edit components: + + + [% IF components.size -%] + [% FOREACH component = components %] + [% component.name FILTER html %]:  + [% IF component.description %] + [% component.description FILTER none %] + [% ELSE %] + description missing + [% END %] +
+ [% END %] + [% ELSE %] + missing + [% END %] +
+ Edit +versions: + + [%- IF versions.size -%] + [% FOREACH v = versions %] + [% v FILTER html %] +
+ [% END %] + [% ELSE %] + missing + [% END %] +
+ + Edit milestones: + + [%- IF milestones.size -%] + [%- FOREACH m = milestones -%] + [% m FILTER html %] +
+ [% END %] + [% ELSE %] + missing + [% END %] +
+ + Edit Group Access Controls: + + + [% IF groups.size %] + [% FOREACH g = groups %] + [% g.name FILTER html %]:  + [% IF g.isactive %] + [% g.membercontrol FILTER html %]/ + [% g.othercontrol FILTER html %] + [% IF g.entry %], ENTRY[% END %] + [% IF g.canedit %], CANEDIT[% END %] + [% ELSE %] + DISABLED + [% END %] +
+ [% END %] + [% ELSE %] + no groups + [% END %] +
[% terms.Bugs %]:[% bug_count FILTER html %]
+ + + + + + + + + + + + +
+ +[% PROCESS "admin/products/footer.html.tmpl" no_add_product_link = 1 %] + +[% PROCESS global/footer.html.tmpl %] -- cgit v1.2.3-24-g4f1b