FIX Allow for long lists of users by using a GridField #92 (#96)

This commit is contained in:
torleif 2018-08-15 14:47:52 +12:00 committed by Robbie Averill
parent 01c77790f7
commit 5245cda255
4 changed files with 81 additions and 15 deletions

View File

@ -51,6 +51,15 @@ class ContentReviewDefaultSettings extends DataExtension
*/
private static $content_review_template = 'ContentReviewEmail';
/**
* The number of members in which the dropdown will morph into a gridfield
*
* @config
*
* @var int
*/
private static $content_review_gridfield_threshold = 500;
/**
* @return string
*/
@ -120,10 +129,18 @@ class ContentReviewDefaultSettings extends DataExtension
$usersMap = $users->map('ID', 'Title')->toArray();
asort($usersMap);
$userField = ListboxField::create('OwnerUsers', _t('ContentReview.PAGEOWNERUSERS', 'Users'), $usersMap)
->setMultiple(true)
->setAttribute('data-placeholder', _t('ContentReview.ADDUSERS', 'Add users'))
->setDescription(_t('ContentReview.OWNERUSERSDESCRIPTION', 'Page owners that are responsible for reviews'));
if(Member::get()->count() > Config::inst()->get('SiteConfig', 'content_review_gridfield_threshold')) {
$gridfieldconfig = GridFieldConfig_RelationEditor::create();
$gridfieldconfig->removeComponentsByType(new GridFieldAddNewButton());
$userField = GridField::create('OwnerUsers', _t("ContentReview.PAGEOWNERUSERS", "Users"),
$this->OwnerUsers(), $gridfieldconfig)
->setDescription(_t('ContentReview.OWNERUSERSDESCRIPTION', 'Page owners that are responsible for reviews'));
} else {
$userField = ListboxField::create('OwnerUsers', _t('ContentReview.PAGEOWNERUSERS', 'Users'), $usersMap)
->setMultiple(true)
->setAttribute('data-placeholder', _t('ContentReview.ADDUSERS', 'Add users'))
->setDescription(_t('ContentReview.OWNERUSERSDESCRIPTION', 'Page owners that are responsible for reviews'));
}
$fields->addFieldToTab('Root.ContentReview', $userField);

View File

@ -344,17 +344,25 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
$viewersOptionsField = OptionsetField::create("ContentReviewType", _t("ContentReview.OPTIONS", "Options"), $options);
$users = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
$users = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
$usersMap = $users->map("ID", "Title")->toArray();
asort($usersMap);
$userField = ListboxField::create("OwnerUsers", _t("ContentReview.PAGEOWNERUSERS", "Users"), $usersMap)
->setMultiple(true)
->addExtraClass('custom-setting')
->setAttribute("data-placeholder", _t("ContentReview.ADDUSERS", "Add users"))
->setDescription(_t('ContentReview.OWNERUSERSDESCRIPTION', 'Page owners that are responsible for reviews'));
if(Member::get()->count() > Config::inst()->get('SiteConfig', 'content_review_gridfield_threshold')) {
// grid field for large numbers of users
$gridfieldconfig = GridFieldConfig_RelationEditor::create();
$gridfieldconfig->removeComponentsByType(new GridFieldAddNewButton());
$userField = GridField::create('OwnerUsers', _t("ContentReview.PAGEOWNERUSERS", "Users"),
$this->OwnerUsers(), $gridfieldconfig)
->setDescription(_t('ContentReview.OWNERUSERSDESCRIPTION', 'Page owners that are responsible for reviews'));
} else {
$userField = ListboxField::create("OwnerUsers", _t("ContentReview.PAGEOWNERUSERS", "Users"), $usersMap)
->setMultiple(true)
->addExtraClass('custom-setting')
->setAttribute("data-placeholder", _t("ContentReview.ADDUSERS", "Add users"))
->setDescription(_t('ContentReview.OWNERUSERSDESCRIPTION', 'Page owners that are responsible for reviews'));
}
$groupsMap = array();

View File

@ -23,3 +23,14 @@ CMS users without the permission to change the content review schedule can still
and previous reviews in the same view, but cannot change anything.
![](_images/content-review-settings-ro.png)
## If your database contains a large number of members
The page owners selector will change from a ListboxField to a Gridfield in order
to prevent your browser from crashing. By default this numbers is 500. You can
customise this threshold by editing your .yml with the following settings:
```
SiteTree:
content_review_gridfield_threshold: 500
```

View File

@ -334,4 +334,34 @@ class SiteTreeContentReviewTest extends ContentReviewBaseTest
SS_Datetime::clear_mock_now();
}
public function testSiteSettingsFieldsListBox()
{
$author = $this->objFromFixture("Member", "editor");
$this->logInAs($author);
/** @var Page|SiteTreeContentReview $page */
$page = $this->objFromFixture("Page", "contact");
$fields = $page->getSettingsFields();
$this->assertInstanceOf('ListboxField', $fields->dataFieldByName('OwnerUsers'));
}
public function testSiteSettingsFieldsGridfield()
{
$author = $this->objFromFixture("Member", "editor");
$this->logInAs($author);
/** @var Page|SiteTreeContentReview $page */
$page = $this->objFromFixture("Page", "contact");
// update the minimum threshhold to change to gridfield
Config::inst()->update('SiteConfig', 'content_review_gridfield_threshold', 1);
$fields = $page->getSettingsFields();
$this->assertInstanceOf('GridField', $fields->dataFieldByName('OwnerUsers'));
}
}