{{-- @intent Widget de Timeline de Auditoria (CMS). @param $model (Model) Opcional. @param $history (Collection) Opcional. Histórico já carregado. @param $title (String) Opcional. Padrão: "Histórico de Alterações" @param $icon (String) Opcional. Padrão: "bi-clock-history" --}} @php if (!isset($history)) { $history = isset($model) ? app(\V2\Services\ActivityLogger\ActivityLoggerService::class)->getHistory($model) : collect(); } $widgetId = 'timeline-' . ($model->id ?? uniqid()); @endphp @if($history->isNotEmpty())

{{ $title ?? 'Histórico de Alterações' }}

    @foreach($history as $activity) @php $desc = strtolower($activity->description); if ($desc === 'created') { $theme = ['icon' => 'bi-plus-lg', 'bg' => 'bg-success', 'text' => 'text-success', 'border' => 'border-success']; } elseif ($desc === 'deleted') { $theme = ['icon' => 'bi-trash', 'bg' => 'bg-danger', 'text' => 'text-danger', 'border' => 'border-danger']; } else { $theme = ['icon' => 'bi-pencil', 'bg' => 'bg-primary', 'text' => 'text-primary', 'border' => 'border-primary']; } @endphp
  • @php $isSuperAdmin = \Cartalyst\Sentinel\Laravel\Facades\Sentinel::check() && \Cartalyst\Sentinel\Laravel\Facades\Sentinel::getUser()->email === config('v2.support.email'); @endphp

    @php $userName = 'Sistema'; if ($activity->causer) { $userName = trim($activity->causer->first_name . ' ' . $activity->causer->last_name); if (empty($userName)) { $userName = $activity->causer->email; } } @endphp {{ $userName }} @php $actionKey = "activitylog::action.{$activity->description}"; $actionText = Lang::has($actionKey) ? trans($actionKey) : ucfirst($activity->description); @endphp {{ $actionText }}

    {{-- Exibição Parcial de Mudanças --}} @php $changedPayload = []; $oldPayload = []; if(!empty($activity->properties)) { if (isset($activity->properties['attributes'])) { $changedPayload = $activity->properties['attributes']; $oldPayload = $activity->properties['old'] ?? []; } elseif (isset($activity->properties['new'])) { $changedPayload = $activity->properties['new']; $oldPayload = $activity->properties['old'] ?? []; } } $ignoredKeys = ['updated_at', 'created_at', 'v2_audit', 'transaction_snapshot_id']; if(is_array($changedPayload)) { $changedPayload = collect($changedPayload)->except($ignoredKeys)->toArray(); } if(is_array($oldPayload)) { $oldPayload = collect($oldPayload)->except($ignoredKeys)->toArray(); } $isList = is_array($changedPayload) && count($changedPayload) > 0 && count(array_filter(array_keys($changedPayload), 'is_string')) === 0; @endphp @if(!empty($changedPayload))
    @if($isList)
    Lista Atualizada Contém {{ count($changedPayload) }} item(ns)
    @php $titles = collect($changedPayload)->pluck('title')->filter()->take(3); if ($titles->isEmpty()) $titles = collect($changedPayload)->pluck('nome')->filter()->take(3); if ($titles->isEmpty()) $titles = collect($changedPayload)->pluck('name')->filter()->take(3); @endphp @if($titles->isNotEmpty())
    @foreach($titles as $t) {{ $t }} @endforeach @if(count($changedPayload) > 3) +{{ count($changedPayload) - 3 }} @endif
    @endif
    @else
    @php $displayLimit = 4; $counter = 0; @endphp @foreach($changedPayload as $key => $value) @if($counter < $displayLimit) @php $oldValue = $oldPayload[$key] ?? null; @endphp
    {{ str_replace('_', ' ', $key) }}
    @if($oldValue !== null && $oldValue !== $value)
    @if(is_array($oldValue) || is_object($oldValue)) Dados @else {{ str_limit((string)$oldValue, 20) }} @endif
    @endif
    @if(is_array($value) || is_object($value)) Dados @else {{ str_limit((string)$value, 30) }} @endif
    @php $counter++; @endphp @endif @endforeach @if(count($changedPayload) > $displayLimit)
    + {{ count($changedPayload) - $displayLimit }} alteração(ões)
    @endif
    @endif
    @endif @if($isSuperAdmin)
    {{ json_encode($activity->properties, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) }}
    @endif @if(!empty($activity->properties) && isset($activity->properties['motivo']))
    {{ $activity->properties['motivo'] }}
    @endif
  • @endforeach
@endif