From: mkanat%kerio.com <> Date: Thu, 17 Feb 2005 02:05:05 +0000 (+0000) Subject: Bug 280412: Templatize the 'list products' bit of editproducts X-Git-Tag: bugzilla-2.19.3~301 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc3aa3e7aa78106e8148b3ecbd92e65e5ad63985;p=thirdparty%2Fbugzilla.git Bug 280412: Templatize the 'list products' bit of editproducts Patch By Gavin Shelly r=wurblzap, a=myk --- diff --git a/editproducts.cgi b/editproducts.cgi index 3faa88563f..0fa2ddbaeb 100755 --- a/editproducts.cgi +++ b/editproducts.cgi @@ -22,6 +22,7 @@ # Terry Weissman # Dawn Endico # Joe Robins +# Gavin Shelley # # Direct any questions on this source code to # @@ -117,6 +118,28 @@ sub CheckClassification ($) } } +# For the transition period, as this file is templatised bit by bit, +# we need this routine, which does things properly, and will +# eventually be the only version. (The older versions assume a +# PutHeader() call has been made) +sub CheckClassificationNew ($) +{ + my $cl = shift; + + # do we have a classification? + unless ($cl) { + ThrowUserError('classification_not_specified'); + exit; + } + + unless (TestClassification $cl) { + ThrowUserError('classification_doesnt_exist', + {'name' => $cl}); + exit; + } +} + + sub CheckClassificationProduct ($$) { my $cl = shift; @@ -308,59 +331,50 @@ if (Param('useclassification')) { # unless ($action) { + if (Param('useclassification')) { - PutHeader("Select product in " . $classification); - } else { - PutHeader("Select product"); + CheckClassificationNew($classification); } - my $query="SELECT products.name,products.description,disallownew, - votesperuser,maxvotesperbug,votestoconfirm,COUNT(bug_id) - FROM products"; + my $dbh = Bugzilla->dbh; + my @execute_params = (); + my @products = (); + + my $query = "SELECT products.name, + COALESCE(products.description,'') AS description, + NOT(disallownew) AS status, + votesperuser, maxvotesperbug, votestoconfirm, + COUNT(bug_id) AS bug_count + FROM products"; + if (Param('useclassification')) { - $query .= ",classifications"; + $query .= ", classifications"; } + $query .= " LEFT JOIN bugs ON products.id = bugs.product_id"; + if (Param('useclassification')) { - $query .= " WHERE classifications.name=" . - SqlQuote($classification) . - " AND classifications.id=products.classification_id"; + $query .= " WHERE classifications.name = ? " . + " AND classifications.id = products.classification_id"; + + # trick_taint is OK because we use this in a placeholder in a SELECT + trick_taint($classification); + + push(@execute_params, + $classification); } + $query .= " GROUP BY products.name ORDER BY products.name"; - SendSQL($query); - print "\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print ""; - while ( MoreSQLData() ) { - my ($product, $description, $disallownew, $votesperuser, - $maxvotesperbug, $votestoconfirm, $bugs) = FetchSQLData(); - $description ||= "missing"; - $disallownew = $disallownew ? 'closed' : 'open'; - $bugs ||= 'none'; - print "\n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print " \n"; - print ""; - } - print "\n"; - print " \n"; - print " \n"; - print "
Edit product ...DescriptionStatusVotes
per
user
Max
Votes
per
bug
Votes
to
confirm
BugsAction
$product$description$disallownew$votesperuser$maxvotesperbug$votestoconfirm$bugsDelete
Add a new productAdd
\n"; - PutTrailer(); + $vars->{'products'} = $dbh->selectall_arrayref($query, + {'Slice' => {}}, + @execute_params); + + $vars->{'classification'} = $classification; + $template->process("admin/products/list.html.tmpl", + $vars) + || ThrowTemplateError($template->error()); + exit; } diff --git a/template/en/default/admin/products/footer.html.tmpl b/template/en/default/admin/products/footer.html.tmpl new file mode 100644 index 0000000000..0276437f3e --- /dev/null +++ b/template/en/default/admin/products/footer.html.tmpl @@ -0,0 +1,86 @@ +[%# 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): Gavin Shelley + #%] + +[%# INTERFACE: + # name: string; the name of the product + # + # classification: string; If classifications are enabled, then this is + # the currently selected classification + # + # no_XXX_link: boolean; if defined, then don't show the corresponding + # link. Supported parameters are: + # + # no_edit_product_link + # no_edit_other_products_link + # no_add_product_link + #%] + +[% IF classification %] + [% classification_url_part = BLOCK %]&classification= + [%- classification FILTER url_quote %] + [% END %] + [% classification_text = BLOCK %] + of classification '[% classification FILTER html %]' + [% END %] +[% END %] + +

+ +


