From d69ae9f2cc2d243a79dd0e4dee38dd44bccab8c3 Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Thu, 11 Apr 2013 10:16:09 -0400 Subject: Bug 860657 - 'Illegal division by zero' on product dashboard when the product has zero bugs --- extensions/ProductDashboard/Extension.pm | 22 ++++++++++----- .../pages/productdashboard/summary.html.tmpl | 32 +++++++++++----------- 2 files changed, 31 insertions(+), 23 deletions(-) diff --git a/extensions/ProductDashboard/Extension.pm b/extensions/ProductDashboard/Extension.pm index 57192f195..1e6ddffe9 100644 --- a/extensions/ProductDashboard/Extension.pm +++ b/extensions/ProductDashboard/Extension.pm @@ -108,8 +108,16 @@ sub _page_dashboard { $vars->{'total_closed_bugs'} = total_closed_bugs($product); $vars->{'severities'} = get_legal_field_values('bug_severity'); - $vars->{'open_bugs_percentage'} = int($vars->{'total_open_bugs'} / $vars->{'total_bugs'} * 100); - $vars->{'closed_bugs_percentage'} = int($vars->{'total_closed_bugs'} / $vars->{'total_bugs'} * 100); + if ($vars->{'total_bugs'}) { + $vars->{'open_bugs_percentage'} + = int($vars->{'total_open_bugs'} / $vars->{'total_bugs'} * 100); + $vars->{'closed_bugs_percentage'} + = int($vars->{'total_closed_bugs'} / $vars->{'total_bugs'} * 100); + } + else { + $vars->{'open_bugs_percentage'} = 0; + $vars->{'closed_bugs_percentage'} = 0; + } if ($current_tab_name eq 'summary') { $vars->{'by_priority'} = by_priority($product, $bug_status); @@ -142,14 +150,14 @@ sub _page_dashboard { $vars->{'summary'} = by_value_summary($product, 'component', $input->{'component'}, $bug_status); $vars->{'summary'}{'type'} = 'component'; $vars->{'summary'}{'value'} = $input->{'component'}; - } + } elsif ($input->{'version'}) { - $vars->{'summary'} = by_value_summary($product, 'version', $input->{'version'}, $bug_status); + $vars->{'summary'} = by_value_summary($product, 'version', $input->{'version'}, $bug_status); $vars->{'summary'}{'type'} = 'version'; $vars->{'summary'}{'value'} = $input->{'version'}; - } + } elsif ($input->{'target_milestone'} && Bugzilla->params->{'usetargetmilestone'}) { - $vars->{'summary'} = by_value_summary($product, 'target_milestone', $input->{'target_milestone'}, $bug_status); + $vars->{'summary'} = by_value_summary($product, 'target_milestone', $input->{'target_milestone'}, $bug_status); $vars->{'summary'}{'type'} = 'target_milestone'; $vars->{'summary'}{'value'} = $input->{'target_milestone'}; } @@ -180,7 +188,7 @@ sub _page_dashboard { $milestone_stats{'link_total'} = bug_milestone_link_total($product, $milestone); $milestone_stats{'link_open'} = bug_milestone_link_open($product, $milestone); $milestone_stats{'link_closed'} = bug_milestone_link_closed($product, $milestone); - $milestone_stats{'percentage'} = $milestone_stats{'total_bugs'} + $milestone_stats{'percentage'} = $milestone_stats{'total_bugs'} ? int(($milestone_stats{'closed_bugs'} / $milestone_stats{'total_bugs'}) * 100) : 0; push (@{$vars->{'by_roadmap'}}, \%milestone_stats); diff --git a/extensions/ProductDashboard/template/en/default/pages/productdashboard/summary.html.tmpl b/extensions/ProductDashboard/template/en/default/pages/productdashboard/summary.html.tmpl index 5afba25a9..30b6f3dca 100644 --- a/extensions/ProductDashboard/template/en/default/pages/productdashboard/summary.html.tmpl +++ b/extensions/ProductDashboard/template/en/default/pages/productdashboard/summary.html.tmpl @@ -11,36 +11,36 @@ // global counts PD.summary.bug_counts = [ - { + { name: "Total [% terms.Bugs %]", count: [% total_bugs || 0 FILTER js %], - percentage: 100, - link: 'Link', - }, + percentage: [% total_bugs ? "100" : "0" %], + link: 'Link', + }, { name: "Open [% terms.Bugs %]", count: [% total_open_bugs || 0 FILTER js %], percentage: [% open_bugs_percentage FILTER js %], - link: 'Link', + link: 'Link', }, { - name: "Closed [% terms.Bugs %]", + name: "Closed [% terms.Bugs %]", count: [% total_closed_bugs || 0 FILTER js %], percentage: [% closed_bugs_percentage FILTER js %], link: 'Link', } ]; - + // Status counts PD.summary.status_counts = [ [% FOREACH col = by_status %] [% NEXT IF col.0 == 'CLOSED' %] { - name: "[% col.0 FILTER js %]", + name: "[% col.0 FILTER js %]", count: [% col.1 || 0 FILTER js %], - percentage: [% col.2 || 0 FILTER js %], + percentage: [% col.2 || 0 FILTER js %], link: 'Link' - }, + }, [% END %] ]; @@ -48,11 +48,11 @@ PD.summary.priority_counts = [ [% FOREACH col = by_priority %] { - name: "[% col.0 FILTER js %]", + name: "[% col.0 FILTER js %]", count: [% col.1 || 0 FILTER js %], - percentage: [% col.2 || 0 FILTER js %], + percentage: [% col.2 || 0 FILTER js %], link: 'Link' - }, + }, [% END %] ]; @@ -60,11 +60,11 @@ PD.summary.severity_counts = [ [% FOREACH col = by_severity %] { - name: "[% col.0 FILTER js %]", + name: "[% col.0 FILTER js %]", count: [% col.1 || 0 FILTER js %], - percentage: [% col.2 || 0 FILTER js %], + percentage: [% col.2 || 0 FILTER js %], link: 'Link' - }, + }, [% END %] ]; -- cgit v1.2.3-24-g4f1b