mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 05:34:06 -08:00
Improved files display
This commit is contained in:
parent
97f748d58e
commit
0be69f57ac
|
@ -787,6 +787,66 @@ class Helper
|
|||
}
|
||||
|
||||
|
||||
public static function filetype_icon($filename) {
|
||||
|
||||
$extension = substr(strrchr($filename,'.'),1);
|
||||
|
||||
if ($extension) {
|
||||
switch ($extension) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
case 'gif':
|
||||
case 'png':
|
||||
return "fa fa-file-image-o";
|
||||
break;
|
||||
case 'doc':
|
||||
case 'docx':
|
||||
return "fa fa-file-word-o";
|
||||
break;
|
||||
case 'xls':
|
||||
case 'xlsx':
|
||||
return "fa fa-file-excel-o";
|
||||
break;
|
||||
case 'zip':
|
||||
case 'rar':
|
||||
return "fa fa-file-archive-o";
|
||||
break;
|
||||
case 'pdf':
|
||||
return "fa fa-file-pdf-o";
|
||||
break;
|
||||
case 'txt':
|
||||
return "fa fa-file-text-o";
|
||||
break;
|
||||
case 'lic':
|
||||
return "fa fa-floppy-o";
|
||||
break;
|
||||
default:
|
||||
return "fa fa-file-o";
|
||||
}
|
||||
}
|
||||
return "fa fa-file-o";
|
||||
}
|
||||
|
||||
public static function show_file_inline($filename) {
|
||||
|
||||
$extension = substr(strrchr($filename,'.'),1);
|
||||
|
||||
if ($extension) {
|
||||
switch ($extension) {
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
case 'gif':
|
||||
case 'png':
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ class ReportsController extends Controller
|
|||
if (($request->has('target_type')) && ($request->has('target_id'))) {
|
||||
$actionlogs = $actionlogs->where('target_id','=',$request->input('target_id'))
|
||||
->where('target_type','=',"App\\Models\\".ucwords($request->input('target_type')));
|
||||
|
||||
}
|
||||
|
||||
if (($request->has('item_type')) && ($request->has('item_id'))) {
|
||||
|
@ -40,6 +39,10 @@ class ReportsController extends Controller
|
|||
$actionlogs = $actionlogs->where('action_type','=',$request->input('action_type'))->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
if ($request->has('uploads')) {
|
||||
$actionlogs = $actionlogs->whereNotNull('filename')->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
$allowed_columns = [
|
||||
'id',
|
||||
'created_at',
|
||||
|
|
|
@ -1004,17 +1004,18 @@ class AssetsController extends Controller
|
|||
* @since [v1.0]
|
||||
* @return View
|
||||
*/
|
||||
public function displayFile($assetId = null, $fileId = null)
|
||||
public function displayFile($assetId = null, $fileId = null, $download = true)
|
||||
{
|
||||
|
||||
$asset = Asset::find($assetId);
|
||||
// the asset is valid
|
||||
|
||||
if (isset($asset->id)) {
|
||||
|
||||
$this->authorize('view', $asset);
|
||||
|
||||
if (!$log = Actionlog::find($fileId)) {
|
||||
return response('No matching record for that asset/file', 500)
|
||||
->header('Content-Type', 'text/plain');
|
||||
|
||||
}
|
||||
|
||||
$file = $log->get_src('assets');
|
||||
|
@ -1023,14 +1024,13 @@ class AssetsController extends Controller
|
|||
$file = $log->get_src('audits');
|
||||
}
|
||||
|
||||
$filetype = Helper::checkUploadIsImage($file);
|
||||
|
||||
if (!file_exists($file)) {
|
||||
return response('File '.$file.' not found on server', 404)
|
||||
->header('Content-Type', 'text/plain');
|
||||
}
|
||||
|
||||
if ($filetype) {
|
||||
if ($download != 'true') {
|
||||
if ($contents = file_get_contents($file)) {
|
||||
return Response::make($contents)->header('Content-Type', $filetype);
|
||||
}
|
||||
|
|
|
@ -508,7 +508,7 @@ class LicensesController extends Controller
|
|||
foreach (Input::file('licensefile') as $file) {
|
||||
|
||||
$rules = array(
|
||||
'licensefile' => 'required|mimes:png,gif,jpg,jpeg,doc,docx,pdf,txt,zip,rar,rtf,xml,lic|max:2000'
|
||||
'licensefile' => 'required|mimes:png,gif,jpg,jpeg,doc,docx,pdf,txt,zip,rar,rtf,xml,lic'
|
||||
);
|
||||
$validator = Validator::make(array('licensefile'=> $file), $rules);
|
||||
|
||||
|
@ -516,8 +516,7 @@ class LicensesController extends Controller
|
|||
return redirect()->back()->with('error', trans('admin/licenses/message.upload.invalidfiles'));
|
||||
}
|
||||
$extension = $file->getClientOriginalExtension();
|
||||
$filename = 'license-'.$license->id.'-'.str_random(8);
|
||||
$filename .= '-'.str_slug($file->getClientOriginalName()).'.'.$extension;
|
||||
$filename = 'license-'.$license->id.'-'.str_random(8).'-'.str_slug(basename($file->getClientOriginalName(), '.'.$extension)).'.'.$extension;
|
||||
$upload_success = $file->move($destinationPath, $filename);
|
||||
|
||||
//Log the upload to the log
|
||||
|
@ -583,7 +582,7 @@ class LicensesController extends Controller
|
|||
* @param int $fileId
|
||||
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse
|
||||
*/
|
||||
public function displayFile($licenseId = null, $fileId = null)
|
||||
public function displayFile($licenseId = null, $fileId = null, $download = true)
|
||||
{
|
||||
|
||||
$license = License::find($licenseId);
|
||||
|
@ -593,8 +592,31 @@ class LicensesController extends Controller
|
|||
$this->authorize('view', $license);
|
||||
$log = Actionlog::find($fileId);
|
||||
$file = $log->get_src('licenses');
|
||||
|
||||
|
||||
if ($file =='') {
|
||||
return response('File not found on server', 404)
|
||||
->header('Content-Type', 'text/plain');
|
||||
}
|
||||
|
||||
$mimetype = \File::mimeType($file);
|
||||
|
||||
|
||||
if (!file_exists($file)) {
|
||||
return response('File '.$file.' not found on server', 404)
|
||||
->header('Content-Type', 'text/plain');
|
||||
}
|
||||
|
||||
if ($download != 'true') {
|
||||
if ($contents = file_get_contents($file)) {
|
||||
return Response::make($contents)->header('Content-Type', $mimetype);
|
||||
}
|
||||
return JsonResponse::create(["error" => "Failed validation: "], 500);
|
||||
}
|
||||
return Response::download($file);
|
||||
}
|
||||
|
||||
|
||||
return redirect()->route('licenses.index')->with('error', trans('admin/licenses/message.does_not_exist', compact('id')));
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,9 @@ class AssetFileRequest extends Request
|
|||
*/
|
||||
public function rules()
|
||||
{
|
||||
$max_file_size = \App\Helpers\Helper::file_upload_max_size();
|
||||
return [
|
||||
'file.*' => 'required|mimes:png,gif,jpg,jpeg,doc,docx,pdf,txt,zip,rar|max:2000'
|
||||
'file.*' => 'required|mimes:png,gif,jpg,jpeg,doc,docx,pdf,txt,zip,rar|max:'.$max_file_size,
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -22,11 +22,20 @@ class ActionlogsTransformer
|
|||
|
||||
public function transformActionlog (Actionlog $actionlog, $settings = null)
|
||||
{
|
||||
$icon = $actionlog->present()->icon();
|
||||
if ($actionlog->filename!='') {
|
||||
$icon = e(\App\Helpers\Helper::filetype_icon($actionlog->filename));
|
||||
}
|
||||
$array = [
|
||||
'id' => (int) $actionlog->id,
|
||||
'icon' => $actionlog->present()->icon(),
|
||||
'image' => (method_exists($actionlog->item, 'getImageUrl')) ? $actionlog->item->getImageUrl() : null,
|
||||
'file' => ($actionlog->filename!='') ? route('show/assetfile', ['assetId' => $actionlog->item->id, 'fileId' => $actionlog->id]) : null,
|
||||
'icon' => $icon,
|
||||
'file' => ($actionlog->filename!='') ?
|
||||
[
|
||||
'url' => route('show/assetfile', ['assetId' => $actionlog->item->id, 'fileId' => $actionlog->id]),
|
||||
'filename' => $actionlog->filename,
|
||||
'inlineable' => (bool) \App\Helpers\Helper::show_file_inline($actionlog->filename),
|
||||
] : null,
|
||||
|
||||
'item' => ($actionlog->item) ? [
|
||||
'id' => (int) $actionlog->item->id,
|
||||
'name' => e($actionlog->item->getDisplayNameAttribute()),
|
||||
|
@ -60,12 +69,11 @@ class ActionlogsTransformer
|
|||
|
||||
];
|
||||
|
||||
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function transformCheckedoutActionlog (Collection $accessories_users, $total)
|
||||
{
|
||||
|
||||
|
|
|
@ -133,9 +133,12 @@ class Actionlog extends SnipeModel
|
|||
**/
|
||||
public function get_src($type = 'assets', $fieldname = 'filename')
|
||||
{
|
||||
if ($this->filename!='') {
|
||||
$file = config('app.private_uploads') . '/' . $type . '/' . $this->{$fieldname};
|
||||
return $file;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ return array(
|
|||
'deployable' => 'Deployable',
|
||||
'deleted' => 'This asset has been deleted. <a href="/hardware/:asset_id/restore">Click here to restore it</a>.',
|
||||
'edit' => 'Edit Asset',
|
||||
'filetype_info' => 'Allowed filetypes are png, gif, jpg, jpeg, doc, docx, pdf, txt, zip, and rar.',
|
||||
'model_deleted' => 'This Assets model has been deleted. You must restore the model before you can restore the Asset.<br/> <a href="/hardware/models/:model_id/restore">Click here to restore the model</a>.',
|
||||
'requestable' => 'Requestable',
|
||||
'requested' => 'Requested',
|
||||
|
|
|
@ -206,6 +206,7 @@
|
|||
'unknown_admin' => 'Unknown Admin',
|
||||
'username_format' => 'Username Format',
|
||||
'update' => 'Update',
|
||||
'upload_filetypes_help' => 'Allowed filetypes are png, gif, jpg, jpeg, doc, docx, pdf, txt, zip, and rar. Max upload size allowed is :size.',
|
||||
'uploaded' => 'Uploaded',
|
||||
'user' => 'User',
|
||||
'accepted' => 'accepted',
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
{{-- Right header --}}
|
||||
@section('header_right')
|
||||
|
||||
@can('manage', \App\Models\Asset::class)
|
||||
<div class="dropdown pull-right">
|
||||
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">{{ trans('button.actions') }}
|
||||
|
@ -733,27 +734,25 @@
|
|||
data-sort-name="created_at"
|
||||
data-show-export="true"
|
||||
data-export-options='{
|
||||
"fileName": "export{{ (Input::has('status')) ? '-'.str_slug(Input::get('status')) : '' }}-assets",
|
||||
"fileName": "export-asset-{{ $asset->id }}-history",
|
||||
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
|
||||
}'
|
||||
|
||||
data-url="{{ route('api.activity.index', ['item_id' => $asset->id, 'item_type' => 'asset']) }}"
|
||||
data-cookie-id-table="assetHistory">
|
||||
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<th data-field="icon" style="width: 40px;" class="hidden-xs" data-formatter="iconFormatter"></th>
|
||||
<th class="col-sm-2" data-field="created_at" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th>
|
||||
<th class="col-sm-1" data-field="admin" data-formatter="usersLinkObjFormatter">{{ trans('general.admin') }}</th>
|
||||
<th class="col-sm-1" data-field="action_type">{{ trans('general.action') }}</th>
|
||||
<th class="col-sm-2" data-field="item" data-formatter="polymorphicItemFormatter">{{ trans('general.item') }}</th>
|
||||
<th class="col-sm-2" data-field="target" data-formatter="polymorphicItemFormatter">{{ trans('general.target') }}</th>
|
||||
<th data-field="icon" data-visible="true" style="width: 40px;" class="hidden-xs" data-formatter="iconFormatter"></th>
|
||||
<th class="col-sm-2" data-visible="true" data-field="created_at" data-formatter="dateDisplayFormatter">{{ trans('general.date') }}</th>
|
||||
<th class="col-sm-1" data-visible="true" data-field="admin" data-formatter="usersLinkObjFormatter">{{ trans('general.admin') }}</th>
|
||||
<th class="col-sm-1" data-visible="true" data-field="action_type">{{ trans('general.action') }}</th>
|
||||
<th class="col-sm-2" data-visible="true" data-field="item" data-formatter="polymorphicItemFormatter">{{ trans('general.item') }}</th>
|
||||
<th class="col-sm-2" data-visible="true" data-field="target" data-formatter="polymorphicItemFormatter">{{ trans('general.target') }}</th>
|
||||
<th class="col-sm-2" data-field="note">{{ trans('general.notes') }}</th>
|
||||
@if ($snipeSettings->require_accept_signature=='1')
|
||||
<th class="col-md-3" data-field="signature_file" data-visible="false" data-formatter="imageFormatter">{{ trans('general.signature') }}</th>
|
||||
@endif
|
||||
<th class="col-md-3" data-visible="false" data-field="file" data-visible="false" data-formatter="imageFormatter">{{ trans('general.image') }}</th>
|
||||
<th class="col-md-3" data-visible="false" data-field="file" data-visible="false" data-formatter="fileUploadFormatter">{{ trans('general.download') }}</th>
|
||||
<th class="col-sm-2" data-field="log_meta" data-visible="true" data-formatter="changeLogFormatter">Changed</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -785,7 +784,7 @@
|
|||
</div>
|
||||
|
||||
<div class="col-md-12">
|
||||
<p>{{ trans('admin/hardware/general.filetype_info') }}</p>
|
||||
<p>{{ trans('general.upload_filetypes_help', ['size' => \App\Helpers\Helper::file_upload_max_size_readable()]) }}</p>
|
||||
<hr>
|
||||
</div>
|
||||
|
||||
|
@ -793,20 +792,38 @@
|
|||
@endcan
|
||||
|
||||
<div class="col-md-12">
|
||||
<table class="table table-hover">
|
||||
<table
|
||||
class="table table-striped snipe-table"
|
||||
id="assetFileHistory"
|
||||
data-pagination="true"
|
||||
data-id-table="assetFileHistory"
|
||||
data-search="true"
|
||||
data-side-pagination="client"
|
||||
data-show-columns="true"
|
||||
data-show-refresh="true"
|
||||
data-sort-order="desc"
|
||||
data-sort-name="created_at"
|
||||
data-show-export="true"
|
||||
data-export-options='{
|
||||
"fileName": "export-asset-{{ $asset->id }}-files",
|
||||
"ignoreColumn": ["actions","image","change","checkbox","checkincheckout","icon"]
|
||||
}'
|
||||
data-cookie-id-table="assetFileHistory">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="col-md-4">{{ trans('general.notes') }}</th>
|
||||
<th class="col-md-2"></th>
|
||||
<th class="col-md-4">{{ trans('general.file_name') }}</th>
|
||||
<th class="col-md-2"></th>
|
||||
<th class="col-md-2"></th>
|
||||
<th data-visible="true"></th>
|
||||
<th class="col-md-2" data-searchable="true" data-visible="true">{{ trans('general.notes') }}</th>
|
||||
<th class="col-md-2" data-searchable="true" data-visible="true">{{ trans('general.image') }}</th>
|
||||
<th class="col-md-2" data-searchable="true" data-visible="true">{{ trans('general.file_name') }}</th>
|
||||
<th class="col-md-2" data-searchable="true" data-visible="true">{{ trans('general.download') }}</th>
|
||||
<th class="col-md-1" data-searchable="true" data-visible="true">{{ trans('general.actions') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@if ($asset->uploads->count() > 0)
|
||||
@foreach ($asset->uploads as $file)
|
||||
<tr>
|
||||
<td><i class="{{ \App\Helpers\Helper::filetype_icon($file->filename) }} icon-med"></i></td>
|
||||
<td>
|
||||
@if ($file->note)
|
||||
{{ $file->note }}
|
||||
|
@ -822,12 +839,12 @@
|
|||
</td>
|
||||
<td>
|
||||
@if ($file->filename)
|
||||
<a href="{{ route('show/assetfile', [$asset->id, $file->id]) }}" class="btn btn-default">{{ trans('general.download') }}</a>
|
||||
<a href="{{ route('show/assetfile', [$asset->id, $file->id]) }}" class="btn btn-default"><i class="fa fa-download"></i></a>
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
@can('update', \App\Models\Asset::class)
|
||||
<a class="btn delete-asset btn-danger btn-sm" href="{{ route('delete/assetfile', [$asset->id, $file->id]) }}" data-tooltip="true" data-title="Delete" data-content="Are you sure you wish to delete {{$file->filename}}"><i class="fa fa-trash icon-white"></i></a>
|
||||
<a class="btn delete-asset btn-sm btn-danger btn-sm" href="{{ route('delete/assetfile', [$asset->id, $file->id]) }}" data-tooltip="true" data-title="Delete" data-content="{{ trans('delete_confirm', ['item' => $file->filename]) }}"><i class="fa fa-trash icon-white"></i></a>
|
||||
@endcan
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -285,9 +285,10 @@
|
|||
}'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
<th class="col-md-4" data-field="file_name" data-visible="true" data-sortable="true" data-switchable="true">{{ trans('general.file_name') }}</th>
|
||||
<th class="col-md-4" data-field="notes" data-visible="true" data-sortable="true" data-switchable="true">{{ trans('general.notes') }}</th>
|
||||
<th class="col-md-4" data-field="created_at" data-visible="true" data-sortable="true" data-switchable="true">{{ trans('general.created_at') }}</th>
|
||||
<th class="col-md-2" data-field="created_at" data-visible="true" data-sortable="true" data-switchable="true">{{ trans('general.created_at') }}</th>
|
||||
<th class="col-md-2" data-field="download" data-visible="true" data-sortable="false" data-switchable="true">Download</th>
|
||||
<th class="col-md-2" data-field="delete" data-visible="true" data-sortable="false" data-switchable="true">Delete</th>
|
||||
</tr>
|
||||
|
@ -296,7 +297,11 @@
|
|||
@if ($license->uploads->count()> 0)
|
||||
@foreach ($license->uploads as $file)
|
||||
<tr>
|
||||
<td>{{ $file->filename }}</td>
|
||||
<td><i class="{{ \App\Helpers\Helper::filetype_icon($file->filename) }} icon-med"></i></td>
|
||||
<td>
|
||||
{{ $file->filename }}
|
||||
|
||||
</td>
|
||||
<td>
|
||||
@if ($file->note)
|
||||
{{ $file->note }}
|
||||
|
@ -304,11 +309,10 @@
|
|||
</td>
|
||||
<td>{{ $file->created_at }}</td>
|
||||
<td>
|
||||
|
||||
@if ($file->filename)
|
||||
<a href="{{ route('show/licensefile', [$license->id, $file->id]) }}" class="btn btn-default">
|
||||
Download
|
||||
</a>
|
||||
@if ( \App\Helpers\Helper::checkUploadIsImage($file->get_src('licenses')))
|
||||
<a href="{{ route('show.licensefile', ['licenseId' => $license->id, 'fileId' => $file->id, 'download' => 'false']) }}" data-toggle="lightbox" data-type="image"><img src="{{ route('show.licensefile', ['licenseId' => $license->id, 'fileId' => $file->id]) }}" class="img-thumbnail" style="max-width: 50px;"></a>
|
||||
@endif
|
||||
@endif
|
||||
</td>
|
||||
<td>
|
||||
|
@ -379,8 +383,9 @@
|
|||
'method' => 'POST',
|
||||
'route' => ['upload/license', $license->id],
|
||||
'files' => true, 'class' => 'form-horizontal' ]) }}
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
|
||||
<div class="modal-body">
|
||||
<p>{{ trans('admin/licenses/general.filetype_info') }}</p>
|
||||
<p>{{ trans('general.upload_filetypes_help', ['size' => \App\Helpers\Helper::file_upload_max_size_readable()]) }}</p>
|
||||
<div class="form-group col-md-12">
|
||||
<div class="input-group col-md-12">
|
||||
<input class="col-md-12 form-control" type="text" name="notes" id="notes" placeholder="Notes">
|
||||
|
|
|
@ -507,6 +507,22 @@
|
|||
}
|
||||
}
|
||||
|
||||
function fileUploadFormatter(value) {
|
||||
if ((value) && (value.url) && (value.inlineable)) {
|
||||
return '<a href="' + value.url + '" data-toggle="lightbox" data-type="image"><img src="' + value.url + '" style="max-height: {{ $snipeSettings->thumbnail_max_h }}px; width: auto;" class="img-responsive"></a>';
|
||||
} else if ((value) && (value.url)) {
|
||||
return '<a href="' + value.url + '" class="btn btn-default"><i class="fa fa-download"></i></a>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function fileUploadNameFormatter(value) {
|
||||
console.dir(value);
|
||||
if ((value) && (value.filename) && (value.url)) {
|
||||
return '<a href="' + value.url + '">' + value.filename + '</a>';
|
||||
}
|
||||
}
|
||||
|
||||
function sumFormatter(data) {
|
||||
if (Array.isArray(data)) {
|
||||
var field = this.field;
|
||||
|
|
|
@ -38,8 +38,8 @@ Route::group([ 'prefix' => 'licenses', 'middleware' => ['auth'] ], function () {
|
|||
[ 'as' => 'delete/licensefile', 'uses' => 'LicensesController@getDeleteFile' ]
|
||||
);
|
||||
Route::get(
|
||||
'{licenseId}/showfile/{fileId}',
|
||||
[ 'as' => 'show/licensefile', 'uses' => 'LicensesController@displayFile' ]
|
||||
'{licenseId}/showfile/{fileId}/{download?}',
|
||||
[ 'as' => 'show.licensefile', 'uses' => 'LicensesController@displayFile' ]
|
||||
);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue