Gear planner: - Personal gear sets (18 slots) with enchant, exceed, soul imprint and manastones, stat totals by source and side-by-side comparison of 2-4 sets - Sets can be shown on the own profile page (read-only for other members) - Admin catalog: import items from aion2hub.com (Global client), compare stored values with the source one by one or all at once, at most one request per second - New permissions gear.view (all with dashboard access) and gear.manage Dashboard: - Role badges ordered like the member list (roster_order) - Stronger hover effect on "Rangliste & Verlauf" / "Zum Lumishop", no more blue hover on secondary buttons - "Anstehende Raids" box links to the raids page, next raids link to the raid and to the calendar day - Raid attendance only knows present/absent (old "excused" entries count as unset) Bug reports: - Up to 5 images per report, pasting copied images with Ctrl+V (also for the gallery) - Images are only served to the reporter and bugs.manage via bug_image.php Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
218 lines
9.5 KiB
JavaScript
218 lines
9.5 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;
|
|
}
|
|
|
|
/** IDs nacheinander abarbeiten; kind = 'import' oder 'check'. */
|
|
function run(ids, kind, source) {
|
|
var counts = { added: 0, changed: 0, same: 0, failed: 0 };
|
|
var apply = kind === 'import' || (applyBox && applyBox.checked);
|
|
var index = 0;
|
|
setBusy(true);
|
|
progress.hidden = false;
|
|
log.innerHTML = '';
|
|
|
|
function next() {
|
|
fill.style.width = (ids.length ? Math.round(index / ids.length * 100) : 100) + '%';
|
|
progressText.textContent = index + ' von ' + ids.length + ' · neu ' + counts.added + ' · geändert ' + counts.changed
|
|
+ ' · unverändert ' + counts.same + (counts.failed ? ' · Fehler ' + counts.failed : '');
|
|
if (index >= ids.length || stopRequested) {
|
|
if (stopRequested) addLog('Angehalten.', 'info');
|
|
setBusy(false);
|
|
if (ids.length > 1 && index > 0) {
|
|
post({ action: 'batch_done', kind: kind, 'new': counts.added, changed: counts.changed, same: counts.same, failed: counts.failed, source: source || '' });
|
|
}
|
|
if (counts.added || (apply && counts.changed)) {
|
|
addLog('Fertig - Seite neu laden, um die Liste zu aktualisieren.', 'info');
|
|
}
|
|
return;
|
|
}
|
|
var id = ids[index++];
|
|
post({ action: kind, id: id, batch: ids.length > 1 ? 1 : '', apply: apply ? 1 : '' }).then(function (result) {
|
|
if (!result.ok) {
|
|
counts.failed++;
|
|
addLog('#' + id + ': ' + result.error, 'error');
|
|
} else if (result['new']) {
|
|
counts.added++;
|
|
addLog(result.name + ' übernommen', 'new');
|
|
} else if (result.diffs.length) {
|
|
counts.changed++;
|
|
addLog(result.name + (result.applied ? ' aktualisiert' : ' hat Änderungen (nicht übernommen)'), 'changed', result.diffs);
|
|
} else {
|
|
counts.same++;
|
|
if (ids.length === 1) addLog(result.name + ' ist aktuell - keine Änderungen.', 'same');
|
|
}
|
|
next();
|
|
});
|
|
}
|
|
next();
|
|
}
|
|
|
|
startButton.addEventListener('click', function () {
|
|
var value = input.value.trim();
|
|
if (!value || running) return;
|
|
startButton.disabled = true;
|
|
post({ action: 'list', url: value }).then(function (result) {
|
|
startButton.disabled = false;
|
|
if (!result.ok) {
|
|
showMessage(result.error, 'error');
|
|
return;
|
|
}
|
|
var known = result.known || [];
|
|
var ids = skipKnown.checked ? result.ids.filter(function (id) { return known.indexOf(id) === -1; }) : result.ids;
|
|
if (!ids.length) {
|
|
showMessage(result.ids.length === 1 ? 'Dieser Gegenstand ist schon im Katalog - „Abgleichen“ in der Liste prüft ihn.' : 'Alle ' + result.ids.length + ' Gegenstände sind schon im Katalog.', 'same');
|
|
return;
|
|
}
|
|
run(ids, 'import', value);
|
|
});
|
|
});
|
|
input.addEventListener('keydown', function (event) {
|
|
if (event.key === 'Enter') {
|
|
event.preventDefault();
|
|
startButton.click();
|
|
}
|
|
});
|
|
|
|
if (checkAllButton) {
|
|
checkAllButton.addEventListener('click', 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 && !window.confirm(ids.length + ' Gegenstände abgleichen? Das dauert etwa ' + minutes + ' Minuten - die Seite muss so lange offen bleiben.')) return;
|
|
run(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; });
|
|
})();
|