diff --git a/classes/headers/ChartHeader.php b/classes/headers/ChartHeader.php index cdbe6f23..ad3077da 100644 --- a/classes/headers/ChartHeader.php +++ b/classes/headers/ChartHeader.php @@ -236,7 +236,7 @@ protected static function getRowInfo(&$rows, $params, $num, &$report) { $val->datatype = 'date'; } elseif($types[$key] === 'number') { - $val->setValue(round(floatval(preg_replace('/[^0-9\.]*/','',$val->getValue())),6)); + $val->setValue(round(floatval(preg_replace('/[^-0-9\.]*/','',$val->getValue())),6)); $val->datatype = 'number'; } else { diff --git a/classes/report_formats/HtmlReportFormat.php b/classes/report_formats/HtmlReportFormat.php index a92cc731..0d889d32 100644 --- a/classes/report_formats/HtmlReportFormat.php +++ b/classes/report_formats/HtmlReportFormat.php @@ -15,11 +15,13 @@ public static function display(&$report, &$request) { } try { - $html = $report->renderReportPage($template); + $additional_vars = array(); + if(isset($request->query['no_charts'])) $additional_vars['no_charts'] = true; + + $html = $report->renderReportPage($template,$additional_vars); echo $html; } - catch(Exception $e) { - + catch(Exception $e) { if(isset($request->query['content_only'])) { $template = 'html/blank_page'; } diff --git a/config/config.php.sample b/config/config.php.sample index 72ac34cf..fd3ac65f 100644 --- a/config/config.php.sample +++ b/config/config.php.sample @@ -3,6 +3,9 @@ return array( //the root directory of all your reports //reports can be organized in subdirectories 'reportDir' => 'sample_reports', + + //the root directory of all dashboards + 'dashboardDir' => 'sample_dashboards', //the directory where things will be cached //this is relative to the project root by default, but can be set to an absolute path too diff --git a/index.php b/index.php index 5e81180a..15953b0d 100644 --- a/index.php +++ b/index.php @@ -14,6 +14,14 @@ PhpReports::listReports(); }); +Flight::route('/dashboards',function() { + PhpReports::listDashboards(); +}); + +Flight::route('/dashboard/@name',function($name) { + PhpReports::displayDashboard($name); +}); + //JSON list of reports (used for typeahead search) Flight::route('/report-list-json',function() { header("Content-Type: application/json"); diff --git a/lib/PhpReports/PhpReports.php b/lib/PhpReports/PhpReports.php index 59a1be7a..50953305 100644 --- a/lib/PhpReports/PhpReports.php +++ b/lib/PhpReports/PhpReports.php @@ -232,6 +232,48 @@ public static function listReports() { $start = microtime(true); echo self::render('html/report_list',$template_vars); } + + public static function listDashboards() { + $dashboards = self::getDashboards(); + + uasort($dashboards,function($a,$b) { + return strcmp($a['title'],$b['title']); + }); + + echo self::render('html/dashboard_list',array( + 'dashboards'=>$dashboards + )); + } + + public static function displayDashboard($dashboard) { + $content = self::getDashboard($dashboard); + + echo self::render('html/dashboard',array( + 'dashboard'=>$content + )); + } + + public static function getDashboards() { + $dashboards = glob(PhpReports::$config['dashboardDir'].'/*.json'); + + $ret = array(); + foreach($dashboards as $key=>$value) { + $name = basename($value,'.json'); + $ret[$name] = self::getDashboard($name); + } + + return $ret; + } + + public static function getDashboard($dashboard) { + $file = PhpReports::$config['dashboardDir'].'/'.$dashboard.'.json'; + if(!file_exists($file)) { + throw "Unknown dashboard - ".$dashboard; + } + + return json_decode(file_get_contents($file),true); + } + public static function getRecentReports() { $recently_run = FileSystemCache::retrieve(FileSystemCache::generateCacheKey('recently_run')); $recent = array(); diff --git a/sample_dashboards/timezones.json b/sample_dashboards/timezones.json new file mode 100644 index 00000000..773471e7 --- /dev/null +++ b/sample_dashboards/timezones.json @@ -0,0 +1,27 @@ +{ + "title": "Timezone Dashboard", + "description": "Shows off the dashboard feature of Php Reports", + "reports": [ + { + "report": "php/timezones.php", + "title": "ACST Timezone", + "macros": { + "region": "acst" + }, + "format": "html", + "newRow": false, + "style": "max-height: 400px; overflow-y: auto; overflow-x: hidden;", + "class": "col-md-6" + }, + { + "report": "php/timezones.php", + "title": "CDT Timezone", + "macros": { + "region": "cdt" + }, + "format": "chart", + "newRow": false, + "class": "col-md-6" + } + ] +} diff --git a/sample_reports/php/timezones.php b/sample_reports/php/timezones.php index e3ebfe08..24594246 100644 --- a/sample_reports/php/timezones.php +++ b/sample_reports/php/timezones.php @@ -8,6 +8,7 @@ // options: ["cdt","acst","pdt"], // default: "acst" // } +// CHART: {type: "LineChart"} $timezone_abbreviations = DateTimeZone::listAbbreviations(); diff --git a/templates/default/html/dashboard.twig b/templates/default/html/dashboard.twig new file mode 100644 index 00000000..0934e197 --- /dev/null +++ b/templates/default/html/dashboard.twig @@ -0,0 +1,104 @@ +{% extends "html/page.twig" %} + +{% block title %}Dashboard List{% endblock %} + +{% block header %} +
{{dashboard.description|raw}}
{% endif %} +{% endblock %} + +{% block content %} +