/
UzhvaD
/
Web_application_development_Course_work
Обзор
Документация
Войти
/
UzhvaD
/
Web_application_development_Course_work
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
js/app.js
142 строки
6 KB
UzhvaD
create: style.css, app.js, database.js, scheduler.js, transforms.js, ui.js, utils.js
03 май 2026, 16:07
Верифицирован
03 май 2026, 16:07
b7726da
Код
Авторство
О чём код?
// ==================== ОСНОВНОЙ ФАЙЛ ПРИЛОЖЕНИЯ ==================== async function runETLPipeline(sourceDBName, transformType) { try { addLogToUI(`🚀 Запуск ETL: ${sourceDBName} → ${transformType}`, 'info'); const sourceDB = await getDatabase(sourceDBName); if (!sourceDB) { addLogToUI(`❌ Источник "${sourceDBName}" не найден`, 'error'); return false; } // ========== НОВАЯ ПРОВЕРКА ========== // Проверка на пустую БД if (!sourceDB.dataCsv || sourceDB.dataCsv.trim() === '') { addLogToUI(`❌ БД "${sourceDBName}" пуста. Нет данных для трансформации`, 'error'); return false; } // Проверка на валидность CSV const validation = validateCSV(sourceDB.dataCsv); if (!validation.valid) { addLogToUI(`❌ БД "${sourceDBName}" содержит ошибки: ${validation.error}`, 'error'); return false; } // Проверка на минимальное количество строк if (validation.rowCount === 0) { addLogToUI(`❌ БД "${sourceDBName}" не содержит строк данных (только заголовки)`, 'error'); return false; } // ================================== const result = applyTransform(transformType, sourceDB.dataCsv); addLogToUI(`🔄 Трансформация: ${result.message}`, result.removed > 0 || result.filled > 0 ? 'warn' : 'info'); // Получаем список существующих имён const allDBs = await getAllDatabases(); const existingNames = allDBs.map(db => db.name); // Генерируем уникальное имя const newDBName = generateUniqueName(sourceDBName, transformType, existingNames); const newHeaders = result.csv.split('\n')[0].split(',').map(h => h.trim()); await saveDatabase(newDBName, result.csv, newHeaders); addLogToUI(`💾 Создана новая БД: "${newDBName}"`, 'ok'); addLogToUI(`✅ ETL пайплайн завершён`, 'ok'); await renderDatabaseList(); return true; } catch (error) { addLogToUI(`❌ Ошибка ETL: ${error.message}`, 'error'); return false; } } function setupThemes() { const savedTheme = localStorage.getItem('etl_theme') || 'light'; document.body.classList.add(savedTheme); const themeBtn = document.createElement('div'); themeBtn.className = 'theme-toggle'; themeBtn.textContent = '🎨'; document.body.appendChild(themeBtn); const themeMenu = document.createElement('div'); themeMenu.className = 'theme-menu'; themeMenu.innerHTML = ` <div class="theme-option" data-theme="light">☀️ Светлая</div> <div class="theme-option" data-theme="dark">🌙 Тёмная</div> <div class="theme-option" data-theme="sunset">🌅 Закатная</div> <div class="theme-option" data-theme="forest">🌿 Лесная</div> `; document.body.appendChild(themeMenu); themeBtn.onclick = (e) => { e.stopPropagation(); themeMenu.classList.toggle('show'); }; document.querySelectorAll('.theme-option').forEach(opt => { opt.onclick = () => { const theme = opt.dataset.theme; document.body.classList.remove('light', 'dark', 'sunset', 'forest'); document.body.classList.add(theme); localStorage.setItem('etl_theme', theme); themeMenu.classList.remove('show'); addLogToUI(`Тема изменена на ${theme}`, 'info'); }; }); document.addEventListener('click', (e) => { if (!themeBtn.contains(e.target) && !themeMenu.contains(e.target)) { themeMenu.classList.remove('show'); } }); } async function initApp() { try { await initDatabase(); await loadLogHistory(); await renderDatabaseList(); // Переключение режимов document.getElementById('btnCreateMode').onclick = () => switchMode('create'); document.getElementById('btnImportMode').onclick = () => switchMode('import'); document.getElementById('btnEditMode').onclick = () => switchMode('edit'); // Действия с БД document.getElementById('btnSaveDb').onclick = createNewDatabase; document.getElementById('btnImportJson').onclick = importFromAnyFormatWrapper; document.getElementById('btnRefreshList').onclick = renderDatabaseList; document.getElementById('btnExportAll').onclick = exportAllDatabasesUI; document.getElementById('btnClearLogs').onclick = clearLogsUI; // Редактирование document.getElementById('editDbSelect').onchange = loadDatabaseForEdit; document.getElementById('btnSaveEdit').onclick = saveEditedDatabase; document.getElementById('btnCancelEdit').onclick = cancelEdit; // Планировщик document.getElementById('btnStartScheduler').onclick = () => { const interval = parseInt(document.getElementById('scheduleInterval').value); const source = document.getElementById('scheduleSource').value; const transform = document.getElementById('scheduleTransform').value; startScheduler(interval, source, transform); }; document.getElementById('btnStopScheduler').onclick = stopScheduler; setupThemes(); addLogToUI('🎉 Приложение готово к работе!', 'ok'); } catch (error) { console.error('Ошибка инициализации:', error); addLogToUI(`❌ Ошибка инициализации: ${error.message}`, 'error'); } } document.addEventListener('DOMContentLoaded', () => { initApp(); });