{{-- resources/views/agent/files/index.blade.php --}} @extends('layouts.contentLayoutMaster') @section('title', 'Files') @php use Illuminate\Support\Facades\Route as Routes; use Illuminate\Support\Facades\Storage as Disk; use Illuminate\Support\Str; // Human-readable size function human_size($bytes) { $bytes = (int) ($bytes ?? 0); $units = ['B', 'KB', 'MB', 'GB', 'TB']; $i = 0; while ($bytes >= 1024 && $i < count($units) - 1) { $bytes /= 1024; $i++; } return number_format($bytes, $i ? 1 : 0) . ' ' . $units[$i]; } // Exclude archives/snapshots from this page $isArchiveFile = function ($file) { $cat = (string) ($file->category ?? ''); if (str_starts_with($cat, 'archive-') || $cat === 'purchased_archive') return true; if (!empty($file->snapshot_json)) return true; $notes = (string) ($file->notes ?? ''); return str_contains($notes, 'purchased_archive'); }; // Label for "Document" column $docLabelFor = function ($f) { return $f->document_type ?? ($f->doc_type ?? ($f->mime ?? ($f->category ?? '—'))); }; // Restrict to real file types for filter & upload $docTypes = ['pdf','word','excel','csv','image','text','ppt','zip','audio','video','json','xml','html','other']; // Archive link (use params if provided by controller) $archiveUrl = isset($archParams) ? route('agent.files.archive', $archParams) : route('agent.files.archive'); // Index URL (for "Clear display") $indexUrl = Routes::has('agent.files.index') ? route('agent.files.index') : (Routes::has('agent.files') ? route('agent.files') : url()->current()); // Only show rows when filters exist; otherwise leave body blank // NOTE: back to a single date range: upload_from / upload_to $showResults = request()->filled('title') || request()->filled('document_type') || request()->filled('upload_from') || request()->filled('upload_to') || request()->filled('q'); // flexible keyword @endphp @section('content')
{{-- Title left / Lead Archives button right --}}

Files

Lead Archives
{{-- Flash messages --}} @if (session('success')) @endif @if ($errors->any()) @endif {{-- TOP FILTER BAR (back to a simple date range) --}}
{{-- DATE RANGE (created_at) --}}
Clear
{{-- UPLOAD --}}
@csrf
{{-- You can keep name="doc_type" (controller accepts both doc_type/document_type) --}}
{{-- Notes (preferred over legacy "info") --}}
{{-- FILES TABLE (card always visible; body blank until filters are applied) --}}
@if ($showResults) @forelse ($files as $f) @php $title = $f->title ?? ($f->name ?? ($f->original_name ?? basename($f->path ?? ($f->stored_path ?? 'file')))); $doc = $docLabelFor($f); $size = $f->size ?? ($f->filesize ?? 0); // Prefer notes; fall back to legacy info (read-only) $notes = trim((string) ($f->notes ?? '')); if ($notes === '' && isset($f->info)) $notes = (string) $f->info; $path = $f->stored_path ?? $f->path ?? null; $publicUrl = $path ? Disk::url($path) : null; // Build "View" URL and preserve current filters via ?return=... $hasShow = Routes::has('agent.files.show'); $hasView = Routes::has('agent.files.view'); if ($hasShow) { $viewUrl = route('agent.files.show', [ 'id' => $f->id ?? $f, 'return' => request()->fullUrl(), // keep filters when returning ]); } elseif ($hasView) { $viewUrl = route('agent.files.view', [ 'id' => $f->id ?? $f, 'return' => request()->fullUrl(), ]); } else { $viewUrl = $publicUrl ?: '#'; } // Only open a new tab when falling back to a raw public URL $openInNewTab = (!$hasShow && !$hasView && $publicUrl); $editUrl = Routes::has('agent.files.edit') ? route('agent.files.edit', [ 'id' => $f->id ?? $f, 'return' => request()->fullUrl(), // keep current filters when returning ]) : '#'; $destroyRouteExists = Routes::has('agent.files.destroy'); $destroyUrl = $destroyRouteExists ? route('agent.files.destroy', $f->id ?? $f) : '#'; @endphp @if (!$isArchiveFile($f)) @endif @empty @endforelse @else {{-- Blank initial state: render no rows to keep the display empty --}} @endif
Title Document Upload Date Last Modified Date Size Notes Actions
{{ $title }} {{ is_string($doc) ? strtoupper($doc) : '—' }} {{ optional($f->created_at)->format('Y-m-d H:i') }} {{ optional($f->updated_at)->format('Y-m-d H:i') }} {{ human_size($size) }} {{ $notes !== '' ? Str::limit($notes, 120) : '—' }}
No matching documents.
{{-- Only show pagination when results are displayed --}} @if ($showResults) @endif
@endsection