diff --git a/patch_app_js.js b/patch_app_js.js new file mode 100644 index 0000000..6ca9d9e --- /dev/null +++ b/patch_app_js.js @@ -0,0 +1,482 @@ +const fs = require('fs'); +const path = require('path'); + +const appFile = path.join(__dirname, 'public', 'app.js'); +let appCode = fs.readFileSync(appFile, 'utf8'); + +const startIndex = appCode.indexOf('// ============================================================\n // MODAL: MINHA TURMA'); +const endIndex = appCode.indexOf('// ============================================================\n // CRUD DE MODELOS DE RELATÓRIO'); + +if (startIndex === -1 || endIndex === -1) { + console.error("Could not find start or end index for replacement"); + process.exit(1); +} + +const newLogic = `// ============================================================ + // MODAL: MINHA TURMA (COM MÚLTIPLAS TURMAS E SUPABASE) + // ============================================================ + const minhaTurmaModal = document.getElementById('minhaTurmaModal'); + const btnMinhaTurma = document.getElementById('btnMinhaTurma'); + const btnCloseMinhaTurmaModal = document.getElementById('btnCloseMinhaTurmaModal'); + + // Turmas List & Form + const turmasList = document.getElementById('turmasList'); + const btnCreateTurma = document.getElementById('btnCreateTurma'); + const btnCancelTurma = document.getElementById('btnCancelTurma'); + const btnSaveTurmaConfig = document.getElementById('btnSaveTurmaConfig'); + const configTurmaId = document.getElementById('configTurmaId'); + const configTurmaNome = document.getElementById('configTurmaNome'); + const configTurmaSala = document.getElementById('configTurmaSala'); + const configTurmaPeriodo = document.getElementById('configTurmaPeriodo'); + const configTurmaProfTitular = document.getElementById('configTurmaProfTitular'); + const configTurmaProfAux1 = document.getElementById('configTurmaProfAux1'); + const configTurmaProfAux2 = document.getElementById('configTurmaProfAux2'); + const configTurmaCuidadora = document.getElementById('configTurmaCuidadora'); + const turmaFormTitle = document.getElementById('turmaFormTitle'); + + // Alunos List & Form + const filterAlunosTurma = document.getElementById('filterAlunosTurma'); + const childrenList = document.getElementById('childrenList'); + const btnCreateChild = document.getElementById('btnCreateChild'); + const btnCancelChild = document.getElementById('btnCancelChild'); + const btnSaveChild = document.getElementById('btnSaveChild'); + const childFormTitle = document.getElementById('childFormTitle'); + const cFormId = document.getElementById('childFormId'); + const cFormTurma = document.getElementById('childFormTurma'); + const cFormNome = document.getElementById('childFormNome'); + const cFormApelido = document.getElementById('childFormApelido'); + const cFormDataNasc = document.getElementById('childFormDataNasc'); + const cFormEspecial = document.getElementById('childFormEspecial'); + const divEspecialDetalhes = document.getElementById('divEspecialDetalhes'); + const cFormEspecialDetalhes = document.getElementById('childFormEspecialDetalhes'); + const cFormPais = document.getElementById('childFormPais'); + const cFormAutorizados = document.getElementById('childFormAutorizados'); + + // Tabs + const tabTurmaConfig = document.getElementById('tabTurmaConfig'); + const tabTurmaAlunos = document.getElementById('tabTurmaAlunos'); + const turmaConfigSection = document.getElementById('turmaConfigSection'); + const turmaAlunosSection = document.getElementById('turmaAlunosSection'); + + let currentTurmas = []; + let currentAlunos = []; + + // API Calls + const fetchTurmas = async () => { + try { + const res = await fetch('/api/turmas'); + currentTurmas = await res.json(); + populateTurmaSelects(); + return currentTurmas; + } catch(e) { console.error(e); return []; } + }; + + const fetchAlunos = async () => { + try { + const res = await fetch('/api/alunos'); + currentAlunos = await res.json(); + localStorage.setItem('camila_turma', JSON.stringify(currentAlunos)); + return currentAlunos; + } catch(e) { console.error(e); return []; } + }; + + const populateTurmaSelects = () => { + const opts = '' + currentTurmas.map(t => \`\`).join(''); + if(filterAlunosTurma) filterAlunosTurma.innerHTML = opts; + const formOpts = '' + currentTurmas.map(t => \`\`).join(''); + if(cFormTurma) cFormTurma.innerHTML = formOpts; + if(document.getElementById('emitirFilterTurma')) { + document.getElementById('emitirFilterTurma').innerHTML = '' + currentTurmas.map(t => \`\`).join(''); + } + }; + + // Tabs Logic + if (tabTurmaConfig) { + tabTurmaConfig.addEventListener('click', () => { + tabTurmaConfig.classList.add('active'); + tabTurmaConfig.style.borderBottomColor = 'var(--brand-green)'; + tabTurmaConfig.style.color = 'var(--brand-green)'; + tabTurmaAlunos.classList.remove('active'); + tabTurmaAlunos.style.borderBottomColor = 'transparent'; + tabTurmaAlunos.style.color = 'var(--text-secondary)'; + turmaConfigSection.style.display = 'flex'; + turmaAlunosSection.style.display = 'none'; + }); + } + if (tabTurmaAlunos) { + tabTurmaAlunos.addEventListener('click', () => { + tabTurmaAlunos.classList.add('active'); + tabTurmaAlunos.style.borderBottomColor = 'var(--brand-green)'; + tabTurmaAlunos.style.color = 'var(--brand-green)'; + tabTurmaConfig.classList.remove('active'); + tabTurmaConfig.style.borderBottomColor = 'transparent'; + tabTurmaConfig.style.color = 'var(--text-secondary)'; + turmaAlunosSection.style.display = 'flex'; + turmaConfigSection.style.display = 'none'; + }); + } + + // Turmas Logic + const clearTurmaForm = () => { + configTurmaId.value = ''; + configTurmaNome.value = ''; + configTurmaSala.value = ''; + configTurmaPeriodo.value = 'Integral'; + configTurmaProfTitular.value = ''; + configTurmaProfAux1.value = ''; + configTurmaProfAux2.value = ''; + configTurmaCuidadora.value = ''; + turmaFormTitle.textContent = 'Cadastrar Turma'; + }; + + const renderTurmasList = () => { + if(!turmasList) return; + if(currentTurmas.length === 0) { + turmasList.innerHTML = '