Merge pull request #36 from open-sausages/features/4.0/gridfield-styles

Class change for new gridfield styles, moved report actions to appear above gridfield
This commit is contained in:
Hamish Friedlander 2016-08-04 11:54:19 +12:00 committed by GitHub
commit 77a696ecdd
5 changed files with 421 additions and 409 deletions

View File

@ -158,7 +158,6 @@ class SS_Report extends ViewableData
public function getLink($action = null)
{
return Controller::join_links(
ReportAdmin::singleton()->Link('show'),
get_class($this),
@ -312,12 +311,14 @@ class SS_Report extends ViewableData
$items = $this->sourceRecords($params, null, null);
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldButtonRow('before'),
new GridFieldPrintButton('buttons-before-left'),
new GridFieldExportButton('buttons-before-left'),
new GridFieldToolbarHeader(),
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(),
new GridFieldButtonRow('after'),
new GridFieldPrintButton('buttons-after-left'),
new GridFieldExportButton('buttons-after-left')
new GridFieldPaginator()
);
$gridField = new GridField('Report', null, $items, $gridFieldConfig);
$columns = $gridField->getConfig()->getComponentByType('GridFieldDataColumns');
@ -342,8 +343,14 @@ class SS_Report extends ViewableData
}
if (isset($info['link']) && $info['link']) {
$link = singleton('CMSPageEditController')->Link('show');
$fieldFormatting[$source] = '<a href=\"' . $link . '/$ID\">$value</a>';
$fieldFormatting[$source] = function($value, $item) {
/** @var CMSPreviewable $item */
return sprintf(
'<a class="grid-field__link-block" href="%s">%s</a>',
Convert::raw2att($item->CMSEditLink()),
Convert::raw2xml($value)
);
};
}
$displayFields[$source] = isset($info['title']) ? $info['title'] : $source;
@ -386,14 +393,17 @@ class SS_Report extends ViewableData
* @param Member|int $member
* @return boolean|null
*/
public function extendedCan($methodName, $member) {
public function extendedCan($methodName, $member)
{
$results = $this->extend($methodName, $member);
if ($results && is_array($results)) {
// Remove NULLs
$results = array_filter($results, function ($v) {return !is_null($v);});
// If there are any non-NULL responses, then return the lowest one of them.
// If any explicitly deny the permission, then we don't get access
if($results) return min($results);
if ($results) {
return min($results);
}
}
return null;
}

View File

@ -101,7 +101,8 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
return $output;
}
public function handleAction($request, $action) {
public function handleAction($request, $action)
{
$this->reportClass = $request->param('ReportClass');
// Check report
@ -204,7 +205,7 @@ class ReportAdmin extends LeftAndMain implements PermissionProvider
));
$columns->setFieldFormatting(array(
'title' => '<a href=\"$Link\" class=\"cms-panel-link\">$value ($Count)</a>'
'title' => '<a href=\"$Link\" class=\"grid-field__link-block\">$value ($Count)</a>'
));
$gridField->addExtraClass('all-reports-gridfield');
$fields->push($gridField);

View File

@ -64,7 +64,8 @@ class ReportTest extends SapphireTest
'ReportTest_FakeTest_Abstract is NOT in reports list as it is abstract');
}
public function testPermissions() {
public function testPermissions()
{
$report = new ReportTest_FakeTest2();
// Visitor cannot view