Lumipunkte ranking shows the top 24, leadership can expand the rest

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Maaxxs 2026-09-22 10:18:44 +02:00
parent c58e7dd0c3
commit c62c996a3f
5 changed files with 45 additions and 16 deletions

View file

@ -2562,6 +2562,9 @@ button.contribution-chip-remove:hover { background: none; color: var(--danger);
.contribution-award { flex-wrap: wrap; } .contribution-award { flex-wrap: wrap; }
} }
.contribution-more { display: flex; justify-content: center; margin-top: 1rem; }
.contribution-card[hidden] { display: none; }
.contribution-top-label { .contribution-top-label {
padding: 0.1rem 0.5rem; padding: 0.1rem 0.5rem;
border: 1px solid var(--gold); border: 1px solid var(--gold);

View file

@ -10,16 +10,34 @@
var ranking = document.getElementById('contribution-ranking'); var ranking = document.getElementById('contribution-ranking');
if (rankingSearch && ranking) { if (rankingSearch && ranking) {
var noMatch = document.getElementById('contribution-no-match'); var noMatch = document.getElementById('contribution-no-match');
rankingSearch.addEventListener('input', function () { var showAll = document.getElementById('contribution-show-all');
var expanded = false;
// Ohne Suche nur die ersten Plaetze (Karten mit data-extra bleiben eingeklappt, bis man
// "Alle anzeigen" drueckt); mit Suche werden alle Treffer gezeigt.
function applyRanking() {
var term = rankingSearch.value.trim().toLowerCase(); var term = rankingSearch.value.trim().toLowerCase();
var visible = 0; var visible = 0;
ranking.querySelectorAll('.contribution-card').forEach(function (card) { ranking.querySelectorAll('.contribution-card').forEach(function (card) {
card.hidden = !matches(card, term); var collapsed = card.hasAttribute('data-extra') && !expanded && term === '';
card.hidden = collapsed || !matches(card, term);
if (!card.hidden) visible++; if (!card.hidden) visible++;
}); });
if (noMatch) noMatch.hidden = visible > 0; if (noMatch) noMatch.hidden = visible > 0;
if (showAll) {
showAll.hidden = term !== '';
showAll.textContent = expanded ? showAll.dataset.less : showAll.dataset.more;
}
}
rankingSearch.addEventListener('input', applyRanking);
if (showAll) {
showAll.addEventListener('click', function () {
expanded = !expanded;
applyRanking();
}); });
} }
}
// ---- Formular "Punkte vergeben" ---- // ---- Formular "Punkte vergeben" ----
var form = document.getElementById('contribution-form'); var form = document.getElementById('contribution-form');

View file

@ -36,9 +36,9 @@ foreach ($balances as $member) {
$myEntry = $member; $myEntry = $member;
} }
} }
$visibleBalances = $canViewAll // Gezeigt werden immer nur die ersten Plaetze (genau CONTRIBUTION_PUBLIC_RANKS Karten). Mit voller
? $balances // Sicht kommen die uebrigen mit auf die Seite, bleiben aber eingeklappt (aufklappen / Suche).
: array_values(array_filter($balances, static fn (array $m): bool => (int) $m['rank'] <= CONTRIBUTION_PUBLIC_RANKS)); $visibleBalances = $canViewAll ? $balances : array_slice($balances, 0, CONTRIBUTION_PUBLIC_RANKS);
$visibleIds = array_map(static fn (array $m): int => (int) $m['id'], $visibleBalances); $visibleIds = array_map(static fn (array $m): int => (int) $m['id'], $visibleBalances);
$showMyEntrySeparately = $myEntry !== null && !in_array((int) $myEntry['id'], $visibleIds, true); $showMyEntrySeparately = $myEntry !== null && !in_array((int) $myEntry['id'], $visibleIds, true);
$hiddenCount = count($balances) - count($visibleBalances); $hiddenCount = count($balances) - count($visibleBalances);
@ -77,13 +77,13 @@ $awards = $canSeeHistory ? contribution_awards($filterUserId, $perPage, ($page -
$displayName = static fn (array $u): string => (string) ($u['display_name'] !== '' ? $u['display_name'] : $u['username']); $displayName = static fn (array $u): string => (string) ($u['display_name'] !== '' ? $u['display_name'] : $u['username']);
$renderCard = static function (array $member) use ($currentUser, $canManage, $canSeeHistory, $displayName): void { $renderCard = static function (array $member, bool $extra = false) use ($currentUser, $canManage, $canSeeHistory, $displayName): void {
?> ?>
<?php <?php
$isMe = (int) $member['id'] === (int) $currentUser['id']; $isMe = (int) $member['id'] === (int) $currentUser['id'];
$rankClass = in_array((int) $member['rank'], [1, 2, 3], true) && (int) $member['points'] > 0 ? ' rank-' . (int) $member['rank'] : ''; $rankClass = in_array((int) $member['rank'], [1, 2, 3], true) && (int) $member['points'] > 0 ? ' rank-' . (int) $member['rank'] : '';
?> ?>
<div class="contribution-card<?= $isMe ? ' is-me' : '' ?><?= $rankClass ?>" data-name="<?= e(mb_strtolower($displayName($member))) ?>"> <div class="contribution-card<?= $isMe ? ' is-me' : '' ?><?= $rankClass ?>" data-name="<?= e(mb_strtolower($displayName($member))) ?>"<?= $extra ? ' data-extra hidden' : '' ?>>
<?php if ($canSeeHistory): ?> <?php if ($canSeeHistory): ?>
<a class="contribution-card-link" href="/contributions.php?user=<?= (int) $member['id'] ?>#verlauf" title="Verlauf von <?= e($displayName($member)) ?>"> <a class="contribution-card-link" href="/contributions.php?user=<?= (int) $member['id'] ?>#verlauf" title="Verlauf von <?= e($displayName($member)) ?>">
<?php else: ?> <?php else: ?>
@ -123,18 +123,26 @@ include __DIR__ . '/includes/header.php';
<div class="panel"> <div class="panel">
<div class="contribution-head"> <div class="contribution-head">
<h2>Rangliste<?= $canViewAll ? '' : ' <span class="contribution-top-label">Top ' . CONTRIBUTION_PUBLIC_RANKS . '</span>' ?></h2> <h2>Rangliste <span class="contribution-top-label">Top <?= CONTRIBUTION_PUBLIC_RANKS ?></span></h2>
<input type="search" id="contribution-search" placeholder="Mitglied suchen …" autocomplete="off"> <input type="search" id="contribution-search" placeholder="Mitglied suchen …" autocomplete="off">
</div> </div>
<?php if (empty($balances)): ?> <?php if (empty($balances)): ?>
<p class="text-muted">Noch keine Mitglieder.</p> <p class="text-muted">Noch keine Mitglieder.</p>
<?php else: ?> <?php else: ?>
<div class="contribution-grid" id="contribution-ranking"> <div class="contribution-grid" id="contribution-ranking" data-limit="<?= CONTRIBUTION_PUBLIC_RANKS ?>">
<?php foreach ($visibleBalances as $member): ?> <?php foreach ($visibleBalances as $index => $member): ?>
<?php $renderCard($member); ?> <?php $renderCard($member, $index >= CONTRIBUTION_PUBLIC_RANKS); ?>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
<p class="text-muted" id="contribution-no-match" hidden>Kein Mitglied passt zur Suche.</p> <p class="text-muted" id="contribution-no-match" hidden>Kein Mitglied passt zur Suche.</p>
<?php if (count($visibleBalances) > CONTRIBUTION_PUBLIC_RANKS): ?>
<div class="contribution-more">
<button type="button" class="button button-secondary" id="contribution-show-all"
data-more="Alle <?= count($visibleBalances) ?> anzeigen" data-less="Nur die besten <?= CONTRIBUTION_PUBLIC_RANKS ?> anzeigen">
Alle <?= count($visibleBalances) ?> anzeigen
</button>
</div>
<?php endif; ?>
<?php if ($showMyEntrySeparately): ?> <?php if ($showMyEntrySeparately): ?>
<div class="contribution-own"> <div class="contribution-own">
<h3>Dein Platz</h3> <h3>Dein Platz</h3>

View file

@ -22,9 +22,9 @@ const CONTRIBUTION_SYSTEM_CATEGORIES = [
'shop' => 'Lumishop', 'shop' => 'Lumishop',
]; ];
// So viele Plaetze der Rangliste sieht jeder mit contributions.view - den Rest nur mit // So viele Plaetze zeigt die Rangliste. Mit contributions.view sieht man nur diese, mit
// contributions.view_all (oder contributions.manage). // contributions.view_all (oder contributions.manage) laesst sich der Rest aufklappen und durchsuchen.
const CONTRIBUTION_PUBLIC_RANKS = 25; const CONTRIBUTION_PUBLIC_RANKS = 24;
// Obergrenze pro Mitglied und Vergabe - schuetzt vor Tippfehlern wie 10000 statt 100. // Obergrenze pro Mitglied und Vergabe - schuetzt vor Tippfehlern wie 10000 statt 100.
const CONTRIBUTION_MAX_POINTS = 10000; const CONTRIBUTION_MAX_POINTS = 10000;

View file

@ -26,7 +26,7 @@ const CORE_PERMISSIONS = [
['key' => 'warehouse.view', 'description' => 'Lagerhaus: Bestand und Verlauf einsehen'], ['key' => 'warehouse.view', 'description' => 'Lagerhaus: Bestand und Verlauf einsehen'],
['key' => 'warehouse.manage', 'description' => 'Lagerhaus: Gegenstände einlagern, entnehmen und Einträge löschen'], ['key' => 'warehouse.manage', 'description' => 'Lagerhaus: Gegenstände einlagern, entnehmen und Einträge löschen'],
['key' => 'contributions.view', 'description' => 'Lumipunkte: Punktestände und Verlauf einsehen'], ['key' => 'contributions.view', 'description' => 'Lumipunkte: Punktestände und Verlauf einsehen'],
['key' => 'contributions.view_all', 'description' => 'Lumipunkte: vollständige Rangliste sehen (sonst nur die besten 25)'], ['key' => 'contributions.view_all', 'description' => 'Lumipunkte: vollständige Rangliste sehen (sonst nur die besten 24)'],
['key' => 'contributions.manage', 'description' => 'Lumipunkte vergeben, abziehen und Vergaben löschen'], ['key' => 'contributions.manage', 'description' => 'Lumipunkte vergeben, abziehen und Vergaben löschen'],
['key' => 'shop.view', 'description' => 'Lumishop: Angebot ansehen und Gegenstände gegen Lumipunkte beantragen'], ['key' => 'shop.view', 'description' => 'Lumishop: Angebot ansehen und Gegenstände gegen Lumipunkte beantragen'],
['key' => 'shop.manage', 'description' => 'Lumishop: Kategorien, Gegenstände, Bestand und Preise verwalten, Anträge bewilligen oder ablehnen'], ['key' => 'shop.manage', 'description' => 'Lumishop: Kategorien, Gegenstände, Bestand und Preise verwalten, Anträge bewilligen oder ablehnen'],