mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Use computed fields in CustomFieldSetDefaultValuesForModel component
This commit is contained in:
parent
74e7b1cfa5
commit
f6c1642bf2
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Livewire;
|
namespace App\Livewire;
|
||||||
|
|
||||||
|
use Livewire\Attributes\Computed;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
use App\Models\CustomFieldset;
|
use App\Models\CustomFieldset;
|
||||||
|
@ -15,30 +16,23 @@ class CustomFieldSetDefaultValuesForModel extends Component
|
||||||
public $fields;
|
public $fields;
|
||||||
public $model_id;
|
public $model_id;
|
||||||
|
|
||||||
public function mount()
|
public function mount($model_id = null)
|
||||||
{
|
{
|
||||||
if(is_null($this->model_id)){
|
$this->model_id = $model_id;
|
||||||
return;
|
$this->fieldset_id = $this->model?->fieldset_id;
|
||||||
}
|
$this->add_default_values = ($this->model?->defaultValues->count() > 0);
|
||||||
|
|
||||||
$this->model = AssetModel::find($this->model_id); // It's possible to do some clever route-model binding here, but let's keep it simple, shall we?
|
|
||||||
$this->fieldset_id = $this->model->fieldset_id;
|
|
||||||
|
|
||||||
$this->fields = null;
|
|
||||||
|
|
||||||
if ($fieldset = CustomFieldset::find($this->fieldset_id)) {
|
|
||||||
$this->fields = CustomFieldset::find($this->fieldset_id)->fields;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->add_default_values = ($this->model->defaultValues->count() > 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updatedFieldsetId()
|
#[Computed]
|
||||||
|
public function model()
|
||||||
{
|
{
|
||||||
if (CustomFieldset::find($this->fieldset_id)) {
|
return AssetModel::find($this->model_id);
|
||||||
$this->fields = CustomFieldset::find($this->fieldset_id)->fields;
|
}
|
||||||
}
|
|
||||||
|
#[Computed]
|
||||||
|
public function customFields()
|
||||||
|
{
|
||||||
|
return CustomFieldset::find($this->fieldset_id)?->fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@if ($this->add_default_values ) {{-- 'if the checkbox is enabled *AND* there are more than 0 fields in the fieldsset' --}}
|
@if ($add_default_values ) {{-- 'if the checkbox is enabled *AND* there are more than 0 fields in the fieldsset' --}}
|
||||||
@if ($fields)
|
@if ($this->customFields)
|
||||||
|
|
||||||
@foreach ($fields as $field)
|
@foreach ($this->customFields as $field)
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
||||||
<label class="col-md-3 control-label{{ $errors->has($field->name) ? ' has-error' : '' }}">{{ $field->name }}</label>
|
<label class="col-md-3 control-label{{ $errors->has($field->name) ? ' has-error' : '' }}">{{ $field->name }}</label>
|
||||||
|
|
Loading…
Reference in a new issue