Refactor out common code for 'custom fields view' partial

This commit is contained in:
Brady Wetherington 2023-09-05 20:45:43 +01:00
parent 0f91e898fd
commit 0086adab86
4 changed files with 50 additions and 95 deletions

View file

@ -11,7 +11,7 @@ use Illuminate\Support\Facades\Gate;
* *
* The 'present' method is designed for when you're trying to generate fieldlists for use in Bootstrap tables * The 'present' method is designed for when you're trying to generate fieldlists for use in Bootstrap tables
* - typically the 'dataTableLayout' method * - typically the 'dataTableLayout' method
* *
*********************/ *********************/
class CustomFieldHelper { class CustomFieldHelper {

View file

@ -396,52 +396,7 @@
</div> </div>
</div> </div>
@if (($asset->model) && ($asset->model->fieldset)) @include('partials.custom-fields-view', ['item' => $asset,'width' => 2])
@foreach($asset->model->fieldset->fields as $field)
<div class="row">
<div class="col-md-2">
<strong>
{{ $field->name }}
</strong>
</div>
<div class="col-md-6{{ (($field->format=='URL') && ($asset->{$field->db_column_name()}!='')) ? ' ellipsis': '' }}">
@if ($field->field_encrypted=='1')
<i class="fas fa-lock" data-tooltip="true" data-placement="top" title="{{ trans('admin/custom_fields/general.value_encrypted') }}"></i>
@endif
@if ($field->isFieldDecryptable($asset->{$field->db_column_name()} ))
@can('assets.view.encrypted_custom_fields')
@if (($field->format=='URL') && ($asset->{$field->db_column_name()}!=''))
<a href="{{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }}" target="_new">{{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }}</a>
@elseif (($field->format=='DATE') && ($asset->{$field->db_column_name()}!=''))
{{ \App\Helpers\Helper::gracefulDecrypt($field, \App\Helpers\Helper::getFormattedDateObject($asset->{$field->db_column_name()}, 'date', false)) }}
@else
{{ Helper::gracefulDecrypt($field, $asset->{$field->db_column_name()}) }}
@endif
@else
{{ strtoupper(trans('admin/custom_fields/general.encrypted')) }}
@endcan
@else
@if (($field->format=='BOOLEAN') && ($asset->{$field->db_column_name()}!=''))
{!! ($asset->{$field->db_column_name()} == 1) ? "<span class='fas fa-check-circle' style='color:green' />" : "<span class='fas fa-times-circle' style='color:red' />" !!}
@elseif (($field->format=='URL') && ($asset->{$field->db_column_name()}!=''))
<a href="{{ $asset->{$field->db_column_name()} }}" target="_new">{{ $asset->{$field->db_column_name()} }}</a>
@elseif (($field->format=='DATE') && ($asset->{$field->db_column_name()}!=''))
{{ \App\Helpers\Helper::getFormattedDateObject($asset->{$field->db_column_name()}, 'date', false) }}
@else
{!! nl2br(e($asset->{$field->db_column_name()})) !!}
@endif
@endif
@if ($asset->{$field->db_column_name()}=='')
&nbsp;
@endif
</div>
</div>
@endforeach
@endif
@if ($asset->purchase_date) @if ($asset->purchase_date)

View file

@ -0,0 +1,47 @@
{{-- FIXME - this doesn't work for Assets (crap!) --}}
@if ($item->getFieldset())
@foreach($item->getFieldset()->fields as $field)
<div class="row">
<div class="col-md-{{ $width }}">
<strong>
{{ $field->name }}
</strong>
</div>
<div class="col-md-{{ 12 - $width }}{{ (($field->format=='URL') && ($item->{$field->db_column_name()}!='')) ? ' ellipsis': '' }}">
@if ($field->field_encrypted=='1')
<i class="fas fa-lock" data-tooltip="true" data-placement="top" title="{{ trans('admin/custom_fields/general.value_encrypted') }}"></i>
@endif
@if ($field->isFieldDecryptable($item->{$field->db_column_name()} ))
@can('assets.view.encrypted_custom_fields')
@if (($field->format=='URL') && ($item->{$field->db_column_name()}!=''))
<a href="{{ Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) }}" target="_new">{{ Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) }}</a>
@elseif (($field->format=='DATE') && ($item->{$field->db_column_name()}!=''))
{{ \App\Helpers\Helper::gracefulDecrypt($field, \App\Helpers\Helper::getFormattedDateObject($item->{$field->db_column_name()}, 'date', false)) }}
@else
{{ Helper::gracefulDecrypt($field, $item->{$field->db_column_name()}) }}
@endif
@else
{{ strtoupper(trans('admin/custom_fields/general.encrypted')) }}
@endcan
@else
@if (($field->format=='BOOLEAN') && ($item->{$field->db_column_name()}!=''))
{!! ($item->{$field->db_column_name()} == 1) ? "<span class='fas fa-check-circle' style='color:green' />" : "<span class='fas fa-times-circle' style='color:red' />" !!}
@elseif (($field->format=='URL') && ($item->{$field->db_column_name()}!=''))
<a href="{{ $item->{$field->db_column_name()} }}" target="_new">{{ $item->{$field->db_column_name()} }}</a>
@elseif (($field->format=='DATE') && ($item->{$field->db_column_name()}!=''))
{{ \App\Helpers\Helper::getFormattedDateObject($item->{$field->db_column_name()}, 'date', false) }}
@else
{!! nl2br(e($item->{$field->db_column_name()})) !!}
@endif
@endif
@if ($item->{$field->db_column_name()}=='')
&nbsp;
@endif
</div>
</div>
@endforeach
@endif

View file

@ -638,54 +638,7 @@
</div> </div>
@endif @endif
{{-- FIXME - copypasta from hardware/view.blade.php! <start> --}} @include('partials.custom-fields-view',['item' => $user,'width' => 3])
@if (($user->getFieldsetKey()) && (App\Models\CustomFieldset::find($user->getFieldsetKey())))
@foreach(App\Models\CustomFieldset::find($user->getFieldsetKey())->fields as $field)
<div class="row">
<div class="col-md-3">
<strong>
{{ $field->name }}
</strong>
</div>
<div class="col-md-9{{ (($field->format=='URL') && ($user->{$field->db_column_name()}!='')) ? ' ellipsis': '' }}">
@if ($field->field_encrypted=='1')
<i class="fas fa-lock" data-tooltip="true" data-placement="top" title="{{ trans('admin/custom_fields/general.value_encrypted') }}"></i>
@endif
@if ($field->isFieldDecryptable($user->{$field->db_column_name()} ))
@can('assets.view.encrypted_custom_fields')
@if (($field->format=='URL') && ($user->{$field->db_column_name()}!=''))
<a href="{{ Helper::gracefulDecrypt($field, $user->{$field->db_column_name()}) }}" target="_new">{{ Helper::gracefulDecrypt($field, $user->{$field->db_column_name()}) }}</a>
@elseif (($field->format=='DATE') && ($user->{$field->db_column_name()}!=''))
{{ \App\Helpers\Helper::gracefulDecrypt($field, \App\Helpers\Helper::getFormattedDateObject($user->{$field->db_column_name()}, 'date', false)) }}
@else
{{ Helper::gracefulDecrypt($field, $user->{$field->db_column_name()}) }}
@endif
@else
{{ strtoupper(trans('admin/custom_fields/general.encrypted')) }}
@endcan
@else
@if (($field->format=='BOOLEAN') && ($user->{$field->db_column_name()}!=''))
{!! ($user->{$field->db_column_name()} == 1) ? "<span class='fas fa-check-circle' style='color:green' />" : "<span class='fas fa-times-circle' style='color:red' />" !!}
@elseif (($field->format=='URL') && ($user->{$field->db_column_name()}!=''))
<a href="{{ $user->{$field->db_column_name()} }}" target="_new">{{ $user->{$field->db_column_name()} }}</a>
@elseif (($field->format=='DATE') && ($user->{$field->db_column_name()}!=''))
{{ \App\Helpers\Helper::getFormattedDateObject($user->{$field->db_column_name()}, 'date', false) }}
@else
{!! nl2br(e($user->{$field->db_column_name()})) !!}
@endif
@endif
@if ($user->{$field->db_column_name()}=='')
&nbsp;
@endif
</div>
</div>
@endforeach
@endif
{{-- FIXME <end> copypasta from hardware/view.blade.php --}}
</div> <!--/end striped container--> </div> <!--/end striped container-->
</div> <!-- end col-md-9 --> </div> <!-- end col-md-9 -->