Data (cards, enchant points, skill pools, sets, pets, genus insight, daevanion boards, pantheon decorations, closet skins, stat names and units) is read from the build planner's JS chunks and recognised by content; one admin import "Planer-Daten übernehmen" (also brings the specializations) plus "Bilder laden". Plans are stored per set and page (gear_set_plans, schema v40), saved instantly, shown in the compare view, copied with the set and transferable from another own set. The skills page shows the skill bonuses from Daevanion and Arcana. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
537 lines
26 KiB
JavaScript
537 lines
26 KiB
JavaScript
/**
|
||
* Gear-Planer, Katalog (admin/gear_items.php): Gegenstaende und die Skill-Listen der Klassen
|
||
* nacheinander von aion2hub uebernehmen bzw. abgleichen - immer ein Abruf nach dem anderen (der
|
||
* Server wartet zusaetzlich mindestens eine Sekunde dazwischen), 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; });
|
||
|
||
// ---- Skills: Klasse fuer Klasse die Liste abgleichen, danach fehlende Icons laden ----
|
||
var skillRoot = document.getElementById('skill-import');
|
||
if (skillRoot) {
|
||
var skillClass = document.getElementById('skill-import-class');
|
||
var skillStart = document.getElementById('skill-import-start');
|
||
var skillStop = document.getElementById('skill-import-stop');
|
||
var skillProgress = document.getElementById('skill-import-progress');
|
||
var skillFill = document.getElementById('skill-progress-fill');
|
||
var skillText = document.getElementById('skill-progress-text');
|
||
var skillLog = document.getElementById('skill-import-log');
|
||
var skillStopRequested = false;
|
||
|
||
var skillLogLine = function (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 (detail) {
|
||
var item = document.createElement('li');
|
||
item.textContent = detail;
|
||
list.appendChild(item);
|
||
});
|
||
li.appendChild(list);
|
||
}
|
||
skillLog.insertBefore(li, skillLog.firstChild);
|
||
};
|
||
|
||
var runSkills = async function (classes) {
|
||
skillStopRequested = false;
|
||
skillStart.disabled = true;
|
||
skillStop.hidden = false;
|
||
skillProgress.hidden = false;
|
||
skillLog.innerHTML = '';
|
||
var totals = { total: 0, added: 0, changed: 0, unlisted: 0, icons: 0, failed: 0 };
|
||
var done = [];
|
||
for (var i = 0; i < classes.length && !skillStopRequested; i++) {
|
||
var name = classes[i];
|
||
skillFill.style.width = Math.round(i / classes.length * 100) + '%';
|
||
skillText.textContent = name + ' · Skill-Liste wird gelesen … (' + (i + 1) + ' von ' + classes.length + ')';
|
||
var result = await post({ action: 'skills_class', class_name: name });
|
||
if (!result.ok) {
|
||
totals.failed++;
|
||
skillLogLine(name + ': ' + result.error, 'error');
|
||
continue;
|
||
}
|
||
done.push(name);
|
||
totals.total += result.total;
|
||
totals.added += result['new'].length;
|
||
totals.changed += result.changed.length;
|
||
totals.unlisted += result.unlisted.length;
|
||
var details = [];
|
||
if (result['new'].length) details.push('Neu: ' + result['new'].join(', '));
|
||
result.changed.forEach(function (text) { details.push('Geändert: ' + text); });
|
||
if (result.unlisted.length) details.push('Nicht mehr in der Liste: ' + result.unlisted.join(', '));
|
||
|
||
// Fehlende Icons nacheinander (der Server wartet zwischen zwei Abrufen)
|
||
var icons = result.missing_icons || [];
|
||
var iconErrors = 0;
|
||
for (var k = 0; k < icons.length && !skillStopRequested; k++) {
|
||
skillText.textContent = name + ' · Icons ' + (k + 1) + ' von ' + icons.length + ' (' + (i + 1) + ' von ' + classes.length + ')';
|
||
skillFill.style.width = Math.round((i + (k + 1) / (icons.length + 1)) / classes.length * 100) + '%';
|
||
var icon = await post({ action: 'skill_icon', id: icons[k] });
|
||
if (icon.ok) {
|
||
totals.icons++;
|
||
} else {
|
||
iconErrors++;
|
||
details.push(icon.error);
|
||
}
|
||
}
|
||
if (iconErrors) totals.failed += iconErrors;
|
||
var kind = result['new'].length || result.changed.length ? 'new' : (iconErrors || result.unlisted.length ? 'changed' : 'same');
|
||
skillLogLine(name + ': ' + result.total + ' Skills'
|
||
+ (result['new'].length ? ' · ' + result['new'].length + ' neu' : '')
|
||
+ (result.changed.length ? ' · ' + result.changed.length + ' geändert' : '')
|
||
+ (result.unlisted.length ? ' · ' + result.unlisted.length + ' nicht mehr gelistet' : '')
|
||
+ (icons.length > iconErrors ? ' · ' + (icons.length - iconErrors) + ' Icons geladen' : '')
|
||
+ (!result['new'].length && !result.changed.length && !result.unlisted.length && !icons.length ? ' · alles aktuell' : ''),
|
||
kind, details);
|
||
}
|
||
skillFill.style.width = skillStopRequested ? skillFill.style.width : '100%';
|
||
skillText.textContent = (skillStopRequested ? 'Angehalten' : 'Fertig') + ' · ' + totals.total + ' Skills'
|
||
+ (totals.added ? ' · neu ' + totals.added : '') + (totals.changed ? ' · geändert ' + totals.changed : '')
|
||
+ (totals.icons ? ' · Icons ' + totals.icons : '') + (totals.failed ? ' · Fehler ' + totals.failed : '');
|
||
if (done.length) {
|
||
post({
|
||
action: 'skills_done', classes: done.join(', '), total: totals.total, 'new': totals.added,
|
||
changed: totals.changed, unlisted: totals.unlisted, icons: totals.icons, failed: totals.failed
|
||
});
|
||
skillLogLine('Seite neu laden, um die Übersicht zu aktualisieren.', 'info');
|
||
}
|
||
skillStart.disabled = false;
|
||
skillStop.hidden = true;
|
||
};
|
||
|
||
skillStart.addEventListener('click', async function () {
|
||
var all = JSON.parse(skillRoot.dataset.classes || '[]');
|
||
var classes = skillClass.value ? [skillClass.value] : all;
|
||
if (!classes.length) return;
|
||
if (classes.length > 1 && !(await window.luminaDialog.confirm('Die Skill-Listen aller ' + classes.length + ' Klassen werden von aion2hub gelesen. '
|
||
+ 'Beim ersten Mal kommen die Icons dazu - das dauert etwa 5-10 Minuten, die Seite muss so lange offen bleiben (Anhalten geht jederzeit).',
|
||
{ title: 'Skills übernehmen?', okLabel: 'Starten' }))) return;
|
||
runSkills(classes);
|
||
});
|
||
skillStop.addEventListener('click', function () { skillStopRequested = true; });
|
||
}
|
||
|
||
// ---- Planer-Daten (Arcana, Pets, Daevanion, Pantheon, Closet, Spezialisierungen): die Dateien des
|
||
// Build-Planers nacheinander durchsuchen, bis alles gefunden ist; danach fehlende Bilder laden ----
|
||
var plannerRoot = document.getElementById('planner-import');
|
||
if (plannerRoot) {
|
||
var plannerStart = document.getElementById('planner-import-start');
|
||
var iconsStart = document.getElementById('planner-icons-start');
|
||
var plannerStop = document.getElementById('planner-import-stop');
|
||
var plannerProgress = document.getElementById('planner-import-progress');
|
||
var plannerFill = document.getElementById('planner-progress-fill');
|
||
var plannerText = document.getElementById('planner-progress-text');
|
||
var plannerLog = document.getElementById('planner-import-log');
|
||
var plannerStopRequested = false;
|
||
|
||
var plannerLogLine = function (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 (detail) {
|
||
var item = document.createElement('li');
|
||
item.textContent = detail;
|
||
list.appendChild(item);
|
||
});
|
||
li.appendChild(list);
|
||
}
|
||
plannerLog.insertBefore(li, plannerLog.firstChild);
|
||
};
|
||
var plannerBusy = function (busy) {
|
||
plannerStart.disabled = busy;
|
||
iconsStart.disabled = busy;
|
||
plannerStop.hidden = !busy;
|
||
if (busy) {
|
||
plannerStopRequested = false;
|
||
plannerProgress.hidden = false;
|
||
plannerLog.innerHTML = '';
|
||
plannerFill.style.width = '0%';
|
||
}
|
||
};
|
||
|
||
plannerStart.addEventListener('click', async function () {
|
||
plannerBusy(true);
|
||
plannerText.textContent = 'Build-Planer von aion2hub wird gelesen …';
|
||
var plan = await post({ action: 'planner_plan' });
|
||
var found = {};
|
||
var status = { 'new': [], changed: [], same: 0 };
|
||
var specsText = '';
|
||
if (!plan.ok) {
|
||
plannerLogLine(plan.error, 'error');
|
||
} else {
|
||
var missing = function () {
|
||
return plan.expected.filter(function (name) { return !found[name]; });
|
||
};
|
||
for (var i = 0; i < plan.chunks.length && !plannerStopRequested && missing().length; i++) {
|
||
plannerText.textContent = 'Daten werden gesucht … Datei ' + (i + 1) + ' von ' + plan.chunks.length + ' (noch ' + missing().length + ' Datensätze)';
|
||
plannerFill.style.width = Math.round((i + 1) / plan.chunks.length * 100) + '%';
|
||
var result = await post({ action: 'planner_chunk', path: plan.chunks[i] });
|
||
if (!result.ok) {
|
||
plannerLogLine(result.error, 'error');
|
||
break;
|
||
}
|
||
result.found.forEach(function (name) { found[name] = true; });
|
||
Object.keys(result.stored).forEach(function (name) {
|
||
if (result.stored[name] === 'same') status.same++;
|
||
else status[result.stored[name]].push(name);
|
||
});
|
||
if (result.specs) {
|
||
var specs = result.specs;
|
||
var details = [];
|
||
if (specs.missing.length) details.push('Ohne Daten bei aion2hub: ' + specs.missing.join(', '));
|
||
if (specs.kr) details.push(specs.kr + ' Texte stammen dort aus den Korea-Daten (im Planer markiert).');
|
||
if (specs.warning) details.push(specs.warning);
|
||
specsText = specs.updated + ' aktualisiert, ' + specs.same + ' unverändert';
|
||
plannerLogLine('Spezialisierungen & Stigma-Boni (Stand ' + specs.built_at + '): ' + specsText + '.',
|
||
specs.missing.length || specs.warning ? 'changed' : 'new', details);
|
||
}
|
||
if (result.found.length) {
|
||
plannerLogLine(plan.chunks[i].split('/').pop() + ': ' + result.found.filter(function (name) { return name.indexOf(':') === -1; }).join(', '), 'info');
|
||
}
|
||
}
|
||
var left = missing();
|
||
if (!plannerStopRequested) {
|
||
plannerLogLine('Neu: ' + (status['new'].length ? status['new'].join(', ') : '–') + ' · geändert: '
|
||
+ (status.changed.length ? status.changed.join(', ') : '–') + ' · unverändert: ' + status.same,
|
||
left.length ? 'changed' : 'new', left.length ? ['Nicht gefunden: ' + left.join(', ') + ' – hat sich der Planer von aion2hub geändert?'] : []);
|
||
await post({ action: 'planner_done', 'new': status['new'].join(','), changed: status.changed.join(','), same: status.same, specs: specsText, missing: left.join(',') });
|
||
plannerLogLine('Seite neu laden, um die Übersicht zu aktualisieren. Danach „Bilder laden“, falls Bilder fehlen.', 'info');
|
||
}
|
||
}
|
||
plannerFill.style.width = '100%';
|
||
plannerText.textContent = plannerStopRequested ? 'Angehalten' : 'Fertig';
|
||
plannerBusy(false);
|
||
});
|
||
|
||
iconsStart.addEventListener('click', async function () {
|
||
plannerBusy(true);
|
||
plannerText.textContent = 'Fehlende Bilder werden gesucht …';
|
||
var list = await post({ action: 'planner_icons' });
|
||
if (!list.ok) {
|
||
plannerLogLine(list.error, 'error');
|
||
} else if (!list.ids.length) {
|
||
plannerLogLine('Alle ' + list.total + ' Bilder sind schon da.', 'new');
|
||
} else {
|
||
var loaded = 0;
|
||
var failed = 0;
|
||
for (var i = 0; i < list.ids.length && !plannerStopRequested; i++) {
|
||
plannerText.textContent = 'Bild ' + (i + 1) + ' von ' + list.ids.length + ' …';
|
||
plannerFill.style.width = Math.round((i + 1) / list.ids.length * 100) + '%';
|
||
var result = await post({ action: 'planner_icon', id: list.ids[i] });
|
||
if (result.ok) {
|
||
loaded++;
|
||
} else {
|
||
failed++;
|
||
if (failed <= 10) plannerLogLine(result.error, 'error');
|
||
}
|
||
}
|
||
plannerLogLine(loaded + ' Bilder geladen' + (failed ? ', ' + failed + ' fehlgeschlagen' : '') + '.', failed ? 'changed' : 'new');
|
||
}
|
||
plannerFill.style.width = '100%';
|
||
plannerText.textContent = plannerStopRequested ? 'Angehalten' : 'Fertig';
|
||
plannerBusy(false);
|
||
});
|
||
plannerStop.addEventListener('click', function () { plannerStopRequested = 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; });
|
||
})();
|