Reports: two-step popup for adding role weights instead of a full list
Roles at the default weight (1) are no longer listed - only roles with
an explicit, non-default point value show up, each editable/removable
inline. A new green "+ Rolle hinzufuegen" button opens a two-step popup:
pick one or more still-unconfigured roles, then set a single point
value applied to all of them at once (new report_action.php action
add_weights). Fixed two CSS specificity bugs while building this
(input[type=text] beating a plain class on width, and the generic
form{flex-direction:column} rule leaking into the inline edit row).
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
60661ef5fc
commit
ed4116414f
4 changed files with 281 additions and 14 deletions
|
|
@ -430,6 +430,15 @@ input[type="datetime-local"]::-webkit-calendar-picker-indicator {
|
||||||
.button-secondary { background: var(--bg-panel-alt); color: var(--text); border: 1px solid var(--border); }
|
.button-secondary { background: var(--bg-panel-alt); color: var(--text); border: 1px solid var(--border); }
|
||||||
.button-secondary:hover { background: #30304a; }
|
.button-secondary:hover { background: #30304a; }
|
||||||
|
|
||||||
|
.button-success { background: var(--success); color: #fff; }
|
||||||
|
.button-success:hover { background: #3d8b40; }
|
||||||
|
|
||||||
|
.button:disabled, button:disabled {
|
||||||
|
opacity: 0.5;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
.button:disabled:hover, button:disabled:hover { background: var(--gold); }
|
||||||
|
|
||||||
.inline-form { display: inline; }
|
.inline-form { display: inline; }
|
||||||
|
|
||||||
.badge {
|
.badge {
|
||||||
|
|
@ -1236,3 +1245,91 @@ input[type="datetime-local"]::-webkit-calendar-picker-indicator {
|
||||||
|
|
||||||
.raid-modal-feedback.success { color: var(--success); }
|
.raid-modal-feedback.success { color: var(--success); }
|
||||||
.raid-modal-feedback.error { color: var(--danger); }
|
.raid-modal-feedback.error { color: var(--danger); }
|
||||||
|
|
||||||
|
/* --- Reports: Punktwert-Liste + "Rolle hinzufuegen"-Popup --- */
|
||||||
|
|
||||||
|
.role-weight-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-weight-row {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.6rem;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
background: var(--bg-panel-alt);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-weight-dot {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 50%;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-weight-name {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* flex-shrink:0 auf beiden Formularen der Zeile - sonst nimmt sich .role-weight-name (flex:1)
|
||||||
|
den gesamten Platz und quetscht die Buttons/das Eingabefeld unter ihre Mindestbreite,
|
||||||
|
wodurch der Speichern-Button in die naechste Zeile umbricht. */
|
||||||
|
.role-weight-row > form {
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-weight-form {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.4rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* input[type="text"] (Attribut-Selektor, hoehere Spezifitaet als eine einzelne Klasse) setzt
|
||||||
|
sonst width:100% und ueberstimmt die feste Breite hier. */
|
||||||
|
input.role-weight-input {
|
||||||
|
width: 70px;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-picker-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 0.5rem;
|
||||||
|
max-height: 340px;
|
||||||
|
overflow-y: auto;
|
||||||
|
margin: 1.25rem 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-picker-option {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 0.6rem;
|
||||||
|
padding: 0.5rem 0.75rem;
|
||||||
|
background: var(--bg-panel-alt);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 8px;
|
||||||
|
color: var(--text);
|
||||||
|
cursor: pointer;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.role-picker-option:hover { border-color: var(--gold); }
|
||||||
|
|
||||||
|
.role-picker-option input[type="checkbox"] { width: auto; flex-shrink: 0; }
|
||||||
|
|
||||||
|
.role-picker-dot {
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 50%;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
89
assets/js/reports.js
Normal file
89
assets/js/reports.js
Normal file
|
|
@ -0,0 +1,89 @@
|
||||||
|
(function () {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var modal = document.getElementById('report-add-role-modal');
|
||||||
|
var addBtn = document.getElementById('report-add-role-btn');
|
||||||
|
if (!modal || !addBtn) return;
|
||||||
|
|
||||||
|
var step1 = modal.querySelector('.report-role-step[data-step="1"]');
|
||||||
|
var step2 = modal.querySelector('.report-role-step[data-step="2"]');
|
||||||
|
var nextBtn = document.getElementById('report-role-step1-next');
|
||||||
|
var backBtn = document.getElementById('report-role-step2-back');
|
||||||
|
var submitBtn = document.getElementById('report-role-step2-submit');
|
||||||
|
var summaryEl = document.getElementById('report-role-step2-summary');
|
||||||
|
var pointsInput = document.getElementById('report-role-points');
|
||||||
|
var form = document.getElementById('report-add-role-form');
|
||||||
|
var pointsField = document.getElementById('report-add-role-points-field');
|
||||||
|
var idsContainer = document.getElementById('report-add-role-ids-container');
|
||||||
|
var closeBtn = modal.querySelector('.modal-close');
|
||||||
|
var checkboxes = modal.querySelectorAll('input[name="role_ids[]"]');
|
||||||
|
|
||||||
|
function showStep(n) {
|
||||||
|
step1.hidden = n !== 1;
|
||||||
|
step2.hidden = n !== 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateNextState() {
|
||||||
|
var anyChecked = Array.prototype.some.call(checkboxes, function (cb) { return cb.checked; });
|
||||||
|
nextBtn.disabled = !anyChecked;
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetModal() {
|
||||||
|
checkboxes.forEach(function (cb) { cb.checked = false; });
|
||||||
|
pointsInput.value = '1';
|
||||||
|
updateNextState();
|
||||||
|
showStep(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function openModal() {
|
||||||
|
resetModal();
|
||||||
|
modal.hidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeModal() {
|
||||||
|
modal.hidden = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
addBtn.addEventListener('click', openModal);
|
||||||
|
closeBtn.addEventListener('click', closeModal);
|
||||||
|
modal.addEventListener('click', function (e) {
|
||||||
|
if (e.target === modal) closeModal();
|
||||||
|
});
|
||||||
|
|
||||||
|
checkboxes.forEach(function (cb) {
|
||||||
|
cb.addEventListener('change', updateNextState);
|
||||||
|
});
|
||||||
|
|
||||||
|
nextBtn.addEventListener('click', function () {
|
||||||
|
var names = [];
|
||||||
|
checkboxes.forEach(function (cb) {
|
||||||
|
if (cb.checked) names.push(cb.getAttribute('data-role-name') || '');
|
||||||
|
});
|
||||||
|
summaryEl.textContent = names.join(', ');
|
||||||
|
showStep(2);
|
||||||
|
});
|
||||||
|
|
||||||
|
backBtn.addEventListener('click', function () {
|
||||||
|
showStep(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
submitBtn.addEventListener('click', function () {
|
||||||
|
var points = pointsInput.value.trim();
|
||||||
|
if (points === '' || isNaN(Number(points))) {
|
||||||
|
pointsInput.focus();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
idsContainer.innerHTML = '';
|
||||||
|
checkboxes.forEach(function (cb) {
|
||||||
|
if (!cb.checked) return;
|
||||||
|
var hidden = document.createElement('input');
|
||||||
|
hidden.type = 'hidden';
|
||||||
|
hidden.name = 'role_ids[]';
|
||||||
|
hidden.value = cb.value;
|
||||||
|
idsContainer.appendChild(hidden);
|
||||||
|
});
|
||||||
|
pointsField.value = points;
|
||||||
|
form.submit();
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
|
@ -44,6 +44,8 @@ try {
|
||||||
set_mute_threshold($threshold);
|
set_mute_threshold($threshold);
|
||||||
set_flash('success', 'Mute-Schwelle wurde gespeichert.');
|
set_flash('success', 'Mute-Schwelle wurde gespeichert.');
|
||||||
} elseif ($action === 'set_weights') {
|
} elseif ($action === 'set_weights') {
|
||||||
|
// Bearbeiten/Entfernen einzelner bereits konfigurierter Rollen (siehe role-weight-list) -
|
||||||
|
// "Entfernen" schickt hier einfach wieder den Default-Wert 1 mit.
|
||||||
$weights = is_array($_POST['weights'] ?? null) ? $_POST['weights'] : [];
|
$weights = is_array($_POST['weights'] ?? null) ? $_POST['weights'] : [];
|
||||||
foreach ($weights as $roleId => $points) {
|
foreach ($weights as $roleId => $points) {
|
||||||
$roleId = (int) $roleId;
|
$roleId = (int) $roleId;
|
||||||
|
|
@ -54,6 +56,25 @@ try {
|
||||||
set_report_weight($roleId, $points);
|
set_report_weight($roleId, $points);
|
||||||
}
|
}
|
||||||
set_flash('success', 'Punktwerte wurden gespeichert.');
|
set_flash('success', 'Punktwerte wurden gespeichert.');
|
||||||
|
} elseif ($action === 'add_weights') {
|
||||||
|
// "Rolle hinzufügen"-Popup: eine oder mehrere neue Rollen bekommen denselben Punktwert.
|
||||||
|
$roleIds = is_array($_POST['role_ids'] ?? null) ? array_map('intval', $_POST['role_ids']) : [];
|
||||||
|
$points = (int) ($_POST['points'] ?? 1);
|
||||||
|
$roleIds = array_values(array_filter($roleIds, fn ($id) => $id > 0));
|
||||||
|
|
||||||
|
if (empty($roleIds)) {
|
||||||
|
set_flash('error', 'Bitte mindestens eine Rolle auswählen.');
|
||||||
|
redirect('/reports.php');
|
||||||
|
}
|
||||||
|
if ($points < 0) {
|
||||||
|
set_flash('error', 'Der Punktwert darf nicht negativ sein.');
|
||||||
|
redirect('/reports.php');
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($roleIds as $roleId) {
|
||||||
|
set_report_weight($roleId, $points);
|
||||||
|
}
|
||||||
|
set_flash('success', 'Rollen-Gewichtung wurde hinzugefügt.');
|
||||||
}
|
}
|
||||||
} catch (Throwable $e) {
|
} catch (Throwable $e) {
|
||||||
set_flash('error', 'Aktion fehlgeschlagen: ' . $e->getMessage());
|
set_flash('error', 'Aktion fehlgeschlagen: ' . $e->getMessage());
|
||||||
|
|
|
||||||
88
reports.php
88
reports.php
|
|
@ -191,26 +191,86 @@ include __DIR__ . '/includes/header.php';
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<h3>Punktwert pro Discord-Rolle</h3>
|
<h3>Punktwert pro Discord-Rolle</h3>
|
||||||
<p class="text-muted">Ein Report zählt so viele Punkte, wie die höchste Rolle des Melders hier einträgt (unkonfigurierte Rollen zählen 1 Punkt).</p>
|
<p class="text-muted">Ein Report zählt so viele Punkte, wie die höchste Rolle des Melders hier einträgt. Rollen ohne eigenen Eintrag zählen standardmäßig 1 Punkt und werden hier nicht aufgelistet.</p>
|
||||||
<?php if (empty($roleWeights)): ?>
|
<?php if (empty($roleWeights)): ?>
|
||||||
<p class="text-muted">Keine Rollen gefunden - ist der Discord-Bot gerade online?</p>
|
<p class="text-muted">Keine Rollen gefunden - ist der Discord-Bot gerade online?</p>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<form method="post" action="/report_action.php">
|
<?php
|
||||||
<?= csrf_field() ?>
|
$configuredRoleWeights = array_values(array_filter($roleWeights, fn (array $r) => (int) ($r['points'] ?? 1) !== 1));
|
||||||
<input type="hidden" name="action" value="set_weights">
|
$unconfiguredRoles = array_values(array_filter($roleWeights, fn (array $r) => (int) ($r['points'] ?? 1) === 1));
|
||||||
<div class="checkbox-grid">
|
?>
|
||||||
<?php foreach ($roleWeights as $role): ?>
|
<?php if (!empty($configuredRoleWeights)): ?>
|
||||||
<div>
|
<div class="role-weight-list">
|
||||||
<label>
|
<?php foreach ($configuredRoleWeights as $role): ?>
|
||||||
<span style="color: <?= e((string) ($role['color'] ?? '')) ?>;">●</span>
|
<?php $roleId = (int) ($role['role_id'] ?? 0); ?>
|
||||||
<?= e((string) ($role['name'] ?? '')) ?>
|
<div class="role-weight-row">
|
||||||
<input type="text" name="weights[<?= (int) ($role['role_id'] ?? 0) ?>]" value="<?= (int) ($role['points'] ?? 1) ?>">
|
<span class="role-weight-dot" style="background: <?= e((string) ($role['color'] ?? '')) ?>;"></span>
|
||||||
</label>
|
<span class="role-weight-name"><?= e((string) ($role['name'] ?? '')) ?></span>
|
||||||
|
<form method="post" action="/report_action.php" class="role-weight-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<input type="hidden" name="action" value="set_weights">
|
||||||
|
<input type="text" name="weights[<?= $roleId ?>]" value="<?= (int) ($role['points'] ?? 1) ?>" class="role-weight-input">
|
||||||
|
<button type="submit" class="icon-button" title="Speichern"><?= icon('edit') ?></button>
|
||||||
|
</form>
|
||||||
|
<form method="post" action="/report_action.php" class="inline-form">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<input type="hidden" name="action" value="set_weights">
|
||||||
|
<input type="hidden" name="weights[<?= $roleId ?>]" value="1">
|
||||||
|
<button type="submit" class="icon-button icon-button-danger" title="Entfernen (zurück auf 1 Punkt)"><?= icon('x') ?></button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" style="margin-top:1rem;">Alle speichern</button>
|
<?php else: ?>
|
||||||
</form>
|
<p class="text-muted">Aktuell hat keine Rolle eine eigene Gewichtung - alle zählen 1 Punkt.</p>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if (!empty($unconfiguredRoles)): ?>
|
||||||
|
<button type="button" class="button-success" id="report-add-role-btn" style="margin-top:1rem;">+ Rolle hinzufügen</button>
|
||||||
|
|
||||||
|
<div id="report-add-role-modal" class="modal-overlay" hidden>
|
||||||
|
<div class="modal">
|
||||||
|
<button type="button" class="modal-close icon-button" title="Schließen"><?= icon('x') ?></button>
|
||||||
|
|
||||||
|
<div class="report-role-step" data-step="1">
|
||||||
|
<h2>Rolle(n) auswählen</h2>
|
||||||
|
<p class="text-muted">Wähle eine oder mehrere Rollen, denen du eine eigene Punkte-Gewichtung geben möchtest.</p>
|
||||||
|
<div class="role-picker-list">
|
||||||
|
<?php foreach ($unconfiguredRoles as $role): ?>
|
||||||
|
<label class="role-picker-option">
|
||||||
|
<input type="checkbox" name="role_ids[]" value="<?= (int) ($role['role_id'] ?? 0) ?>" data-role-name="<?= e((string) ($role['name'] ?? '')) ?>">
|
||||||
|
<span class="role-picker-dot" style="background: <?= e((string) ($role['color'] ?? '')) ?>;"></span>
|
||||||
|
<span><?= e((string) ($role['name'] ?? '')) ?></span>
|
||||||
|
</label>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</div>
|
||||||
|
<div class="actions" style="margin-top:1.25rem;justify-content:flex-end;">
|
||||||
|
<button type="button" id="report-role-step1-next" disabled>Weiter</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="report-role-step" data-step="2" hidden>
|
||||||
|
<h2>Punktwert festlegen</h2>
|
||||||
|
<p class="text-muted">Ausgewählt: <strong id="report-role-step2-summary"></strong></p>
|
||||||
|
<div>
|
||||||
|
<label>Punkte pro Report</label>
|
||||||
|
<input type="text" id="report-role-points" value="1">
|
||||||
|
</div>
|
||||||
|
<div class="actions" style="margin-top:1.25rem;justify-content:space-between;">
|
||||||
|
<button type="button" class="button-secondary" id="report-role-step2-back">Zurück</button>
|
||||||
|
<button type="button" id="report-role-step2-submit">Hinzufügen</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<form id="report-add-role-form" method="post" action="/report_action.php" style="display:none;">
|
||||||
|
<?= csrf_field() ?>
|
||||||
|
<input type="hidden" name="action" value="add_weights">
|
||||||
|
<input type="hidden" name="points" id="report-add-role-points-field">
|
||||||
|
<div id="report-add-role-ids-container"></div>
|
||||||
|
</form>
|
||||||
|
<script src="/assets/js/reports.js"></script>
|
||||||
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue