Skip to content

Commit

Permalink
Merge pull request #46 from pxlrbt/tonypartridge/main
Browse files Browse the repository at this point in the history
Ensure we have fields for rendering restore and table.
  • Loading branch information
pxlrbt authored Jul 1, 2024
2 parents af3f158 + 3e6a330 commit 37a083e
Showing 1 changed file with 47 additions and 43 deletions.
90 changes: 47 additions & 43 deletions resources/views/pages/list-activities.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<x-filament-panels::page>
<div class="space-y-6">
@foreach($this->getActivities() as $activityItem)

@php
/* @var \Spatie\Activitylog\Models\Activity $activityItem */
$changes = $activityItem->getChangesAttribute();
@endphp

<div @class([
'p-2 space-y-2 bg-white rounded-xl shadow',
'dark:border-gray-600 dark:bg-gray-800',
Expand All @@ -22,7 +28,7 @@
</div>
</div>
<div class="flex flex-col text-xs text-gray-500 justify-end">
@if ($this->canRestoreActivity())
@if ($this->canRestoreActivity() && $changes->isNotEmpty())
<x-filament::button
tag="button"
icon="heroicon-o-arrow-path-rounded-square"
Expand All @@ -38,48 +44,46 @@ class="right"
</div>
</div>

<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>
@if ($changes->isNotEmpty())
<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 37a083e

Please sign in to comment.