very much WIP, but dupe queries reduced

but i think this can be cleaned up a bit more
This commit is contained in:
slong753 2023-04-12 14:46:48 -05:00
parent 830e3e5594
commit 8b9aea8874
3 changed files with 24 additions and 20 deletions

View file

@ -44,17 +44,19 @@ class BulkAssetsController extends Controller
$asset_ids = array_values(array_unique($request->input('ids')));
//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);
})->get();
$models = $asset_custom_field->unique('model_id')->pluck('model');
$models = $asset_custom_field->unique('model_id');
$custom_fields = new Collection();
foreach ($asset_custom_field as $asset_key => $asset) {
$custom_fields->push($asset->model->fieldset->fields);
}
$custom_fields = $custom_fields->flatten()->unique('id');
ray($asset_custom_field);
ray($models);
// $custom_fields = new Collection();
// foreach ($models as $asset_key => $asset) {
// $custom_fields->push($asset->model->customFields);
// }
$custom_fields = $asset_custom_field->pluck('model.fieldset.fields')->flatten()->unique('id');
if ($request->filled('bulk_actions')) {
switch ($request->input('bulk_actions')) {
@ -75,8 +77,8 @@ class BulkAssetsController extends Controller
return view('hardware/bulk')
->with('assets', $asset_ids)
->with('statuslabel_list', Helper::statusLabelList())
->with('custom_fields', $custom_fields)
->with('models', $models);
// ->with('custom_fields', $custom_fields)
->with('models', $models->pluck('model'));
}
}

View file

@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Model;
use Illuminate\Validation\Rule;
use Schema;
use Watson\Validating\ValidatingTrait;
// use App\Models\SnipeModel;
class CustomField extends Model
{
use HasFactory;
@ -181,6 +181,8 @@ class CustomField extends Model
public function assetModels()
{
return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id');
// return $this->models->where(, AssetModel::class);
}
/**

View file

@ -7,17 +7,17 @@
@endphp
@foreach($models as $model)
@if (($model) && ($model->fieldset))
@foreach($model->customFields AS $field)
@foreach($model->fieldset->fields AS $field)
@php
if (in_array($field->db_column_name(), $fields)) {
$duplicate = true;
continue;
} else {
$duplicate = false;
}
$fields[] = $field->db_column_name();
@endphp
@php
if (in_array($field->db_column_name(), $fields)) {
$duplicate = true;
continue;
} else {
$duplicate = false;
}
$fields[] = $field->db_column_name();
@endphp
<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>