Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
bugzilla
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
etersoft
bugzilla
Commits
f1f2319b
Commit
f1f2319b
authored
Aug 04, 2006
by
lpsolit%gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bug 304889: Templatize reports.cgi - Patch by Frédéric Buclin <LpSolit@gmail.com> r=mkanat a=myk
parent
c11f670e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
143 additions
and
140 deletions
+143
-140
reports.cgi
reports.cgi
+74
-140
old-charts.html.tmpl
template/en/default/reports/old-charts.html.tmpl
+69
-0
No files found.
reports.cgi
View file @
f1f2319b
...
@@ -30,8 +30,10 @@
...
@@ -30,8 +30,10 @@
# daily stats file, so now works independently of collectstats.pl
# daily stats file, so now works independently of collectstats.pl
# version
# version
# Added image caching by date and datasets
# Added image caching by date and datasets
# Myk Melez <myk@mozilla.org
)
:
# Myk Melez <myk@mozilla.org
>
:
# Implemented form field validation and reorganized code.
# Implemented form field validation and reorganized code.
# Frédéric Buclin <LpSolit@gmail.com>:
# Templatization.
use
strict
;
use
strict
;
...
@@ -47,9 +49,9 @@ $@ && ThrowCodeError("gd_not_installed");
...
@@ -47,9 +49,9 @@ $@ && ThrowCodeError("gd_not_installed");
eval
"use Chart::Lines"
;
eval
"use Chart::Lines"
;
$@
&&
ThrowCodeError
(
"chart_lines_not_installed"
);
$@
&&
ThrowCodeError
(
"chart_lines_not_installed"
);
local
our
$dir
=
bz_locations
()
->
{
'datadir'
}
.
"/mining"
;
my
$dir
=
bz_locations
()
->
{
'datadir'
}
.
"/mining"
;
local
our
$graph_url
=
'graphs'
;
my
$graph_url
=
'graphs'
;
local
our
$graph_dir
=
bz_locations
()
->
{
'libpath'
}
.
'/'
.
$graph_url
;
my
$graph_dir
=
bz_locations
()
->
{
'libpath'
}
.
'/'
.
$graph_url
;
# If we're using bug groups for products, we should apply those restrictions
# If we're using bug groups for products, we should apply those restrictions
# to viewing reports, as well. Time to check the login in that case.
# to viewing reports, as well. Time to check the login in that case.
...
@@ -59,7 +61,7 @@ Bugzilla->switch_to_shadow_db();
...
@@ -59,7 +61,7 @@ Bugzilla->switch_to_shadow_db();
my
$cgi
=
Bugzilla
->
cgi
;
my
$cgi
=
Bugzilla
->
cgi
;
my
$template
=
Bugzilla
->
template
;
my
$template
=
Bugzilla
->
template
;
local
our
$vars
=
{};
my
$vars
=
{};
# We only want those products that the user has permissions for.
# We only want those products that the user has permissions for.
my
@myproducts
;
my
@myproducts
;
...
@@ -68,11 +70,33 @@ push( @myproducts, "-All-");
...
@@ -68,11 +70,33 @@ push( @myproducts, "-All-");
push
(
@myproducts
,
map
{
$_
->
name
}
@
{
$user
->
get_selectable_products
}
);
push
(
@myproducts
,
map
{
$_
->
name
}
@
{
$user
->
get_selectable_products
}
);
if
(
!
defined
$cgi
->
param
(
'product'
))
{
if
(
!
defined
$cgi
->
param
(
'product'
))
{
# Can we do bug charts?
(
-
d
$dir
&&
-
d
$graph_dir
)
||
ThrowCodeError
(
'chart_dir_nonexistent'
,
{
dir
=>
$dir
,
graph_dir
=>
$graph_dir
});
my
%
default_sel
=
map
{
$_
=>
1
}
qw/UNCONFIRMED NEW ASSIGNED REOPENED/
;
my
@datasets
;
my
@data
=
get_data
(
$dir
);
foreach
my
$dataset
(
@data
)
{
my
$datasets
=
{};
$datasets
->
{
'value'
}
=
$dataset
;
$datasets
->
{
'selected'
}
=
$default_sel
{
$dataset
}
?
1
:
0
;
push
(
@datasets
,
$datasets
);
}
$vars
->
{
'datasets'
}
=
\
@datasets
;
$vars
->
{
'products'
}
=
\
@myproducts
;
choose_product
(
@myproducts
);
print
$cgi
->
header
();
$template
->
put_footer
();
}
else
{
$template
->
process
(
'reports/old-charts.html.tmpl'
,
$vars
)
||
ThrowTemplateError
(
$template
->
error
());
exit
;
}
else
{
my
$product
=
$cgi
->
param
(
'product'
);
my
$product
=
$cgi
->
param
(
'product'
);
# For security and correctness, validate the value of the "product" form variable.
# For security and correctness, validate the value of the "product" form variable.
...
@@ -85,96 +109,49 @@ if (! defined $cgi->param('product')) {
...
@@ -85,96 +109,49 @@ if (! defined $cgi->param('product')) {
# This means that is OK to detaint
# This means that is OK to detaint
trick_taint
(
$product
);
trick_taint
(
$product
);
print
$cgi
->
header
(
-
Content_Disposition
=>
'inline; filename=bugzilla_report.html
'
);
defined
(
$cgi
->
param
(
'datasets'
))
||
ThrowUserError
(
'missing_datasets
'
);
$template
->
put_header
(
"Bug Charts"
);
my
$datasets
=
join
(
''
,
$cgi
->
param
(
'datasets'
));
$vars
->
{
'header_done'
}
=
1
;
show_chart
(
$product
);
my
$type
=
chart_image_type
();
my
$data_file
=
daily_stats_filename
(
$product
);
my
$image_file
=
chart_image_name
(
$data_file
,
$type
,
$datasets
);
my
$url_image
=
correct_urlbase
()
.
"$graph_url/$image_file"
;
$template
->
put_footer
();
if
(
!
-
e
"$graph_dir/$image_file"
)
{
}
generate_chart
(
"$dir/$data_file"
,
"$graph_dir/$image_file"
,
$type
,
$product
,
$datasets
);
}
$vars
->
{
'url_image'
}
=
$url_image
;
##################################
print
$cgi
->
header
(
-
Content_Disposition
=>
'inline; filename=bugzilla_report.html'
);
# user came in with no form data #
##################################
sub
choose_product
{
$template
->
process
(
'reports/old-charts.html.tmpl'
,
$vars
)
my
@myproducts
=
(
@_
);
||
ThrowTemplateError
(
$template
->
error
()
);
my
$cgi
=
Bugzilla
->
cgi
;
exit
;
my
$template
=
Bugzilla
->
template
;
}
#####################
# Subroutines #
#####################
sub
get_data
{
my
$dir
=
shift
;
my
@datasets
;
my
$datafile
=
daily_stats_filename
(
'-All-'
);
my
$datafile
=
daily_stats_filename
(
'-All-'
);
open
(
DATA
,
'<'
,
"$dir/$datafile"
)
||
ThrowCodeError
(
'chart_file_open_fail'
,
{
filename
=>
"$dir/$datafile"
});
# Can we do bug charts?
while
(
<
DATA
>
)
{
(
-
d
$dir
&&
-
d
$graph_dir
)
if
(
/^# fields?: (.+)\s*$/
)
{
||
ThrowCodeError
(
"chart_dir_nonexistent"
,
@datasets
=
grep
!
/date/i
,
(
split
/\|/
,
$1
);
{
dir
=>
$dir
,
graph_dir
=>
$graph_dir
});
last
;
}
open
(
DATA
,
"$dir/$datafile"
)
}
||
ThrowCodeError
(
"chart_file_open_fail"
,
{
filename
=>
"$dir/$datafile"
});
close
(
DATA
);
return
@datasets
;
print
$cgi
->
header
();
$template
->
put_header
(
"Bug Charts"
);
$vars
->
{
'header_done'
}
=
1
;
print
<<FIN;
<center>
<h1>Welcome to the Bugzilla Charting Kitchen</h1>
<form method=get action=reports.cgi>
<table border=1 cellpadding=5>
<tr>
<td align=center><b>Product:</b></td>
<td align=center>
<select name="product">
FIN
foreach
my
$product
(
@myproducts
)
{
$product
=
html_quote
(
$product
);
print
qq{<option value="$product">$product</option>}
;
}
print
<<FIN;
</select>
</td>
</tr>
<tr>
<td align=center><b>Chart datasets:</b></td>
<td align=center>
<select name="datasets" multiple size=5>
FIN
my
@datasets
=
();
while
(
<
DATA
>
)
{
if
(
/^# fields?: (.+)\s*$/
)
{
@datasets
=
grep
!
/date/i
,
(
split
/\|/
,
$1
);
last
;
}
}
close
(
DATA
);
my
%
default_sel
=
map
{
$_
=>
1
}
qw/UNCONFIRMED NEW ASSIGNED REOPENED/
;
foreach
my
$dataset
(
@datasets
)
{
my
$sel
=
$default_sel
{
$dataset
}
?
' selected'
:
''
;
print
qq{<option value="$dataset:"$sel>$dataset</option>\n}
;
}
print
<<FIN;
</select>
</td>
</tr>
<tr>
<td colspan=2 align=center>
<input type=submit value=Continue>
</td>
</tr>
</table>
</center>
</form>
<p>
FIN
}
}
sub
daily_stats_filename
{
sub
daily_stats_filename
{
...
@@ -183,37 +160,6 @@ sub daily_stats_filename {
...
@@ -183,37 +160,6 @@ sub daily_stats_filename {
return
$prodname
;
return
$prodname
;
}
}
sub
show_chart
{
my
(
$product
)
=
@_
;
my
$cgi
=
Bugzilla
->
cgi
;
if
(
!
defined
$cgi
->
param
(
'datasets'
))
{
ThrowUserError
(
"missing_datasets"
,
$vars
);
}
my
$datasets
=
join
(
''
,
$cgi
->
param
(
'datasets'
));
print
<<FIN;
<center>
FIN
my
$type
=
chart_image_type
();
my
$data_file
=
daily_stats_filename
(
$product
);
my
$image_file
=
chart_image_name
(
$data_file
,
$type
,
$datasets
);
my
$url_image
=
correct_urlbase
()
.
"$graph_url/"
.
url_quote
(
$image_file
);
if
(
!
-
e
"$graph_dir/$image_file"
)
{
generate_chart
(
"$dir/$data_file"
,
"$graph_dir/$image_file"
,
$type
,
$product
,
$datasets
);
}
print
<<FIN;
<img src="$url_image">
<br clear=left>
<br>
FIN
}
sub
chart_image_type
{
sub
chart_image_type
{
# what chart type should we be generating?
# what chart type should we be generating?
my
$testimg
=
Chart::
Lines
->
new
(
2
,
2
);
my
$testimg
=
Chart::
Lines
->
new
(
2
,
2
);
...
@@ -234,8 +180,7 @@ sub chart_image_name {
...
@@ -234,8 +180,7 @@ sub chart_image_name {
# numbers, underscores and hyphens.
# numbers, underscores and hyphens.
if
(
$datasets
!~
m/^[A-Za-z0-9:_-]+$/
)
{
if
(
$datasets
!~
m/^[A-Za-z0-9:_-]+$/
)
{
$vars
->
{
'datasets'
}
=
$datasets
;
ThrowUserError
(
'invalid_datasets'
,
{
'datasets'
=>
$datasets
});
ThrowUserError
(
'invalid_datasets'
,
$vars
);
}
}
# Since we pass the tests, consider it OK
# Since we pass the tests, consider it OK
...
@@ -248,23 +193,14 @@ sub chart_image_name {
...
@@ -248,23 +193,14 @@ sub chart_image_name {
return
"${data_file}_${id}.$type"
;
return
"${data_file}_${id}.$type"
;
}
}
sub
day_of_year
{
my
(
$mday
,
$month
,
$year
)
=
(
localtime
())[
3
..
5
];
$month
+=
1
;
$year
+=
1900
;
my
$date
=
sprintf
"%02d%02d%04d"
,
$mday
,
$month
,
$year
;
}
sub
generate_chart
{
sub
generate_chart
{
my
(
$data_file
,
$image_file
,
$type
,
$product
,
$datasets
)
=
@_
;
my
(
$data_file
,
$image_file
,
$type
,
$product
,
$datasets
)
=
@_
;
if
(
!
open
FILE
,
$data_file
)
{
if
(
!
open
FILE
,
$data_file
)
{
if
(
$product
eq
'-All-'
)
{
if
(
$product
eq
'-All-'
)
{
$product
=
''
;
$product
=
''
;
}
}
ThrowCodeError
(
'chart_data_not_generated'
,
{
'product'
=>
$product
});
$vars
->
{
'product'
}
=
$product
;
ThrowCodeError
(
"chart_data_not_generated"
,
$vars
);
}
}
my
@fields
;
my
@fields
;
...
@@ -279,8 +215,7 @@ sub generate_chart {
...
@@ -279,8 +215,7 @@ sub generate_chart {
if
(
/^# fields?: (.*)\s*$/
)
{
if
(
/^# fields?: (.*)\s*$/
)
{
@fields
=
split
/\||\r/
,
$1
;
@fields
=
split
/\||\r/
,
$1
;
unless
(
$fields
[
0
]
=~
/date/i
)
{
unless
(
$fields
[
0
]
=~
/date/i
)
{
$vars
->
{
'file'
}
=
$data_file
;
ThrowCodeError
(
'chart_datafile_corrupt'
,
{
'file'
=>
$data_file
});
ThrowCodeError
(
"chart_datafile_corrupt"
,
$vars
);
}
}
push
@labels
,
grep
(
$datasets
{
$_
},
@fields
);
push
@labels
,
grep
(
$datasets
{
$_
},
@fields
);
}
}
...
@@ -288,10 +223,9 @@ sub generate_chart {
...
@@ -288,10 +223,9 @@ sub generate_chart {
}
}
unless
(
@fields
)
{
unless
(
@fields
)
{
$vars
->
{
'file'
}
=
$data_file
;
ThrowCodeError
(
'chart_datafile_corrupt'
,
{
'file'
=>
$data_file
});
ThrowCodeError
(
"chart_datafile_corrupt"
,
$vars
);
}
}
my
@line
=
split
/\|/
;
my
@line
=
split
/\|/
;
my
$date
=
$line
[
0
];
my
$date
=
$line
[
0
];
my
(
$yy
,
$mm
,
$dd
)
=
$date
=~
/^\d{2}(\d{2})(\d{2})(\d{2})$/
;
my
(
$yy
,
$mm
,
$dd
)
=
$date
=~
/^\d{2}(\d{2})(\d{2})(\d{2})$/
;
...
@@ -316,9 +250,9 @@ sub generate_chart {
...
@@ -316,9 +250,9 @@ sub generate_chart {
close
FILE
;
close
FILE
;
if
(
!
@
{
$data
{
DATE
}})
{
if
(
!
@
{
$data
{
DATE
}})
{
ThrowUserError
(
"insufficient_data_points"
,
$vars
);
ThrowUserError
(
'insufficient_data_points'
);
}
}
my
$img
=
Chart::
Lines
->
new
(
800
,
600
);
my
$img
=
Chart::
Lines
->
new
(
800
,
600
);
my
$i
=
0
;
my
$i
=
0
;
...
...
template/en/default/reports/old-charts.html.tmpl
0 → 100644
View file @
f1f2319b
[%# 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): Frédéric Buclin <LpSolit@gmail.com>
#%]
[%# INTERFACE:
# products: an array of product names the user is allowed to view.
# datasets: an array of hashes with available statuses and resolutions.
# url_image: URL of the generated graph.
#%]
[% PROCESS "global/field-descs.none.tmpl" %]
[% PROCESS global/header.html.tmpl title = "$terms.Bug Charts"
h1 = "Welcome to the $terms.Bugzilla Charting Kitchen" %]
<div align="center">
[% IF url_image %]
<img src="[% url_image FILTER html %]">
<br clear="both">
[% ELSE %]
<form id="choose_product" method="get" action="reports.cgi">
<table border="1" cellpadding="5" cellspacing="2">
<tr>
<th>Product:</th>
<td align="center">
<select id="product" name="product">
[% FOREACH product = products %]
<option value="[% product FILTER html %]">[% product FILTER html %]</option>
[% END %]
</select>
</td>
</tr>
<tr>
<th>Chart datasets:</th>
<td align="center">
<select id="datasets" name="datasets" multiple="multiple" size="5">
[%# We cannot use translated statuses and resolutions from field-descs.none.html
# because old charts do not distinguish statuses from resolutions. %]
[% FOREACH dataset = datasets %]
<option value="[% dataset.value FILTER html %]:"
[% " selected=\"selected\"" IF dataset.selected %]>
[% dataset.value FILTER html %]</option>
[% END %]
</select>
</td>
</tr>
<tr>
<th colspan="2">
<input type="submit" id="submit" value="Continue">
</th>
</tr>
</table>
</form>
[% END %]
</div>
[% PROCESS global/footer.html.tmpl %]
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment