- Raids: "Max. Spieler" only whole numbers up to groups x 5 (max. 10 groups / 50), gearscore only a number; fixed +1 Lumipunkt per participation, other values only with the new raids.points permission; pick an existing premade per group when creating a raid; unchanged legacy values no longer block editing - Raid page updates itself every 15 s while visible (raids_live.php, cards rendered by includes/raid_card.php), open editors and confirm dialogs are kept - Restore takes the new raid_id from the bot (archived messages are now deleted in Discord) and moves settings, attendance and awards; website signups send the server display name - Premades: dissolve by leadership needs a reason, lead gets DMs on join/assign/decline/remove (source/actor_id sent to the bot), transfer picker skips players who already lead a group, website accept keeps the one-group rule, no commas in names - Site-wide Lumina dialog (assets/js/confirm-dialog.js) replaces confirm/prompt/alert via data-confirm; error flashes are a dialog you confirm with OK - Calendar: audience per entry (all / leadership takes part / internal) with the new calendar.leadership permission; day cells list all entries and scroll - Gear planner: main-hand picker filtered by the set's class, mismatches marked, "keine Klasse" option, link to an external skill/Daevanion plan per set - Map: correct kisk icons (Elyos on Verteron/Abyss, Altgard fixed), per-map max zoom and bounded panning, German texts, data source note - Tactics: toolbar as a uniform grid, whole-tactic copy, automatic versions with restore and a 90-day trash, official tactics protected - Global thin gold scrollbars, readable hover colours, "Sedes Luminis" spelling, patch notes and README, schema version 34 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
305 lines
13 KiB
JavaScript
305 lines
13 KiB
JavaScript
/**
|
|
* Gear-Planer, Katalog (admin/gear_items.php): Gegenstaende nacheinander von aion2hub
|
|
* uebernehmen bzw. abgleichen - immer einer nach dem anderen (der Server wartet zusaetzlich
|
|
* mindestens eine Sekunde zwischen zwei Abrufen), mit Fortschritt und Protokoll.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
|
|
var root = document.getElementById('gear-import');
|
|
if (!root) return;
|
|
|
|
var endpoint = root.dataset.action;
|
|
var csrf = root.dataset.csrf;
|
|
var input = document.getElementById('gear-import-input');
|
|
var skipKnown = document.getElementById('gear-import-skip');
|
|
var startButton = document.getElementById('gear-import-start');
|
|
var checkAllButton = document.getElementById('gear-check-all');
|
|
var applyBox = document.getElementById('gear-check-apply');
|
|
var stopButton = document.getElementById('gear-import-stop');
|
|
var progress = document.getElementById('gear-import-progress');
|
|
var fill = document.getElementById('gear-progress-fill');
|
|
var progressText = document.getElementById('gear-progress-text');
|
|
var log = document.getElementById('gear-import-log');
|
|
var running = false;
|
|
var stopRequested = false;
|
|
|
|
function post(data) {
|
|
var body = new FormData();
|
|
body.append('csrf_token', csrf);
|
|
Object.keys(data).forEach(function (key) { body.append(key, data[key]); });
|
|
return fetch(endpoint, { method: 'POST', body: body, headers: { 'Accept': 'application/json' }, credentials: 'same-origin' })
|
|
.then(function (response) {
|
|
return response.json().catch(function () {
|
|
return { ok: false, error: 'Unerwartete Antwort vom Server (' + response.status + ').' };
|
|
});
|
|
})
|
|
.catch(function () { return { ok: false, error: 'Keine Verbindung zum Server.' }; });
|
|
}
|
|
|
|
function addLog(text, kind, details) {
|
|
var li = document.createElement('li');
|
|
li.className = 'gear-log-' + kind;
|
|
li.textContent = text;
|
|
if (details && details.length) {
|
|
var list = document.createElement('ul');
|
|
details.forEach(function (diff) {
|
|
var item = document.createElement('li');
|
|
item.textContent = diff[0] + ': ' + diff[1] + ' → ' + diff[2];
|
|
list.appendChild(item);
|
|
});
|
|
li.appendChild(list);
|
|
}
|
|
log.insertBefore(li, log.firstChild);
|
|
}
|
|
|
|
function showMessage(text, kind) {
|
|
progress.hidden = false;
|
|
log.innerHTML = '';
|
|
addLog(text, kind);
|
|
}
|
|
|
|
function setBusy(busy) {
|
|
running = busy;
|
|
startButton.disabled = busy;
|
|
if (checkAllButton) checkAllButton.disabled = busy;
|
|
stopButton.hidden = !busy;
|
|
stopRequested = false;
|
|
}
|
|
|
|
var CATEGORY_LABELS = { Weapons: 'Waffen', Armor: 'Rüstungen', Accessories: 'Schmuck' };
|
|
|
|
/** Zustand eines Durchlaufs; kind = 'import' oder 'check'. */
|
|
function newRun(kind, source, total) {
|
|
setBusy(true);
|
|
progress.hidden = false;
|
|
log.innerHTML = '';
|
|
return {
|
|
kind: kind,
|
|
source: source || '',
|
|
apply: kind === 'import' || (applyBox && applyBox.checked),
|
|
total: total,
|
|
done: 0,
|
|
label: '',
|
|
counts: { added: 0, changed: 0, same: 0, skipped: 0, failed: 0 }
|
|
};
|
|
}
|
|
|
|
function showProgress(run) {
|
|
var c = run.counts;
|
|
fill.style.width = (run.total ? Math.min(100, Math.round(run.done / run.total * 100)) : 0) + '%';
|
|
progressText.textContent = (run.label ? run.label + ' · ' : '') + run.done + ' von ' + run.total
|
|
+ ' · neu ' + c.added + ' · geändert ' + c.changed + ' · unverändert ' + c.same
|
|
+ (c.skipped ? ' · übersprungen ' + c.skipped : '') + (c.failed ? ' · Fehler ' + c.failed : '');
|
|
}
|
|
|
|
/** Gegenstaende nacheinander uebernehmen bzw. abgleichen. */
|
|
async function processIds(run, ids) {
|
|
for (var i = 0; i < ids.length && !stopRequested; i++) {
|
|
var id = ids[i];
|
|
var result = await post({ action: run.kind, id: id, batch: run.total > 1 ? 1 : '', apply: run.apply ? 1 : '' });
|
|
if (!result.ok) {
|
|
run.counts.failed++;
|
|
addLog('#' + id + ': ' + result.error, 'error');
|
|
} else if (result['new']) {
|
|
run.counts.added++;
|
|
addLog(result.name + ' übernommen', 'new');
|
|
} else if (result.diffs.length) {
|
|
run.counts.changed++;
|
|
addLog(result.name + (result.applied ? ' aktualisiert' : ' hat Änderungen (nicht übernommen)'), 'changed', result.diffs);
|
|
} else {
|
|
run.counts.same++;
|
|
if (run.total === 1) addLog(result.name + ' ist aktuell - keine Änderungen.', 'same');
|
|
}
|
|
run.done++;
|
|
showProgress(run);
|
|
}
|
|
}
|
|
|
|
function finishRun(run) {
|
|
var c = run.counts;
|
|
if (stopRequested) addLog('Angehalten.', 'info');
|
|
setBusy(false);
|
|
showProgress(run);
|
|
if (run.total > 1 && (c.added || c.changed || c.same || c.failed)) {
|
|
post({ action: 'batch_done', kind: run.kind, 'new': c.added, changed: c.changed, same: c.same, failed: c.failed, source: run.source });
|
|
}
|
|
if (c.added || (run.apply && c.changed)) {
|
|
addLog('Fertig - Seite neu laden, um die Liste zu aktualisieren.', 'info');
|
|
} else if (!c.failed && !stopRequested && c.skipped === run.done && run.done > 0) {
|
|
addLog('Alles schon im Katalog - nichts Neues gefunden.', 'same');
|
|
}
|
|
}
|
|
|
|
/** Feste Liste von IDs (einzelner Gegenstand, "Alle abgleichen"). */
|
|
async function runIds(ids, kind, source) {
|
|
var run = newRun(kind, source, ids.length);
|
|
showProgress(run);
|
|
await processIds(run, ids);
|
|
finishRun(run);
|
|
}
|
|
|
|
/**
|
|
* Listen von aion2hub Seite fuer Seite: erst die erste Seite jeder Kategorie (Gesamtzahl fuer
|
|
* Fortschritt und Rueckfrage), dann jede Seite laden und ihre Gegenstaende gleich uebernehmen.
|
|
*/
|
|
async function runLists(lists, source) {
|
|
var run = newRun('import', source, 0);
|
|
progressText.textContent = 'Listen werden gelesen …';
|
|
var firsts = [];
|
|
for (var i = 0; i < lists.length && !stopRequested; i++) {
|
|
var first = await post({ action: 'list', url: lists[i], page: 1 });
|
|
if (!first.ok) {
|
|
addLog(first.error, 'error');
|
|
continue;
|
|
}
|
|
firsts.push({ url: lists[i], page: first });
|
|
run.total += first.total;
|
|
}
|
|
if (!firsts.length || stopRequested) {
|
|
finishRun(run);
|
|
return;
|
|
}
|
|
var pageCount = firsts.reduce(function (sum, f) { return sum + f.page.pages; }, 0);
|
|
if (run.total > 100 && !(await window.luminaDialog.confirm(run.total + ' Gegenstände auf ' + pageCount + ' Seiten gefunden'
|
|
+ (skipKnown.checked ? ' (schon vorhandene werden übersprungen)' : '') + '.\n\nIn voller Länge dauert das etwa '
|
|
+ Math.ceil((run.total + pageCount) * 1.3 / 60) + ' Minuten - die Seite muss so lange offen bleiben (Anhalten geht jederzeit).',
|
|
{ title: 'Import starten?', okLabel: 'Starten' }))) {
|
|
setBusy(false);
|
|
progress.hidden = true;
|
|
return;
|
|
}
|
|
|
|
for (var f = 0; f < firsts.length && !stopRequested; f++) {
|
|
var category = (firsts[f].url.match(/[?&]cat=([^&]+)/) || [])[1] || '';
|
|
var result = firsts[f].page;
|
|
for (var page = 1; page <= result.pages && !stopRequested; page++) {
|
|
if (page > 1) {
|
|
result = await post({ action: 'list', url: firsts[f].url, page: page });
|
|
if (!result.ok) {
|
|
addLog((CATEGORY_LABELS[category] || category) + ', Seite ' + page + ': ' + result.error, 'error');
|
|
continue;
|
|
}
|
|
}
|
|
run.label = (CATEGORY_LABELS[category] || category) + ' · Seite ' + page + '/' + result.pages;
|
|
var known = result.known || [];
|
|
var ids = result.ids;
|
|
if (skipKnown.checked) {
|
|
ids = ids.filter(function (id) { return known.indexOf(id) === -1; });
|
|
run.counts.skipped += result.ids.length - ids.length;
|
|
run.done += result.ids.length - ids.length;
|
|
}
|
|
showProgress(run);
|
|
await processIds(run, ids);
|
|
}
|
|
}
|
|
run.label = '';
|
|
finishRun(run);
|
|
}
|
|
|
|
startButton.addEventListener('click', async function () {
|
|
var value = input.value.trim();
|
|
if (!value || running) return;
|
|
startButton.disabled = true;
|
|
var plan = await post({ action: 'plan', url: value });
|
|
startButton.disabled = false;
|
|
if (!plan.ok) {
|
|
showMessage(plan.error, 'error');
|
|
return;
|
|
}
|
|
if (plan.lists) {
|
|
runLists(plan.lists, value);
|
|
return;
|
|
}
|
|
if (skipKnown.checked && plan.known.length) {
|
|
showMessage('Dieser Gegenstand ist schon im Katalog - „Abgleichen“ in der Liste prüft ihn.', 'same');
|
|
return;
|
|
}
|
|
runIds(plan.ids, 'import', value);
|
|
});
|
|
input.addEventListener('keydown', function (event) {
|
|
if (event.key === 'Enter') {
|
|
event.preventDefault();
|
|
startButton.click();
|
|
}
|
|
});
|
|
|
|
if (checkAllButton) {
|
|
checkAllButton.addEventListener('click', async function () {
|
|
var ids = JSON.parse(root.dataset.allIds || '[]');
|
|
if (!ids.length || running) return;
|
|
var minutes = Math.ceil(ids.length * 1.3 / 60);
|
|
if (ids.length > 30 && !(await window.luminaDialog.confirm('Das dauert etwa ' + minutes + ' Minuten - die Seite muss so lange offen bleiben.',
|
|
{ title: ids.length + ' Gegenstände abgleichen?', okLabel: 'Abgleichen' }))) return;
|
|
runIds(ids, 'check', 'alle');
|
|
});
|
|
}
|
|
stopButton.addEventListener('click', function () { stopRequested = true; });
|
|
|
|
// ---- Einzelnen Gegenstand abgleichen: Unterschiede im Dialog, dann uebernehmen ----
|
|
var modal = document.getElementById('gear-diff-modal');
|
|
var title = document.getElementById('gear-diff-title');
|
|
var body = document.getElementById('gear-diff-body');
|
|
var applyButton = document.getElementById('gear-diff-apply');
|
|
var currentId = null;
|
|
|
|
function paragraph(text, className) {
|
|
var p = document.createElement('p');
|
|
if (className) p.className = className;
|
|
p.textContent = text;
|
|
body.appendChild(p);
|
|
}
|
|
|
|
function openDiff(id) {
|
|
currentId = id;
|
|
title.textContent = 'Abgleich #' + id;
|
|
body.innerHTML = '';
|
|
paragraph('Werte werden von aion2hub geladen …', 'text-muted');
|
|
applyButton.hidden = true;
|
|
modal.hidden = false;
|
|
post({ action: 'check', id: id }).then(function (result) {
|
|
body.innerHTML = '';
|
|
if (!result.ok) {
|
|
paragraph(result.error, 'gear-log-error');
|
|
return;
|
|
}
|
|
title.textContent = result.name;
|
|
if (!result.diffs.length) {
|
|
paragraph('Alles aktuell - die Werte stimmen mit aion2hub überein (als geprüft vermerkt).');
|
|
return;
|
|
}
|
|
var table = document.createElement('table');
|
|
table.className = 'gear-diff-table';
|
|
table.innerHTML = '<thead><tr><th>Feld</th><th>Gespeichert</th><th>aion2hub jetzt</th></tr></thead>';
|
|
var tbody = document.createElement('tbody');
|
|
result.diffs.forEach(function (diff) {
|
|
var tr = document.createElement('tr');
|
|
diff.forEach(function (cell, i) {
|
|
var td = document.createElement(i === 0 ? 'th' : 'td');
|
|
td.textContent = cell;
|
|
if (i === 2) td.className = 'is-new';
|
|
tr.appendChild(td);
|
|
});
|
|
tbody.appendChild(tr);
|
|
});
|
|
table.appendChild(tbody);
|
|
body.appendChild(table);
|
|
applyButton.hidden = false;
|
|
});
|
|
}
|
|
|
|
document.querySelectorAll('[data-gear-check]').forEach(function (button) {
|
|
button.addEventListener('click', function () { openDiff(button.dataset.gearCheck); });
|
|
});
|
|
applyButton.addEventListener('click', function () {
|
|
applyButton.disabled = true;
|
|
post({ action: 'import', id: currentId }).then(function (result) {
|
|
applyButton.disabled = false;
|
|
if (result.ok) window.location.reload();
|
|
else paragraph(result.error, 'gear-log-error');
|
|
});
|
|
});
|
|
modal.querySelector('.modal-close').addEventListener('click', function () { modal.hidden = true; });
|
|
modal.addEventListener('click', function (event) { if (event.target === modal) modal.hidden = true; });
|
|
document.addEventListener('keydown', function (event) { if (event.key === 'Escape') modal.hidden = true; });
|
|
})();
|