A few more small tweaks

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2025-02-24 14:24:15 +00:00
parent 9555825a67
commit 2bf4ec0ae8
3 changed files with 47 additions and 56 deletions

View file

@ -26,11 +26,8 @@ class AssetFilesController extends Controller
*@since [v1.0]
* @author [A. Gianotto] [<snipe@snipe.net>]
*/
public function store(UploadFileRequest $request, $assetId = null) : RedirectResponse
public function store(UploadFileRequest $request, Asset $asset) : RedirectResponse
{
if (! $asset = Asset::find($assetId)) {
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
}
$this->authorize('update', $asset);
@ -59,31 +56,28 @@ class AssetFilesController extends Controller
* @param int $fileId
* @since [v1.0]
*/
public function show($assetId = null, $fileId = null) : View | RedirectResponse | Response | StreamedResponse | BinaryFileResponse
public function show(Asset $asset, $fileId = null) : View | RedirectResponse | Response | StreamedResponse | BinaryFileResponse
{
if ($asset = Asset::find($assetId)) {
$this->authorize('view', $asset);
$this->authorize('view', $asset);
if ($log = Actionlog::whereNotNull('filename')->where('item_id', $asset->id)->find($fileId)) {
$file = 'private_uploads/assets/'.$log->filename;
if ($log->action_type == 'audit') {
$file = 'private_uploads/audits/'.$log->filename;
}
try {
return StorageHelper::showOrDownloadFile($file, $log->filename);
} catch (\Exception $e) {
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.file_not_found'));
}
if ($log = Actionlog::whereNotNull('filename')->where('item_id', $asset->id)->find($fileId)) {
$file = 'private_uploads/assets/'.$log->filename;
if ($log->action_type == 'audit') {
$file = 'private_uploads/audits/'.$log->filename;
}
try {
return StorageHelper::showOrDownloadFile($file, $log->filename);
} catch (\Exception $e) {
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.file_not_found'));
}
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.log_record_not_found'));
}
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.log_record_not_found'));
}
@ -95,23 +89,20 @@ class AssetFilesController extends Controller
* @param int $fileId
* @since [v1.0]
*/
public function destroy($assetId = null, $fileId = null) : RedirectResponse
public function destroy(Asset $asset, $fileId = null) : RedirectResponse
{
if ($asset = Asset::find($assetId)) {
$this->authorize('update', $asset);
$rel_path = 'private_uploads/assets';
$this->authorize('update', $asset);
$rel_path = 'private_uploads/assets';
if ($log = Actionlog::find($fileId)) {
if (Storage::exists($rel_path.'/'.$log->filename)) {
Storage::delete($rel_path.'/'.$log->filename);
}
$log->delete();
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
if ($log = Actionlog::find($fileId)) {
if (Storage::exists($rel_path.'/'.$log->filename)) {
Storage::delete($rel_path.'/'.$log->filename);
}
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.log_record_not_found'));
$log->delete();
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
}
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.log_record_not_found'));
}
}

View file

@ -37,6 +37,15 @@
</div>
@endif
@if ($asset->deleted_at!='')
<div class="col-md-12">
<div class="callout callout-warning">
<x-icon type="warning" />
{{ trans('general.asset_deleted_warning') }}
</div>
</div>
@endif
<div class="col-md-12">
<div class="nav-tabs-custom">
<ul class="nav nav-tabs hidden-print">
@ -169,15 +178,6 @@
<div class="tab-pane fade in active" id="details">
<div class="row">
@if ($asset->deleted_at!='')
<div class="col-md-12">
<div class="callout callout-warning">
<x-icon type="warning" />
{{ trans('general.asset_deleted_warning') }}
</div>
</div>
@endif
<div class="info-stack-container">
<!-- Start button column -->
<div class="col-md-3 col-xs-12 col-sm-push-9 info-stack">
@ -300,7 +300,7 @@
</button>
<span class="sr-only">{{ trans('general.delete') }}</span>
@else
<form method="POST" action="{{ route('restore/hardware', ['assetId' => $asset->id]) }}">
<form method="POST" action="{{ route('restore/hardware', [$asset]) }}">
@csrf
<button class="btn btn-sm btn-block btn-warning btn-social delete-asset">
<x-icon type="restore" />

View file

@ -131,27 +131,27 @@ Route::group(
Route::get('{asset}/qr_code',
[AssetsController::class, 'getQrCode']
)->name('qr_code/hardware');
)->name('qr_code/hardware')->withTrashed();
Route::get('{assetId}/barcode',
Route::get('{asset}/barcode',
[AssetsController::class, 'getBarCode']
)->name('barcode/hardware');
)->name('barcode/hardware')->withTrashed();
Route::post('{assetId}/restore',
Route::post('{asset}/restore',
[AssetsController::class, 'getRestore']
)->name('restore/hardware');
)->name('restore/hardware')->withTrashed();
Route::post('{assetId}/upload',
Route::post('{asset}/upload',
[AssetFilesController::class, 'store']
)->name('upload/asset');
)->name('upload/asset')->withTrashed();
Route::get('{assetId}/showfile/{fileId}/{download?}',
Route::get('{asset}/showfile/{fileId}/{download?}',
[AssetFilesController::class, 'show']
)->name('show/assetfile');
)->name('show/assetfile')->withTrashed();
Route::delete('{assetId}/showfile/{fileId}/delete',
Route::delete('{asset}/showfile/{fileId}/delete',
[AssetFilesController::class, 'destroy']
)->name('delete/assetfile');
)->name('delete/assetfile')->withTrashed();
Route::post(
'bulkedit',
@ -190,7 +190,7 @@ Route::group(
Route::resource('hardware',
AssetsController::class,
['middleware' => ['auth']
])->parameters(['hardware' => 'asset']);
])->parameters(['hardware' => 'asset'])->withTrashed();
// Asset Maintenances