add sorting for every getData and navigator, Favourites need to be fixed

This commit is contained in:
Milos Holba
2020-12-08 19:14:53 +01:00
parent 2ba92ed3b6
commit 7e325c5101
8 changed files with 93 additions and 36 deletions

View File

@@ -36,6 +36,7 @@ class BrowseController extends Controller
->with(['parent'])
->where('user_id', $user_id)
->whereIn('unique_id', filter_folders_ids($folders_trashed))
->sortable()
->get();
// Get files trashed
@@ -43,6 +44,7 @@ class BrowseController extends Controller
->with(['parent'])
->where('user_id', $user_id)
->whereNotIn('folder_id', array_values(array_unique(recursiveFind($folders_trashed->toArray(), 'unique_id'))))
->sortable()
->get();
// Collect folders and files to single array
@@ -72,11 +74,13 @@ class BrowseController extends Controller
$folders = FileManagerFolder::with(['parent', 'shared:token,id,item_id,permission,protected,expire_in'])
->where('user_id', $user_id)
->whereIn('unique_id', $folder_ids)
->sortable()
->get();
$files = FileManagerFile::with(['parent', 'shared:token,id,item_id,permission,protected,expire_in'])
->where('user_id', $user_id)
->whereIn('unique_id', $file_ids)
->sortable()
->get();
// Collect folders and files to single array
@@ -91,7 +95,8 @@ class BrowseController extends Controller
public function latest() {
// Get User
$user = User::with(['latest_uploads'])
$user = User::with(['latest_uploads' => function($query) {
$query->sortable(); }])
->where('id', Auth::id())
->first();
@@ -107,7 +112,7 @@ class BrowseController extends Controller
// Get User
$uploads = FileManagerFile::with(['parent'])->where('user_id', Auth::id())
->whereUserScope('editor')->orderBy('created_at', 'DESC')->get();
->whereUserScope('editor')->sortable()->get();
return $uploads;
}
@@ -148,14 +153,12 @@ class BrowseController extends Controller
$folders = FileManagerFolder::with(['parent', 'shared:token,id,item_id,permission,protected,expire_in'])
->where('user_id', $user_id)
->where('parent_id', $unique_id)
// ->orderBy('created_at', 'DESC')
->sortable(['name', 'DESC'])
->get();
$files = FileManagerFile::with(['parent', 'shared:token,id,item_id,permission,protected,expire_in'])
->where('user_id', $user_id)
->where('folder_id', $unique_id)
// ->orderBy('created_at', 'DESC')
->sortable(['name', 'DESC'])
->get();

View File

@@ -195,10 +195,14 @@ class User extends Authenticatable
*/
public function getFolderTreeAttribute()
{
$sort = strtolower(request()->input('sort'));
$direction = strtolower(request()->input('direction'));
return FileManagerFolder::with(['folders.shared', 'shared:token,id,item_id,permission,protected,expire_in'])
->where('parent_id', 0)
->where('user_id', $this->id)
->orderByDesc('created_at')
->orderBy($sort , $direction)
->get();
}
@@ -301,7 +305,10 @@ class User extends Authenticatable
*/
public function favourite_folders()
{
return $this->belongsToMany(FileManagerFolder::class, 'favourite_folder', 'user_id', 'folder_unique_id', 'id', 'unique_id')->with('shared:token,id,item_id,permission,protected,expire_in');
$sort = strtolower(request()->input('sort') ? request()->input('sort') : 'created_at' );
$direction = strtolower(request()->input('direction') ? request()->input('direction') : 'desc');
return $this->belongsToMany(FileManagerFolder::class, 'favourite_folder', 'user_id', 'folder_unique_id', 'id', 'unique_id')->with('shared:token,id,item_id,permission,protected,expire_in')->orderBy($sort , $direction);
}
/**
@@ -311,7 +318,7 @@ class User extends Authenticatable
*/
public function latest_uploads()
{
return $this->hasMany(FileManagerFile::class)->with(['parent'])->orderBy('created_at', 'DESC')->take(40);
return $this->hasMany(FileManagerFile::class)->with(['parent'])->take(40);
}
/**