Skip to content

Commit

Permalink
Added breadcrumb navigation and a top bar to all pages.
Browse files Browse the repository at this point in the history
Fixed bug with dates in charts in Firefox.
Fixed bug with shorthand Chart syntax.
Improved look of reports.
  • Loading branch information
jdorn committed Jul 2, 2012
1 parent 6c9908b commit 53f8a94
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 92 deletions.
19 changes: 15 additions & 4 deletions classes/headers/ChartHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ class ChartHeader extends HeaderBase {
'yrange'=>array(
'type'=>'string',
'default'=>''
)
),
'all'=>array(
'type'=>'boolean',
'default'=>false
),
);

public static function init($params, &$report) {
Expand Down Expand Up @@ -103,9 +107,10 @@ public static function parseShortcut($value) {
}

if(isset($value['x'])) $value['columns'] = $value['x'];
else $value['columns'] = array();
else $value['columns'] = array(1);

if(isset($value['y'])) $value['columns'] = array_merge($value['x'],$value['y']);
if(isset($value['y'])) $value['columns'] = array_merge($value['columns'],$value['y']);
else $value['all'] = true;

unset($value['x']);
unset($value['y']);
Expand All @@ -123,6 +128,7 @@ protected static function getRowInfo($rows, $params, $num, &$report) {

if($k===0) {
$i=1;
$unsorted = 1000;
foreach($row['values'] as $key=>$value) {
$row['values'][$key]['i'] = $i;
$i++;
Expand All @@ -133,6 +139,11 @@ protected static function getRowInfo($rows, $params, $num, &$report) {
elseif(($temp = array_search($row['values'][$key]['key'], $report->options['Charts'][$num]['columns']))!==false) {
$cols[$temp] = $key;
}
//if all columns are included, add after any specifically defined ones
elseif($report->options['Charts'][$num]['all']) {
$cols[$unsorted] = $key;
$unsorted ++;
}
}

ksort($cols);
Expand Down Expand Up @@ -192,7 +203,7 @@ protected static function getRowInfo($rows, $params, $num, &$report) {
$val['is_null'] = true;
}
elseif($types[$key] === 'date') {
$val['value'] = date('Y-m-d H:i:s',strtotime($val['value']));
$val['value'] = date('m/d/Y H:i:s',strtotime($val['value']));
$val['is_date'] = true;
}
elseif($types[$key] === 'number') {
Expand Down
5 changes: 3 additions & 2 deletions classes/report_formats/HtmlReportFormat.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,18 @@ public static function display(&$report, &$request) {
try {
$page_template = array(
'content'=>$report->renderReportPage('html/table','html/report'),
'has_charts'=>$report->options['has_charts']
'has_charts'=>$report->options['has_charts'],
);
}
catch(Exception $e) {
$page_template = array(
'error'=>$e->getMessage(),
'content'=>$report->options['Query_Formatted']
'content'=>$report->options['Query_Formatted'],
);
}

$page_template['title'] = $report->options['Name'];
$page_template['breadcrumb'] = array('Report List'=>'',$report->options['Name']=>true);

if(isset($request->query['content_only'])) {
echo PhpReports::render('html/content_only',$page_template);
Expand Down
6 changes: 3 additions & 3 deletions classes/report_types/MysqlReportType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public static function init(&$report) {
if(isset($params['multiple']) && $params['multiple']) {
//allow {macro} instead of {% for item in macro %}{% if not item.first %},{% endif %}{{ item.value }}{% endfor %}
//this is shorthand for comma separated list
$report->raw_query = preg_replace('/([^\{])\{'.$params['name'].'\}([^\}])/','$1{% for item in '.$params['name'].' %}{% if not item.first %},{% endif %}{{ item.value }}{% endfor %}$2',$report->raw_query);
$report->raw_query = preg_replace('/([^\{])\{'.$key.'\}([^\}])/','$1{% for item in '.$key.' %}{% if not item.first %},{% endif %}{{ item.value }}{% endfor %}$2',$report->raw_query);

//allow {(macro)} instead of {% for item in macro %}{% if not item.first %},{% endif %}{{ item.value }}{% endfor %}
//this is shorthand for quoted, comma separated list
$report->raw_query = preg_replace('/([^\{])\{\('.$params['name'].'\)\}([^\}])/','$1{% for item in '.$params['name'].' %}{% if not item.first %},{% endif %}\'{{ item.value }}\'{% endfor %}$2',$report->raw_query);
$report->raw_query = preg_replace('/([^\{])\{\('.$key.'\)\}([^\}])/','$1{% for item in '.$key.' %}{% if not item.first %},{% endif %}\'{{ item.value }}\'{% endfor %}$2',$report->raw_query);
}
//macros sortcuts for non-arrays
else {
//allow {macro} instead of {{macro}} for legacy support
$report->raw_query = preg_replace('/([^\{])(\{'.$params['name'].'+\})([^\}])/','$1{$2}$3',$report->raw_query);
$report->raw_query = preg_replace('/([^\{])(\{'.$key.'+\})([^\}])/','$1{$2}$3',$report->raw_query);
}
}

Expand Down
6 changes: 4 additions & 2 deletions lib/PhpReports/PhpReports.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public static function displayReport($report,$type) {
echo self::render('html/page',array(
'title'=>$report->report,
'header'=>'<h2>'.$error_header.'</h2>',
'error'=>$e->getMessage()
'error'=>$e->getMessage(),
'breadcrumb'=>array('Report List'=>'', $report->report => true)
));
}
}
Expand All @@ -84,7 +85,8 @@ public static function listReports() {
$template_vars = array(
'content'=>$content,
'title'=>'Report List',
'is_home'=>true
'is_home'=>true,
'breadcrumb'=>array('Report List'=>true)
);

echo self::render('html/page',$template_vars);
Expand Down
9 changes: 8 additions & 1 deletion public/css/jquery.dataTables.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ table.dataTable td {

table.dataTable thead th, table.dataTable td, table.dataTable tfoot th, table.dataTable {
border-style: solid;
border-color: #ccc;
border-color: #aaa;
}
table.dataTable thead th, table.dataTable td, table.dataTable tfoot th {
border-width: 1px 1px 0 0;
Expand Down Expand Up @@ -79,6 +79,12 @@ table.dataTable tr.even td.sorting_3 { background-color: #F9F9FF; }
.dataTables_filter {
float: right;
text-align: right;
padding-bottom: 8px;
}
.dataTables_filter input {
border: 1px solid #aaa;
border-radius: 5px;
padding: 2px 8px;
}


Expand All @@ -88,6 +94,7 @@ table.dataTable tr.even td.sorting_3 { background-color: #F9F9FF; }
.dataTables_info {
clear: both;
float: left;
padding-top: 8px;
}


Expand Down
66 changes: 44 additions & 22 deletions templates/html/page.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
<link rel='stylesheet' href='{{base}}/public/css/jquery.dataTables.css' />
{% endif %}
<style>
html, body {
padding: 0;
margin: 0;
}
* {
font-family: arial, san serif;
}
Expand Down Expand Up @@ -54,36 +58,54 @@
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
}
#top_bar {
height: 21px;
line-height: 21px;
font-size: .8em;
color: #333;
border-bottom: 1px solid #aaa;
padding: 0 10px;
}
#holder {
padding: 0 10px 30px;
}
</style>
</head>
<body>
{% if not is_home and report_list_url %}
<div id='links_holder'>
<a href='{{report_list_url}}'>Reports Home</a>
<div id='top_bar'>
<div class='breadcrumb'>
{% for display, url in breadcrumb %}
{% if loop.last %}
<strong>{{display}}</strong>
{% else %}
<a href="{{base}}/{{url}}">{{display}}</a> &gt;
{% endif %}
{% endfor %}
</div>
</div>
{% endif %}
<div id='holder'>
{% if header %}
<div>
{{header|raw}}
</div>
{% endif %}

{% if header %}
<div>
{{header|raw}}
</div>
{% endif %}
{% if error %}
<div class='error'>
{{error}}
</div>
{% endif %}

{% if error %}
<div class='error'>
{{error}}
</div>
{% endif %}
{% if notice %}
<div class='notice'>
{{notice}}
</div>
{% endif %}

{% if notice %}
<div class='notice'>
{{notice}}
<div id='content'>
{{content|raw}}
</div>
</div>
{% endif %}

<div id='content'>
{{content|raw}}
</div>

</body>
</html>
115 changes: 59 additions & 56 deletions templates/html/report.twig
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ h1 {
function drawCharts() {
{% for chart in Charts %}
var data_{{chart.num}} = new google.visualization.DataTable();
{% for value in chart.Rows[0].values %}
{% if value.is_date %}
data_{{chart.num}}.addColumn('date',"{{value.key}}");
Expand All @@ -117,21 +117,24 @@ h1 {
{% endif %}
{% endfor %}
data_{{chart.num}}.addRows([{% for row in chart.Rows %}
{% if not row.first %},{% endif %}
[
{% for value in row.values %}
{% if not value.first %},{% endif %}
{% if value.is_date %}
new Date("{{value.value|raw}}")
{% elseif value.is_number %}
{{ value.value }}
{% else %}
"{{ value.value }}"
{% endif %}
{% endfor %}
]
{% endfor %}]);
var rows = [
{% for row in chart.Rows %}
{% if not row.first %},{% endif %}
[
{% for value in row.values %}
{% if not value.first %},{% endif %}
{% if value.is_date %}
new Date("{{value.value|raw}}")
{% elseif value.is_number %}
{{ value.value }}
{% else %}
"{{ value.value }}"
{% endif %}
{% endfor %}
]
{% endfor %}];
data_{{chart.num}}.addRows(rows);
var options_{{chart.num}} = {
title: '{{chart.title}}',
Expand All @@ -149,11 +152,11 @@ h1 {
</script>

{% for chart in Charts %}
<div id='chart_div_{{chart.num}}' style='{% if chart.width %}width={{chart.width}}px;{% endif %}{% if chart.height %}height={{chart.height}}px{% endif %}'></div>
<div id='chart_div_{{chart.num}}' style='{% if chart.width %}width={{chart.width}};{% endif %}{% if chart.height %}height={{chart.height}};{% endif %}'></div>
{% endfor %}
{% endif %}

{% if query %}
{% if Query_Formatted %}
<a href='#' class='show_query'>show query</a>
<div id='query_holder' style='display:none;'>
{{Query_Formatted|raw}}
Expand Down Expand Up @@ -198,49 +201,49 @@ $('#database_select').change(function() {
{% endif %}

{% if not is_ready %}
<div class='notice'>
This report needs more information before running.
</div>
<div class='notice'>
This report needs more information before running.
</div>
{% endif %}
{% if async %}
<div class='waiting' id='async_notice'>
<div>
Your report is running.
{% if time_estimate %}
{% if time_estimate.median %}
This report usually takes {{time_estimate.median}} seconds.
<div class='waiting' id='async_notice'>
<div>
Your report is running.
{% if time_estimate %}
{% if time_estimate.median %}
This report usually takes {{time_estimate.median}} seconds.
{% endif %}
{% endif %}
{% endif %}
</div>
</div>
</div>
<script>
$.ajax({
'url': '{{report_url|raw}}',
'dataType': 'html',
'data': {'content_only': true},
'success': function(data) {
$('#content').html(data);
}
});
</script>
<script>
$.ajax({
'url': '{{report_url|raw}}',
'dataType': 'html',
'data': {'content_only': true},
'success': function(data) {
$('#content').html(data);
}
});
</script>
{% endif %}

{% if time_estimate %}
<div style='margin-top: 20px;'>
<a href='#' id='show_time_estimate'>show time estimate data</a>
<div style='font-size: .8em; display:none;' id='time_estimate_holder'>
<div><strong>Number of Samples: </strong> {{time_estimate.count}}</div>
<div><strong>Minimum Time: </strong> {{time_estimate.min}}</div>
<div><strong>Maximum Time: </strong> {{time_estimate.max}}</div>
<div><strong>Median: </strong> {{time_estimate.median}}</div>
<div><strong>Average: </strong> {{time_estimate.average}}</div>
<div><strong>Standard Deviation: </strong> {{time_estimate.stdev}}</div>
<div style='margin-top: 20px;'>
<a href='#' id='show_time_estimate'>show time estimate data</a>
<div style='font-size: .8em; display:none;' id='time_estimate_holder'>
<div><strong>Number of Samples: </strong> {{time_estimate.count}}</div>
<div><strong>Minimum Time: </strong> {{time_estimate.min}}</div>
<div><strong>Maximum Time: </strong> {{time_estimate.max}}</div>
<div><strong>Median: </strong> {{time_estimate.median}}</div>
<div><strong>Average: </strong> {{time_estimate.average}}</div>
<div><strong>Standard Deviation: </strong> {{time_estimate.stdev}}</div>
</div>
</div>
</div>
<script>
$('#show_time_estimate').click(function() {
$('#time_estimate_holder').toggle(200);
return false;
});
</script>
{% endif %}
<script>
$('#show_time_estimate').click(function() {
$('#time_estimate_holder').toggle(200);
return false;
});
</script>
{% endif %}
6 changes: 6 additions & 0 deletions templates/html/report_list.twig
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@
margin-left: 10px;
font-weight:normal;
}
#search {
border: 1px solid #aaa;
border-radius: 5px;
padding: 2px 8px;
margin-left: 12px;
}
</style>
<script>
$(document).ready(function() {
Expand Down
Loading

0 comments on commit 53f8a94

Please sign in to comment.