Skip to content

Commit b634053

Browse files
committed
Improve the error and success messages and linking
1 parent c714114 commit b634053

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

app/Http/Controllers/Assets/AssetsController.php

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ public function store(ImageUploadRequest $request) : RedirectResponse
112112

113113
$settings = Setting::getSettings();
114114

115-
$successes = 0;
116-
$failures = 0;
115+
$successes = [];
116+
$failures = [];
117117
$serials = $request->input('serials');
118-
$last_succesful_asset = null;
118+
$asset = null;
119119

120120
for ($a = 1; $a <= count($asset_tags); $a++) {
121121
$asset = new Asset();
@@ -202,33 +202,32 @@ public function store(ImageUploadRequest $request) : RedirectResponse
202202
$asset->checkOut($target, auth()->user(), date('Y-m-d H:i:s'), $request->input('expected_checkin', null), 'Checked out on asset creation', $request->get('name'), $location);
203203
}
204204

205-
$last_succesful_asset = $asset;
206-
$successes++;
205+
$successes[] = "<a href='" . route('hardware.show', ['hardware' => $asset->id]) . "' style='color: white;'>" . e($asset->asset_tag) . "</a>";
207206

208207
} else {
209-
$failures++;
208+
$failures[] = join(",", $asset->getErrors()->all());
210209
}
211210
}
212211

213212
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]);
214213

215214

216-
if ($successes > 0) {
217-
if ($failures > 0) {
215+
if ($successes) {
216+
if ($failures) {
218217
//some succeeded, some failed
219-
return redirect()->to(Helper::getRedirectOption($request, $last_succesful_asset->id, 'Assets'))
220-
->with('success-unescaped', trans_choice('admin/hardware/message.create.multi_success_linked', $successes, ['link' => route('hardware.show', ['hardware' => $last_succesful_asset->id]), 'id', 'tag' => e($last_succesful_asset->asset_tag)]))
221-
->with('warning', trans_choice('admin/hardware/message.create.partial_failure', $failures));
218+
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets')) //FIXME - not tested
219+
->with('success-unescaped', trans_choice('admin/hardware/message.create.multi_success_linked', $successes, ['links' => join(", ", $successes)]))
220+
->with('warning', trans_choice('admin/hardware/message.create.partial_failure', $failures, ['failures' => join("; ", $failures)]));
222221
} else {
223-
if ($successes == 1) {
222+
if (count($successes) == 1) {
224223
//the most common case, keeping it so we don't have to make every use of that translation string be trans_choice'ed
225224
//and re-translated
226-
return redirect()->to(Helper::getRedirectOption($request, $last_succesful_asset->id, 'Assets'))
227-
->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', ['hardware' => $last_succesful_asset->id]), 'id', 'tag' => e($last_succesful_asset->asset_tag)]));
225+
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
226+
->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', ['hardware' => $asset->id]), 'id', 'tag' => e($asset->asset_tag)]));
228227
} else {
229228
//multi-success
230-
return redirect()->to(Helper::getRedirectOption($request, $last_succesful_asset->id, 'Assets'))
231-
->with('success-unescaped', trans_choice('admin/hardware/message.create.multi_success_linked', $successes, ['link' => route('hardware.show', ['hardware' => $last_succesful_asset->id]), 'id', 'tag' => e($last_succesful_asset->asset_tag)]));
229+
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
230+
->with('success-unescaped', trans_choice('admin/hardware/message.create.multi_success_linked', $successes, ['links' => join(", ", $successes)]));
232231
}
233232
}
234233

resources/lang/en-US/admin/hardware/message.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
'error' => 'Asset was not created, please try again. :(',
1515
'success' => 'Asset created successfully. :)',
1616
'success_linked' => 'Asset with tag :tag was created successfully. <strong><a href=":link" style="color: white;">Click here to view</a></strong>.',
17-
'multi_success_linked' => 'Asset with tag :tag was created successfully. <strong><a href=":link" style="color: white;">Click here to view</a></strong>.|:count assets were created succesfully. The last one was :tag. <strong><a href=":link" style="color: white;">Click here to view</a></strong>.',
18-
'partial_success_linked' => 'Asset with tag :tag was created successfully. <strong><a href=":link" style="color: white;">Click here to view</a></strong>.',
19-
'partial_failure' => 'An asset was unable to be created.|:count assets were unable to be created.'
17+
'multi_success_linked' => 'Asset with tag :links was created successfully.|:count assets were created succesfully. :links.',
18+
'partial_failure' => 'An asset was unable to be created. Reason: :failures|:count assets were unable to be created. Reasons: :failures',
2019
],
2120

2221
'update' => [

0 commit comments

Comments
 (0)