mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
ENHANCEMENT: Use GridFields to show reports in the ReportAdmin
This commit is contained in:
parent
029f83347b
commit
4c76c8563c
@ -58,9 +58,9 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function currentPageID() {
|
function currentReport() {
|
||||||
$id = parent::currentPageID();
|
$id = parent::currentPageID();
|
||||||
$reports = SS_Report::get_reports('ReportAdmin');
|
$reports = SS_Report::get_reports();
|
||||||
return (isset($reports[$id])) ? $reports[$id] : null;
|
return (isset($reports[$id])) ? $reports[$id] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
*/
|
*/
|
||||||
public function Reports() {
|
public function Reports() {
|
||||||
$output = new ArrayList();
|
$output = new ArrayList();
|
||||||
foreach(SS_Report::get_reports('ReportAdmin') as $report) {
|
foreach(SS_Report::get_reports() as $report) {
|
||||||
if($report->canView()) $output->push($report);
|
if($report->canView()) $output->push($report);
|
||||||
}
|
}
|
||||||
return $output;
|
return $output;
|
||||||
@ -90,7 +90,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public static function has_reports() {
|
public static function has_reports() {
|
||||||
return sizeof(SS_Report::get_reports('ReportAdmin')) > 0;
|
return sizeof(SS_Report::get_reports()) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updatereport() {
|
public function updatereport() {
|
||||||
@ -107,5 +107,67 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -134,6 +134,10 @@ class SS_Report extends ViewableData {
|
|||||||
return $this->dataClass;
|
return $this->dataClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getLink() {
|
||||||
|
return 'admin/reports/show/' . $this->class;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,7 +201,7 @@ class SS_Report extends ViewableData {
|
|||||||
if (in_array($report, self::$excluded_reports)) continue; //don't use the SS_Report superclass
|
if (in_array($report, self::$excluded_reports)) continue; //don't use the SS_Report superclass
|
||||||
$reportObj = new $report;
|
$reportObj = new $report;
|
||||||
if (method_exists($reportObj,'sort')) $reportObj->sort = $reportObj->sort(); //use the sort method to specify the sort field
|
if (method_exists($reportObj,'sort')) $reportObj->sort = $reportObj->sort(); //use the sort method to specify the sort field
|
||||||
$reportsArray[] = $reportObj;
|
$reportsArray[$report] = $reportObj;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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">
|
<div class="cms-content-header north">
|
||||||
<h2><% _t('REPORTS','Reports') %></h2>
|
<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 %>
|
||||||
|
|
||||||
|
<h2 id="page-title-heading">
|
||||||
|
<% control Controller %>
|
||||||
|
<% include CMSBreadcrumbs %>
|
||||||
|
<% end_control %>
|
||||||
|
</h2>
|
||||||
|
<% end_control %>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
$Tools
|
<div class="cms-content-fields center ui-widget-content" data-layout-type="border">
|
||||||
|
|
||||||
<div class="cms-content-fields center ui-widget-content">
|
|
||||||
$EditForm
|
$EditForm
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
@ -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>
|
|
Loading…
Reference in New Issue
Block a user