mirror of
https://github.com/snipe/snipe-it.git
synced 2024-12-25 21:54:14 -08:00
wip
This commit is contained in:
parent
815c77f943
commit
1d2596fc54
|
@ -16,6 +16,8 @@ use App\Http\Requests\AssetCheckoutRequest;
|
|||
use App\Models\CustomField;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
use function Amp\Promise\wait;
|
||||
|
||||
class BulkAssetsController extends Controller
|
||||
{
|
||||
use CheckInOutRequest;
|
||||
|
@ -32,6 +34,7 @@ class BulkAssetsController extends Controller
|
|||
public function edit(Request $request)
|
||||
{
|
||||
// dd($request->all());
|
||||
// dd(Session::get('ids'));
|
||||
|
||||
$this->authorize('update', Asset::class);
|
||||
|
||||
|
@ -113,7 +116,9 @@ class BulkAssetsController extends Controller
|
|||
|
||||
$custom_field_columns = CustomField::all()->pluck('db_column')->toArray();
|
||||
|
||||
if (! $request->filled('ids') || count($request->input('ids')) <= 0) {
|
||||
if(Session::exists('ids')) {
|
||||
$assets = Session::get('ids');
|
||||
} elseif (! $request->filled('ids') || count($request->input('ids')) <= 0) {
|
||||
return redirect($bulk_back_url)->with('error', trans('admin/hardware/message.update.no_assets_selected'));
|
||||
}
|
||||
|
||||
|
@ -211,7 +216,8 @@ class BulkAssetsController extends Controller
|
|||
if($custom_fields_present) {
|
||||
$asset = Asset::find($assetId);
|
||||
$assetCustomFields = $asset->model()->first()->fieldset;
|
||||
foreach ($assetCustomFields->fields as $field) {
|
||||
if($assetCustomFields?->fields) {
|
||||
foreach ($assetCustomFields?->fields as $field) {
|
||||
if (array_key_exists($field->db_column, $this->update_array)) {
|
||||
$asset->{$field->db_column} = $this->update_array[$field->db_column];
|
||||
$asset->save();
|
||||
|
@ -220,16 +226,19 @@ class BulkAssetsController extends Controller
|
|||
$array = $this->update_array;
|
||||
array_except($array, $field->db_column);
|
||||
$asset->update($array);
|
||||
//call update on parent model
|
||||
$asset->save();
|
||||
}
|
||||
if (!$asset->save()) {
|
||||
$error_bag[] = $asset->getErrors()->toArray();
|
||||
$error_bag[] = $asset->getErrors();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Asset::find($assetId)->update($this->update_array);
|
||||
}
|
||||
} // endforeach ($assets)
|
||||
ray($error_bag);
|
||||
if(!empty($error_bag)) {
|
||||
// $errors = collect($error_bag)->unique();
|
||||
// foreach ($errors as $key => $value) {
|
||||
|
@ -241,8 +250,11 @@ class BulkAssetsController extends Controller
|
|||
$errors[] = $value;
|
||||
}
|
||||
}
|
||||
ray($errors);
|
||||
return redirect($bulk_back_url)->with('bulk_errors', $errors);
|
||||
ray($error_bag);
|
||||
Session::save('ids', $assets);
|
||||
|
||||
// return redirect()->route('hardware/bulkedit');
|
||||
return redirect()->back()->with('bulk_errors', $errors);
|
||||
}
|
||||
return redirect($bulk_back_url)->with('success', trans('admin/hardware/message.update.success'));
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@
|
|||
@endif
|
||||
|
||||
|
||||
@if ($messages = Session::get('bulk_errors'))
|
||||
{{-- @if ($messages = Session::get('bulk_errors'))
|
||||
<div class="col-md-12">
|
||||
<div class="alert alert alert-danger fade in">
|
||||
<button type="button" class="close" data-dismiss="alert">×</button>
|
||||
|
@ -127,7 +127,7 @@
|
|||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
@endif --}}
|
||||
|
||||
|
||||
@if ($message = Session::get('warning'))
|
||||
|
|
Loading…
Reference in a new issue