mirror of
https://github.com/symbiote/silverstripe-gridfieldextensions.git
synced 2024-10-22 15:05:39 +00:00
Merge branch '3'
This commit is contained in:
commit
cbffc5b935
@ -3,6 +3,7 @@
|
||||
namespace Symbiote\GridFieldExtensions;
|
||||
|
||||
use SilverStripe\Core\Convert;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\Forms\Form;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridField_HTMLProvider;
|
||||
@ -13,7 +14,6 @@ use SilverStripe\ORM\DataObjectInterface;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\ORM\ManyManyList;
|
||||
use SilverStripe\View\ArrayData;
|
||||
use SilverStripe\Core\Injector\Injector;
|
||||
use SilverStripe\View\Requirements;
|
||||
use Exception;
|
||||
|
||||
|
@ -244,7 +244,7 @@ class GridFieldAddNewMultiClass implements GridField_HTMLProvider, GridField_URL
|
||||
|
||||
GridFieldExtensions::include_requirements();
|
||||
|
||||
$field = new DropdownField(sprintf('%s[ClassName]', self::POST_KEY), '', $classes, $this->defaultClass);
|
||||
$field = new DropdownField(sprintf('%s[%s]', __CLASS__, $grid->getName()), '', $classes, $this->defaultClass);
|
||||
if (Config::inst()->get(__CLASS__, 'showEmptyString')) {
|
||||
$field->setEmptyString(_t('GridFieldExtensions.SELECTTYPETOCREATE', '(Select type to create)'));
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ use SilverStripe\Forms\ReadonlyField;
|
||||
use SilverStripe\ORM\DataList;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
use SilverStripe\ORM\DataObjectInterface;
|
||||
use SilverStripe\ORM\FieldType\DBField;
|
||||
use SilverStripe\ORM\ManyManyList;
|
||||
|
||||
/**
|
||||
|
@ -21,6 +21,7 @@ use SilverStripe\ORM\DB;
|
||||
use SilverStripe\ORM\ManyManyList;
|
||||
use SilverStripe\ORM\Map;
|
||||
use SilverStripe\ORM\SS_List;
|
||||
use SilverStripe\ORM\FieldType\DBDatetime;
|
||||
use SilverStripe\Versioned\Versioned;
|
||||
use SilverStripe\View\ViewableData;
|
||||
|
||||
@ -537,14 +538,13 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
// match to order the objects.
|
||||
if (!$isVersioned) {
|
||||
$sortTable = $this->getSortTable($list);
|
||||
$now = DBDatetime::now()->Rfc2822();
|
||||
$additionalSQL = '';
|
||||
$baseTable = $sortTable;
|
||||
if (class_exists($sortTable)) {
|
||||
$baseTable = singleton($sortTable)->baseTable();
|
||||
}
|
||||
$baseTable = DataObject::getSchema()->baseDataTable($list->dataClass());
|
||||
|
||||
$isBaseTable = ($baseTable == $sortTable);
|
||||
if (!$list instanceof ManyManyList && $isBaseTable) {
|
||||
$additionalSQL = ', "LastEdited" = NOW()';
|
||||
$additionalSQL = ", \"LastEdited\" = '$now'";
|
||||
}
|
||||
|
||||
foreach ($sortedIDs as $sortValue => $id) {
|
||||
@ -558,10 +558,11 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$this->getSortTableClauseForIds($list, $id)
|
||||
));
|
||||
|
||||
if (!$isBaseTable) {
|
||||
if (!$isBaseTable && !$list instanceof ManyManyList) {
|
||||
DB::query(sprintf(
|
||||
'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s',
|
||||
'UPDATE "%s" SET "LastEdited" = \'%s\' WHERE %s',
|
||||
$baseTable,
|
||||
$now,
|
||||
$this->getSortTableClauseForIds($list, $id)
|
||||
));
|
||||
}
|
||||
@ -590,15 +591,13 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$field = $this->getSortField();
|
||||
$table = $this->getSortTable($list);
|
||||
$clause = sprintf('"%s"."%s" = 0', $table, $this->getSortField());
|
||||
|
||||
$now = DBDatetime::now()->Rfc2822();
|
||||
$additionalSQL = '';
|
||||
$baseTable = $table;
|
||||
if (class_exists($table)) {
|
||||
$baseTable = singleton($table)->baseTable();
|
||||
}
|
||||
$baseTable = DataObject::getSchema()->baseDataTable($list->dataClass());
|
||||
|
||||
$isBaseTable = ($baseTable == $table);
|
||||
if (!$list instanceof ManyManyList && $isBaseTable) {
|
||||
$additionalSQL = ', "LastEdited" = NOW()';
|
||||
$additionalSQL = ", \"LastEdited\" = '$now'";
|
||||
}
|
||||
|
||||
foreach ($list->where($clause)->column('ID') as $id) {
|
||||
@ -614,10 +613,11 @@ class GridFieldOrderableRows extends RequestHandler implements
|
||||
$this->getSortTableClauseForIds($list, $id)
|
||||
));
|
||||
|
||||
if (!$isBaseTable) {
|
||||
if (!$isBaseTable && !$list instanceof ManyManyList) {
|
||||
DB::query(sprintf(
|
||||
'UPDATE "%s" SET "LastEdited" = NOW() WHERE %s',
|
||||
'UPDATE "%s" SET "LastEdited" = \'%s\' WHERE %s',
|
||||
$baseTable,
|
||||
$now,
|
||||
$this->getSortTableClauseForIds($list, $id)
|
||||
));
|
||||
}
|
||||
|
@ -165,7 +165,7 @@ class GridFieldConfigurablePaginatorTest extends SapphireTest
|
||||
public function testGetPageSizesAsList()
|
||||
{
|
||||
$paginator = new GridFieldConfigurablePaginator(10, array(10, 20, 30));
|
||||
$this->assertDOSEquals(array(
|
||||
$this->assertListEquals(array(
|
||||
array('Size' => '10', 'Selected' => true),
|
||||
array('Size' => '20', 'Selected' => false),
|
||||
array('Size' => '30', 'Selected' => false),
|
||||
|
@ -7,9 +7,11 @@ use SilverStripe\Dev\SapphireTest;
|
||||
use SilverStripe\Forms\GridField\GridField;
|
||||
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor;
|
||||
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;
|
||||
use Symbiote\GridFieldExtensions\Tests\Stub\StubOrderableChild;
|
||||
use Symbiote\GridFieldExtensions\Tests\Stub\StubOrdered;
|
||||
use Symbiote\GridFieldExtensions\Tests\Stub\StubParent;
|
||||
use Symbiote\GridFieldExtensions\Tests\Stub\StubSubclass;
|
||||
use Symbiote\GridFieldExtensions\Tests\Stub\StubUnorderable;
|
||||
|
||||
/**
|
||||
* Tests for the {@link GridFieldOrderableRows} component.
|
||||
@ -21,11 +23,13 @@ class GridFieldOrderableRowsTest extends SapphireTest
|
||||
|
||||
protected static $fixture_file = 'GridFieldOrderableRowsTest.yml';
|
||||
|
||||
protected static $extra_dataobjects = array(
|
||||
protected static $extra_dataobjects = [
|
||||
StubParent::class,
|
||||
StubOrdered::class,
|
||||
StubSubclass::class,
|
||||
);
|
||||
StubUnorderable::class,
|
||||
StubOrderableChild::class,
|
||||
];
|
||||
|
||||
public function testReorderItems()
|
||||
{
|
||||
@ -46,7 +50,7 @@ class GridFieldOrderableRowsTest extends SapphireTest
|
||||
);
|
||||
|
||||
$originalOrder = $parent->MyManyMany()->sort('ManyManySort')->column('ID');
|
||||
$desiredOrder = array();
|
||||
$desiredOrder = [];
|
||||
|
||||
// Make order non-contiguous, and 1-based
|
||||
foreach (array_reverse($originalOrder) as $index => $id) {
|
||||
@ -62,8 +66,38 @@ class GridFieldOrderableRowsTest extends SapphireTest
|
||||
$this->assertEquals($desiredOrder, $newOrder);
|
||||
}
|
||||
|
||||
public function testSortableChildClass()
|
||||
{
|
||||
$orderable = new GridFieldOrderableRows('Sort');
|
||||
$reflection = new ReflectionMethod($orderable, 'executeReorder');
|
||||
$reflection->setAccessible(true);
|
||||
|
||||
$parent = $this->objFromFixture(StubOrdered::class, 'nestedtest');
|
||||
|
||||
$config = new GridFieldConfig_RelationEditor();
|
||||
$config->addComponent($orderable);
|
||||
|
||||
$grid = new GridField(
|
||||
'Children',
|
||||
'Children',
|
||||
$parent->Children(),
|
||||
$config
|
||||
);
|
||||
|
||||
$originalOrder = $parent->Children()->column('ID');
|
||||
$desiredOrder = array_reverse($originalOrder);
|
||||
|
||||
$this->assertNotEquals($originalOrder, $desiredOrder);
|
||||
|
||||
$reflection->invoke($orderable, $grid, $desiredOrder);
|
||||
|
||||
$newOrder = $parent->Children()->column('ID');
|
||||
|
||||
$this->assertEquals($desiredOrder, $newOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers GridFieldOrderableRows::getSortTable
|
||||
* @covers \Symbiote\GridFieldExtensions\GridFieldOrderableRows::getSortTable
|
||||
*/
|
||||
public function testGetSortTable()
|
||||
{
|
||||
|
@ -1,3 +1,12 @@
|
||||
Symbiote\GridFieldExtensions\Tests\Stub\StubOrderableChild:
|
||||
item1:
|
||||
Sort: 1
|
||||
item2:
|
||||
Sort: 2
|
||||
item3:
|
||||
Sort: 3
|
||||
item4:
|
||||
Sort: 4
|
||||
Symbiote\GridFieldExtensions\Tests\Stub\StubOrdered:
|
||||
item1:
|
||||
Sort: 1
|
||||
@ -11,7 +20,8 @@ Symbiote\GridFieldExtensions\Tests\Stub\StubOrdered:
|
||||
Sort: 5
|
||||
item6:
|
||||
Sort: 6
|
||||
|
||||
nestedtest:
|
||||
Children: =>Symbiote\GridFieldExtensions\Tests\Stub\StubOrderableChild.item1,=>Symbiote\GridFieldExtensions\Tests\Stub\StubOrderableChild.item2,=>Symbiote\GridFieldExtensions\Tests\Stub\StubOrderableChild.item3,=>Symbiote\GridFieldExtensions\Tests\Stub\StubOrderableChild.item4
|
||||
Symbiote\GridFieldExtensions\Tests\Stub\StubParent:
|
||||
parent:
|
||||
MyManyMany:
|
||||
|
18
tests/Stub/StubOrderableChild.php
Normal file
18
tests/Stub/StubOrderableChild.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Symbiote\GridFieldExtensions\Tests\Stub;
|
||||
|
||||
class StubOrderableChild extends StubUnorderable
|
||||
{
|
||||
private static $db = [
|
||||
'Sort' => 'Int',
|
||||
];
|
||||
|
||||
private static $has_one = [
|
||||
'Parent' => StubOrdered::class,
|
||||
];
|
||||
|
||||
private static $default_sort = '"Sort" ASC';
|
||||
|
||||
private static $table_name = 'StubOrderableChild';
|
||||
}
|
@ -15,6 +15,10 @@ class StubOrdered extends DataObject implements TestOnly
|
||||
'Parent' => StubParent::class
|
||||
);
|
||||
|
||||
private static $has_many = array(
|
||||
'Children' => StubOrderableChild::class,
|
||||
);
|
||||
|
||||
private static $belongs_many_many =array(
|
||||
'MyManyMany' => StubParent::class,
|
||||
);
|
||||
|
15
tests/Stub/StubUnorderable.php
Normal file
15
tests/Stub/StubUnorderable.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Symbiote\GridFieldExtensions\Tests\Stub;
|
||||
|
||||
use SilverStripe\Dev\TestOnly;
|
||||
use SilverStripe\ORM\DataObject;
|
||||
|
||||
class StubUnorderable extends DataObject implements TestOnly
|
||||
{
|
||||
private static $db = [
|
||||
'Title' => 'Varchar',
|
||||
];
|
||||
|
||||
private static $table_name = 'StubUnorderable';
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user