Skip to content

Commit 04004a6

Browse files
committed
Bug 1191706: When editing flag types, components do not match the selected product when classifications are enabled
r/a=dkl
1 parent 26a693a commit 04004a6

7 files changed

Lines changed: 51 additions & 86 deletions

File tree

editflagtypes.cgi

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -436,17 +436,30 @@ sub get_products_and_components {
436436

437437
my @products;
438438
if ($user->in_group('editcomponents')) {
439-
@products = Bugzilla::Product->get_all;
439+
if (Bugzilla->params->{useclassification}) {
440+
# We want products grouped by classifications.
441+
@products = map { @{ $_->products } } Bugzilla::Classification->get_all;
442+
}
443+
else {
444+
@products = Bugzilla::Product->get_all;
445+
}
440446
}
441447
else {
442448
@products = @{$user->get_products_by_permission('editcomponents')};
449+
450+
if (Bugzilla->params->{useclassification}) {
451+
my %class;
452+
push(@{$class{$_->classification_id}}, $_) foreach @products;
453+
454+
# Let's sort the list by classifications.
455+
@products = ();
456+
push(@products, @{$class{$_->id}}) foreach Bugzilla::Classification->get_all;
457+
}
443458
}
444-
# We require all unique component names.
459+
445460
my %components;
446461
foreach my $product (@products) {
447-
foreach my $component (@{$product->components}) {
448-
$components{$component->name} = 1;
449-
}
462+
$components{$_->name} = 1 foreach @{$product->components};
450463
}
451464
$vars->{'products'} = \@products;
452465
$vars->{'components'} = [sort(keys %components)];

js/productform.js

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,26 @@
1010
// collection of javascript arrays containing strings.
1111

1212
/**
13-
* Reads the selected products and updates component, version and milestone
14-
* lists accordingly.
13+
* Reads the selected products and updates the component list accordingly.
1514
*
1615
* @param product Select element that contains products.
17-
* @param component Select element that contains components. Can be null if
18-
* there is no such element to update.
19-
* @param version Select element that contains versions. Can be null if
20-
* there is no such element to update.
21-
* @param milestone Select element that contains milestones. Can be null if
22-
* there is no such element to update.
16+
* @param component Select element that contains components.
2317
* @param anyval Value to use for a special "Any" list item. Can be null
2418
* to not use any. If used must and will be first item in
2519
* the select element.
2620
*
2721
* @global cpts Array of arrays, indexed by product name. The subarrays
2822
* contain a list of components to be fed to the respective
2923
* select element.
30-
* @global vers Array of arrays, indexed by product name. The subarrays
31-
* contain a list of versions to be fed to the respective
32-
* select element.
33-
* @global tms Array of arrays, indexed by product name. The subarrays
34-
* contain a list of milestones to be fed to the respective
35-
* select element.
3624
* @global first_load Boolean; true if this is the first time this page loads
3725
* or false if not.
3826
* @global last_sel Array that contains last list of products so we know what
3927
* has changed, and optimize for additions.
4028
*/
41-
function selectProduct(product, component, version, milestone, anyval) {
29+
function selectProduct(product, component, anyval) {
4230
// This is to avoid handling events that occur before the form
4331
// itself is ready, which could happen in buggy browsers.
44-
if (!product)
32+
if (!product || !component)
4533
return;
4634

4735
// Do nothing if no products are defined. This is to avoid the
@@ -78,15 +66,8 @@ function selectProduct(product, component, version, milestone, anyval) {
7866
var findall = (product.selectedIndex == -1
7967
|| (anyval != null && product.options[0].selected));
8068

81-
if (useclassification) {
82-
// Update index based on the complete product array.
83-
sel = get_selection(product, findall, true, anyval);
84-
for (var i=0; i<sel.length; i++)
85-
sel[i] = prods[sel[i]];
86-
}
87-
else {
88-
sel = get_selection(product, findall, false, anyval);
89-
}
69+
sel = get_selection(product, findall, false, anyval);
70+
9071
if (!findall) {
9172
// Save sel for the next invocation of selectProduct().
9273
var tmp = sel;
@@ -103,23 +84,9 @@ function selectProduct(product, component, version, milestone, anyval) {
10384
}
10485

10586
// Do the actual fill/update.
106-
if (component) {
107-
var saved_cpts = get_selection(component, false, true, null);
108-
updateSelect(cpts, sel, component, merging, anyval);
109-
restoreSelection(component, saved_cpts);
110-
}
111-
112-
if (version) {
113-
var saved_vers = get_selection(version, false, true, null);
114-
updateSelect(vers, sel, version, merging, anyval);
115-
restoreSelection(version, saved_vers);
116-
}
117-
118-
if (milestone) {
119-
var saved_tms = get_selection(milestone, false, true, null);
120-
updateSelect(tms, sel, milestone, merging, anyval);
121-
restoreSelection(milestone, saved_tms);
122-
}
87+
var saved_cpts = get_selection(component, false, true, null);
88+
updateSelect(cpts, sel, component, merging, anyval);
89+
restoreSelection(component, saved_cpts);
12390
}
12491

12592
/**

request.cgi

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,22 @@ sub queue {
305305
$vars->{'requests'} = \@requests;
306306
$vars->{'types'} = \@types;
307307

308-
my %components;
309-
foreach my $prod (@{$user->get_selectable_products}) {
310-
foreach my $comp (@{$prod->components}) {
311-
$components{$comp->name} = 1;
308+
# This code is needed to populate the Product and Component select fields.
309+
my ($products, %components);
310+
if (Bugzilla->params->{useclassification}) {
311+
foreach my $class (@{$user->get_selectable_classifications}) {
312+
push @$products, @{$user->get_selectable_products($class->id)};
312313
}
313314
}
314-
$vars->{'components'} = [ sort { $a cmp $b } keys %components ];
315+
else {
316+
$products = $user->get_selectable_products;
317+
}
318+
319+
foreach my $product (@$products) {
320+
$components{$_->name} = 1 foreach @{$product->components};
321+
}
322+
$vars->{'products'} = $products;
323+
$vars->{'components'} = [ sort keys %components ];
315324

316325
$vars->{'urlquerypart'} = $cgi->canonicalise_query('ctype');
317326

template/en/default/admin/flag-type/edit.html.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
title = title
2424
style_urls = ['skins/standard/admin.css']
2525
onload="var f = document.forms['flagtype_properties'];
26-
selectProduct(f.product, f.component, null, null, '__Any__');"
26+
selectProduct(f.product, f.component, '__Any__');"
2727
javascript_urls=["js/productform.js"]
2828
doc_section = "administering/flags.html"
2929
%]
@@ -92,7 +92,7 @@
9292
id => "product"
9393
name => "product"
9494
add => "__Any__"
95-
onchange => "selectProduct(this, this.form.component, null, null, '__Any__');"
95+
onchange => "selectProduct(this, this.form.component, '__Any__');"
9696
products => products
9797
%]<br>
9898
<select name="component">

template/en/default/admin/flag-type/list.html.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
[% PROCESS global/header.html.tmpl
1212
title = 'Administer Flag Types'
1313
style_urls = ['skins/standard/admin.css']
14-
onload="var f = document.flagtype_form; selectProduct(f.product, f.component, null, null, '__All__');"
14+
onload="var f = document.flagtype_form; selectProduct(f.product, f.component, '__All__');"
1515
javascript_urls=["js/productform.js"]
1616
doc_section = "administering/flags.html"
1717
%]
@@ -43,7 +43,7 @@
4343
id => "product"
4444
name => "product"
4545
add => "__Any__"
46-
onchange => "selectProduct(this, this.form.component, null, null, '__Any__');"
46+
onchange => "selectProduct(this, this.form.component, '__Any__');"
4747
products => products
4848
%]
4949
</div>

template/en/default/global/js-products.html.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88

99
[%# The javascript block gets used in header.html.tmpl. %]
1010
[% javascript = BLOCK %]
11-
var useclassification = false; // No classification level in use
1211
var first_load = true; // Is this the first time we load the page?
1312
var last_sel = []; // Caches last selection
1413
var cpts = new Array();
14+
1515
[% n = 1 %]
1616
[% FOREACH prod = products %]
17-
cpts['[% n %]'] = [
18-
[%- FOREACH comp = prod.components %]'[% comp.name FILTER js %]'[% ", " UNLESS loop.last %] [%- END -%] ];
17+
cpts['[% n %]'] = [[% FOREACH comp = prod.components %]'[% comp.name FILTER js %]'[% ", " UNLESS loop.last %] [%- END -%]];
1918
[% n = n+1 %]
2019
[% END %]
2120
[% END %]

template/en/default/request/queue.html.tmpl

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,40 +9,17 @@
99
[% USE Bugzilla %]
1010
[% cgi = Bugzilla.cgi %]
1111

12+
[% PROCESS "global/js-products.html.tmpl" %]
13+
1214
[% PROCESS global/header.html.tmpl
1315
title="Request Queue"
1416
generate_api_token = 1
15-
onload="var f = document.request_form; selectProduct(f.product, f.component, null, null, 'Any');"
17+
onload="var f = document.request_form; selectProduct(f.product, f.component, 'Any');"
1618
javascript_urls=["js/productform.js", "js/field.js"]
1719
style_urls = ['skins/standard/buglist.css']
1820
yui = ['autocomplete']
1921
%]
2022

21-
<script type="text/javascript">
22-
var useclassification = false; // No classification level in use
23-
var first_load = true; // Is this the first time we load the page?
24-
var last_sel = []; // Caches last selection
25-
var cpts = new Array();
26-
[% n = 1 %]
27-
[% IF Param('useclassification') %]
28-
[% FOREACH clas = user.get_selectable_classifications %]
29-
[% FOREACH prod = user.get_selectable_products(clas.id) %]
30-
[%+ PROCESS js_comp %]
31-
[% END %]
32-
[% END %]
33-
[% ELSE %]
34-
[% FOREACH prod = user.get_selectable_products %]
35-
[%+ PROCESS js_comp %]
36-
[% END %]
37-
[% END %]
38-
</script>
39-
40-
[% BLOCK js_comp %]
41-
cpts['[% n %]'] = [
42-
[%- FOREACH comp = prod.components %]'[% comp.name FILTER js %]'[% ", " UNLESS loop.last %] [%- END -%]];
43-
[% n = n+1 %]
44-
[% END %]
45-
4623
<p>
4724
When you are logged in, only requests made by you or addressed to you
4825
are shown by default. You can change the criteria using the form below.
@@ -72,7 +49,7 @@ to some group are shown by default.
7249
id => "product"
7350
name => "product"
7451
add => "Any"
75-
onchange => "selectProduct(this, this.form.component, null, null, 'Any');"
52+
onchange => "selectProduct(this, this.form.component, 'Any');"
7653
%]
7754
</td>
7855
<th>Flag:</th>

0 commit comments

Comments
 (0)