mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-12 14:27:33 -08:00
ok, this works but needs to be tested more
This commit is contained in:
parent
29e3d202fe
commit
3929526a57
|
@ -150,6 +150,11 @@ class AssetModel extends SnipeModel
|
|||
{
|
||||
return $this->belongsTo(\App\Models\CustomFieldset::class, 'fieldset_id');
|
||||
}
|
||||
|
||||
public function customFields()
|
||||
{
|
||||
return $this->fieldset()->first()->fields();
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the model -> custom field default values relationship
|
||||
|
|
|
@ -177,6 +177,11 @@ class CustomField extends Model
|
|||
{
|
||||
return $this->belongsToMany(\App\Models\CustomFieldset::class);
|
||||
}
|
||||
|
||||
public function assetModels()
|
||||
{
|
||||
return $this->fieldset()->with('models')->get()->pluck('models')->flatten()->unique('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the customfield -> admin user relationship
|
||||
|
|
|
@ -187,8 +187,8 @@
|
|||
{{-- @foreach ($models as $model)
|
||||
<label class="col-md-12 text-center">
|
||||
{{ $model->name }} asset model
|
||||
</label> --}}
|
||||
{{-- @include("models/custom_fields_form",["model" => $model]) --}}
|
||||
</label>
|
||||
@include("models/custom_fields_form",["model" => $model]) --}}
|
||||
@include("models/custom_fields_form_bulk_edit",["models" => $models])
|
||||
{{-- @endforeach --}}
|
||||
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
@php
|
||||
$fields = [];
|
||||
foreach($model->fieldset->fields AS $field) {
|
||||
$fields[] = $field->db_column_name();
|
||||
}
|
||||
ray($fields);
|
||||
$duplicates = array_diff_assoc($fields, array_unique($fields));
|
||||
ray($duplicates);
|
||||
@endphp
|
||||
@if (($model) && ($model->fieldset))
|
||||
@foreach($model->fieldset->fields AS $field)
|
||||
<div class="form-group{{ $errors->has($field->db_column_name()) ? ' has-error' : '' }}">
|
||||
|
|
|
@ -1,32 +1,28 @@
|
|||
@php
|
||||
$fields = [];
|
||||
$modelNames = [];
|
||||
foreach($models as $model) {
|
||||
$modelNames[] = $model->name;
|
||||
}
|
||||
|
||||
@endphp
|
||||
@foreach($models as $model)
|
||||
<div>{{$model->name}}</div>
|
||||
|
||||
|
||||
@if (($model) && ($model->fieldset))
|
||||
@foreach($model->fieldset->fields AS $field)
|
||||
{{-- if field has already been displayed, skip --}}
|
||||
{{-- @php
|
||||
@foreach($model->customFields AS $field)
|
||||
@php
|
||||
if (in_array($field->db_column_name(), $fields)) {
|
||||
$duplicate = true;
|
||||
ray($field->db_column_name() . ' is a duplicate');
|
||||
continue;
|
||||
} else {
|
||||
$duplicate = false;
|
||||
}
|
||||
$fields[] = $field->db_column_name();
|
||||
ray($fields);
|
||||
@endphp --}}
|
||||
|
||||
$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>
|
||||
{{--hmmm, this doesn't make sense, duh.
|
||||
need to determine duplicates _before_ any rendering --}}
|
||||
{{-- @if($duplicate) --}}
|
||||
{{-- <p class="">On Models: {{$model->name}}</p> --}}
|
||||
{{-- @endif --}}
|
||||
<div class="col-md-7 col-sm-12{{ ($field->pivot->required=='1') ? ' required' : '' }}">
|
||||
|
||||
|
||||
|
@ -87,13 +83,17 @@ $fields = [];
|
|||
|
||||
@endif
|
||||
|
||||
@if ($field->help_text!='')
|
||||
<p class="help-block">{{ $field->help_text }}</p>
|
||||
@endif
|
||||
@if ($field->help_text!='')
|
||||
<p class="help-block">{{ $field->help_text }}</p>
|
||||
@endif
|
||||
|
||||
|
||||
@foreach($field->assetModels() as $assetModel)
|
||||
@if(in_array($assetModel->name, $modelNames))
|
||||
<p>{{$assetModel->name}}</p>
|
||||
@endif
|
||||
@endforeach
|
||||
|
||||
@if($duplicate)
|
||||
<p class="">This custom field is present on multiple models</p>
|
||||
@endif
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue