Reports: add a live filter by reported/reporter user
A text input above the table filters rows client-side as you type, matching against both the reported and the reporter name (each row carries lowercased data-reported-name/data-reporter-name attributes). Shows a "no matches" message when the filter empties the table. Also consolidated the previously duplicated reports.js <script> include into a single unconditional one at the bottom of the page, since the filter needs it regardless of reports.manage permission. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
0dae6298af
commit
5a2ff73836
3 changed files with 37 additions and 3 deletions
|
|
@ -780,6 +780,12 @@ input[type="datetime-local"]::-webkit-calendar-picker-indicator {
|
|||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.report-user-filter-input {
|
||||
display: block;
|
||||
max-width: 320px;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.filter-tab {
|
||||
padding: 0.4rem 0.9rem;
|
||||
border-radius: 999px;
|
||||
|
|
|
|||
|
|
@ -122,6 +122,30 @@
|
|||
});
|
||||
}
|
||||
|
||||
// ---- Nach Nutzer filtern (gemeldet oder Melder) ----
|
||||
function initUserFilter() {
|
||||
var input = document.getElementById('report-user-filter');
|
||||
var rows = document.querySelectorAll('.report-row');
|
||||
var emptyMessage = document.getElementById('report-filter-empty');
|
||||
if (!input || !rows.length) return;
|
||||
|
||||
input.addEventListener('input', function () {
|
||||
var query = input.value.trim().toLowerCase();
|
||||
var visibleCount = 0;
|
||||
|
||||
rows.forEach(function (row) {
|
||||
var matches = query === ''
|
||||
|| (row.getAttribute('data-reported-name') || '').indexOf(query) !== -1
|
||||
|| (row.getAttribute('data-reporter-name') || '').indexOf(query) !== -1;
|
||||
row.hidden = !matches;
|
||||
if (matches) visibleCount++;
|
||||
});
|
||||
|
||||
if (emptyMessage) emptyMessage.hidden = visibleCount !== 0;
|
||||
});
|
||||
}
|
||||
|
||||
initAddWeightModal();
|
||||
initAddExclusionModal();
|
||||
initUserFilter();
|
||||
})();
|
||||
|
|
|
|||
10
reports.php
10
reports.php
|
|
@ -87,6 +87,9 @@ include __DIR__ . '/includes/header.php';
|
|||
<a href="/reports.php?status=<?= e($value) ?>" class="filter-tab<?= $status === $value ? ' active' : '' ?>"><?= e($label) ?></a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php if (!empty($reports)): ?>
|
||||
<input type="text" id="report-user-filter" placeholder="Nach Nutzer filtern (gemeldet oder Melder)…" class="report-user-filter-input">
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<?php if ($apiError): ?>
|
||||
|
|
@ -129,7 +132,7 @@ include __DIR__ . '/includes/header.php';
|
|||
$timestamp = (int) ($report['timestamp'] ?? 0);
|
||||
?>
|
||||
<?php $evidenceIsLink = $evidence !== '' && preg_match('#^https?://#i', $evidence) === 1; ?>
|
||||
<tr>
|
||||
<tr class="report-row" data-reported-name="<?= e(mb_strtolower($reportedName)) ?>" data-reporter-name="<?= e(mb_strtolower($reporterName)) ?>">
|
||||
<td>
|
||||
<div class="report-reported-cell">
|
||||
<?= avatar_html($reportedUser, 28) ?>
|
||||
|
|
@ -182,6 +185,7 @@ include __DIR__ . '/includes/header.php';
|
|||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p class="text-muted" id="report-filter-empty" hidden>Keine Reports passen zum Filter.</p>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
|
@ -341,10 +345,10 @@ include __DIR__ . '/includes/header.php';
|
|||
</form>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<script src="/assets/js/reports.js"></script>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<script src="/assets/js/reports.js"></script>
|
||||
|
||||
<?php include __DIR__ . '/includes/footer.php'; ?>
|
||||
|
|
|
|||
Loading…
Reference in a new issue