datamatters24 commited on
Commit
ffc3d8c
·
verified ·
1 Parent(s): d09bb98

Upload web/src/views/browse.php with huggingface_hub

Browse files
Files changed (1) hide show
  1. web/src/views/browse.php +236 -0
web/src/views/browse.php ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Browse / Document Listing
4
+ *
5
+ * Variables:
6
+ * $collection - Collection slug (source_section)
7
+ * $collectionName - Human-readable collection name
8
+ * $documents - Array of documents with: id, file_path, pages, file_size, processed_at
9
+ * $total - Total document count
10
+ * $page - Current page number
11
+ * $perPage - Results per page
12
+ * $sort - Current sort field (name, pages, size)
13
+ */
14
+
15
+ $page = $page ?? 1;
16
+ $perPage = $perPage ?? 25;
17
+ $sort = $sort ?? 'name';
18
+ $totalPages = ($perPage > 0) ? (int)ceil(($total ?? 0) / $perPage) : 1;
19
+
20
+ /**
21
+ * Format bytes to human-readable size
22
+ */
23
+ function formatSizeBrowse(int $bytes): string {
24
+ if ($bytes >= 1073741824) {
25
+ return number_format($bytes / 1073741824, 1) . ' GB';
26
+ } elseif ($bytes >= 1048576) {
27
+ return number_format($bytes / 1048576, 1) . ' MB';
28
+ } elseif ($bytes >= 1024) {
29
+ return number_format($bytes / 1024, 1) . ' KB';
30
+ }
31
+ return $bytes . ' B';
32
+ }
33
+
34
+ /**
35
+ * Extract filename from full path
36
+ */
37
+ function extractFilename(string $path): string {
38
+ return basename($path);
39
+ }
40
+
41
+ /**
42
+ * Build sort URL preserving current parameters
43
+ */
44
+ function sortUrl(string $collection, string $field, string $currentSort): string {
45
+ $dir = 'asc';
46
+ if ($field === $currentSort) {
47
+ $dir = 'desc';
48
+ }
49
+ return '/browse/' . urlencode($collection) . '?sort=' . urlencode($field) . '&dir=' . $dir;
50
+ }
51
+
52
+ /**
53
+ * Sort indicator arrow
54
+ */
55
+ function sortIndicator(string $field, string $currentSort): string {
56
+ if ($field === $currentSort) {
57
+ return '<svg class="inline h-4 w-4 ml-1" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M19 9l-7 7-7-7" /></svg>';
58
+ }
59
+ return '<svg class="inline h-4 w-4 ml-1 opacity-0 group-hover:opacity-50" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M8 9l4-4 4 4m0 6l-4 4-4-4" /></svg>';
60
+ }
61
+
62
+ $title = htmlspecialchars($collectionName ?? 'Browse') . ' - Research Document Archive';
63
+ $content = '';
64
+ ob_start();
65
+ ?>
66
+
67
+ <!-- Header -->
68
+ <div class="mb-5">
69
+ <!-- Breadcrumb -->
70
+ <nav class="flex items-center text-xs text-gray-500 mb-3" aria-label="Breadcrumb">
71
+ <a href="/" class="hover:text-gray-700 transition-colors">Home</a>
72
+ <svg class="h-3 w-3 mx-1.5 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
73
+ <path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
74
+ </svg>
75
+ <span class="text-gray-900 font-medium"><?= htmlspecialchars($collectionName ?? '') ?></span>
76
+ </nav>
77
+
78
+ <div class="flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3">
79
+ <div>
80
+ <h1 class="text-xl font-bold text-gray-900"><?= htmlspecialchars($collectionName ?? 'Documents') ?></h1>
81
+ <p class="mt-0.5 text-sm text-gray-600">
82
+ <?= number_format($total ?? 0) ?> document<?= ($total ?? 0) !== 1 ? 's' : '' ?> in this collection
83
+ </p>
84
+ </div>
85
+
86
+ <!-- Sort Controls -->
87
+ <div class="flex items-center space-x-2">
88
+ <span class="text-sm text-gray-500">Sort by:</span>
89
+ <div class="inline-flex rounded-lg border border-gray-200 bg-white shadow-sm">
90
+ <a href="<?= sortUrl($collection, 'name', $sort) ?>"
91
+ class="group px-3 py-2 text-sm font-medium rounded-l-lg transition-colors
92
+ <?= $sort === 'name' ? 'bg-blue-50 text-blue-700' : 'text-gray-600 hover:bg-gray-50' ?>">
93
+ Name<?= sortIndicator('name', $sort) ?>
94
+ </a>
95
+ <a href="<?= sortUrl($collection, 'pages', $sort) ?>"
96
+ class="group px-3 py-2 text-sm font-medium border-l border-gray-200 transition-colors
97
+ <?= $sort === 'pages' ? 'bg-blue-50 text-blue-700' : 'text-gray-600 hover:bg-gray-50' ?>">
98
+ Pages<?= sortIndicator('pages', $sort) ?>
99
+ </a>
100
+ <a href="<?= sortUrl($collection, 'size', $sort) ?>"
101
+ class="group px-3 py-2 text-sm font-medium border-l border-gray-200 rounded-r-lg transition-colors
102
+ <?= $sort === 'size' ? 'bg-blue-50 text-blue-700' : 'text-gray-600 hover:bg-gray-50' ?>">
103
+ Size<?= sortIndicator('size', $sort) ?>
104
+ </a>
105
+ </div>
106
+ </div>
107
+ </div>
108
+ </div>
109
+
110
+ <!-- Document Table -->
111
+ <?php if (!empty($documents)): ?>
112
+
113
+ <!-- Desktop Table -->
114
+ <div class="hidden md:block bg-white rounded-lg shadow-sm border border-gray-200 overflow-hidden">
115
+ <table class="min-w-full divide-y divide-gray-200">
116
+ <thead class="bg-gray-50">
117
+ <tr>
118
+ <th scope="col" class="px-4 py-2.5 text-left text-[11px] font-semibold text-gray-500 uppercase tracking-wider">
119
+ Document Name
120
+ </th>
121
+ <th scope="col" class="px-4 py-2.5 text-center text-[11px] font-semibold text-gray-500 uppercase tracking-wider w-20">
122
+ Pages
123
+ </th>
124
+ <th scope="col" class="px-4 py-2.5 text-center text-[11px] font-semibold text-gray-500 uppercase tracking-wider w-24">
125
+ Size
126
+ </th>
127
+ <th scope="col" class="px-4 py-2.5 text-center text-[11px] font-semibold text-gray-500 uppercase tracking-wider w-28">
128
+ Processed
129
+ </th>
130
+ <th scope="col" class="relative px-4 py-2.5 w-16">
131
+ <span class="sr-only">View</span>
132
+ </th>
133
+ </tr>
134
+ </thead>
135
+ <tbody class="divide-y divide-gray-100">
136
+ <?php foreach ($documents as $doc): ?>
137
+ <?php $filename = extractFilename($doc['file_path'] ?? ''); ?>
138
+ <tr class="hover:bg-gray-50 transition-colors">
139
+ <td class="px-4 py-2.5">
140
+ <a href="/document/<?= (int)($doc['id'] ?? 0) ?>" class="group flex items-center">
141
+ <svg class="flex-shrink-0 h-4 w-4 text-red-400 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
142
+ <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />
143
+ </svg>
144
+ <span class="text-xs font-medium text-gray-900 group-hover:text-blue-600 transition-colors truncate max-w-md">
145
+ <?= htmlspecialchars($filename) ?>
146
+ </span>
147
+ </a>
148
+ <?php if (!empty($doc['topics'])): ?>
149
+ <div class="mt-1 flex flex-wrap gap-1">
150
+ <?php foreach ($doc['topics'] as $topic => $score):
151
+ if ($score < 0.3) continue;
152
+ ?>
153
+ <span class="inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium bg-indigo-50 text-indigo-700">
154
+ <?= htmlspecialchars($topic) ?>
155
+ </span>
156
+ <?php endforeach; ?>
157
+ </div>
158
+ <?php endif; ?>
159
+ </td>
160
+ <td class="px-4 py-2.5 text-center text-xs text-gray-600">
161
+ <?= number_format($doc['total_pages'] ?? 0) ?>
162
+ </td>
163
+ <td class="px-4 py-2.5 text-center text-xs text-gray-600">
164
+ <?= formatSizeBrowse($doc['file_size'] ?? 0) ?>
165
+ </td>
166
+ <td class="px-4 py-2.5 text-center text-xs text-gray-500">
167
+ <?php if (!empty($doc['processed_at'])): ?>
168
+ <?= date('M j, Y', strtotime($doc['processed_at'])) ?>
169
+ <?php else: ?>
170
+ <span class="text-gray-400">&mdash;</span>
171
+ <?php endif; ?>
172
+ </td>
173
+ <td class="px-4 py-2.5 text-right">
174
+ <a href="/document/<?= (int)($doc['id'] ?? 0) ?>"
175
+ class="text-blue-600 hover:text-blue-800 text-xs font-medium transition-colors">
176
+ View
177
+ </a>
178
+ </td>
179
+ </tr>
180
+ <?php endforeach; ?>
181
+ </tbody>
182
+ </table>
183
+ </div>
184
+
185
+ <!-- Mobile Card List -->
186
+ <div class="md:hidden space-y-3">
187
+ <?php foreach ($documents as $doc): ?>
188
+ <?php $filename = extractFilename($doc['file_path'] ?? ''); ?>
189
+ <a href="/document/<?= (int)($doc['id'] ?? 0) ?>"
190
+ class="block bg-white rounded-lg shadow-sm border border-gray-200 p-4 hover:shadow-md transition-shadow">
191
+ <div class="flex items-start space-x-3">
192
+ <svg class="flex-shrink-0 h-5 w-5 text-red-400 mt-0.5" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
193
+ <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m2.25 0H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />
194
+ </svg>
195
+ <div class="min-w-0 flex-1">
196
+ <p class="text-sm font-medium text-gray-900 truncate"><?= htmlspecialchars($filename) ?></p>
197
+ <div class="mt-2 flex items-center space-x-4 text-xs text-gray-500">
198
+ <span><?= number_format($doc['total_pages'] ?? 0) ?> pages</span>
199
+ <span><?= formatSizeBrowse($doc['file_size'] ?? 0) ?></span>
200
+ <?php if (!empty($doc['processed_at'])): ?>
201
+ <span><?= date('M j, Y', strtotime($doc['processed_at'])) ?></span>
202
+ <?php endif; ?>
203
+ </div>
204
+ </div>
205
+ <svg class="flex-shrink-0 h-5 w-5 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
206
+ <path stroke-linecap="round" stroke-linejoin="round" d="M8.25 4.5l7.5 7.5-7.5 7.5" />
207
+ </svg>
208
+ </div>
209
+ </a>
210
+ <?php endforeach; ?>
211
+ </div>
212
+
213
+ <!-- Pagination -->
214
+ <?php
215
+ $currentPage = $page;
216
+ $baseUrl = '/browse/' . urlencode($collection) . '?sort=' . urlencode($sort);
217
+ include __DIR__ . '/partials/pagination.php';
218
+ ?>
219
+
220
+ <?php else: ?>
221
+ <div class="text-center py-10 bg-white rounded-lg border border-gray-200">
222
+ <svg class="mx-auto h-8 w-8 text-gray-400" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="1.5">
223
+ <path stroke-linecap="round" stroke-linejoin="round" d="M19.5 14.25v-2.625a3.375 3.375 0 00-3.375-3.375h-1.5A1.125 1.125 0 0113.5 7.125v-1.5a3.375 3.375 0 00-3.375-3.375H8.25m6.75 12H9.75m0 0l3-3m-3 3l3 3m2.25-12H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 00-9-9z" />
224
+ </svg>
225
+ <h3 class="mt-3 text-sm font-medium text-gray-900">No documents found</h3>
226
+ <p class="mt-1 text-xs text-gray-500">This collection does not contain any documents yet.</p>
227
+ <a href="/" class="mt-4 inline-flex items-center px-3 py-1.5 text-xs font-medium text-blue-600 bg-blue-50 rounded-md hover:bg-blue-100 transition-colors">
228
+ Back to Home
229
+ </a>
230
+ </div>
231
+ <?php endif; ?>
232
+
233
+ <?php
234
+ $content = ob_get_clean();
235
+ include __DIR__ . '/layout.php';
236
+ ?>