Files
usher-manage-stack/resources/views/admin/documents/statistics.blade.php
2025-11-20 23:21:05 +08:00

259 lines
14 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<x-app-layout>
<x-slot name="header">
<div class="flex items-center justify-between">
<h2 class="text-xl font-semibold leading-tight text-gray-800">
文件統計分析
</h2>
<a href="{{ route('admin.documents.index') }}" class="text-sm text-gray-600 hover:text-gray-900">
返回文件列表
</a>
</div>
</x-slot>
<div class="py-12">
<div class="mx-auto max-w-7xl sm:px-6 lg:px-8 space-y-6">
<!-- Summary Stats -->
<div class="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-5">
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<div class="flex items-center">
<div class="flex-shrink-0 text-3xl">📚</div>
<div class="ml-4">
<div class="text-2xl font-bold text-gray-900">{{ $stats['total_documents'] }}</div>
<div class="text-sm text-gray-500">活躍文件</div>
</div>
</div>
</div>
</div>
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<div class="flex items-center">
<div class="flex-shrink-0 text-3xl">🔄</div>
<div class="ml-4">
<div class="text-2xl font-bold text-gray-900">{{ $stats['total_versions'] }}</div>
<div class="text-sm text-gray-500">總版本數</div>
</div>
</div>
</div>
</div>
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<div class="flex items-center">
<div class="flex-shrink-0 text-3xl">👁️</div>
<div class="ml-4">
<div class="text-2xl font-bold text-gray-900">{{ number_format($stats['total_views']) }}</div>
<div class="text-sm text-gray-500">總檢視次數</div>
</div>
</div>
</div>
</div>
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<div class="flex items-center">
<div class="flex-shrink-0 text-3xl">⬇️</div>
<div class="ml-4">
<div class="text-2xl font-bold text-gray-900">{{ number_format($stats['total_downloads']) }}</div>
<div class="text-sm text-gray-500">總下載次數</div>
</div>
</div>
</div>
</div>
<div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
<div class="p-6">
<div class="flex items-center">
<div class="flex-shrink-0 text-3xl">📦</div>
<div class="ml-4">
<div class="text-2xl font-bold text-gray-900">{{ $stats['archived_documents'] }}</div>
<div class="text-sm text-gray-500">已封存</div>
</div>
</div>
</div>
</div>
</div>
<!-- Documents by Category -->
<div class="bg-white shadow sm:rounded-lg">
<div class="px-6 py-5 border-b border-gray-200">
<h3 class="text-lg font-medium text-gray-900">各類別文件數量</h3>
</div>
<div class="px-6 py-5">
<div class="space-y-4">
@foreach($documentsByCategory as $category)
<div>
<div class="flex items-center justify-between mb-1">
<span class="text-sm font-medium text-gray-700">
{{ $category->icon }} {{ $category->name }}
</span>
<span class="text-sm font-bold text-gray-900">{{ $category->active_documents_count }}</span>
</div>
<div class="w-full bg-gray-200 rounded-full h-2">
<div class="bg-indigo-600 h-2 rounded-full"
style="width: {{ $stats['total_documents'] > 0 ? ($category->active_documents_count / $stats['total_documents'] * 100) : 0 }}%">
</div>
</div>
</div>
@endforeach
</div>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Most Viewed -->
<div class="bg-white shadow sm:rounded-lg">
<div class="px-6 py-5 border-b border-gray-200">
<h3 class="text-lg font-medium text-gray-900">最常檢視文件</h3>
</div>
<div class="divide-y divide-gray-200">
@forelse($mostViewed as $document)
<div class="px-6 py-4">
<div class="flex items-center justify-between">
<div class="flex-1 min-w-0">
<a href="{{ route('admin.documents.show', $document) }}" class="text-sm font-medium text-gray-900 hover:text-indigo-600">
{{ $document->title }}
</a>
<p class="text-xs text-gray-500 mt-1">{{ $document->category->name }}</p>
</div>
<div class="ml-4 flex-shrink-0">
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-blue-100 text-blue-800">
{{ number_format($document->view_count) }}
</span>
</div>
</div>
</div>
@empty
<div class="px-6 py-8 text-center text-sm text-gray-500">尚無資料</div>
@endforelse
</div>
</div>
<!-- Most Downloaded -->
<div class="bg-white shadow sm:rounded-lg">
<div class="px-6 py-5 border-b border-gray-200">
<h3 class="text-lg font-medium text-gray-900">最常下載文件</h3>
</div>
<div class="divide-y divide-gray-200">
@forelse($mostDownloaded as $document)
<div class="px-6 py-4">
<div class="flex items-center justify-between">
<div class="flex-1 min-w-0">
<a href="{{ route('admin.documents.show', $document) }}" class="text-sm font-medium text-gray-900 hover:text-indigo-600">
{{ $document->title }}
</a>
<p class="text-xs text-gray-500 mt-1">{{ $document->category->name }}</p>
</div>
<div class="ml-4 flex-shrink-0">
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
{{ number_format($document->download_count) }}
</span>
</div>
</div>
</div>
@empty
<div class="px-6 py-8 text-center text-sm text-gray-500">尚無資料</div>
@endforelse
</div>
</div>
</div>
<!-- Upload Trends -->
@if($uploadTrends->isNotEmpty())
<div class="bg-white shadow sm:rounded-lg">
<div class="px-6 py-5 border-b border-gray-200">
<h3 class="text-lg font-medium text-gray-900">上傳趨勢最近6個月</h3>
</div>
<div class="px-6 py-5">
<div class="space-y-3">
@foreach($uploadTrends as $trend)
<div class="flex items-center">
<div class="w-24 text-sm font-medium text-gray-700">{{ $trend->month }}</div>
<div class="flex-1">
<div class="flex items-center">
<div class="w-full bg-gray-200 rounded-full h-6 mr-3">
<div class="bg-indigo-600 h-6 rounded-full flex items-center justify-end pr-2"
style="width: {{ $uploadTrends->max('count') > 0 ? ($trend->count / $uploadTrends->max('count') * 100) : 0 }}%">
<span class="text-xs font-medium text-white">{{ $trend->count }}</span>
</div>
</div>
</div>
</div>
</div>
@endforeach
</div>
</div>
</div>
@endif
<!-- Access Level Distribution -->
<div class="bg-white shadow sm:rounded-lg">
<div class="px-6 py-5 border-b border-gray-200">
<h3 class="text-lg font-medium text-gray-900">存取權限分布</h3>
</div>
<div class="px-6 py-5">
<div class="grid grid-cols-2 gap-4 md:grid-cols-4">
@foreach($accessLevelStats as $stat)
<div class="text-center p-4 border rounded-lg">
<div class="text-3xl font-bold text-indigo-600">{{ $stat->count }}</div>
<div class="mt-1 text-sm text-gray-500">
@if($stat->access_level === 'public') 公開
@elseif($stat->access_level === 'members') 會員
@elseif($stat->access_level === 'admin') 管理員
@else 理事會
@endif
</div>
</div>
@endforeach
</div>
</div>
</div>
<!-- Recent Activity -->
@if($recentActivity->isNotEmpty())
<div class="bg-white shadow sm:rounded-lg">
<div class="px-6 py-5 border-b border-gray-200">
<h3 class="text-lg font-medium text-gray-900">最近活動30天內</h3>
</div>
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">時間</th>
<th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">使用者</th>
<th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">文件</th>
<th class="px-6 py-3 text-left text-xs font-medium uppercase tracking-wider text-gray-500">動作</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-200 bg-white">
@foreach($recentActivity as $log)
<tr>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
{{ $log->accessed_at->format('Y-m-d H:i') }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
{{ $log->getUserDisplay() }}
</td>
<td class="px-6 py-4 text-sm text-gray-900">
<a href="{{ route('admin.documents.show', $log->document) }}" class="hover:text-indigo-600">
{{ $log->document->title }}
</a>
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
<span class="inline-flex rounded-full px-2 py-1 text-xs font-semibold
{{ $log->action === 'view' ? 'bg-blue-100 text-blue-800' : 'bg-green-100 text-green-800' }}">
{{ $log->getActionLabel() }}
</span>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endif
</div>
</div>
</x-app-layout>