From 7fa88481b7dc3999986a311ae1a162dc3253a466 Mon Sep 17 00:00:00 2001 From: admtracksteel Date: Fri, 5 Jun 2026 13:50:39 +0000 Subject: [PATCH] =?UTF-8?q?Criando=20novo=20m=C3=B3dulo=20Est=C3=BAdio=20d?= =?UTF-8?q?e=20Poesia=20e=20renomeando=20bot=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/app.js | 191 ++++++++++++++++++++++++++++++++++++++++++++++ public/index.html | 90 +++++++++++++++++++++- server.js | 133 ++++++++++++++++++++++++++++++++ 3 files changed, 410 insertions(+), 4 deletions(-) diff --git a/public/app.js b/public/app.js index 00d4900..d2faa7f 100644 --- a/public/app.js +++ b/public/app.js @@ -5170,6 +5170,197 @@ const initApp = () => { } } + // ============================================================ + // ESTÚDIO DE POESIA + // ============================================================ + const poesiaModal = document.getElementById('poesiaModal'); + const btnClosePoesiaModal = document.getElementById('btnClosePoesiaModal'); + const barBtnPoesia = document.getElementById('barBtnPoesia'); + const btnOpenPoesiaHistory = document.getElementById('btnOpenPoesiaHistory'); + const poesiaHistoryModal = document.getElementById('poesiaHistoryModal'); + const btnClosePoesiaHistory = document.getElementById('btnClosePoesiaHistory'); + + const btnGeneratePoesia = document.getElementById('btnGeneratePoesia'); + const poesiaGenerateLoader = document.getElementById('poesiaGenerateLoader'); + const poesiaResultArea = document.getElementById('poesiaResultArea'); + const poesiaTextOutput = document.getElementById('poesiaTextOutput'); + const btnCopyPoesia = document.getElementById('btnCopyPoesia'); + const btnDownloadPoesiaPdf = document.getElementById('btnDownloadPoesiaPdf'); + + const poesiaTemaInput = document.getElementById('poesiaTemaInput'); + const poesiaFaixaEtaria = document.getElementById('poesiaFaixaEtaria'); + + let currentPoesia = null; + let selectedEstrofes = 3; + + // Seleção de estrofes + document.querySelectorAll('.btn-poesia-estrofes').forEach(btn => { + btn.addEventListener('click', (e) => { + document.querySelectorAll('.btn-poesia-estrofes').forEach(b => b.classList.remove('active')); + e.target.classList.add('active'); + selectedEstrofes = parseInt(e.target.dataset.estrofes); + }); + }); + + // Abrir/Fechar Modal Principal + if (barBtnPoesia) { + barBtnPoesia.addEventListener('click', () => { + poesiaModal.style.display = 'flex'; + poesiaTemaInput.value = ''; + poesiaResultArea.style.display = 'none'; + poesiaGenerateLoader.style.display = 'none'; + btnGeneratePoesia.disabled = false; + currentPoesia = null; + }); + } + + if (btnClosePoesiaModal) { + btnClosePoesiaModal.addEventListener('click', () => { + poesiaModal.style.display = 'none'; + }); + } + + // Abrir/Fechar Modal de Histórico + if (btnOpenPoesiaHistory) { + btnOpenPoesiaHistory.addEventListener('click', () => { + poesiaHistoryModal.style.display = 'flex'; + loadPoesiaHistory(); + }); + } + + if (btnClosePoesiaHistory) { + btnClosePoesiaHistory.addEventListener('click', () => { + poesiaHistoryModal.style.display = 'none'; + }); + } + + window.addEventListener('click', (e) => { + if (e.target === poesiaModal) poesiaModal.style.display = 'none'; + if (e.target === poesiaHistoryModal) poesiaHistoryModal.style.display = 'none'; + }); + + // Gerar Poesia + if (btnGeneratePoesia) { + btnGeneratePoesia.addEventListener('click', async () => { + const tema = poesiaTemaInput.value.trim(); + const faixaEtaria = poesiaFaixaEtaria.value; + + if (!tema) { + showToast('Por favor, digite o tema da poesia.', 'error'); + return; + } + + btnGeneratePoesia.disabled = true; + poesiaGenerateLoader.style.display = 'flex'; + poesiaResultArea.style.display = 'none'; + + try { + const response = await fetch('/api/poesias/generate', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ faixaEtaria, estrofes: selectedEstrofes, tema }) + }); + + const data = await response.json(); + + if (response.ok && data.success) { + currentPoesia = data.poesia; + poesiaTextOutput.innerHTML = window.marked ? marked.parse(currentPoesia) : currentPoesia; + poesiaResultArea.style.display = 'flex'; + showToast('Poesia criada com sucesso!', 'success'); + } else { + showToast(data.error || 'Falha ao gerar poesia.', 'error'); + } + } catch (err) { + console.error('Erro na geração da poesia:', err); + showToast('Erro de conexão ao gerar poesia.', 'error'); + } finally { + btnGeneratePoesia.disabled = false; + poesiaGenerateLoader.style.display = 'none'; + } + }); + } + + // Copiar e Baixar + if (btnCopyPoesia) { + btnCopyPoesia.addEventListener('click', () => { + if (currentPoesia) { + navigator.clipboard.writeText(currentPoesia); + showToast('Poesia copiada para a área de transferência!', 'success'); + } + }); + } + + if (btnDownloadPoesiaPdf) { + btnDownloadPoesiaPdf.addEventListener('click', () => { + if (!currentPoesia) return; + const element = document.createElement('div'); + element.innerHTML = window.marked ? marked.parse(currentPoesia) : currentPoesia; + element.style.padding = '20px'; + element.style.fontFamily = 'Arial, sans-serif'; + element.style.color = '#333'; + + html2pdf().set({ + margin: 15, + filename: 'poesia_pedagogica.pdf', + image: { type: 'jpeg', quality: 0.98 }, + html2canvas: { scale: 2 }, + jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' } + }).from(element).save(); + }); + } + + // Carregar Histórico + async function loadPoesiaHistory() { + const listContainer = document.getElementById('poesiaHistoryList'); + if (!listContainer) return; + + listContainer.innerHTML = '

