backports murph-skeleton

This commit is contained in:
Simon Vieille 2022-02-18 18:28:36 +01:00
parent add1a1aedd
commit 2dd51d4768
2 changed files with 20 additions and 24 deletions

View file

@ -111,24 +111,24 @@ class RedirectAdminController extends CrudController
->setField('index', 'Label', Field\TextField::class, [
'property' => 'label',
'attr' => ['class' => 'col-3'],
'attr' => ['class' => 'col-4'],
])
->setField('index', 'Rule', Field\TextField::class, [
'view' => '@Core/redirect/redirect_admin/field/rule.html.twig',
'attr' => ['class' => 'col-5'],
'attr' => ['class' => 'col-6'],
])
->setField('index', 'Enabled', Field\ButtonField::class, [
'property_builder' => function(EntityInterface $entity) {
return $entity->getIsEnabled() ? 'Yes' : 'No';
},
'attr' => ['class' => 'col-2'],
'attr' => ['class' => 'col-1'],
'button_attr_builder' => function(EntityInterface $entity) {
return ['class' => 'btn btn-sm btn-'.($entity->getIsEnabled() ? 'success' : 'primary')];
},
])
->setField('index', 'Type', Field\ButtonField::class, [
'property' => 'redirectCode',
'attr' => ['class' => 'col-2'],
'attr' => ['class' => 'col-1'],
'button_attr' => ['class' => 'btn btn-sm btn-light border-secondary font-weight-bold'],
])
->setBatchAction('index', 'enable', 'Enable', function (EntityInterface $entity, EntityManager $manager) {

View file

@ -72,26 +72,7 @@ class FsFileManager
$finder = new Finder();
$finder->directories()->depth('== 0')->in($this->path.'/'.$directory);
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();
}
}
}
$this->applySort($finder, $options['sort'] ?? 'name', $options['sort_direction'] ?? 'asc');
foreach ($finder as $file) {
$data['directories'][] = [
@ -106,6 +87,8 @@ class FsFileManager
$finder = new Finder();
$finder->files()->depth('== 0')->in($this->path.'/'.$directory);
$this->applySort($finder, $options['sort'] ?? 'name', $options['sort_direction'] ?? 'asc');
foreach ($finder as $file) {
$data['files'][] = [
'basename' => $file->getBasename(),
@ -287,6 +270,19 @@ class FsFileManager
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
{
return (string) u($path)