Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.1'
Browse files Browse the repository at this point in the history
Conflicts:
.travis.yml
  • Loading branch information
Damian Mooyman committed May 5, 2014
2 parents 61ebe08 + 1f4d9e4 commit b369928
Show file tree
Hide file tree
Showing 16 changed files with 594 additions and 236 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Expand Up @@ -26,6 +26,9 @@ matrix:
env: DB=MYSQL CORE_RELEASE=master
- php: 5.4
env: DB=MYSQL CORE_RELEASE=master BEHAT_TEST=1
allow_failures:
- php: 5.6
env: DB=MYSQL CORE_RELEASE=master

before_script:
- composer self-update
Expand All @@ -38,7 +41,7 @@ before_script:
- php ~/travis-support/travis_setup_php54_webserver.php --if-env BEHAT_TEST

script:
- "if [ \"$BEHAT_TEST\" = \"\" ]; then phpunit cms/tests; fi"
- "if [ \"$BEHAT_TEST\" = \"\" ]; then vendor/bin/phpunit cms/tests; fi"
- "if [ \"$BEHAT_TEST\" = \"1\" ]; then vendor/bin/behat @cms; fi"

after_failure:
Expand Down
72 changes: 50 additions & 22 deletions code/controllers/AssetAdmin.php
Expand Up @@ -16,6 +16,14 @@ class AssetAdmin extends LeftAndMain implements PermissionProvider{

private static $tree_class = 'Folder';

/**
* Amount of results showing on a single page.
*
* @config
* @var int
*/
private static $page_length = 15;

/**
* @config
* @see Upload->allowedMaxFileSize
Expand Down Expand Up @@ -98,17 +106,19 @@ public function getList() {
// Don't filter list when a detail view is requested,
// to avoid edge cases where the filtered list wouldn't contain the requested
// record due to faulty session state (current folder not always encoded in URL, see #7408).
if(!$folder->ID && $this->request->requestVar('ID') === null && ($this->request->param('ID') == 'field')) {
if(!$folder->ID
&& $this->request->requestVar('ID') === null
&& ($this->request->param('ID') == 'field')
) {
return $list;
}

// Re-add previously removed "Name" filter as combined filter
// TODO Replace with composite SearchFilter once that API exists
if(isset($params['Name'])) {
$list = $list->where(sprintf(
'"Name" LIKE \'%%%s%%\' OR "Title" LIKE \'%%%s%%\'',
Convert::raw2sql($params['Name']),
Convert::raw2sql($params['Name'])
if(!empty($params['Name'])) {
$list = $list->filterAny(array(
'Name:PartialMatch' => $params['Name'],
'Title:PartialMatch' => $params['Name']
));
}

Expand All @@ -117,23 +127,26 @@ public function getList() {

// If a search is conducted, check for the "current folder" limitation.
// Otherwise limit by the current folder as denoted by the URL.
if(!$params || @$params['CurrentFolderOnly']) {
if(empty($params) || !empty($params['CurrentFolderOnly'])) {
$list = $list->filter('ParentID', $folder->ID);
}

// Category filter
if(isset($params['AppCategory'])) {
if(isset(File::config()->app_categories[$params['AppCategory']])) {
$exts = File::config()->app_categories[$params['AppCategory']];
} else {
$exts = array();
}
$categorySQLs = array();
foreach($exts as $ext) $categorySQLs[] = '"File"."Name" LIKE \'%.' . $ext . '\'';
// TODO Use DataList->filterAny() once OR connectives are implemented properly
if (count($categorySQLs) > 0) {
$list = $list->where('(' . implode(' OR ', $categorySQLs) . ')');
}
if(!empty($params['AppCategory'])
&& !empty(File::config()->app_categories[$params['AppCategory']])
) {
$exts = File::config()->app_categories[$params['AppCategory']];
$list = $list->filter('Name:PartialMatch', $exts);
}

// Date filter
if(!empty($params['CreatedFrom'])) {
$fromDate = new DateField(null, null, $params['CreatedFrom']);
$list = $list->filter("Created:GreaterThanOrEqual", $fromDate->dataValue());
}
if(!empty($params['CreatedTo'])) {
$toDate = new DateField(null, null, $params['CreatedTo']);
$list = $list->filter("Created:LessThanOrEqual", $toDate->dataValue());
}

return $list;
Expand All @@ -150,9 +163,9 @@ public function getEditForm($id = null, $fields = null) {
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldToolbarHeader(),
new GridFieldSortableHeader(),
new GridFieldFilterHeader(),
new GridFieldFilterHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(15),
new GridFieldPaginator(self::config()->page_length),
new GridFieldEditButton(),
new GridFieldDeleteAction(),
new GridFieldDetailForm(),
Expand Down Expand Up @@ -342,6 +355,21 @@ public function getSearchContext() {
foreach($context->getFilters() as $filter) $filter->setFullName(sprintf('q[%s]', $filter->getFullName()));

// Customize fields
$context->addField(
new HeaderField('q[Date]', _t('CMSSearch.FILTERDATEHEADING', 'Date'), 4)
);
$context->addField(
DateField::create(
'q[CreatedFrom]',
_t('CMSSearch.FILTERDATEFROM', 'From')
)->setConfig('showcalendar', true)
);
$context->addField(
DateField::create(
'q[CreatedTo]',
_t('CMSSearch.FILTERDATETO', 'To')
)->setConfig('showcalendar', true)
);
$appCategories = array(
'image' => _t('AssetAdmin.AppCategoryImage', 'Image'),
'audio' => _t('AssetAdmin.AppCategoryAudio', 'Audio'),
Expand Down Expand Up @@ -382,7 +410,7 @@ public function SearchForm() {
$fields = $context->getSearchFields();
$actions = new FieldList(
FormAction::create('doSearch', _t('CMSMain_left_ss.APPLY_FILTER', 'Apply Filter'))
->addExtraClass('ss-ui-action-constructive'),
->addExtraClass('ss-ui-action-constructive'),
Object::create('ResetFormAction', 'clear', _t('CMSMain_left_ss.RESET', 'Reset'))
);

Expand Down
10 changes: 9 additions & 1 deletion code/controllers/CMSMain.php
Expand Up @@ -27,6 +27,14 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr

private static $subitem_class = "Member";

/**
* Amount of results showing on a single page.
*
* @config
* @var int
*/
private static $page_length = 15;

private static $allowed_actions = array(
'buildbrokenlinks',
'deleteitems',
Expand Down Expand Up @@ -726,7 +734,7 @@ public function ListViewForm() {
$gridFieldConfig = GridFieldConfig::create()->addComponents(
new GridFieldSortableHeader(),
new GridFieldDataColumns(),
new GridFieldPaginator(15)
new GridFieldPaginator(self::config()->page_length)
);
if($parentID){
$gridFieldConfig->addComponent(
Expand Down

0 comments on commit b369928

Please sign in to comment.