backports murph-skeleton
This commit is contained in:
parent
b2bf0ef504
commit
fe6688ab02
|
@ -23,6 +23,14 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="breadcrumb mb-0 file-manager-views">
|
<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="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 class="fa fa-grip-horizontal" v-on:click="setView('grid')"></span>
|
||||||
</span>
|
</span>
|
||||||
|
@ -203,6 +211,8 @@ export default {
|
||||||
directories: [],
|
directories: [],
|
||||||
breadcrumb: [],
|
breadcrumb: [],
|
||||||
files: [],
|
files: [],
|
||||||
|
sort: 'name',
|
||||||
|
sortDirection: 'asc',
|
||||||
parent: null,
|
parent: null,
|
||||||
modalUrl: null,
|
modalUrl: null,
|
||||||
ajax: 0,
|
ajax: 0,
|
||||||
|
@ -221,6 +231,10 @@ export default {
|
||||||
|
|
||||||
localStorage.setItem('file-manager.view', view)
|
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) {
|
generateInfoLink (item, directory, context) {
|
||||||
if (directory) {
|
if (directory) {
|
||||||
return Routing.generate('admin_file_manager_info', {
|
return Routing.generate('admin_file_manager_info', {
|
||||||
|
@ -280,6 +294,8 @@ export default {
|
||||||
directory: that.directory,
|
directory: that.directory,
|
||||||
context: that.context,
|
context: that.context,
|
||||||
ajax: this.ajax,
|
ajax: this.ajax,
|
||||||
|
_sort: this.sort,
|
||||||
|
_sort_direction: this.sortDirection,
|
||||||
time: Date.now(),
|
time: Date.now(),
|
||||||
}))
|
}))
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
@ -305,11 +321,21 @@ export default {
|
||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
const view = localStorage.getItem('file-manager.view')
|
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) {
|
if (['grid', 'list'].indexOf(view) !== -1) {
|
||||||
this.view = view
|
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)
|
const query = new URLSearchParams(window.location.search)
|
||||||
|
|
||||||
if (query.has('path')) {
|
if (query.has('path')) {
|
||||||
|
@ -338,6 +364,14 @@ export default {
|
||||||
watch: {
|
watch: {
|
||||||
directory (directory) {
|
directory (directory) {
|
||||||
this.refresh()
|
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
|
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);
|
return $this->json($files);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ class FsFileManager
|
||||||
$this->pathLocked = $config['path_locked'];
|
$this->pathLocked = $config['path_locked'];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function list(string $directory): array
|
public function list(string $directory, array $options = []): array
|
||||||
{
|
{
|
||||||
$directory = $this->normalizePath($directory);
|
$directory = $this->normalizePath($directory);
|
||||||
|
|
||||||
|
@ -73,6 +73,26 @@ class FsFileManager
|
||||||
$finder = new Finder();
|
$finder = new Finder();
|
||||||
$finder->directories()->depth('== 0')->in($this->path.'/'.$directory);
|
$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) {
|
foreach ($finder as $file) {
|
||||||
$data['directories'][] = [
|
$data['directories'][] = [
|
||||||
'basename' => $file->getBasename(),
|
'basename' => $file->getBasename(),
|
||||||
|
|
Loading…
Reference in a new issue