FEATURE #1417: add uploaded files overview
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace App\Helpers;
|
||||
|
||||
use App\Models\File;
|
||||
|
||||
class FileManager
|
||||
{
|
||||
/**
|
||||
* @param File $file
|
||||
*
|
||||
* @return \Illuminate\Contracts\Routing\UrlGenerator|string
|
||||
*/
|
||||
public static function getPreview(File $file)
|
||||
{
|
||||
list($type, $subtype) = explode('/', $file->mime_type);
|
||||
|
||||
switch ($type) {
|
||||
case 'image':
|
||||
|
||||
// try to check if file have thumbnail
|
||||
if (file_exists(config('app.thumbnail_url') . '/' . $file->filename)) {
|
||||
$url = config('app.thumbnail_url') . '/' . $file->filename;
|
||||
} else {
|
||||
$url = config('app.upload_url') . '/' . $file->filename;
|
||||
}
|
||||
|
||||
return '<img src="' . $url . '" alt="' . $file->description . '" />';
|
||||
break;
|
||||
case 'text':
|
||||
return '<i class="fa fa-file-text-o"></i>';
|
||||
break;
|
||||
case 'application':
|
||||
switch ($subtype) {
|
||||
case 'pdf':
|
||||
return '<i class="fa fa-file-pdf-o"></i>';
|
||||
break;
|
||||
default:
|
||||
return '<i class="fa fa-newspaper-o"></i>';
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return '<i class="fa fa-question"></i>';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param File $file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getFormattedSize(File $file)
|
||||
{
|
||||
$bytes = $file->file_size;
|
||||
|
||||
$label = ['B', 'KB', 'MB', 'GB', 'TB', 'PB'];
|
||||
for ($i = 0; $bytes >= 1024 && $i < (count($label) - 1); $bytes /= 1024, $i++) {
|
||||
;
|
||||
}
|
||||
|
||||
return (round($bytes, 2) . " " . $label[$i]);
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,27 @@
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
use App\Http\Requests;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests;
|
||||
use App\Models\File;
|
||||
|
||||
class UploadedFilesOverview extends Controller
|
||||
{
|
||||
//
|
||||
public function getOverview($type = null)
|
||||
{
|
||||
$directories = [];
|
||||
|
||||
$files = File::orderBy('updated_at', 'DESC')
|
||||
->paginate(18);
|
||||
|
||||
// try to filter by given type
|
||||
if (!is_null($type)) {
|
||||
$files = $files->where('mime_type', 'LIKE', $type);
|
||||
}
|
||||
|
||||
return view('admin.fileManager.overview', [
|
||||
'direcories' => $directories,
|
||||
'files' => $files
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -96,7 +96,8 @@ Route::group([
|
||||
Route::get('upload/image', 'UploadFile@getImage')
|
||||
->name('upload.image');
|
||||
|
||||
Route::get('upload/overview', function () {})->name('upload.overview');
|
||||
Route::get('upload/overview', 'UploadedFilesOverview@getOverview')
|
||||
->name('upload.overview');
|
||||
|
||||
// uploader methods
|
||||
Route::post('upload/file', 'UploadFile@postFile')
|
||||
|
||||
@@ -93,6 +93,9 @@ return [
|
||||
* Upload path used for storing all uploaded files
|
||||
*/
|
||||
'upload_path' => env('UPLOAD_PATH', public_path('uploads')),
|
||||
'upload_url' => env('UPLOAD_URL', url('uploads')),
|
||||
'thumbnail_path' => env('THUMBNAIL_PATH', public_path('uploads/thumbnails')),
|
||||
'thumbnail_url' => env('THUMBNAIL_URL', url('uploads/thumbnails')),
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
|
||||
Vendored
+26
@@ -43,6 +43,32 @@ ins {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
.tile-overview .item {
|
||||
position: relative;
|
||||
padding-bottom: 3em;
|
||||
}
|
||||
|
||||
.tile-overview .controls {
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.tile-overview .controls .button {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.tile-overview .small {
|
||||
font-size: 80%;
|
||||
}
|
||||
|
||||
.tile-overview .preview {
|
||||
font-size: 350%;
|
||||
text-align: center;
|
||||
line-height: 3em;
|
||||
max-height: 3em;
|
||||
overflow:hidden;
|
||||
}
|
||||
|
||||
#static-page-overview .page {
|
||||
position: relative;
|
||||
padding-bottom: 3em;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
return [
|
||||
'overview' => 'List of all files',
|
||||
'upload' => 'Upload new file',
|
||||
'newFile' => 'New file',
|
||||
'invalidFile' => 'The file you submitted is somehow not valid file!',
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
@extends('admin.layout')
|
||||
|
||||
@section('pageName', @trans('admin/fileManager.overview'))
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="row">
|
||||
<h2>@lang('admin/fileManager.overview')</h2>
|
||||
</div>
|
||||
|
||||
<div class="row tile-overview" data-equalizer>
|
||||
@forelse($files as $file)
|
||||
|
||||
<div class="columns large-2">
|
||||
<div class="item" data-equalizer-watch>
|
||||
<div class="preview row" title="{{ \App\Helpers\FileManager::getFormattedSize($file) }}">
|
||||
{!! \App\Helpers\FileManager::getPreview($file) !!}
|
||||
</div>
|
||||
<div class="detail row text-center">
|
||||
<div class="highlight">
|
||||
{{str_limit($file->original_filename, 15)}}
|
||||
</div>
|
||||
<div class="small">
|
||||
{{$file->mime_type}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="controls row">
|
||||
<button class="button text-center primary column large-6" title="@lang('admin/fileManager.edit')"><i class="fa fa-edit"></i></button>
|
||||
<button class="button text-center confirm alert column large-6" title="@lang('admin/fileManager.delete')"><i class="fa fa-remove"></i></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@empty
|
||||
<em>@lang('admin/fileManager.noFiles')</em>
|
||||
@endforelse
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
{!! $files->render() !!}
|
||||
</div>
|
||||
@stop
|
||||
Reference in New Issue
Block a user