adasd
This commit is contained in:
@@ -9,32 +9,27 @@ let form;
|
||||
let tablesInput;
|
||||
let tablesPreview;
|
||||
let modeInputs;
|
||||
let importInputs;
|
||||
let directFields;
|
||||
let configFields;
|
||||
let statusLabel;
|
||||
let loadBtn;
|
||||
let configExampleBtn;
|
||||
let configExampleDialog;
|
||||
let bridgeFields;
|
||||
|
||||
export function initBridgeSetupPage() {
|
||||
form = document.getElementById('bridgeSetupForm');
|
||||
if (!form) return;
|
||||
tablesInput = form.elements.tables;
|
||||
tablesPreview = document.getElementById('selectedTables');
|
||||
bridgeFields = document.getElementById('bridgeFields');
|
||||
directFields = document.getElementById('directFields');
|
||||
configFields = document.getElementById('configFields');
|
||||
statusLabel = document.getElementById('setupStatus');
|
||||
loadBtn = document.getElementById('btn-load-remote');
|
||||
configExampleBtn = document.getElementById('btn-config-example');
|
||||
configExampleDialog = document.getElementById('configExampleDialog');
|
||||
modeInputs = Array.from(form.querySelectorAll('input[name="db_mode"]'));
|
||||
importInputs = Array.from(form.querySelectorAll('input[name="bridge_import"]'));
|
||||
|
||||
form.addEventListener('submit', submitBridgeSetup);
|
||||
tablesInput?.addEventListener('input', () => updateTablesPreview(parseTablesInput()));
|
||||
loadBtn?.addEventListener('click', loadTablesFromBridge);
|
||||
configExampleBtn?.addEventListener('click', () => {
|
||||
if (configExampleDialog?.showModal) configExampleDialog.showModal();
|
||||
});
|
||||
modeInputs.forEach(input => {
|
||||
input.addEventListener('change', () => applyModeVisibility(input.value));
|
||||
});
|
||||
@@ -45,7 +40,8 @@ export function initBridgeSetupPage() {
|
||||
function defaultSetup() {
|
||||
return {
|
||||
tables: [],
|
||||
mode: 'direct',
|
||||
mode: 'bridge',
|
||||
import_type: 'schema',
|
||||
direct: {
|
||||
host: '',
|
||||
port: 3306,
|
||||
@@ -54,16 +50,6 @@ function defaultSetup() {
|
||||
password: '',
|
||||
charset: 'utf8mb4',
|
||||
},
|
||||
config: {
|
||||
file: '',
|
||||
base: '',
|
||||
host_key: '',
|
||||
port_key: '',
|
||||
database_key: '',
|
||||
user_key: '',
|
||||
password_key: '',
|
||||
charset_key: '',
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -95,6 +81,13 @@ function fillForm(setup) {
|
||||
});
|
||||
applyModeVisibility(activeMode);
|
||||
|
||||
if (importInputs.length) {
|
||||
const importType = (data.import_type || 'schema').toLowerCase();
|
||||
importInputs.forEach(input => {
|
||||
input.checked = input.value === importType;
|
||||
});
|
||||
}
|
||||
|
||||
if (directFields) {
|
||||
const directMap = {
|
||||
direct_host: data.direct.host || '',
|
||||
@@ -110,29 +103,12 @@ function fillForm(setup) {
|
||||
});
|
||||
}
|
||||
|
||||
if (configFields) {
|
||||
const configMap = {
|
||||
config_file: data.config.file || '',
|
||||
config_base: data.config.base || '',
|
||||
config_host_key: data.config.host_key || '',
|
||||
config_port_key: data.config.port_key || '',
|
||||
config_database_key: data.config.database_key || '',
|
||||
config_user_key: data.config.user_key || '',
|
||||
config_password_key: data.config.password_key || '',
|
||||
config_charset_key: data.config.charset_key || '',
|
||||
};
|
||||
Object.entries(configMap).forEach(([name, value]) => {
|
||||
const input = configFields.querySelector(`[name="${name}"]`);
|
||||
if (input) input.value = value;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function applyModeVisibility(mode) {
|
||||
const direct = mode === 'config' ? 'add' : 'remove';
|
||||
const config = mode === 'config' ? 'remove' : 'add';
|
||||
directFields?.classList[direct]('hidden');
|
||||
configFields?.classList[config]('hidden');
|
||||
const showDirect = mode === 'direct';
|
||||
directFields?.classList[showDirect ? 'remove' : 'add']('hidden');
|
||||
bridgeFields?.classList[showDirect ? 'add' : 'remove']('hidden');
|
||||
}
|
||||
|
||||
function parseTablesInput() {
|
||||
@@ -157,23 +133,17 @@ async function submitBridgeSetup(ev) {
|
||||
ev.preventDefault();
|
||||
if (!form) return;
|
||||
const mode = form.querySelector('input[name="db_mode"]:checked')?.value || 'direct';
|
||||
const importType = form.querySelector('input[name="bridge_import"]:checked')?.value || 'schema';
|
||||
const payload = {
|
||||
tables: parseTablesInput(),
|
||||
mode,
|
||||
import_type: importType,
|
||||
direct_host: form.direct_host?.value.trim() || '',
|
||||
direct_port: Number(form.direct_port?.value || 0) || 3306,
|
||||
direct_database: form.direct_database?.value.trim() || '',
|
||||
direct_charset: form.direct_charset?.value.trim() || 'utf8mb4',
|
||||
direct_user: form.direct_user?.value.trim() || '',
|
||||
direct_password: form.direct_password?.value || '',
|
||||
config_file: form.config_file?.value.trim() || '',
|
||||
config_base: form.config_base?.value.trim() || '',
|
||||
config_host_key: form.config_host_key?.value.trim() || '',
|
||||
config_port_key: form.config_port_key?.value.trim() || '',
|
||||
config_database_key: form.config_database_key?.value.trim() || '',
|
||||
config_user_key: form.config_user_key?.value.trim() || '',
|
||||
config_password_key: form.config_password_key?.value.trim() || '',
|
||||
config_charset_key: form.config_charset_key?.value.trim() || '',
|
||||
};
|
||||
|
||||
try {
|
||||
@@ -193,20 +163,26 @@ async function loadTablesFromBridge(ev) {
|
||||
if (!loadBtn) return;
|
||||
loadBtn.disabled = true;
|
||||
try {
|
||||
const res = await apiAction('account.bridge.test', { method: 'POST', data: {} });
|
||||
const mode = form?.querySelector('input[name="db_mode"]:checked')?.value || 'bridge';
|
||||
const importType = form?.querySelector('input[name="bridge_import"]:checked')?.value || 'schema';
|
||||
const payload = {
|
||||
mode,
|
||||
import_type: importType,
|
||||
direct_host: form?.direct_host?.value.trim() || '',
|
||||
direct_port: Number(form?.direct_port?.value || 0) || 3306,
|
||||
direct_database: form?.direct_database?.value.trim() || '',
|
||||
direct_charset: form?.direct_charset?.value.trim() || 'utf8mb4',
|
||||
direct_user: form?.direct_user?.value.trim() || '',
|
||||
direct_password: form?.direct_password?.value || '',
|
||||
};
|
||||
const res = await apiAction('account.bridge.test', { method: 'POST', data: payload });
|
||||
if (!res?.ok) throw new Error(res?.error || 'Bridge konnte nicht abgefragt werden');
|
||||
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 || {}) };
|
||||
}
|
||||
fillForm(merged);
|
||||
updateStatus(`Tabellen geladen (${fetchedTables.length}).`);
|
||||
toast('Tabellen erfolgreich geladen', true);
|
||||
@@ -259,11 +235,12 @@ 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 validMode = mode === 'direct' ? 'direct' : 'bridge';
|
||||
const importType = (input.import_type || base.import_type).toLowerCase();
|
||||
const validImport = importType === 'settings' ? 'settings' : 'schema';
|
||||
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 };
|
||||
return { tables, mode: validMode, import_type: validImport, direct };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user