From b47f286efd4727dfee8f1423d6f995d232bc0d20 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 20 Jan 2017 15:31:47 +1300 Subject: [PATCH] FIX Bootstrap style for clear all button, and add paginator for LogViewerAdmin --- src/Admin/LogViewerAdmin.php | 2 ++ src/Forms/GridField/GridFieldClearAllButton.php | 6 ++++-- tests/Admin/LogViewerAdminTest.php | 12 ++++++++++++ .../Forms/GridField/GridFieldClearAllButtonTest.php | 5 ++++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Admin/LogViewerAdmin.php b/src/Admin/LogViewerAdmin.php index 74bec7b..0f73a67 100644 --- a/src/Admin/LogViewerAdmin.php +++ b/src/Admin/LogViewerAdmin.php @@ -6,6 +6,7 @@ use SilverLeague\LogViewer\Forms\GridField\GridFieldClearAllButton; use SilverStripe\Admin\ModelAdmin; use SilverStripe\Forms\GridField\GridFieldAddNewButton; +use SilverStripe\Forms\GridField\GridFieldPaginator; use SilverStripe\View\Requirements; /** @@ -65,6 +66,7 @@ public function getEditForm($id = null, $fields = null) $config = $gridField->getConfig(); $config->removeComponentsByType($config->getComponentByType(GridFieldAddNewButton::class)); $config->addComponent(new GridFieldClearAllButton('buttons-before-left')); + $config->addComponent(new GridFieldPaginator); return $form; } diff --git a/src/Forms/GridField/GridFieldClearAllButton.php b/src/Forms/GridField/GridFieldClearAllButton.php index fc207ee..7a7c8a7 100644 --- a/src/Forms/GridField/GridFieldClearAllButton.php +++ b/src/Forms/GridField/GridFieldClearAllButton.php @@ -41,10 +41,12 @@ public function getHTMLFragments($gridField) { $button = GridField_FormAction::create($gridField, 'clear', 'Clear all', 'clear', null); $button->setAttribute('data-icon', 'clear-all-logs'); - $button->addExtraClass('font-icon-trash-bin action_clear action action-delete'); + $button->addExtraClass('font-icon-trash-bin action_clear action action-delete btn btn-secondary'); $button->setForm($gridField->getForm()); - return [$this->targetFragment => '

' . $button->Field() . '

']; + return [ + $this->targetFragment => '

' . $button->Field() . '

' + ]; } /** diff --git a/tests/Admin/LogViewerAdminTest.php b/tests/Admin/LogViewerAdminTest.php index 44afeae..e0d953d 100644 --- a/tests/Admin/LogViewerAdminTest.php +++ b/tests/Admin/LogViewerAdminTest.php @@ -6,6 +6,7 @@ use SilverLeague\LogViewer\Forms\GridField\GridFieldClearAllButton; use SilverStripe\Dev\FunctionalTest; use SilverStripe\Forms\GridField\GridFieldAddNewButton; +use SilverStripe\Forms\GridField\GridFieldPaginator; use SilverStripe\Forms\ReadonlyField; /** @@ -66,6 +67,17 @@ public function testHasClearAllButton() ); } + /** + * Test that the GridField has a Paginator component + */ + public function testHasPagination() + { + $this->assertInstanceOf( + GridFieldPaginator::class, + $this->getConfig()->getComponentByType(GridFieldPaginator::class) + ); + } + /** * Test that the entry and level fields are displayed in the GridField, and can be exported */ diff --git a/tests/Forms/GridField/GridFieldClearAllButtonTest.php b/tests/Forms/GridField/GridFieldClearAllButtonTest.php index 34e6ce8..c910ac5 100644 --- a/tests/Forms/GridField/GridFieldClearAllButtonTest.php +++ b/tests/Forms/GridField/GridFieldClearAllButtonTest.php @@ -26,6 +26,9 @@ class GridFieldClearAllButtonTest extends SapphireTest */ protected $usesDatabase = true; + /** + * @var GridField + */ protected $gridField; /** @@ -66,7 +69,7 @@ public function testGetHtmlFragments() $this->assertContains('Clear all', $fragments['before']); $this->assertContains('clear-all-logs', $fragments['before']); $this->assertContains('font-icon-trash-bin action_clear', $fragments['before']); - $this->assertContains('

', $fragments['before']); + $this->assertContains('

', $fragments['before']); } /**