Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

ENHANCEMENT: Use GridFields to show reports in the ReportAdmin

  • Loading branch information...
commit 4c76c8563c314e4abaadf0f7315e72c6125b1a1f 1 parent 029f833
@ajoneil ajoneil authored
View
70 code/controllers/ReportAdmin.php
@@ -58,9 +58,9 @@ function canView($member = null) {
return false;
}
- function currentPageID() {
+ function currentReport() {
$id = parent::currentPageID();
- $reports = SS_Report::get_reports('ReportAdmin');
+ $reports = SS_Report::get_reports();
return (isset($reports[$id])) ? $reports[$id] : null;
}
@@ -72,7 +72,7 @@ function currentPageID() {
*/
public function Reports() {
$output = new ArrayList();
- foreach(SS_Report::get_reports('ReportAdmin') as $report) {
+ foreach(SS_Report::get_reports() as $report) {
if($report->canView()) $output->push($report);
}
return $output;
@@ -90,7 +90,7 @@ public function Reports() {
* @return boolean
*/
public static function has_reports() {
- return sizeof(SS_Report::get_reports('ReportAdmin')) > 0;
+ return sizeof(SS_Report::get_reports()) > 0;
}
public function updatereport() {
@@ -107,5 +107,67 @@ function providePermissions() {
)
);
}
+
+ public function getEditForm($id = null, $fields = null) {
+ $fields = new FieldList();
+
+ $report = $this->currentReport();
+
+ if($report) {
+ // List all reports
+ $gridFieldConfig = GridFieldConfig::create()->addComponents(
+ new GridFieldToolbarHeader(),
+ new GridFieldSortableHeader(),
+ new GridFieldDataColumns(),
+ new GridFieldPaginator(),
+ new GridFieldPrintButton(),
+ new GridFieldExportButton()
+ );
+ $gridField = new GridField('Report',$report->title(), $report->sourceRecords(array(), null, null), $gridFieldConfig);
+ $displayFields = array();
+ $fieldCasting = array();
+ $fieldFormatting = array();
+
+ // Parse the column information
+ foreach($report->columns() as $source => $info) {
+ if(is_string($info)) $info = array('title' => $info);
+
+ if(isset($info['formatting'])) $fieldFormatting[$source] = $info['formatting'];
+ if(isset($info['csvFormatting'])) $csvFieldFormatting[$source] = $info['csvFormatting'];
+ if(isset($info['casting'])) $fieldCasting[$source] = $info['casting'];
+
+ $displayFields[$source] = isset($info['title']) ? $info['title'] : $source;
+ }
+ $gridField->setDisplayFields($displayFields);
+ $gridField->setFieldCasting($fieldCasting);
+ $gridField->setFieldFormatting($fieldFormatting);
+
+ $fields->push($gridField);
+ } else {
+ // List all reports
+ $gridFieldConfig = GridFieldConfig::create()->addComponents(
+ new GridFieldToolbarHeader(),
+ new GridFieldSortableHeader(),
+ new GridFieldDataColumns()
+ );
+ $gridField = new GridField('Reports','Reports', $this->Reports(), $gridFieldConfig);
+ $gridField->setDisplayFields(array(
+ 'title' => 'Title',
+ 'description' => 'Description'
+ ));
+ $gridField->setFieldFormatting(array(
+ 'title' => '<a href=\"$Link\">$value</a>'
+ ));
+ $fields->push($gridField);
+ }
+
+ $actions = new FieldList();
+ $form = new Form($this, "EditForm", $fields, $actions);
+ $form->addExtraClass('cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses());
+
+ $this->extend('updateEditForm', $form);
+
+ return $form;
+ }
}
View
6 code/reports/Report.php
@@ -134,6 +134,10 @@ function dataClass() {
return $this->dataClass;
}
+ function getLink() {
+ return 'admin/reports/show/' . $this->class;
+ }
+
/**
@@ -197,7 +201,7 @@ static function get_reports() {
if (in_array($report, self::$excluded_reports)) continue; //don't use the SS_Report superclass
$reportObj = new $report;
if (method_exists($reportObj,'sort')) $reportObj->sort = $reportObj->sort(); //use the sort method to specify the sort field
- $reportsArray[] = $reportObj;
+ $reportsArray[$report] = $reportObj;
}
}
View
25 templates/Includes/ReportAdmin_Content.ss
@@ -1,13 +1,28 @@
-<div class="cms-content center $BaseCSSClasses" data-layout-type="border">
+<div class="cms-content center ss-tabset $BaseCSSClasses" data-layout-type="border">
<div class="cms-content-header north">
- <h2><% _t('REPORTS','Reports') %></h2>
- </div>
+ <div>
+ <% control EditForm %>
+ <% if Backlink %>
+ <a class="backlink ss-ui-button cms-panel-link" data-icon="back" href="$Backlink">
+ <% _t('Back', 'Back') %>
+ </a>
+ <% end_if %>
- $Tools
+ <h2 id="page-title-heading">
+ <% control Controller %>
+ <% include CMSBreadcrumbs %>
+ <% end_control %>
+ </h2>
+ <% end_control %>
+
+ </div>
+ </div>
- <div class="cms-content-fields center ui-widget-content">
+ <div class="cms-content-fields center ui-widget-content" data-layout-type="border">
+
$EditForm
+
</div>
</div>
View
11 templates/Includes/ReportAdmin_Tools.ss
@@ -1,11 +0,0 @@
-<div class="cms-content-tools west" id="cms-content-tools-ReportAdmin">
-
- <ul class="ui-widget-content">
- <% control Reports %>
- <li id="record-$ID">
- <a href="admin/reports/show/$ID" title="$TreeDescription">$TreeTitle</a>
- </li>
- <% end_control %>
- </ul>
-
-</div>
Please sign in to comment.
Something went wrong with that request. Please try again.