fix filemanager sorting
This commit is contained in:
parent
d6e38c0ef1
commit
85f44fcabb
|
@ -115,20 +115,20 @@ class RedirectAdminController extends CrudController
|
||||||
])
|
])
|
||||||
->setField('index', 'Rule', Field\TextField::class, [
|
->setField('index', 'Rule', Field\TextField::class, [
|
||||||
'view' => '@Core/redirect/redirect_admin/field/rule.html.twig',
|
'view' => '@Core/redirect/redirect_admin/field/rule.html.twig',
|
||||||
'attr' => ['class' => 'col-4'],
|
'attr' => ['class' => 'col-6'],
|
||||||
])
|
])
|
||||||
->setField('index', 'Enabled', Field\ButtonField::class, [
|
->setField('index', 'Enabled', Field\ButtonField::class, [
|
||||||
'property_builder' => function(EntityInterface $entity) {
|
'property_builder' => function(EntityInterface $entity) {
|
||||||
return $entity->getIsEnabled() ? 'Yes' : 'No';
|
return $entity->getIsEnabled() ? 'Yes' : 'No';
|
||||||
},
|
},
|
||||||
'attr' => ['class' => 'col-2'],
|
'attr' => ['class' => 'col-1'],
|
||||||
'button_attr_builder' => function(EntityInterface $entity) {
|
'button_attr_builder' => function(EntityInterface $entity) {
|
||||||
return ['class' => 'btn btn-sm btn-'.($entity->getIsEnabled() ? 'success' : 'primary')];
|
return ['class' => 'btn btn-sm btn-'.($entity->getIsEnabled() ? 'success' : 'primary')];
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
->setField('index', 'Type', Field\ButtonField::class, [
|
->setField('index', 'Type', Field\ButtonField::class, [
|
||||||
'property' => 'redirectCode',
|
'property' => 'redirectCode',
|
||||||
'attr' => ['class' => 'col-2'],
|
'attr' => ['class' => 'col-1'],
|
||||||
'button_attr' => ['class' => 'btn btn-sm btn-light border-secondary font-weight-bold'],
|
'button_attr' => ['class' => 'btn btn-sm btn-light border-secondary font-weight-bold'],
|
||||||
])
|
])
|
||||||
->setBatchAction('index', 'enable', 'Enable', function (EntityInterface $entity, EntityManager $manager) {
|
->setBatchAction('index', 'enable', 'Enable', function (EntityInterface $entity, EntityManager $manager) {
|
||||||
|
|
|
@ -72,26 +72,7 @@ class FsFileManager
|
||||||
|
|
||||||
$finder = new Finder();
|
$finder = new Finder();
|
||||||
$finder->directories()->depth('== 0')->in($this->path.'/'.$directory);
|
$finder->directories()->depth('== 0')->in($this->path.'/'.$directory);
|
||||||
|
$this->applySort($finder, $options['sort'] ?? 'name', $options['sort_direction'] ?? 'asc');
|
||||||
if (isset($options['sort'])) {
|
|
||||||
$sort = $options['sort'];
|
|
||||||
$sorted = false;
|
|
||||||
$direction = $options['sort_direction'];
|
|
||||||
|
|
||||||
if ('name' === $sort) {
|
|
||||||
$finder->sortByName();
|
|
||||||
$sorted = true;
|
|
||||||
} elseif ('modification_date' === $sort) {
|
|
||||||
$sorted = true;
|
|
||||||
$finder->sortByModifiedTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($sorted) {
|
|
||||||
if ('desc' === $direction) {
|
|
||||||
$finder->reverseSorting();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($finder as $file) {
|
foreach ($finder as $file) {
|
||||||
$data['directories'][] = [
|
$data['directories'][] = [
|
||||||
|
@ -106,6 +87,8 @@ class FsFileManager
|
||||||
$finder = new Finder();
|
$finder = new Finder();
|
||||||
$finder->files()->depth('== 0')->in($this->path.'/'.$directory);
|
$finder->files()->depth('== 0')->in($this->path.'/'.$directory);
|
||||||
|
|
||||||
|
$this->applySort($finder, $options['sort'] ?? 'name', $options['sort_direction'] ?? 'asc');
|
||||||
|
|
||||||
foreach ($finder as $file) {
|
foreach ($finder as $file) {
|
||||||
$data['files'][] = [
|
$data['files'][] = [
|
||||||
'basename' => $file->getBasename(),
|
'basename' => $file->getBasename(),
|
||||||
|
@ -287,6 +270,19 @@ class FsFileManager
|
||||||
return $this->pathLocked;
|
return $this->pathLocked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function applySort(Finder $finder, string $sort, string $direction)
|
||||||
|
{
|
||||||
|
if ('name' === $sort) {
|
||||||
|
$finder->sortByName();
|
||||||
|
} elseif ('modification_date' === $sort) {
|
||||||
|
$finder->sortByModifiedTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('desc' === $direction) {
|
||||||
|
$finder->reverseSorting();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function normalizePath(string $path): string
|
protected function normalizePath(string $path): string
|
||||||
{
|
{
|
||||||
return (string) u($path)
|
return (string) u($path)
|
||||||
|
|
Loading…
Reference in a new issue