add sort in file manager
This commit is contained in:
parent
475b907ff5
commit
610c27072a
|
@ -23,6 +23,14 @@
|
|||
</div>
|
||||
|
||||
<div class="breadcrumb mb-0 file-manager-views">
|
||||
<select v-model="sort" class="form-control form-control-sm d-inline w-auto ml-1">
|
||||
<option value="name">Name</option>
|
||||
<option value="modification_date">Date</option>
|
||||
</select>
|
||||
<select v-model="sortDirection" class="form-control form-control-sm d-inline w-auto ml-1">
|
||||
<option value="asc">ASC</option>
|
||||
<option value="desc">DESC</option>
|
||||
</select>
|
||||
<span class="btn btn-sm btn-dark ml-1" v-on:click="setView('grid')">
|
||||
<span class="fa fa-grip-horizontal" v-on:click="setView('grid')"></span>
|
||||
</span>
|
||||
|
@ -203,6 +211,8 @@ export default {
|
|||
directories: [],
|
||||
breadcrumb: [],
|
||||
files: [],
|
||||
sort: 'name',
|
||||
sortDirection: 'asc',
|
||||
parent: null,
|
||||
modalUrl: null,
|
||||
ajax: 0,
|
||||
|
@ -221,6 +231,10 @@ export default {
|
|||
|
||||
localStorage.setItem('file-manager.view', view)
|
||||
},
|
||||
saveSort () {
|
||||
localStorage.setItem('file-manager.sort', this.sort)
|
||||
localStorage.setItem('file-manager.sortDirection', this.sortDirection)
|
||||
},
|
||||
generateInfoLink (item, directory, context) {
|
||||
if (directory) {
|
||||
return Routing.generate('admin_file_manager_info', {
|
||||
|
@ -280,6 +294,8 @@ export default {
|
|||
directory: that.directory,
|
||||
context: that.context,
|
||||
ajax: this.ajax,
|
||||
_sort: this.sort,
|
||||
_sort_direction: this.sortDirection,
|
||||
time: Date.now(),
|
||||
}))
|
||||
.then((response) => {
|
||||
|
@ -305,11 +321,21 @@ export default {
|
|||
},
|
||||
mounted () {
|
||||
const view = localStorage.getItem('file-manager.view')
|
||||
const sort = localStorage.getItem('file-manager.sort')
|
||||
const sortDirection = localStorage.getItem('file-manager.sortDirection')
|
||||
|
||||
if (['grid', 'list'].indexOf(view) !== -1) {
|
||||
this.view = view
|
||||
}
|
||||
|
||||
if (['name', 'modification_date'].indexOf(sort) !== -1) {
|
||||
this.sort = sort
|
||||
}
|
||||
|
||||
if (['asc', 'desc'].indexOf(sortDirection) !== -1) {
|
||||
this.sortDirection = sortDirection
|
||||
}
|
||||
|
||||
const query = new URLSearchParams(window.location.search)
|
||||
|
||||
if (query.has('path')) {
|
||||
|
@ -338,6 +364,14 @@ export default {
|
|||
watch: {
|
||||
directory (directory) {
|
||||
this.refresh()
|
||||
},
|
||||
sort (sort) {
|
||||
this.saveSort()
|
||||
this.refresh()
|
||||
},
|
||||
sortDirection (sortDirection) {
|
||||
this.saveSort()
|
||||
this.refresh()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,12 @@ class FileManagerAdminController extends AdminController
|
|||
*/
|
||||
public function directory(FsFileManager $manager, Request $request): Response
|
||||
{
|
||||
$files = $manager->list($request->query->get('directory', '/'));
|
||||
$options = [
|
||||
'sort' => $request->query->get('_sort', 'name'),
|
||||
'sort_direction' => $request->query->get('_sort_direction', 'asc'),
|
||||
];
|
||||
|
||||
$files = $manager->list($request->query->get('directory', '/'), $options);
|
||||
|
||||
return $this->json($files);
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ class FsFileManager
|
|||
$this->pathLocked = $config['path_locked'];
|
||||
}
|
||||
|
||||
public function list(string $directory): array
|
||||
public function list(string $directory, array $options = []): array
|
||||
{
|
||||
$directory = $this->normalizePath($directory);
|
||||
|
||||
|
@ -73,6 +73,26 @@ 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 ('asc' === $direction) {
|
||||
$finder->reverseSorting();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($finder as $file) {
|
||||
$data['directories'][] = [
|
||||
'basename' => $file->getBasename(),
|
||||
|
|
Loading…
Reference in a new issue