bulk actions are handled before sorting
This commit is contained in:
parent
95ef3a336b
commit
d83827a44e
3 changed files with 47 additions and 47 deletions
|
@ -50,7 +50,6 @@ class BulkAssetsController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$asset_ids = $request->input('ids');
|
$asset_ids = $request->input('ids');
|
||||||
|
|
||||||
// Figure out where we need to send the user after the update is complete, and store that in the session
|
// Figure out where we need to send the user after the update is complete, and store that in the session
|
||||||
$bulk_back_url = request()->headers->get('referer');
|
$bulk_back_url = request()->headers->get('referer');
|
||||||
session(['bulk_back_url' => $bulk_back_url]);
|
session(['bulk_back_url' => $bulk_back_url]);
|
||||||
|
@ -93,6 +92,51 @@ class BulkAssetsController extends Controller
|
||||||
|
|
||||||
$assets = Asset::with('assignedTo', 'location', 'model')->whereIn('assets.id', $asset_ids);
|
$assets = Asset::with('assignedTo', 'location', 'model')->whereIn('assets.id', $asset_ids);
|
||||||
|
|
||||||
|
$assets = $assets->get();
|
||||||
|
|
||||||
|
$models = $assets->unique('model_id');
|
||||||
|
$modelNames = [];
|
||||||
|
foreach($models as $model) {
|
||||||
|
$modelNames[] = $model->model->name;
|
||||||
|
}
|
||||||
|
if ($request->filled('bulk_actions')) {
|
||||||
|
|
||||||
|
switch ($request->input('bulk_actions')) {
|
||||||
|
case 'labels':
|
||||||
|
$this->authorize('view', Asset::class);
|
||||||
|
|
||||||
|
return (new Label)
|
||||||
|
->with('assets', $assets)
|
||||||
|
->with('settings', Setting::getSettings())
|
||||||
|
->with('bulkedit', true)
|
||||||
|
->with('count', 0);
|
||||||
|
|
||||||
|
case 'delete':
|
||||||
|
$this->authorize('delete', Asset::class);
|
||||||
|
$assets->each(function ($assets) {
|
||||||
|
$this->authorize('delete', $assets);
|
||||||
|
});
|
||||||
|
|
||||||
|
return view('hardware/bulk-delete')->with('assets', $assets);
|
||||||
|
|
||||||
|
case 'restore':
|
||||||
|
$this->authorize('update', Asset::class);
|
||||||
|
$assets = Asset::withTrashed()->find($asset_ids);
|
||||||
|
$assets->each(function ($asset) {
|
||||||
|
$this->authorize('delete', $asset);
|
||||||
|
});
|
||||||
|
return view('hardware/bulk-restore')->with('assets', $assets);
|
||||||
|
|
||||||
|
case 'edit':
|
||||||
|
$this->authorize('update', Asset::class);
|
||||||
|
|
||||||
|
return view('hardware/bulk')
|
||||||
|
->with('assets', $asset_ids)
|
||||||
|
->with('statuslabel_list', Helper::statusLabelList())
|
||||||
|
->with('models', $models->pluck(['model']))
|
||||||
|
->with('modelNames', $modelNames);
|
||||||
|
}
|
||||||
|
}
|
||||||
switch ($sort_override) {
|
switch ($sort_override) {
|
||||||
case 'model':
|
case 'model':
|
||||||
$assets->OrderModels($order);
|
$assets->OrderModels($order);
|
||||||
|
@ -128,53 +172,8 @@ class BulkAssetsController extends Controller
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$assets = $assets->get();
|
|
||||||
|
|
||||||
$models = $assets->unique('model_id');
|
|
||||||
$modelNames = [];
|
|
||||||
foreach($models as $model) {
|
|
||||||
$modelNames[] = $model->model->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($request->filled('bulk_actions')) {
|
|
||||||
|
|
||||||
|
|
||||||
switch ($request->input('bulk_actions')) {
|
|
||||||
case 'labels':
|
|
||||||
$this->authorize('view', Asset::class);
|
|
||||||
|
|
||||||
return (new Label)
|
|
||||||
->with('assets', $assets)
|
|
||||||
->with('settings', Setting::getSettings())
|
|
||||||
->with('bulkedit', true)
|
|
||||||
->with('count', 0);
|
|
||||||
|
|
||||||
case 'delete':
|
|
||||||
$this->authorize('delete', Asset::class);
|
|
||||||
$assets->each(function ($assets) {
|
|
||||||
$this->authorize('delete', $assets);
|
|
||||||
});
|
|
||||||
|
|
||||||
return view('hardware/bulk-delete')->with('assets', $assets);
|
|
||||||
|
|
||||||
case 'restore':
|
|
||||||
$this->authorize('update', Asset::class);
|
|
||||||
$assets = Asset::withTrashed()->find($asset_ids);
|
|
||||||
$assets->each(function ($asset) {
|
|
||||||
$this->authorize('delete', $asset);
|
|
||||||
});
|
|
||||||
return view('hardware/bulk-restore')->with('assets', $assets);
|
|
||||||
|
|
||||||
case 'edit':
|
|
||||||
$this->authorize('update', Asset::class);
|
|
||||||
|
|
||||||
return view('hardware/bulk')
|
|
||||||
->with('assets', $asset_ids)
|
|
||||||
->with('statuslabel_list', Helper::statusLabelList())
|
|
||||||
->with('models', $models->pluck(['model']))
|
|
||||||
->with('modelNames', $modelNames);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return redirect()->back()->with('error', 'No action selected');
|
return redirect()->back()->with('error', 'No action selected');
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,7 @@ class DefaultLabel extends RectangleSheet
|
||||||
// Fields
|
// Fields
|
||||||
$fieldsDone = 0;
|
$fieldsDone = 0;
|
||||||
if ($fieldsDone < $this->getSupportFields()) {
|
if ($fieldsDone < $this->getSupportFields()) {
|
||||||
|
// dd($record->get('fields'));
|
||||||
foreach ($record->get('fields') as $field) {
|
foreach ($record->get('fields') as $field) {
|
||||||
static::writeText(
|
static::writeText(
|
||||||
$pdf, $field['label'][0]. ': ' . $field['value'],
|
$pdf, $field['label'][0]. ': ' . $field['value'],
|
||||||
|
|
|
@ -126,7 +126,7 @@ class Label implements View
|
||||||
switch ($settings->label2_2d_target) {
|
switch ($settings->label2_2d_target) {
|
||||||
case 'ht_tag': $barcode2DTarget = route('ht/assetTag', $asset->asset_tag); break;
|
case 'ht_tag': $barcode2DTarget = route('ht/assetTag', $asset->asset_tag); break;
|
||||||
case 'hardware_id':
|
case 'hardware_id':
|
||||||
default: $barcode2DTarget = route('hardware.show', $asset->id); break;
|
default: $barcode2DTarget = route('hardware.show',['hardware' => $asset->id]); break;
|
||||||
}
|
}
|
||||||
$assetData->put('barcode2d', (object)[
|
$assetData->put('barcode2d', (object)[
|
||||||
'type' => $barcode2DType,
|
'type' => $barcode2DType,
|
||||||
|
|
Loading…
Add table
Reference in a new issue