+ +[% UNLESS no_add_product_link %] + Add a product + + + [%# Strictly speaking, we should not have to check for a + classification if they are enabled, but I'm just being paranoid %] + [% IF Param('useclassification') && classification %] + (to + classification '[% classification FILTER html %]') + [% END %]. +[% END %] + +[% IF name && !no_edit_product_link %] + Edit product + '[% name FILTER html %]'FRED +[% END %] + + +[% UNLESS no_edit_other_products_link %] + Edit other products [% classification_text %]' + [%- classification FILTER html %]' + +[% END %] + +[% IF Param('useclassification') && classification %] + Edit classification ' + [%- classification FILTER html %]'. + +[% END %] + +

diff --git a/template/en/default/admin/products/list.html.tmpl b/template/en/default/admin/products/list.html.tmpl new file mode 100644 index 0000000000..98676e198e --- /dev/null +++ b/template/en/default/admin/products/list.html.tmpl @@ -0,0 +1,119 @@ +[%# 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): Gavin Shelley + #%] + +[%# INTERFACE: + # products: array of hashes having the following properties: + # - name: string; The name of the product + # - description: string; The product description (html allowed) + # - status: boolean; Can new bugs be created for the product? + # - votesperuser: number; The number of votes a user is allowed + # in the product + # - maxvotersperbug: number; Maximum votes allowed per bug in this + # product + # - votestoconfirm: number; The number of votes that are needed to + # auto-confirm a bug in this product + # - bug_count: number; The number of bugs in this product + # + # classification: string; If classifications are enabled, then this is + # the currently selected classification + #%] + +[% PROCESS global/variables.none.tmpl %] + +[% IF classification %] + [% classification_url_part = BLOCK %]&classification= + [%- classification FILTER url_quote %] + [%- END %] + [% classification_title = BLOCK %] + in classification '[% classification FILTER html %]' + [% END %] +[% END %] + +[% PROCESS global/header.html.tmpl + title = "Select product $classification_title" +%] + +[% edit_contentlink = BLOCK %] + editproducts.cgi?action=edit&product=%%name%% + [%- classification_url_part %] +[% END %] +[% delete_contentlink = BLOCK %] + editproducts.cgi?action=del&product=%%name%% + [%- classification_url_part %] +[% END %] +[% bug_count_contentlink = BLOCK %]buglist.cgi?product=%%name%%& + [%- classification_url_part %][% END %] + + +[% columns = [ + { + name => "name" + heading => "Edit product..." + contentlink => edit_contentlink + }, + { + name => "description" + heading => "Description" + allow_html_content => 1 + }, + { + name => "status" + heading => "Open For New $terms.Bugs" + yesno_field => 1 + }, + { + name => "votesperuser" + heading => "Votes Per User" + align => 'right' + }, + { + name => "maxvotesperbug" + heading => "Maximum Votes Per $terms.Bug" + align => 'right' + }, + { + name => "votestoconfirm" + heading => "Votes To Confirm" + align => 'right' + }, + { + name => "bug_count" + heading => "$terms.Bug Count" + align => 'right' + contentlink => bug_count_contentlink + }, + ] +%] + +[% columns.push({ + heading => "Action" + content => "Delete" + contentlink => delete_contentlink + }) +%] + +[% PROCESS admin/table.html.tmpl + columns = columns + data = products +%] + +

+ +[% PROCESS admin/products/footer.html.tmpl + no_edit_other_products_link = 1 + %] + +[% PROCESS global/footer.html.tmpl %] diff --git a/template/en/default/admin/table.html.tmpl b/template/en/default/admin/table.html.tmpl index ac4e5a6668..fd1382b140 100644 --- a/template/en/default/admin/table.html.tmpl +++ b/template/en/default/admin/table.html.tmpl @@ -37,6 +37,7 @@ # text in the column. # allow_html_content: if defined, then this column allows html content # so it will not be filtered + # yesno_field: Turn the data from 0/!0 into Yes/No # # data: # array of hashes representing the data for the table. @@ -79,10 +80,18 @@ [% IF c.content %] [% c.content %] [% ELSE %] - [% IF c.allow_html_content %] - [% row.${c.name} FILTER none %] + [% IF c.yesno_field %] + [% IF row.${c.name} %] + Yes + [% ELSE %] + No + [% END %] [% ELSE %] - [% row.${c.name} FILTER html %] + [% IF c.allow_html_content %] + [% row.${c.name} FILTER none %] + [% ELSE %] + [% row.${c.name} FILTER html %] + [% END %] [% END %] [% END %] diff --git a/template/en/default/filterexceptions.pl b/template/en/default/filterexceptions.pl index 8f297ef42b..9fc4232b03 100644 --- a/template/en/default/filterexceptions.pl +++ b/template/en/default/filterexceptions.pl @@ -526,6 +526,15 @@ 'const.CONTROLMAPMANDATORY', ], +'admin/products/list.html.tmpl' => [ + 'classification_url_part', +], + +'admin/products/footer.html.tmpl' => [ + 'classification_url_part', + 'classification_text', +], + 'admin/keywords/edit.html.tmpl' => [ 'keyword_id', 'bug_count',