Skip to content

Commit

Permalink
code-style and remove duplicate $changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pxlrbt committed Jul 1, 2024
1 parent 74192c3 commit c5332db
Showing 1 changed file with 39 additions and 44 deletions.
83 changes: 39 additions & 44 deletions resources/views/pages/list-activities.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$changes = $activityItem->getChangesAttribute();
$changesCount = $changes->count();
@endphp

<div @class([
'p-2 space-y-2 bg-white rounded-xl shadow',
'dark:border-gray-600 dark:bg-gray-800',
Expand Down Expand Up @@ -46,49 +46,44 @@ class="right"
</div>

@if($changesCount > 0)

<x-filament-tables::table class="w-full overflow-hidden text-sm">
<x-slot:header>
<x-filament-tables::header-cell>
@lang('filament-activity-log::activities.table.field')
</x-filament-tables::header-cell>
<x-filament-tables::header-cell>
@lang('filament-activity-log::activities.table.old')
</x-filament-tables::header-cell>
<x-filament-tables::header-cell>
@lang('filament-activity-log::activities.table.new')
</x-filament-tables::header-cell>
</x-slot:header>
@php
/* @var \Spatie\Activitylog\Models\Activity $activityItem */
$changes = $activityItem->getChangesAttribute();
@endphp
@foreach(data_get($changes, 'attributes', []) as $field => $change)
@php
$oldValue = data_get($changes, "old.{$field}");
$newValue = data_get($changes, "attributes.{$field}");
@endphp
<x-filament-tables::row @class(['bg-gray-100/30' => $loop->even])>
<x-filament-tables::cell width="20%" class="px-4 py-2 align-top sm:first-of-type:ps-6 sm:last-of-type:pe-6">
{{ $this->getFieldLabel($field) }}
</x-filament-tables::cell>
<x-filament-tables::cell width="40%" class="px-4 py-2 align-top break-all whitespace-normal">
@if(is_array($oldValue))
<pre class="text-xs text-gray-500">{{ json_encode($oldValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}</pre>
@else
{{ $oldValue }}
@endif
</x-filament-tables::cell>
<x-filament-tables::cell width="40%" class="px-4 py-2 align-top break-all whitespace-normal">
@if(is_array($newValue))
<pre class="text-xs text-gray-500">{{ json_encode($newValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}</pre>
@else
{{ $newValue }}
@endif
</x-filament-tables::cell>
</x-filament-tables::row>
@endforeach
</x-filament-tables::table>
<x-filament-tables::table class="w-full overflow-hidden text-sm">
<x-slot:header>
<x-filament-tables::header-cell>
@lang('filament-activity-log::activities.table.field')
</x-filament-tables::header-cell>
<x-filament-tables::header-cell>
@lang('filament-activity-log::activities.table.old')
</x-filament-tables::header-cell>
<x-filament-tables::header-cell>
@lang('filament-activity-log::activities.table.new')
</x-filament-tables::header-cell>
</x-slot:header>
@foreach(data_get($changes, 'attributes', []) as $field => $change)
@php
$oldValue = data_get($changes, "old.{$field}");
$newValue = data_get($changes, "attributes.{$field}");
@endphp
<x-filament-tables::row @class(['bg-gray-100/30' => $loop->even])>
<x-filament-tables::cell width="20%" class="px-4 py-2 align-top sm:first-of-type:ps-6 sm:last-of-type:pe-6">
{{ $this->getFieldLabel($field) }}
</x-filament-tables::cell>
<x-filament-tables::cell width="40%" class="px-4 py-2 align-top break-all whitespace-normal">
@if(is_array($oldValue))
<pre class="text-xs text-gray-500">{{ json_encode($oldValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}</pre>
@else
{{ $oldValue }}
@endif
</x-filament-tables::cell>
<x-filament-tables::cell width="40%" class="px-4 py-2 align-top break-all whitespace-normal">
@if(is_array($newValue))
<pre class="text-xs text-gray-500">{{ json_encode($newValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}</pre>
@else
{{ $newValue }}
@endif
</x-filament-tables::cell>
</x-filament-tables::row>
@endforeach
</x-filament-tables::table>
@endif
</div>
@endforeach
Expand Down

0 comments on commit c5332db

Please sign in to comment.