Skip to content

Commit 2bf4ec0

Browse files
committed
A few more small tweaks
Signed-off-by: snipe <[email protected]>
1 parent 9555825 commit 2bf4ec0

File tree

3 files changed

+47
-56
lines changed

3 files changed

+47
-56
lines changed

app/Http/Controllers/Assets/AssetFilesController.php

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ class AssetFilesController extends Controller
2626
*@since [v1.0]
2727
* @author [A. Gianotto] [<[email protected]>]
2828
*/
29-
public function store(UploadFileRequest $request, $assetId = null) : RedirectResponse
29+
public function store(UploadFileRequest $request, Asset $asset) : RedirectResponse
3030
{
31-
if (! $asset = Asset::find($assetId)) {
32-
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
33-
}
3431

3532
$this->authorize('update', $asset);
3633

@@ -59,31 +56,28 @@ public function store(UploadFileRequest $request, $assetId = null) : RedirectRes
5956
* @param int $fileId
6057
* @since [v1.0]
6158
*/
62-
public function show($assetId = null, $fileId = null) : View | RedirectResponse | Response | StreamedResponse | BinaryFileResponse
59+
public function show(Asset $asset, $fileId = null) : View | RedirectResponse | Response | StreamedResponse | BinaryFileResponse
6360
{
64-
if ($asset = Asset::find($assetId)) {
65-
66-
$this->authorize('view', $asset);
6761

68-
if ($log = Actionlog::whereNotNull('filename')->where('item_id', $asset->id)->find($fileId)) {
69-
$file = 'private_uploads/assets/'.$log->filename;
62+
$this->authorize('view', $asset);
7063

71-
if ($log->action_type == 'audit') {
72-
$file = 'private_uploads/audits/'.$log->filename;
73-
}
64+
if ($log = Actionlog::whereNotNull('filename')->where('item_id', $asset->id)->find($fileId)) {
65+
$file = 'private_uploads/assets/'.$log->filename;
7466

75-
try {
76-
return StorageHelper::showOrDownloadFile($file, $log->filename);
77-
} catch (\Exception $e) {
78-
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.file_not_found'));
79-
}
67+
if ($log->action_type == 'audit') {
68+
$file = 'private_uploads/audits/'.$log->filename;
69+
}
8070

71+
try {
72+
return StorageHelper::showOrDownloadFile($file, $log->filename);
73+
} catch (\Exception $e) {
74+
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.file_not_found'));
8175
}
8276

83-
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.log_record_not_found'));
8477
}
8578

86-
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
79+
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.log_record_not_found'));
80+
8781

8882
}
8983

@@ -95,23 +89,20 @@ public function show($assetId = null, $fileId = null) : View | RedirectResponse
9589
* @param int $fileId
9690
* @since [v1.0]
9791
*/
98-
public function destroy($assetId = null, $fileId = null) : RedirectResponse
92+
public function destroy(Asset $asset, $fileId = null) : RedirectResponse
9993
{
100-
if ($asset = Asset::find($assetId)) {
101-
$this->authorize('update', $asset);
102-
$rel_path = 'private_uploads/assets';
103-
104-
if ($log = Actionlog::find($fileId)) {
105-
if (Storage::exists($rel_path.'/'.$log->filename)) {
106-
Storage::delete($rel_path.'/'.$log->filename);
107-
}
108-
$log->delete();
109-
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
110-
}
94+
$this->authorize('update', $asset);
95+
$rel_path = 'private_uploads/assets';
11196

112-
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.log_record_not_found'));
97+
if ($log = Actionlog::find($fileId)) {
98+
if (Storage::exists($rel_path.'/'.$log->filename)) {
99+
Storage::delete($rel_path.'/'.$log->filename);
100+
}
101+
$log->delete();
102+
return redirect()->back()->withFragment('files')->with('success', trans('admin/hardware/message.deletefile.success'));
113103
}
114104

115-
return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist'));
105+
return redirect()->route('hardware.show', ['hardware' => $asset])->with('error', trans('general.log_record_not_found'));
116106
}
107+
117108
}

resources/views/hardware/view.blade.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@
3737
</div>
3838
@endif
3939

40+
@if ($asset->deleted_at!='')
41+
<div class="col-md-12">
42+
<div class="callout callout-warning">
43+
<x-icon type="warning" />
44+
{{ trans('general.asset_deleted_warning') }}
45+
</div>
46+
</div>
47+
@endif
48+
4049
<div class="col-md-12">
4150
<div class="nav-tabs-custom">
4251
<ul class="nav nav-tabs hidden-print">
@@ -169,15 +178,6 @@
169178
<div class="tab-pane fade in active" id="details">
170179
<div class="row">
171180

172-
@if ($asset->deleted_at!='')
173-
<div class="col-md-12">
174-
<div class="callout callout-warning">
175-
<x-icon type="warning" />
176-
{{ trans('general.asset_deleted_warning') }}
177-
</div>
178-
</div>
179-
@endif
180-
181181
<div class="info-stack-container">
182182
<!-- Start button column -->
183183
<div class="col-md-3 col-xs-12 col-sm-push-9 info-stack">
@@ -300,7 +300,7 @@ class="form-inline"
300300
</button>
301301
<span class="sr-only">{{ trans('general.delete') }}</span>
302302
@else
303-
<form method="POST" action="{{ route('restore/hardware', ['assetId' => $asset->id]) }}">
303+
<form method="POST" action="{{ route('restore/hardware', [$asset]) }}">
304304
@csrf
305305
<button class="btn btn-sm btn-block btn-warning btn-social delete-asset">
306306
<x-icon type="restore" />

routes/web/hardware.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,27 @@ function () {
131131

132132
Route::get('{asset}/qr_code',
133133
[AssetsController::class, 'getQrCode']
134-
)->name('qr_code/hardware');
134+
)->name('qr_code/hardware')->withTrashed();
135135

136-
Route::get('{assetId}/barcode',
136+
Route::get('{asset}/barcode',
137137
[AssetsController::class, 'getBarCode']
138-
)->name('barcode/hardware');
138+
)->name('barcode/hardware')->withTrashed();
139139

140-
Route::post('{assetId}/restore',
140+
Route::post('{asset}/restore',
141141
[AssetsController::class, 'getRestore']
142-
)->name('restore/hardware');
142+
)->name('restore/hardware')->withTrashed();
143143

144-
Route::post('{assetId}/upload',
144+
Route::post('{asset}/upload',
145145
[AssetFilesController::class, 'store']
146-
)->name('upload/asset');
146+
)->name('upload/asset')->withTrashed();
147147

148-
Route::get('{assetId}/showfile/{fileId}/{download?}',
148+
Route::get('{asset}/showfile/{fileId}/{download?}',
149149
[AssetFilesController::class, 'show']
150-
)->name('show/assetfile');
150+
)->name('show/assetfile')->withTrashed();
151151

152-
Route::delete('{assetId}/showfile/{fileId}/delete',
152+
Route::delete('{asset}/showfile/{fileId}/delete',
153153
[AssetFilesController::class, 'destroy']
154-
)->name('delete/assetfile');
154+
)->name('delete/assetfile')->withTrashed();
155155

156156
Route::post(
157157
'bulkedit',
@@ -190,7 +190,7 @@ function () {
190190
Route::resource('hardware',
191191
AssetsController::class,
192192
['middleware' => ['auth']
193-
])->parameters(['hardware' => 'asset']);
193+
])->parameters(['hardware' => 'asset'])->withTrashed();
194194

195195

196196
// Asset Maintenances

0 commit comments

Comments
 (0)