Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we have fields for rendering restore and table. #46

Merged
merged 5 commits into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading