FEATURE #1442: add uploaded file detail
This commit adds functionality for editing keywords and description of selected file. This commit also includes JS library for syntax highlighting (https://highlighjs.org)
This commit is contained in:
@@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Events\EditFile;
|
||||
use App\Helpers\FileManager;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\EditUploadedFileRequest;
|
||||
use App\Models\File;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
class EditUploadedFile extends Controller
|
||||
{
|
||||
/**
|
||||
* Edit form
|
||||
*
|
||||
* Render edit form for displaying details and updating given file
|
||||
*
|
||||
* @param int $id file id
|
||||
*
|
||||
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
||||
*/
|
||||
public function getDetail($id)
|
||||
{
|
||||
try {
|
||||
$file = File::findOrFail($id);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
return $this->fileNotFound();
|
||||
}
|
||||
|
||||
return view('admin.fileManager.edit', [
|
||||
'file' => $file,
|
||||
'extraInfo' => FileManager::getAdditionalInfo($file)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates file
|
||||
*
|
||||
* User can change only keywords, original filename and description. Mime type, hash and other fields remain
|
||||
* unchanged
|
||||
*
|
||||
* @param EditUploadedFileRequest $request
|
||||
* @param $id
|
||||
*
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function postEdit(EditUploadedFileRequest $request, $id)
|
||||
{
|
||||
try {
|
||||
$file = File::findOrFail($id);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
return $this->fileNotFound();
|
||||
}
|
||||
|
||||
// set values from form
|
||||
$file->keywords = $request->keywords;
|
||||
$file->description = $request->description;
|
||||
$file->save();
|
||||
|
||||
// fire action
|
||||
Event::fire(new EditFile($file));
|
||||
|
||||
// update successfull
|
||||
return redirect()
|
||||
->route('upload.detail', ['id' => $id])
|
||||
->with('success', trans('admin/fileManager.successfullyChanged'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes file
|
||||
*
|
||||
* @param $id
|
||||
*/
|
||||
public function deleteFile($id)
|
||||
{
|
||||
try {
|
||||
$file = File::findOrFail($id);
|
||||
} catch (NotFoundHttpException $e) {
|
||||
return $this->fileNotFound();
|
||||
}
|
||||
|
||||
$file->delete();
|
||||
|
||||
return redirect()
|
||||
->route('upload.overview')
|
||||
->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'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user