Nessun oggetto della modifica
Nessun oggetto della modifica
Riga 308: Riga 308:
   }
   }
};
};
</script>
<script>
/* === Renderer stile ChatGPT: trasforma testo in HTML arioso === */
function renderGpt(text) {
  const box = document.getElementById('gptResponse');
  if (!box) return;
  if (!text) { box.innerHTML = '<em style="opacity:.7">Nessuna risposta</em>'; return; }
  // headings ###, ##, #
  let html = (text || '').replace(/\r\n/g, '\n')
    .replace(/^\s*#{3}\s?(.*)$/gm, '<h3 style="font-size:18px;margin:14px 0 6px;">$1</h3>')
    .replace(/^\s*#{2}\s?(.*)$/gm, '<h2 style="font-size:20px;margin:16px 0 8px;">$1</h2>')
    .replace(/^\s*#\s?(.*)$/gm,  '<h1 style="font-size:22px;margin:18px 0 10px;">$1</h1>')
    .replace(/^\s*-\s+(.*)$/gm,  '<li>$1</li>');
  // racchiudi sequenze di <li> in <ul>
  html = html.replace(/(?:<li>.*<\/li>\n?)+/gs, m => `<ul style="margin:8px 0 14px 22px;">${m}</ul>`);
  // paragrafi (evita di wrappare headings/list)
  html = html.split('\n').map(line => {
    if (/^<h\d|^<ul|^<li|^<\/ul>/.test(line)) return line;
    if (line.trim()==='') return '';
    return `<p style="margin:8px 0;">${line}</p>`;
  }).join('');
  box.innerHTML = html;
}
/* === Costruzione contesto per GPT dai campi pagina === */
function buildProjectContext() {
  const title = (document.getElementById('newProjectTitle')?.value || '').trim();
  const notes = (document.getElementById('newProjectNotes')?.value || '').trim();
  const goal        = (document.getElementById('p_goal')?.value || '').trim();
  const audience    = (document.getElementById('p_audience')?.value || '').trim();
  const deliverable = (document.getElementById('p_deliverable')?.value || '').trim();
  const constraints = (document.getElementById('p_constraints')?.value || '').trim();
  return { title, notes, goal, audience, deliverable, constraints };
}
function buildPromptForGPT() {
  const c = buildProjectContext();
  const out = [];
  out.push(`You are a senior editor and project designer. Provide a clear, actionable plan.`);
  if (c.title)      out.push(`\n# Title\n${c.title}`);
  if (c.notes)      out.push(`\n# Notes\n${c.notes}`);
  if (c.goal)        out.push(`\n# Goal\n${c.goal}`);
  if (c.audience)    out.push(`\n# Audience\n${c.audience}`);
  if (c.deliverable) out.push(`\n# Deliverables\n${c.deliverable}`);
  if (c.constraints) out.push(`\n# Constraints\n${c.constraints}`);
  out.push(`\n# Output format
- Executive Summary
- Strengths & Risks
- Step-by-step Plan (milestones)
- Resources & Budget hints
- Metrics of success`);
  return out.join('\n');
}
/* === Azione: Analizza con GPT (usa la tua API già protetta) ===
* Se NON hai ancora un endpoint dedicato, per test immediato simuliamo la risposta.
* Quando vorrai la chiamata reale, sostituisci la parte "FAKE RESPONSE" con una fetch al tuo endpoint server (/dashboard/api/ai_project_analyze.php).
*/
async function runProjectAnalysis() {
  const btn = document.getElementById('btnAnalyze');
  if (!btn) return;
  btn.disabled = true; btn.textContent = 'Analizzo…';
  try {
    const prompt = buildPromptForGPT();
    // === FAKE RESPONSE PER TEST VISIVO (subito) ===
    const fake = `# Executive Summary
Progetto focalizzato su ${ (document.getElementById('newProjectTitle')?.value || 'il tema indicato') }.
Obiettivo: ${ document.getElementById('p_goal')?.value || 'non specificato' }.
Pubblico: ${ document.getElementById('p_audience')?.value || 'non specificato' }.
## Strengths & Risks
- Strength: contenuti specialistici.
- Risk: mancano vincoli chiari (${ document.getElementById('p_constraints')?.value || '—' }).
## Step-by-step Plan (milestones)
- M1: Definizione indice capitoli.
- M2: Sviluppo contenuti.
- M3: Revisione clinica e bibliografia.
- M4: Pubblicazione.
## Resources & Budget hints
- Autori, revisori, tool AI, hosting video.
## Metrics of success
- Capitoli completati, feedback medici, engagement studenti.`;
    renderGpt(fake);
    // === VERSIONE REALE (quando pronta):
    // const r = await fetch('/dashboard/api/ai_project_analyze.php', {
    //  method: 'POST',
    //  headers: {'Content-Type':'application/x-www-form-urlencoded'},
    //  body: new URLSearchParams({ prompt })
    // });
    // const j = await r.json();
    // if (!j.ok) throw new Error(j.error || 'AI error');
    // renderGpt(j.text);
  } catch (e) {
    renderGpt('❌ Errore: ' + e.message);
  } finally {
    btn.disabled = false; btn.textContent = 'Analizza con GPT';
  }
}
/* bind del bottone */
document.addEventListener('DOMContentLoaded', () => {
  const b = document.getElementById('btnAnalyze');
  if (b) b.addEventListener('click', runProjectAnalysis);
});
</script>
</script>


</html>
</html>

Versione delle 16:36, 14 set 2025

🔧 Dashboard Operativa – Masticationpedia

Centro di comando per progetti, API, file e backup

🧾 Apri Log Dashboard

📁 Importa file dal server (semplificata)




📁 Carica File GPT