From e27a3397ebc747ad97ce4c42104f57ae3fdde353 Mon Sep 17 00:00:00 2001 From: Tony Partridge Date: Mon, 1 Jul 2024 10:15:26 +0100 Subject: [PATCH 1/5] Ensure we have fields for rendering restore and table. --- resources/views/pages/list-activities.blade.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/resources/views/pages/list-activities.blade.php b/resources/views/pages/list-activities.blade.php index 38b54a9..dacc0e6 100644 --- a/resources/views/pages/list-activities.blade.php +++ b/resources/views/pages/list-activities.blade.php @@ -4,6 +4,13 @@
@foreach($this->getActivities() as $activityItem) + + @php + /* @var \Spatie\Activitylog\Models\Activity $activityItem */ + $changes = $activityItem->getChangesAttribute(); + $changesCount = $changes->count(); + @endphp +
- @if ($this->canRestoreActivity()) + @if ($this->canRestoreActivity() && $changesCount > 0)
+ @if($changesCount > 0)) + @@ -80,6 +89,7 @@ class="right" @endforeach + @endif
@endforeach From 74192c3a71cc34126bd89325c7acadb6dc167c3f Mon Sep 17 00:00:00 2001 From: Tony Partridge Date: Mon, 1 Jul 2024 10:21:30 +0100 Subject: [PATCH 2/5] Update list-activities.blade.php --- resources/views/pages/list-activities.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/list-activities.blade.php b/resources/views/pages/list-activities.blade.php index dacc0e6..df3d84e 100644 --- a/resources/views/pages/list-activities.blade.php +++ b/resources/views/pages/list-activities.blade.php @@ -45,7 +45,7 @@ class="right" - @if($changesCount > 0)) + @if($changesCount > 0) From c5332dbfe3613a62ba8393ef96ce0a4444af0887 Mon Sep 17 00:00:00 2001 From: Dennis Koch Date: Mon, 1 Jul 2024 11:41:08 +0200 Subject: [PATCH 3/5] code-style and remove duplicate $changes --- .../views/pages/list-activities.blade.php | 83 +++++++++---------- 1 file changed, 39 insertions(+), 44 deletions(-) diff --git a/resources/views/pages/list-activities.blade.php b/resources/views/pages/list-activities.blade.php index df3d84e..5841773 100644 --- a/resources/views/pages/list-activities.blade.php +++ b/resources/views/pages/list-activities.blade.php @@ -10,7 +10,7 @@ $changes = $activityItem->getChangesAttribute(); $changesCount = $changes->count(); @endphp - +
@if($changesCount > 0) - - - - - @lang('filament-activity-log::activities.table.field') - - - @lang('filament-activity-log::activities.table.old') - - - @lang('filament-activity-log::activities.table.new') - - - @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 - $loop->even])> - - {{ $this->getFieldLabel($field) }} - - - @if(is_array($oldValue)) -
{{ json_encode($oldValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}
- @else - {{ $oldValue }} - @endif -
- - @if(is_array($newValue)) -
{{ json_encode($newValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}
- @else - {{ $newValue }} - @endif -
-
- @endforeach -
+ + + + @lang('filament-activity-log::activities.table.field') + + + @lang('filament-activity-log::activities.table.old') + + + @lang('filament-activity-log::activities.table.new') + + + @foreach(data_get($changes, 'attributes', []) as $field => $change) + @php + $oldValue = data_get($changes, "old.{$field}"); + $newValue = data_get($changes, "attributes.{$field}"); + @endphp + $loop->even])> + + {{ $this->getFieldLabel($field) }} + + + @if(is_array($oldValue)) +
{{ json_encode($oldValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}
+ @else + {{ $oldValue }} + @endif +
+ + @if(is_array($newValue)) +
{{ json_encode($newValue, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) }}
+ @else + {{ $newValue }} + @endif +
+
+ @endforeach +
@endif
@endforeach From 92999e0c74d2e9ae3d4e1891bd7483563d894c1b Mon Sep 17 00:00:00 2001 From: Tony Partridge Date: Mon, 1 Jul 2024 11:15:26 +0200 Subject: [PATCH 4/5] refactoring --- resources/views/pages/list-activities.blade.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/resources/views/pages/list-activities.blade.php b/resources/views/pages/list-activities.blade.php index 5841773..25bde74 100644 --- a/resources/views/pages/list-activities.blade.php +++ b/resources/views/pages/list-activities.blade.php @@ -8,7 +8,6 @@ @php /* @var \Spatie\Activitylog\Models\Activity $activityItem */ $changes = $activityItem->getChangesAttribute(); - $changesCount = $changes->count(); @endphp
- @if ($this->canRestoreActivity() && $changesCount > 0) + @if ($this->canRestoreActivity() && $changes->isNotEmpty()) + q > @lang('filament-activity-log::activities.table.restore') @endif @@ -45,7 +44,7 @@ class="right"
- @if($changesCount > 0) + @if ($changes->isNotEmpty()) @@ -58,7 +57,7 @@ class="right" @lang('filament-activity-log::activities.table.new') - @foreach(data_get($changes, 'attributes', []) as $field => $change) + @foreach (data_get($changes, 'attributes', []) as $field => $change) @php $oldValue = data_get($changes, "old.{$field}"); $newValue = data_get($changes, "attributes.{$field}"); From 3e6a330002c785b28deeee56f15241d125440ed1 Mon Sep 17 00:00:00 2001 From: Dennis Koch Date: Mon, 1 Jul 2024 12:07:04 +0200 Subject: [PATCH 5/5] remove wild char --- resources/views/pages/list-activities.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/pages/list-activities.blade.php b/resources/views/pages/list-activities.blade.php index 25bde74..6d3bc91 100644 --- a/resources/views/pages/list-activities.blade.php +++ b/resources/views/pages/list-activities.blade.php @@ -36,7 +36,7 @@ color="gray" class="right" wire:click="restoreActivity({{ Js::from($activityItem->getKey()) }})" - q > + > @lang('filament-activity-log::activities.table.restore') @endif