Skip to content

Commit 42ec2fa

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 3445b54 + 4d848e4 commit 42ec2fa

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

app/Http/Controllers/Assets/AssetsController.php

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,10 @@ public function store(ImageUploadRequest $request) : RedirectResponse
111111

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

114-
$success = false;
114+
$successes = [];
115+
$failures = [];
115116
$serials = $request->input('serials');
117+
$asset = null;
116118

117119
for ($a = 1; $a <= count($asset_tags); $a++) {
118120
$asset = new Asset();
@@ -199,20 +201,35 @@ public function store(ImageUploadRequest $request) : RedirectResponse
199201
$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);
200202
}
201203

202-
$success = true;
203-
204+
$successes[] = "<a href='" . route('hardware.show', ['hardware' => $asset->id]) . "' style='color: white;'>" . e($asset->asset_tag) . "</a>";
205+
206+
} else {
207+
$failures[] = join(",", $asset->getErrors()->all());
204208
}
205209
}
206210

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

209213

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

212-
return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets'))
213-
->with('success-unescaped', trans('admin/hardware/message.create.success_linked', ['link' => route('hardware.show', ['hardware' => $asset->id]), 'id', 'tag' => e($asset->asset_tag)]));
214-
215-
216233
}
217234

218235
return redirect()->back()->withInput()->withErrors($asset->getErrors());

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +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 :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',
1719
],
1820

1921
'update' => [

resources/views/settings/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@
356356
<h2 class="box-title">{{ trans('admin/settings/general.system') }}</h2>
357357
</div>
358358
<div class="box-body">
359-
<div class="row" style="margin-right:4px;">
359+
<div class="col-md-12" style="margin-right:4px;">
360360
<div class="row row-new-striped" style="line-height: 23px;">
361361

362362
<!-- row -->

0 commit comments

Comments
 (0)