Reports: replace free-text filter with a dropdown of reported users
Builds a deduplicated, alphabetically sorted list of reported users from the currently status-filtered reports and renders it as a <select>. Filtering is now an exact match on reported_id (via a data-reported-id attribute per row) instead of substring matching against lowercased names, so it no longer also matches on the reporter's name. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
5a2ff73836
commit
c3f2f61d3e
3 changed files with 33 additions and 12 deletions
|
|
@ -780,8 +780,9 @@ input[type="datetime-local"]::-webkit-calendar-picker-indicator {
|
||||||
margin-top: 1rem;
|
margin-top: 1rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
.report-user-filter-input {
|
.report-user-filter-select {
|
||||||
display: block;
|
display: block;
|
||||||
|
width: auto;
|
||||||
max-width: 320px;
|
max-width: 320px;
|
||||||
margin-top: 0.75rem;
|
margin-top: 0.75rem;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,21 +122,19 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Nach Nutzer filtern (gemeldet oder Melder) ----
|
// ---- Nach gemeldetem Nutzer filtern (Dropdown) ----
|
||||||
function initUserFilter() {
|
function initUserFilter() {
|
||||||
var input = document.getElementById('report-user-filter');
|
var select = document.getElementById('report-user-filter');
|
||||||
var rows = document.querySelectorAll('.report-row');
|
var rows = document.querySelectorAll('.report-row');
|
||||||
var emptyMessage = document.getElementById('report-filter-empty');
|
var emptyMessage = document.getElementById('report-filter-empty');
|
||||||
if (!input || !rows.length) return;
|
if (!select || !rows.length) return;
|
||||||
|
|
||||||
input.addEventListener('input', function () {
|
select.addEventListener('change', function () {
|
||||||
var query = input.value.trim().toLowerCase();
|
var selectedId = select.value;
|
||||||
var visibleCount = 0;
|
var visibleCount = 0;
|
||||||
|
|
||||||
rows.forEach(function (row) {
|
rows.forEach(function (row) {
|
||||||
var matches = query === ''
|
var matches = selectedId === '' || row.getAttribute('data-reported-id') === selectedId;
|
||||||
|| (row.getAttribute('data-reported-name') || '').indexOf(query) !== -1
|
|
||||||
|| (row.getAttribute('data-reporter-name') || '').indexOf(query) !== -1;
|
|
||||||
row.hidden = !matches;
|
row.hidden = !matches;
|
||||||
if (matches) visibleCount++;
|
if (matches) visibleCount++;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
28
reports.php
28
reports.php
|
|
@ -51,6 +51,23 @@ if (!empty($allDiscordIds)) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Fuer das "Nach Nutzer filtern"-Dropdown: jeder gemeldete Nutzer im aktuell gefilterten
|
||||||
|
// Status genau einmal, alphabetisch sortiert.
|
||||||
|
$reportedUsersList = [];
|
||||||
|
$seenReportedIds = [];
|
||||||
|
foreach ($reports as $r) {
|
||||||
|
$rid = (int) ($r['reported_id'] ?? 0);
|
||||||
|
if (isset($seenReportedIds[$rid])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$seenReportedIds[$rid] = true;
|
||||||
|
$reportedUsersList[] = [
|
||||||
|
'id' => $rid,
|
||||||
|
'name' => premade_name_for($rid, $namesByDiscordId, (string) ($r['reported_name'] ?? '')),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
usort($reportedUsersList, fn (array $a, array $b): int => strcasecmp($a['name'], $b['name']));
|
||||||
|
|
||||||
$statusLabels = ['active' => 'Aktiv', 'archived' => 'Archiviert', 'all' => 'Alle'];
|
$statusLabels = ['active' => 'Aktiv', 'archived' => 'Archiviert', 'all' => 'Alle'];
|
||||||
$emptyLabels = [
|
$emptyLabels = [
|
||||||
'active' => 'Aktuell liegen keine aktiven Reports vor.',
|
'active' => 'Aktuell liegen keine aktiven Reports vor.',
|
||||||
|
|
@ -87,8 +104,13 @@ include __DIR__ . '/includes/header.php';
|
||||||
<a href="/reports.php?status=<?= e($value) ?>" class="filter-tab<?= $status === $value ? ' active' : '' ?>"><?= e($label) ?></a>
|
<a href="/reports.php?status=<?= e($value) ?>" class="filter-tab<?= $status === $value ? ' active' : '' ?>"><?= e($label) ?></a>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php if (!empty($reports)): ?>
|
<?php if (!empty($reportedUsersList)): ?>
|
||||||
<input type="text" id="report-user-filter" placeholder="Nach Nutzer filtern (gemeldet oder Melder)…" class="report-user-filter-input">
|
<select id="report-user-filter" class="report-user-filter-select">
|
||||||
|
<option value="">Alle gemeldeten Nutzer</option>
|
||||||
|
<?php foreach ($reportedUsersList as $reportedUserOption): ?>
|
||||||
|
<option value="<?= (int) $reportedUserOption['id'] ?>"><?= e($reportedUserOption['name']) ?></option>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</select>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
@ -132,7 +154,7 @@ include __DIR__ . '/includes/header.php';
|
||||||
$timestamp = (int) ($report['timestamp'] ?? 0);
|
$timestamp = (int) ($report['timestamp'] ?? 0);
|
||||||
?>
|
?>
|
||||||
<?php $evidenceIsLink = $evidence !== '' && preg_match('#^https?://#i', $evidence) === 1; ?>
|
<?php $evidenceIsLink = $evidence !== '' && preg_match('#^https?://#i', $evidence) === 1; ?>
|
||||||
<tr class="report-row" data-reported-name="<?= e(mb_strtolower($reportedName)) ?>" data-reporter-name="<?= e(mb_strtolower($reporterName)) ?>">
|
<tr class="report-row" data-reported-id="<?= $reportedId ?>">
|
||||||
<td>
|
<td>
|
||||||
<div class="report-reported-cell">
|
<div class="report-reported-cell">
|
||||||
<?= avatar_html($reportedUser, 28) ?>
|
<?= avatar_html($reportedUser, 28) ?>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue