mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-13 06:47:46 -08:00
very much WIP, but dupe queries reduced
but i think this can be cleaned up a bit more
This commit is contained in:
parent
830e3e5594
commit
8b9aea8874
|
@ -44,17 +44,19 @@ class BulkAssetsController extends Controller
|
||||||
$asset_ids = array_values(array_unique($request->input('ids')));
|
$asset_ids = array_values(array_unique($request->input('ids')));
|
||||||
|
|
||||||
//custom fields logic for bulk edit
|
//custom fields logic for bulk edit
|
||||||
$asset_custom_field = Asset::whereIn('id', $asset_ids)->whereHas('model', function ($query) {
|
$asset_custom_field = Asset::with('model.fieldset.fields')->whereIn('id', $asset_ids)->whereHas('model', function ($query) {
|
||||||
return $query->where('fieldset_id', '!=', null);
|
return $query->where('fieldset_id', '!=', null);
|
||||||
})->get();
|
})->get();
|
||||||
|
|
||||||
$models = $asset_custom_field->unique('model_id')->pluck('model');
|
$models = $asset_custom_field->unique('model_id');
|
||||||
|
|
||||||
$custom_fields = new Collection();
|
ray($asset_custom_field);
|
||||||
foreach ($asset_custom_field as $asset_key => $asset) {
|
ray($models);
|
||||||
$custom_fields->push($asset->model->fieldset->fields);
|
// $custom_fields = new Collection();
|
||||||
}
|
// foreach ($models as $asset_key => $asset) {
|
||||||
$custom_fields = $custom_fields->flatten()->unique('id');
|
// $custom_fields->push($asset->model->customFields);
|
||||||
|
// }
|
||||||
|
$custom_fields = $asset_custom_field->pluck('model.fieldset.fields')->flatten()->unique('id');
|
||||||
|
|
||||||
if ($request->filled('bulk_actions')) {
|
if ($request->filled('bulk_actions')) {
|
||||||
switch ($request->input('bulk_actions')) {
|
switch ($request->input('bulk_actions')) {
|
||||||
|
@ -75,8 +77,8 @@ class BulkAssetsController extends Controller
|
||||||
return view('hardware/bulk')
|
return view('hardware/bulk')
|
||||||
->with('assets', $asset_ids)
|
->with('assets', $asset_ids)
|
||||||
->with('statuslabel_list', Helper::statusLabelList())
|
->with('statuslabel_list', Helper::statusLabelList())
|
||||||
->with('custom_fields', $custom_fields)
|
// ->with('custom_fields', $custom_fields)
|
||||||
->with('models', $models);
|
->with('models', $models->pluck('model'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Schema;
|
use Schema;
|
||||||
use Watson\Validating\ValidatingTrait;
|
use Watson\Validating\ValidatingTrait;
|
||||||
|
// use App\Models\SnipeModel;
|
||||||
class CustomField extends Model
|
class CustomField extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
@ -181,6 +181,8 @@ class CustomField extends Model
|
||||||
public function assetModels()
|
public function assetModels()
|
||||||
{
|
{
|
||||||
return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id');
|
return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id');
|
||||||
|
|
||||||
|
// return $this->models->where(, AssetModel::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -7,17 +7,17 @@
|
||||||
@endphp
|
@endphp
|
||||||
@foreach($models as $model)
|
@foreach($models as $model)
|
||||||
@if (($model) && ($model->fieldset))
|
@if (($model) && ($model->fieldset))
|
||||||
@foreach($model->customFields AS $field)
|
@foreach($model->fieldset->fields AS $field)
|
||||||
|
|
||||||
@php
|
@php
|
||||||
if (in_array($field->db_column_name(), $fields)) {
|
if (in_array($field->db_column_name(), $fields)) {
|
||||||
$duplicate = true;
|
$duplicate = true;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
$duplicate = false;
|
$duplicate = false;
|
||||||
}
|
}
|
||||||
$fields[] = $field->db_column_name();
|
$fields[] = $field->db_column_name();
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
<div class="form-group{{ $errors->has($field->db_column_name()) ? ' has-error' : '' }}">
|
<div class="form-group{{ $errors->has($field->db_column_name()) ? ' has-error' : '' }}">
|
||||||
<label for="{{ $field->db_column_name() }}" class="col-md-3 control-label">{{ $field->name }} </label>
|
<label for="{{ $field->db_column_name() }}" class="col-md-3 control-label">{{ $field->name }} </label>
|
||||||
|
|
Loading…
Reference in a new issue