Commit 04004a62 authored by Frédéric Buclin's avatar Frédéric Buclin

Bug 1191706: When editing flag types, components do not match the selected…

Bug 1191706: When editing flag types, components do not match the selected product when classifications are enabled r/a=dkl
parent 26a693ad
...@@ -436,17 +436,30 @@ sub get_products_and_components { ...@@ -436,17 +436,30 @@ sub get_products_and_components {
my @products; my @products;
if ($user->in_group('editcomponents')) { if ($user->in_group('editcomponents')) {
@products = Bugzilla::Product->get_all; if (Bugzilla->params->{useclassification}) {
# We want products grouped by classifications.
@products = map { @{ $_->products } } Bugzilla::Classification->get_all;
}
else {
@products = Bugzilla::Product->get_all;
}
} }
else { else {
@products = @{$user->get_products_by_permission('editcomponents')}; @products = @{$user->get_products_by_permission('editcomponents')};
if (Bugzilla->params->{useclassification}) {
my %class;
push(@{$class{$_->classification_id}}, $_) foreach @products;
# Let's sort the list by classifications.
@products = ();
push(@products, @{$class{$_->id}}) foreach Bugzilla::Classification->get_all;
}
} }
# We require all unique component names.
my %components; my %components;
foreach my $product (@products) { foreach my $product (@products) {
foreach my $component (@{$product->components}) { $components{$_->name} = 1 foreach @{$product->components};
$components{$component->name} = 1;
}
} }
$vars->{'products'} = \@products; $vars->{'products'} = \@products;
$vars->{'components'} = [sort(keys %components)]; $vars->{'components'} = [sort(keys %components)];
......
...@@ -10,16 +10,10 @@ ...@@ -10,16 +10,10 @@
// collection of javascript arrays containing strings. // collection of javascript arrays containing strings.
/** /**
* Reads the selected products and updates component, version and milestone * Reads the selected products and updates the component list accordingly.
* lists accordingly.
* *
* @param product Select element that contains products. * @param product Select element that contains products.
* @param component Select element that contains components. Can be null if * @param component Select element that contains components.
* there is no such element to update.
* @param version Select element that contains versions. Can be null if
* there is no such element to update.
* @param milestone Select element that contains milestones. Can be null if
* there is no such element to update.
* @param anyval Value to use for a special "Any" list item. Can be null * @param anyval Value to use for a special "Any" list item. Can be null
* to not use any. If used must and will be first item in * to not use any. If used must and will be first item in
* the select element. * the select element.
...@@ -27,21 +21,15 @@ ...@@ -27,21 +21,15 @@
* @global cpts Array of arrays, indexed by product name. The subarrays * @global cpts Array of arrays, indexed by product name. The subarrays
* contain a list of components to be fed to the respective * contain a list of components to be fed to the respective
* select element. * select element.
* @global vers Array of arrays, indexed by product name. The subarrays
* contain a list of versions to be fed to the respective
* select element.
* @global tms Array of arrays, indexed by product name. The subarrays
* contain a list of milestones to be fed to the respective
* select element.
* @global first_load Boolean; true if this is the first time this page loads * @global first_load Boolean; true if this is the first time this page loads
* or false if not. * or false if not.
* @global last_sel Array that contains last list of products so we know what * @global last_sel Array that contains last list of products so we know what
* has changed, and optimize for additions. * has changed, and optimize for additions.
*/ */
function selectProduct(product, component, version, milestone, anyval) { function selectProduct(product, component, anyval) {
// This is to avoid handling events that occur before the form // This is to avoid handling events that occur before the form
// itself is ready, which could happen in buggy browsers. // itself is ready, which could happen in buggy browsers.
if (!product) if (!product || !component)
return; return;
// Do nothing if no products are defined. This is to avoid the // Do nothing if no products are defined. This is to avoid the
...@@ -78,15 +66,8 @@ function selectProduct(product, component, version, milestone, anyval) { ...@@ -78,15 +66,8 @@ function selectProduct(product, component, version, milestone, anyval) {
var findall = (product.selectedIndex == -1 var findall = (product.selectedIndex == -1
|| (anyval != null && product.options[0].selected)); || (anyval != null && product.options[0].selected));
if (useclassification) { sel = get_selection(product, findall, false, anyval);
// Update index based on the complete product array.
sel = get_selection(product, findall, true, anyval);
for (var i=0; i<sel.length; i++)
sel[i] = prods[sel[i]];
}
else {
sel = get_selection(product, findall, false, anyval);
}
if (!findall) { if (!findall) {
// Save sel for the next invocation of selectProduct(). // Save sel for the next invocation of selectProduct().
var tmp = sel; var tmp = sel;
...@@ -103,23 +84,9 @@ function selectProduct(product, component, version, milestone, anyval) { ...@@ -103,23 +84,9 @@ function selectProduct(product, component, version, milestone, anyval) {
} }
// Do the actual fill/update. // Do the actual fill/update.
if (component) { var saved_cpts = get_selection(component, false, true, null);
var saved_cpts = get_selection(component, false, true, null); updateSelect(cpts, sel, component, merging, anyval);
updateSelect(cpts, sel, component, merging, anyval); restoreSelection(component, saved_cpts);
restoreSelection(component, saved_cpts);
}
if (version) {
var saved_vers = get_selection(version, false, true, null);
updateSelect(vers, sel, version, merging, anyval);
restoreSelection(version, saved_vers);
}
if (milestone) {
var saved_tms = get_selection(milestone, false, true, null);
updateSelect(tms, sel, milestone, merging, anyval);
restoreSelection(milestone, saved_tms);
}
} }
/** /**
......
...@@ -305,13 +305,22 @@ sub queue { ...@@ -305,13 +305,22 @@ sub queue {
$vars->{'requests'} = \@requests; $vars->{'requests'} = \@requests;
$vars->{'types'} = \@types; $vars->{'types'} = \@types;
my %components; # This code is needed to populate the Product and Component select fields.
foreach my $prod (@{$user->get_selectable_products}) { my ($products, %components);
foreach my $comp (@{$prod->components}) { if (Bugzilla->params->{useclassification}) {
$components{$comp->name} = 1; foreach my $class (@{$user->get_selectable_classifications}) {
push @$products, @{$user->get_selectable_products($class->id)};
} }
} }
$vars->{'components'} = [ sort { $a cmp $b } keys %components ]; else {
$products = $user->get_selectable_products;
}
foreach my $product (@$products) {
$components{$_->name} = 1 foreach @{$product->components};
}
$vars->{'products'} = $products;
$vars->{'components'} = [ sort keys %components ];
$vars->{'urlquerypart'} = $cgi->canonicalise_query('ctype'); $vars->{'urlquerypart'} = $cgi->canonicalise_query('ctype');
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
title = title title = title
style_urls = ['skins/standard/admin.css'] style_urls = ['skins/standard/admin.css']
onload="var f = document.forms['flagtype_properties']; onload="var f = document.forms['flagtype_properties'];
selectProduct(f.product, f.component, null, null, '__Any__');" selectProduct(f.product, f.component, '__Any__');"
javascript_urls=["js/productform.js"] javascript_urls=["js/productform.js"]
doc_section = "administering/flags.html" doc_section = "administering/flags.html"
%] %]
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
id => "product" id => "product"
name => "product" name => "product"
add => "__Any__" add => "__Any__"
onchange => "selectProduct(this, this.form.component, null, null, '__Any__');" onchange => "selectProduct(this, this.form.component, '__Any__');"
products => products products => products
%]<br> %]<br>
<select name="component"> <select name="component">
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title = 'Administer Flag Types' title = 'Administer Flag Types'
style_urls = ['skins/standard/admin.css'] style_urls = ['skins/standard/admin.css']
onload="var f = document.flagtype_form; selectProduct(f.product, f.component, null, null, '__All__');" onload="var f = document.flagtype_form; selectProduct(f.product, f.component, '__All__');"
javascript_urls=["js/productform.js"] javascript_urls=["js/productform.js"]
doc_section = "administering/flags.html" doc_section = "administering/flags.html"
%] %]
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
id => "product" id => "product"
name => "product" name => "product"
add => "__Any__" add => "__Any__"
onchange => "selectProduct(this, this.form.component, null, null, '__Any__');" onchange => "selectProduct(this, this.form.component, '__Any__');"
products => products products => products
%] %]
</div> </div>
......
...@@ -8,14 +8,13 @@ ...@@ -8,14 +8,13 @@
[%# The javascript block gets used in header.html.tmpl. %] [%# The javascript block gets used in header.html.tmpl. %]
[% javascript = BLOCK %] [% javascript = BLOCK %]
var useclassification = false; // No classification level in use
var first_load = true; // Is this the first time we load the page? var first_load = true; // Is this the first time we load the page?
var last_sel = []; // Caches last selection var last_sel = []; // Caches last selection
var cpts = new Array(); var cpts = new Array();
[% n = 1 %] [% n = 1 %]
[% FOREACH prod = products %] [% FOREACH prod = products %]
cpts['[% n %]'] = [ cpts['[% n %]'] = [[% FOREACH comp = prod.components %]'[% comp.name FILTER js %]'[% ", " UNLESS loop.last %] [%- END -%]];
[%- FOREACH comp = prod.components %]'[% comp.name FILTER js %]'[% ", " UNLESS loop.last %] [%- END -%] ];
[% n = n+1 %] [% n = n+1 %]
[% END %] [% END %]
[% END %] [% END %]
...@@ -9,40 +9,17 @@ ...@@ -9,40 +9,17 @@
[% USE Bugzilla %] [% USE Bugzilla %]
[% cgi = Bugzilla.cgi %] [% cgi = Bugzilla.cgi %]
[% PROCESS "global/js-products.html.tmpl" %]
[% PROCESS global/header.html.tmpl [% PROCESS global/header.html.tmpl
title="Request Queue" title="Request Queue"
generate_api_token = 1 generate_api_token = 1
onload="var f = document.request_form; selectProduct(f.product, f.component, null, null, 'Any');" onload="var f = document.request_form; selectProduct(f.product, f.component, 'Any');"
javascript_urls=["js/productform.js", "js/field.js"] javascript_urls=["js/productform.js", "js/field.js"]
style_urls = ['skins/standard/buglist.css'] style_urls = ['skins/standard/buglist.css']
yui = ['autocomplete'] yui = ['autocomplete']
%] %]
<script type="text/javascript">
var useclassification = false; // No classification level in use
var first_load = true; // Is this the first time we load the page?
var last_sel = []; // Caches last selection
var cpts = new Array();
[% n = 1 %]
[% IF Param('useclassification') %]
[% FOREACH clas = user.get_selectable_classifications %]
[% FOREACH prod = user.get_selectable_products(clas.id) %]
[%+ PROCESS js_comp %]
[% END %]
[% END %]
[% ELSE %]
[% FOREACH prod = user.get_selectable_products %]
[%+ PROCESS js_comp %]
[% END %]
[% END %]
</script>
[% BLOCK js_comp %]
cpts['[% n %]'] = [
[%- FOREACH comp = prod.components %]'[% comp.name FILTER js %]'[% ", " UNLESS loop.last %] [%- END -%]];
[% n = n+1 %]
[% END %]
<p> <p>
When you are logged in, only requests made by you or addressed to you When you are logged in, only requests made by you or addressed to you
are shown by default. You can change the criteria using the form below. are shown by default. You can change the criteria using the form below.
...@@ -72,7 +49,7 @@ to some group are shown by default. ...@@ -72,7 +49,7 @@ to some group are shown by default.
id => "product" id => "product"
name => "product" name => "product"
add => "Any" add => "Any"
onchange => "selectProduct(this, this.form.component, null, null, 'Any');" onchange => "selectProduct(this, this.form.component, 'Any');"
%] %]
</td> </td>
<th>Flag:</th> <th>Flag:</th>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment