asdasd
This commit is contained in:
@@ -15,6 +15,8 @@ let statusLabel;
|
||||
let loadBtn;
|
||||
let importBtn;
|
||||
let importInput;
|
||||
let configExampleBtn;
|
||||
let configExampleDialog;
|
||||
|
||||
export function initBridgeSetupPage() {
|
||||
form = document.getElementById('bridgeSetupForm');
|
||||
@@ -27,6 +29,8 @@ export function initBridgeSetupPage() {
|
||||
loadBtn = document.getElementById('btn-load-remote');
|
||||
importBtn = document.getElementById('btn-import-bridge');
|
||||
importInput = document.getElementById('bridgeImportInput');
|
||||
configExampleBtn = document.getElementById('btn-config-example');
|
||||
configExampleDialog = document.getElementById('configExampleDialog');
|
||||
modeInputs = Array.from(form.querySelectorAll('input[name="db_mode"]'));
|
||||
|
||||
form.addEventListener('submit', submitBridgeSetup);
|
||||
@@ -34,6 +38,9 @@ export function initBridgeSetupPage() {
|
||||
loadBtn?.addEventListener('click', loadTablesFromBridge);
|
||||
importBtn?.addEventListener('click', () => importInput?.click());
|
||||
importInput?.addEventListener('change', handleBridgeImport);
|
||||
configExampleBtn?.addEventListener('click', () => {
|
||||
if (configExampleDialog?.showModal) configExampleDialog.showModal();
|
||||
});
|
||||
modeInputs.forEach(input => {
|
||||
input.addEventListener('change', () => applyModeVisibility(input.value));
|
||||
});
|
||||
@@ -71,8 +78,7 @@ async function loadBridgeSetup() {
|
||||
try {
|
||||
const res = await apiAction('account.bridge.setup.get', { method: 'GET' });
|
||||
if (!res?.ok) throw new Error(res?.error || 'Bridge-Setup konnte nicht geladen werden');
|
||||
state.setup = res.setup || defaultSetup();
|
||||
fillForm(state.setup);
|
||||
fillForm(res.setup || state.setup || defaultSetup());
|
||||
updateStatus('Daten geladen.');
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
@@ -83,10 +89,11 @@ async function loadBridgeSetup() {
|
||||
}
|
||||
|
||||
function fillForm(setup) {
|
||||
const data = { ...defaultSetup(), ...(setup || {}) };
|
||||
const data = normalizeSetupInput(setup);
|
||||
state.setup = data;
|
||||
if (tablesInput) {
|
||||
tablesInput.value = (data.tables || []).join(', ');
|
||||
updateTablesPreview(parseTablesInput());
|
||||
tablesInput.value = data.tables.join(', ');
|
||||
updateTablesPreview(data.tables);
|
||||
}
|
||||
const activeMode = (data.mode || 'direct').toLowerCase();
|
||||
modeInputs.forEach(input => {
|
||||
@@ -137,9 +144,7 @@ async function handleBridgeImport(ev) {
|
||||
toast('Bridge-Datei konnte nicht erkannt werden', false);
|
||||
return;
|
||||
}
|
||||
state.setup = { ...defaultSetup(), ...state.setup, ...parsed };
|
||||
fillForm(state.setup);
|
||||
updateTablesPreview(parseTablesInput());
|
||||
fillForm({ ...state.setup, ...parsed });
|
||||
updateStatus('Bridge-Datei importiert');
|
||||
toast('Bridge-Daten übernommen', true);
|
||||
} catch (err) {
|
||||
@@ -203,8 +208,7 @@ async function submitBridgeSetup(ev) {
|
||||
try {
|
||||
const res = await apiAction('account.bridge.setup.save', { method: 'POST', data: payload });
|
||||
if (!res?.ok) throw new Error(res?.error || 'Bridge-Setup konnte nicht gespeichert werden');
|
||||
state.setup = res.setup || payload;
|
||||
fillForm(state.setup);
|
||||
fillForm(res.setup || payload);
|
||||
updateStatus('Bridge-Setup gespeichert.');
|
||||
toast('Bridge-Setup gespeichert', true);
|
||||
} catch (err) {
|
||||
@@ -220,12 +224,20 @@ async function loadTablesFromBridge(ev) {
|
||||
try {
|
||||
const res = await apiAction('account.bridge.test', { method: 'POST', data: {} });
|
||||
if (!res?.ok) throw new Error(res?.error || 'Bridge konnte nicht abgefragt werden');
|
||||
const tables = normalizeTableNames(res.tables);
|
||||
if (tablesInput) {
|
||||
tablesInput.value = tables.join(', ');
|
||||
updateTablesPreview(tables);
|
||||
const fetchedTables = normalizeTableNames(res.tables);
|
||||
const allowedTables = normalizeTableNames(res.setup_hint?.tables ?? fetchedTables);
|
||||
const merged = {
|
||||
...(state.setup || {}),
|
||||
tables: allowedTables,
|
||||
...(res.setup_hint || {}),
|
||||
};
|
||||
if (res.setup_hint) {
|
||||
merged.mode = res.setup_hint.mode || merged.mode;
|
||||
merged.direct = { ...(merged.direct || {}), ...(res.setup_hint.direct || {}) };
|
||||
merged.config = { ...(merged.config || {}), ...(res.setup_hint.config || {}) };
|
||||
}
|
||||
updateStatus(`Tabellen geladen (${tables.length}).`);
|
||||
fillForm(merged);
|
||||
updateStatus(`Tabellen geladen (${fetchedTables.length}).`);
|
||||
toast('Tabellen erfolgreich geladen', true);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
@@ -344,3 +356,16 @@ function parseBridgeBasePath(snippet) {
|
||||
const match = snippet.match(regex);
|
||||
return match ? match[1] : '';
|
||||
}
|
||||
|
||||
function normalizeSetupInput(input) {
|
||||
const base = defaultSetup();
|
||||
if (!input || typeof input !== 'object') return base;
|
||||
const mode = (input.mode || base.mode).toLowerCase();
|
||||
const validMode = mode === 'config' ? 'config' : 'direct';
|
||||
const tables = normalizeTableNames(input.tables || base.tables);
|
||||
const direct = { ...base.direct, ...(input.direct || {}) };
|
||||
direct.port = Number(direct.port || 3306) || 3306;
|
||||
direct.charset = direct.charset || 'utf8mb4';
|
||||
const config = { ...base.config, ...(input.config || {}) };
|
||||
return { tables, mode: validMode, direct, config };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user