mirror of
https://github.com/silverstripe/silverstripe-reports
synced 2024-10-22 11:05:53 +02:00
ENH Reports list filtering and pagination.
This commit is contained in:
parent
75f295f1d8
commit
97c03dbba5
@ -7,12 +7,19 @@ use SilverStripe\Control\Controller;
|
|||||||
use SilverStripe\Forms\FieldList;
|
use SilverStripe\Forms\FieldList;
|
||||||
use SilverStripe\Forms\Form;
|
use SilverStripe\Forms\Form;
|
||||||
use SilverStripe\Forms\GridField\GridField;
|
use SilverStripe\Forms\GridField\GridField;
|
||||||
|
use SilverStripe\Forms\GridField\GridFieldButtonRow;
|
||||||
use SilverStripe\Forms\GridField\GridFieldConfig;
|
use SilverStripe\Forms\GridField\GridFieldConfig;
|
||||||
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
use SilverStripe\Forms\GridField\GridFieldDataColumns;
|
||||||
use SilverStripe\Forms\GridField\GridFieldFooter;
|
use SilverStripe\Forms\GridField\GridFieldFilterHeader;
|
||||||
|
use SilverStripe\Forms\GridField\GridFieldPageCount;
|
||||||
|
use SilverStripe\Forms\GridField\GridFieldPaginator;
|
||||||
use SilverStripe\Forms\GridField\GridFieldSortableHeader;
|
use SilverStripe\Forms\GridField\GridFieldSortableHeader;
|
||||||
|
use SilverStripe\Forms\HiddenField;
|
||||||
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorConfig;
|
||||||
|
use SilverStripe\Forms\TextField;
|
||||||
use SilverStripe\ORM\ArrayList;
|
use SilverStripe\ORM\ArrayList;
|
||||||
|
use SilverStripe\ORM\Filters\PartialMatchFilter;
|
||||||
|
use SilverStripe\ORM\Search\BasicSearchContext;
|
||||||
use SilverStripe\ORM\SS_List;
|
use SilverStripe\ORM\SS_List;
|
||||||
use SilverStripe\Security\Member;
|
use SilverStripe\Security\Member;
|
||||||
use SilverStripe\Security\PermissionProvider;
|
use SilverStripe\Security\PermissionProvider;
|
||||||
@ -104,13 +111,18 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
*/
|
*/
|
||||||
public function Reports()
|
public function Reports()
|
||||||
{
|
{
|
||||||
$output = new ArrayList();
|
$output = ArrayList::create();
|
||||||
foreach (Report::get_reports() as $report) {
|
foreach (Report::get_reports() as $report) {
|
||||||
if ($report->canView()) {
|
if ($report->canView()) {
|
||||||
$output->push($report);
|
$output->push($report);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $output;
|
|
||||||
|
return $output
|
||||||
|
// Provide a good default for the reports order, otherwise this will be using sort by namespace
|
||||||
|
->sort('Title', 'ASC')
|
||||||
|
// Provide a good default for the data class, otherwise this will use the class of the first item in the list
|
||||||
|
->setDataClass(Report::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handleAction($request, $action)
|
public function handleAction($request, $action)
|
||||||
@ -227,28 +239,60 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
|
|||||||
$fields = $report->getCMSFields();
|
$fields = $report->getCMSFields();
|
||||||
} else {
|
} else {
|
||||||
// List all reports
|
// List all reports
|
||||||
$fields = new FieldList();
|
$fields = FieldList::create();
|
||||||
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
$gridFieldConfig = GridFieldConfig::create()->addComponents(
|
||||||
|
// This is a container component that is required by filter header component
|
||||||
|
GridFieldButtonRow::create('before'),
|
||||||
|
$filterHeader = GridFieldFilterHeader::create(),
|
||||||
GridFieldSortableHeader::create(),
|
GridFieldSortableHeader::create(),
|
||||||
GridFieldDataColumns::create(),
|
$columns = GridFieldDataColumns::create(),
|
||||||
GridFieldFooter::create()
|
GridFieldPageCount::create(),
|
||||||
|
GridFieldPaginator::create()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Configure the filter header filter search form
|
||||||
|
$generalField = BasicSearchContext::config()->get('general_search_field_name');
|
||||||
|
$searchFieldList = FieldList::create([
|
||||||
|
HiddenField::create($generalField),
|
||||||
|
TextField::create('Title'),
|
||||||
|
TextField::create('Description'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$searchContext = BasicSearchContext::create(Report::class);
|
||||||
|
$searchContext->setFields($searchFieldList);
|
||||||
|
|
||||||
|
// Setup filter configuration - partial match with case-insensitive modifier
|
||||||
|
$filters = [
|
||||||
|
'Title',
|
||||||
|
'Description',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($filters as $fieldName) {
|
||||||
|
$fieldFilter = PartialMatchFilter::create($fieldName);
|
||||||
|
$fieldFilter->setModifiers([
|
||||||
|
// We want case-insensitive match to be consistent with other areas of the CMS
|
||||||
|
'nocase',
|
||||||
|
]);
|
||||||
|
$searchContext->addFilter($fieldFilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
$filterHeader->setSearchContext($searchContext);
|
||||||
|
|
||||||
$gridField = GridField::create('Reports', false, $this->Reports(), $gridFieldConfig);
|
$gridField = GridField::create('Reports', false, $this->Reports(), $gridFieldConfig);
|
||||||
$columns = $gridField->getConfig()
|
|
||||||
->getComponentByType(GridFieldDataColumns::class);
|
|
||||||
$columns->setDisplayFields(array(
|
$columns->setDisplayFields(array(
|
||||||
'title' => _t('SilverStripe\\Reports\\ReportAdmin.ReportTitle', 'Title'),
|
'title' => _t('SilverStripe\\Reports\\ReportAdmin.ReportTitle', 'Title'),
|
||||||
|
'description' => _t('SilverStripe\\Reports\\ReportAdmin.ReportDescription', 'Description'),
|
||||||
));
|
));
|
||||||
|
|
||||||
$columns->setFieldFormatting(array(
|
$columns->setFieldFormatting([
|
||||||
'title' => '<a href=\"$Link\" class=\"grid-field__link-block\">$value ($CountForOverview)</a>'
|
'title' => '<a href=\"$Link\" class=\"grid-field__link-block\">$value ($CountForOverview)</a>'
|
||||||
));
|
]);
|
||||||
$gridField->addExtraClass('all-reports-gridfield');
|
$gridField->addExtraClass('all-reports-gridfield');
|
||||||
$fields->push($gridField);
|
$fields->push($gridField);
|
||||||
}
|
}
|
||||||
|
|
||||||
$actions = new FieldList();
|
$actions = FieldList::create();
|
||||||
$form = new Form($this, "EditForm", $fields, $actions);
|
$form = Form::create($this, "EditForm", $fields, $actions);
|
||||||
$form->addExtraClass(
|
$form->addExtraClass(
|
||||||
'panel panel--padded panel--scrollable cms-edit-form cms-panel-padded' . $this->BaseCSSClasses()
|
'panel panel--padded panel--scrollable cms-edit-form cms-panel-padded' . $this->BaseCSSClasses()
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user