// Migration workflow: options modal → progress → results view import { api } from './api.js'; import { state, setState } from './state.js'; import { escHtml, formatDateTime, downloadCsv, renderFieldIssues, bindFieldIssueToggles } from './utils.js'; import { navigate } from './router.js'; import { refreshTemplates } from './templates.js'; // ── Helpers ──────────────────────────────────────────────────────────────── const _RESULTS_STORAGE_KEY = 'migrator_last_batch_results'; function getSettings() { try { return JSON.parse(localStorage.getItem('migrator_settings')) || {}; } catch { return {}; } } function persistLastResults(results) { try { sessionStorage.setItem(_RESULTS_STORAGE_KEY, JSON.stringify(results)); } catch { // Best-effort only. } } function loadPersistedResults() { try { const raw = sessionStorage.getItem(_RESULTS_STORAGE_KEY); return raw ? JSON.parse(raw) : null; } catch { return null; } } function buildResultsFromHistory(history) { if (!history || !history.length) return null; const sorted = [...history].sort((a, b) => String(b.timestamp || '').localeCompare(String(a.timestamp || ''))); const newestTimestamp = sorted[0]?.timestamp; const recentBatch = sorted.filter(item => item.timestamp === newestTimestamp); if (!recentBatch.length) return null; return { status: 'completed', completed_at: newestTimestamp, results: recentBatch, summary: { total: recentBatch.length, success: recentBatch.filter(r => r.status === 'success').length, failed: recentBatch.filter(r => r.status === 'failed' || r.status === 'blocked').length, skipped: recentBatch.filter(r => r.status === 'skipped').length, dry_run: recentBatch.filter(r => r.status === 'dry_run').length, }, recovered_from_history: true, }; } // ── Options modal ────────────────────────────────────────────────────────── export function showOptionsModal(ids) { if (!ids || !ids.length) return; const settings = getSettings(); const names = ids.map(id => { const t = state.templates.find(t => t.adobe_id === id); return t ? t.name : id; }); const existing = document.getElementById('migration-modal'); if (existing) existing.remove(); const wrapper = document.createElement('div'); wrapper.id = 'migration-modal'; wrapper.innerHTML = `