REFACTORING #2039 @1h: clean a little bit file manager
This commit is contained in:
@@ -10,33 +10,26 @@ class EditDirectory extends Controller
|
||||
{
|
||||
/**
|
||||
* @param Requests\EditDirectoryRequest $request
|
||||
* @param $directoryId
|
||||
* @param Directory $directory
|
||||
*
|
||||
* @return $this|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
||||
* @internal param $directoryId
|
||||
*
|
||||
*/
|
||||
public function postEdit(Requests\EditDirectoryRequest $request, $directoryId)
|
||||
public function postEdit(Requests\EditDirectoryRequest $request, Directory $directory)
|
||||
{
|
||||
$directory = Directory::findOrFail($directoryId);
|
||||
|
||||
// check if given name is not used in parent directory
|
||||
|
||||
$exists = Directory::where('parent_id', $directory->parent_id)
|
||||
->where('name', $request->name)
|
||||
->where('id', '!=', $directoryId)
|
||||
->where('id', '!=', $directory->id)
|
||||
->exists();
|
||||
|
||||
if ($exists) {
|
||||
if ($request->ajax()) {
|
||||
return response()->json([
|
||||
'status' => 'failed',
|
||||
'message' => trans('admin/fileManager.subdirectoryExists')
|
||||
]);
|
||||
} else {
|
||||
return redirect()
|
||||
->route('upload.overview', ['id' => $directoryId])
|
||||
->withInput()
|
||||
->with('error', trans('admin/fileManager.subdirectoryExists'));
|
||||
}
|
||||
return redirect()
|
||||
->route('upload.overview', ['id' => $directory->id])
|
||||
->withInput()
|
||||
->with('error', trans('admin/fileManager.subdirectoryExists'));
|
||||
}
|
||||
|
||||
$directory->name = $request->name;
|
||||
@@ -45,17 +38,8 @@ class EditDirectory extends Controller
|
||||
$directory->save();
|
||||
|
||||
$message = trans('admin/fileManager.editDirectorySuccess');
|
||||
if (!$request->ajax()) {
|
||||
return redirect()
|
||||
->route('upload.overview', ['id' => $directory->id])
|
||||
->with('success', $message);
|
||||
} else {
|
||||
$payload = [
|
||||
'status' => 'success',
|
||||
'message' => $message
|
||||
];
|
||||
|
||||
return response()->json($payload);
|
||||
}
|
||||
return redirect()
|
||||
->route('upload.overview', ['id' => $directory->id])
|
||||
->with('success', $message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,14 +21,8 @@ class EditUploadedFile extends Controller
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function getDetail($id)
|
||||
public function show(File $file)
|
||||
{
|
||||
try {
|
||||
$file = File::findOrFail($id);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
return $this->fileNotFound();
|
||||
}
|
||||
|
||||
return view('admin.fileManager.edit', [
|
||||
'file' => $file,
|
||||
'extraInfo' => FileManager::getAdditionalInfo($file)
|
||||
@@ -42,18 +36,14 @@ class EditUploadedFile extends Controller
|
||||
* unchanged
|
||||
*
|
||||
* @param EditUploadedFileRequest $request
|
||||
* @param $id
|
||||
* @param File $file
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @internal param $id
|
||||
*
|
||||
*/
|
||||
public function postEdit(EditUploadedFileRequest $request, $id)
|
||||
public function update(EditUploadedFileRequest $request, File $file)
|
||||
{
|
||||
try {
|
||||
$file = File::findOrFail($id);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
return $this->fileNotFound();
|
||||
}
|
||||
|
||||
// set values from form
|
||||
$file->name = $request->name;
|
||||
$file->keywords = $request->keywords;
|
||||
@@ -65,23 +55,19 @@ class EditUploadedFile extends Controller
|
||||
|
||||
// update successfull
|
||||
return redirect()
|
||||
->route('upload.detail', ['id' => $id])
|
||||
->route('upload.detail', ['file' => $file])
|
||||
->with('success', trans('admin/fileManager.successfullyChanged'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes file
|
||||
*
|
||||
* @param $id
|
||||
* @param File $file
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function deleteFile($id)
|
||||
public function delete(File $file)
|
||||
{
|
||||
try {
|
||||
$file = File::findOrFail($id);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
return $this->fileNotFound();
|
||||
}
|
||||
|
||||
$directoryId = $file->directory_id;
|
||||
$file->delete();
|
||||
|
||||
@@ -89,16 +75,4 @@ class EditUploadedFile extends Controller
|
||||
->route('upload.overview', ['id' => $directoryId])
|
||||
->with('success', trans('admin/fileManager.fileDeleted'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirects user to files overview
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
private function fileNotFound()
|
||||
{
|
||||
return redirect()
|
||||
->route('upload.overview')
|
||||
->with('error', trans('admin/fileManager.fileNotFound'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class UploadFile extends Controller
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postFile(Request $request)
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (Input::get('CKEditor')) {
|
||||
return $this->ckEditorUpload($request);
|
||||
|
||||
@@ -3,7 +3,6 @@ namespace App\Http\Controllers\Admin\FileManager;
|
||||
|
||||
use App\Http\Controllers\Admin\Controller;
|
||||
use App\Models\FileManager\Directory;
|
||||
use App\Models\FileManager\File;
|
||||
use Illuminate\Support\Facades\Input;
|
||||
|
||||
class UploadedFilesOverview extends Controller
|
||||
@@ -11,37 +10,20 @@ class UploadedFilesOverview extends Controller
|
||||
/**
|
||||
* List of all files and directories
|
||||
*
|
||||
* @param null $directoryId
|
||||
* @param null $fileType
|
||||
* @param null $fileSubtype
|
||||
* @param Directory $directory
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
||||
*/
|
||||
public function getOverview($directoryId = null, $fileType = null, $fileSubtype = null)
|
||||
public function index(Directory $directory =null)
|
||||
{
|
||||
// get directory information
|
||||
$directory = is_null($directoryId) ? new Directory() : Directory::findOrFail($directoryId);
|
||||
|
||||
// get all files in this directory
|
||||
$files = File::orderBy('updated_at', 'DESC')
|
||||
->where('directory_id', $directory->id);
|
||||
|
||||
// try to filter by given type
|
||||
if (!is_null($fileType)) {
|
||||
if (is_null($fileSubtype)) {
|
||||
$files = $files->where('mime_type', 'LIKE', $fileType . '%');
|
||||
} else {
|
||||
$files = $files->where('mime_type', $fileType . '/' . $fileSubtype);
|
||||
}
|
||||
}
|
||||
|
||||
// include hidden directories?
|
||||
$includeHidden = Input::get('hidden');
|
||||
|
||||
$subdirectories = $includeHidden ? $directory->allSubdirectories : $directory->subdirectories;
|
||||
|
||||
return view('admin.fileManager.overview', [
|
||||
'directory' => $directory,
|
||||
'subdirectories' => $directory->subdirectories($includeHidden),
|
||||
'files' => $files->get(),
|
||||
'subdirectories' => $subdirectories,
|
||||
'newDirectory' => new Directory()
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user