Carregando...

'; + + try { + const response = await fetch('/api/poesias/list'); + const data = await response.json(); + + if (data && data.length > 0) { + listContainer.innerHTML = ''; + data.forEach(item => { + const date = new Date(item.created_at).toLocaleString('pt-BR'); + const div = document.createElement('div'); + div.className = 'history-item-card'; + div.style.cssText = 'background: rgba(255,255,255,0.02); padding: 14px; border-radius: 8px; border: 1px solid var(--border-light); display: flex; flex-direction: column; gap: 8px; cursor: pointer;'; + div.innerHTML = ` +
+ ${item.faixa_etaria} (${item.estrofes} Estrofes) + ${date} +
+

Tema: ${item.tema}

+ `; + + div.addEventListener('click', async () => { + try { + const res = await fetch(`/api/poesias/${item.id}`); + const detail = await res.json(); + if (res.ok) { + currentPoesia = detail.poesia; + poesiaTextOutput.innerHTML = window.marked ? marked.parse(currentPoesia) : currentPoesia; + poesiaResultArea.style.display = 'flex'; + poesiaHistoryModal.style.display = 'none'; + } + } catch (err) { + showToast('Erro ao carregar poesia.', 'error'); + } + }); + + listContainer.appendChild(div); + }); + } else { + listContainer.innerHTML = '

Nenhuma poesia salva ainda.

'; + } + } catch (err) { + listContainer.innerHTML = '

Erro ao carregar histórico.

'; + } + } + // ============================================================ // BRINCARATIVO (CIRCUITOS PSICOMOTORES E BRINCADEIRAS) // ============================================================ diff --git a/public/index.html b/public/index.html index f8954c7..56af47a 100644 --- a/public/index.html +++ b/public/index.html @@ -239,7 +239,7 @@ 🎨 Atividade BNCC -
@@ -736,6 +736,88 @@ + + + + + +