Skip to content

Commit 9dbff16

Browse files
committed
add search feeds in admin
1 parent 8d1e88b commit 9dbff16

File tree

2 files changed

+92
-5
lines changed

2 files changed

+92
-5
lines changed

app/src/Controllers/AdminController.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function feeds(ServerRequestInterface $request): ResponseInterface
139139
$perPage = 50;
140140
$offset = ($page - 1) * $perPage;
141141
$status = $params['status'] ?? '';
142+
$search = $params['search'] ?? '';
142143

143144
$query = "
144145
SELECT f.*,
@@ -148,13 +149,27 @@ public function feeds(ServerRequestInterface $request): ResponseInterface
148149
";
149150
$countQuery = "SELECT COUNT(*) FROM feeds f";
150151
$queryParams = [];
152+
$whereConditions = [];
153+
154+
if (!empty($search)) {
155+
$searchPattern = '%' . $search . '%';
156+
$whereConditions[] = "(f.title LIKE %s OR f.feed_url LIKE %s OR f.site_url LIKE %s)";
157+
$queryParams[] = $searchPattern;
158+
$queryParams[] = $searchPattern;
159+
$queryParams[] = $searchPattern;
160+
}
151161

152162
if (!empty($status) && in_array($status, ['online', 'offline', 'paused', 'pending', 'rejected'])) {
153-
$query .= " WHERE f.status = %s";
154-
$countQuery .= " WHERE f.status = %s";
163+
$whereConditions[] = "f.status = %s";
155164
$queryParams[] = $status;
156165
}
157166

167+
if (!empty($whereConditions)) {
168+
$whereClause = " WHERE " . implode(" AND ", $whereConditions);
169+
$query .= $whereClause;
170+
$countQuery .= $whereClause;
171+
}
172+
158173
$query .= " ORDER BY f.title LIMIT %i, %i";
159174
$finalQueryParams = [...$queryParams, $offset, $perPage];
160175

@@ -190,11 +205,13 @@ public function feeds(ServerRequestInterface $request): ResponseInterface
190205
'allCategories' => $allCategories,
191206
'allTags' => $allTags,
192207
'currentStatus' => $status,
208+
'searchQuery' => $search,
193209
'pagination' => [
194210
'current' => $page,
195211
'total' => $totalPages,
196212
'baseUrl' => '/admin/feeds?' . http_build_query(array_filter([
197-
'status' => $status
213+
'status' => $status,
214+
'search' => $search
198215
]))
199216
],
200217
'title' => 'Gerenciar Feeds'

app/templates/admin/feeds.php

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,26 @@
2121
<!-- Filters and Bulk Actions -->
2222
<div class="card-body border-bottom">
2323
<div class="row g-3 align-items-end">
24+
<!-- Search -->
25+
<div class="col-md-4">
26+
<label for="search-input" class="form-label small fw-medium"><?= __('common.search') ?></label>
27+
<div class="input-group">
28+
<input type="text" id="search-input" class="form-control" placeholder="Buscar feeds..." value="<?= $this->e($searchQuery ?? '') ?>">
29+
<button class="btn btn-primary" type="button" id="search-btn">
30+
<i class="bi bi-search"></i>
31+
</button>
32+
<?php if (!empty($searchQuery)): ?>
33+
<button class="btn btn-outline-secondary" type="button" id="clear-search-btn">
34+
<i class="bi bi-x-lg"></i>
35+
</button>
36+
<?php endif; ?>
37+
</div>
38+
</div>
39+
2440
<!-- Status Filter -->
2541
<div class="col-md-4">
2642
<label for="status-filter" class="form-label small fw-medium"><?= __('admin.feeds.filter_status') ?></label>
27-
<select id="status-filter" class="form-select" onchange="window.location.href='/admin/feeds?status=' + this.value">
43+
<select id="status-filter" class="form-select">
2844
<option value=""><?= __('admin.feeds.all_status') ?></option>
2945
<option value="online" <?= $currentStatus === 'online' ? 'selected' : '' ?>><?= __('status.online') ?></option>
3046
<option value="offline" <?= $currentStatus === 'offline' ? 'selected' : '' ?>><?= __('status.offline') ?></option>
@@ -35,7 +51,7 @@
3551
</div>
3652

3753
<!-- Bulk Actions -->
38-
<div class="col-md-8">
54+
<div class="col-md-4">
3955
<div class="d-flex gap-2 flex-wrap">
4056
<button id="bulk-categories-btn" class="btn btn-outline-primary" disabled>
4157
<i class="bi bi-folder me-1"></i>
@@ -338,6 +354,60 @@
338354
<?php $this->start('scripts') ?>
339355
<script>
340356
document.addEventListener('DOMContentLoaded', function() {
357+
// Search functionality
358+
const searchInput = document.getElementById('search-input');
359+
const searchBtn = document.getElementById('search-btn');
360+
const clearSearchBtn = document.getElementById('clear-search-btn');
361+
const statusFilter = document.getElementById('status-filter');
362+
363+
function performSearch() {
364+
const searchValue = searchInput.value.trim();
365+
const statusValue = statusFilter.value;
366+
const params = new URLSearchParams();
367+
368+
if (searchValue) {
369+
params.append('search', searchValue);
370+
}
371+
if (statusValue) {
372+
params.append('status', statusValue);
373+
}
374+
375+
window.location.href = '/admin/feeds?' + params.toString();
376+
}
377+
378+
searchBtn.addEventListener('click', performSearch);
379+
380+
searchInput.addEventListener('keypress', function(e) {
381+
if (e.key === 'Enter') {
382+
performSearch();
383+
}
384+
});
385+
386+
if (clearSearchBtn) {
387+
clearSearchBtn.addEventListener('click', function() {
388+
const params = new URLSearchParams();
389+
const statusValue = statusFilter.value;
390+
if (statusValue) {
391+
params.append('status', statusValue);
392+
}
393+
window.location.href = '/admin/feeds?' + params.toString();
394+
});
395+
}
396+
397+
statusFilter.addEventListener('change', function() {
398+
const searchValue = searchInput.value.trim();
399+
const params = new URLSearchParams();
400+
401+
if (searchValue) {
402+
params.append('search', searchValue);
403+
}
404+
if (this.value) {
405+
params.append('status', this.value);
406+
}
407+
408+
window.location.href = '/admin/feeds?' + params.toString();
409+
});
410+
341411
function showModal(modalElement) {
342412
modalElement.classList.add('show');
343413
modalElement.style.display = 'block';

0 commit comments

Comments
 (0)