Nessun oggetto della modifica
Nessun oggetto della modifica
Etichetta: Annullato
Riga 166: Riga 166:
<script src="/dashboard/api/dashboard.js?v=20250907a"></script>
<script src="/dashboard/api/dashboard.js?v=20250907a"></script>


<!-- ✅ Mini-script che POPOLA l’elenco e gestisce “Apri” -->
<script>
<script>
document.addEventListener('DOMContentLoaded', () => {
(function(hook){
  const refreshBtn = document.getElementById('mpChatRefresh');
  // Esegui sia con DOM standard sia con il ricarico di MediaWiki
  const listBox    = document.getElementById('mpSavedList');
  hook(() => {
  const answerBox  = document.getElementById('mpChatAnswer');
    const refreshBtn = document.getElementById('mpChatRefresh');
  const projectSel = document.getElementById('mpChatProject');
    const listBox    = document.getElementById('mpSavedList');
    const answerBox  = document.getElementById('mpChatAnswer');
    const projectSel = document.getElementById('mpChatProject');


  function currentProject(){
    function currentProject(){
    return (projectSel?.value || 'Generazione_capitoli').trim();
      return (projectSel?.value || 'Generazione_capitoli').trim();
   }
    }
 
    async function refreshList(){
      console.log('[DEBUG] refreshList() start');
      if (!listBox) { console.warn('[DEBUG] listBox #mpSavedList assente'); return; }
      listBox.innerHTML = '<em style="color:#777;">Aggiorno…</em>';
 
      const prj = currentProject();
      console.log('[DEBUG] project =', prj);
 
      try {
        const url = '/dashboard/api/list_saved_output.php?project=' + encodeURIComponent(prj) + '&sub=output';
        console.log('[DEBUG] fetch URL =', url);
 
        const r   = await fetch(url, { cache:'no-store' });
        const txt = await r.text();
        console.log('[DEBUG] raw response (head)=', txt.slice(0,120).replace(/\n/g,' '));
 
        let j;
        try {
          j = JSON.parse(txt);
        } catch(e){
          console.error('[DEBUG] NON JSON, stampo i primi 400 caratteri:\n', txt.slice(0,400));
          listBox.innerHTML = '<span style="color:#c00;">Risposta non-JSON</span><pre style="white-space:pre-wrap">'+
                              txt.substring(0,400)+'</pre>';
          return;
        }


  async function refreshList(){
        if (!j.ok) {
    if (!listBox) return;
          console.error('[DEBUG] ok=false:', j);
    listBox.innerHTML = '<em style="color:#777;">Aggiorno…</em>';
          listBox.textContent = 'Errore: ' + (j.error || 'sconosciuto');
    const prj = currentProject();
          return;
    try {
        }
      const r = await fetch('/dashboard/api/list_saved_output.php?project=' + encodeURIComponent(prj) + '&sub=output', { cache:'no-store' });
      const txt = await r.text();
      let j;
      try { j = JSON.parse(txt); }
      catch(e){
        listBox.innerHTML = '<span style="color:#c00;">Risposta non-JSON</span><pre style="white-space:pre-wrap">'+txt.substring(0,400)+'</pre>';
        console.error('list_saved_output NON JSON:', txt);
        return;
      }


      if (!j.ok) { listBox.textContent = 'Errore: ' + (j.error || ''); return; }
        if (!j.files || !j.files.length) {
      if (!j.files || !j.files.length) { listBox.innerHTML = '<em style="color:#777;">Nessun file salvato.</em>'; return; }
          console.log('[DEBUG] nessun file');
          listBox.innerHTML = '<em style="color:#777;">Nessun file salvato.</em>';
          return;
        }


      listBox.innerHTML = j.files.map(f => `
        console.log('[DEBUG] files =', j.files.length);
        <div style="display:flex;justify-content:space-between;gap:8px;border-bottom:1px dashed #eee;padding:4px 0;">
        listBox.innerHTML = j.files.map(f => `
          <span>${f.name} <span style="color:#888;">(${f.size} B)</span></span>
          <div style="display:flex;justify-content:space-between;gap:8px;border-bottom:1px dashed #eee;padding:4px 0;">
          <button class="mpOpen" data-name="${f.name}">Apri</button>
            <span>${f.name} <span style="color:#888;">(${f.size} B)</span></span>
        </div>
            <button class="mpOpen" data-name="${f.name}">Apri</button>
      `).join('');
          </div>
        `).join('');


      listBox.querySelectorAll('.mpOpen').forEach(btn => {
        // wiring del bottone Apri (carica contenuto nel box Risposta)
        btn.addEventListener('click', async () => {
        listBox.querySelectorAll('.mpOpen').forEach(btn => {
          const name = btn.getAttribute('data-name');
          btn.addEventListener('click', async () => {
          try {
            const name = btn.getAttribute('data-name');
            const rr = await fetch('/dashboard/api/read_saved_output.php', {
            console.log('[DEBUG] click Apri:', name);
              method:'POST',
            try {
              headers:{'Content-Type':'application/json'},
              const rr = await fetch('/dashboard/api/read_saved_output.php', {
              body: JSON.stringify({ project: prj, file: name })
                method:'POST',
            });
                headers:{'Content-Type':'application/json'},
            const jj = await rr.json();
                body: JSON.stringify({ project: prj, file: name })
            if (!jj.ok) { alert('Errore lettura: ' + (jj.error||'')); return; }
              });
            if (answerBox) answerBox.textContent = jj.content || '';
              const jj = await rr.json();
          } catch (e) {
              if (!jj.ok) { alert('Errore lettura: ' + (jj.error||'')); return; }
            alert('Errore apertura file: ' + e.message);
              if (answerBox) answerBox.textContent = jj.content || '';
           }
              console.log('[DEBUG] file aperto OK');
            } catch(e){
              console.error('[DEBUG] errore apertura', e);
              alert('Errore apertura file: ' + e.message);
            }
           });
         });
         });
       });
       } catch (e) {
    } catch (e) {
        console.error('[DEBUG] errore generale refreshList:', e);
      listBox.textContent = 'Errore JS: ' + e.message;
        listBox.textContent = 'Errore JS: ' + e.message;
       console.error(e);
       }
     }
     }
  }


  refreshBtn && refreshBtn.addEventListener('click', refreshList);
    // click su Aggiorna → refreshList
  // carica subito l'elenco alla prima apertura
    refreshBtn?.addEventListener('click', () => {
  refreshList();
      console.log('[DEBUG] click Aggiorna OK');
});
      refreshList();
    });
 
    // carica subito all’apertura della dashboard
    refreshList();
  });
})(
  (window.mw && mw.hook)
    ? (fn)=>mw.hook('wikipage.content').add(fn)
    : (fn)=>document.addEventListener('DOMContentLoaded', fn)
);
</script>
</script>
</html>

Versione delle 10:47, 7 set 2025

<html>

🔧 Dashboard Operativa – Masticationpedia

Centro di comando per progetti, API, file e backup

 <button class="dashboard-toggle" onclick="toggleDashboardBox('api-settings')">⚙️ Connessione API</button>
 <button class="dashboard-toggle" onclick="toggleDashboardBox('project-status')">📊 Stato Progetti</button>
 <button class="dashboard-toggle" onclick="toggleDashboardBox('chatgpt-plus')">🤖 ChatGPT plus</button>
 <button class="dashboard-toggle" onclick="toggleDashboardBox('test-tools')">🧪 Strumenti di Test</button>
 <button class="dashboard-toggle" onclick="toggleDashboardBox('activity-log')">📘 Registro Attività</button>
 <button class="dashboard-toggle" onclick="uploadToOpenAI()">📄 Carica in OpenAI</button>

📁 Importa file dal server (semplificata)

   <label for="sourcePathInput">📂 Percorso Assoluto del file sorgente:</label>
<input type="text" id="sourcePathInput" placeholder="/percorso/assoluto/file.php" style="width:100%; margin-bottom:0.5rem;">
<label for="projectNameInput">📁 Cartella di destinazione nel progetto:</label>
<input type="text" id="projectNameInput" placeholder="nome_progetto/">

📁 Carica File GPT

 <label>📁 Project: <input type="text" id="gpt-load-project" value="SSO_LinkedIn" /></label>
 <label>📂 Subfolder: <input type="text" id="gpt-load-subfolder" value="php" /></label>
 <label>📄 Filename: <input type="text" id="gpt-load-filename" placeholder="es: testGPT.php" /></label>
 <button onclick="caricaFileGPT()">📁 Carica file</button>

<script src="/dashboard/api/dashboard.js?v=20250907a"></script>

<script> (function(hook){

 // Esegui sia con DOM standard sia con il ricarico di MediaWiki
 hook(() => {
   const refreshBtn = document.getElementById('mpChatRefresh');
   const listBox    = document.getElementById('mpSavedList');
   const answerBox  = document.getElementById('mpChatAnswer');
   const projectSel = document.getElementById('mpChatProject');
   function currentProject(){
     return (projectSel?.value || 'Generazione_capitoli').trim();
   }
   async function refreshList(){
     console.log('[DEBUG] refreshList() start');
     if (!listBox) { console.warn('[DEBUG] listBox #mpSavedList assente'); return; }
     listBox.innerHTML = 'Aggiorno…';
     const prj = currentProject();
     console.log('[DEBUG] project =', prj);
     try {
       const url = '/dashboard/api/list_saved_output.php?project=' + encodeURIComponent(prj) + '&sub=output';
       console.log('[DEBUG] fetch URL =', url);
       const r   = await fetch(url, { cache:'no-store' });
       const txt = await r.text();
       console.log('[DEBUG] raw response (head)=', txt.slice(0,120).replace(/\n/g,' '));
       let j;
       try {
         j = JSON.parse(txt);
       } catch(e){
         console.error('[DEBUG] NON JSON, stampo i primi 400 caratteri:\n', txt.slice(0,400));

listBox.innerHTML = 'Risposta non-JSON

'+
                               txt.substring(0,400)+'

';

         return;
       }
       if (!j.ok) {
         console.error('[DEBUG] ok=false:', j);
         listBox.textContent = 'Errore: ' + (j.error || 'sconosciuto');
         return;
       }
       if (!j.files || !j.files.length) {
         console.log('[DEBUG] nessun file');
         listBox.innerHTML = 'Nessun file salvato.';
         return;
       }
       console.log('[DEBUG] files =', j.files.length);
       listBox.innerHTML = j.files.map(f => `
           ${f.name} (${f.size} B)
           <button class="mpOpen" data-name="${f.name}">Apri</button>
       `).join();
       // wiring del bottone Apri (carica contenuto nel box Risposta)
       listBox.querySelectorAll('.mpOpen').forEach(btn => {
         btn.addEventListener('click', async () => {
           const name = btn.getAttribute('data-name');
           console.log('[DEBUG] click Apri:', name);
           try {
             const rr = await fetch('/dashboard/api/read_saved_output.php', {
               method:'POST',
               headers:{'Content-Type':'application/json'},
               body: JSON.stringify({ project: prj, file: name })
             });
             const jj = await rr.json();
             if (!jj.ok) { alert('Errore lettura: ' + (jj.error||)); return; }
             if (answerBox) answerBox.textContent = jj.content || ;
             console.log('[DEBUG] file aperto OK');
           } catch(e){
             console.error('[DEBUG] errore apertura', e);
             alert('Errore apertura file: ' + e.message);
           }
         });
       });
     } catch (e) {
       console.error('[DEBUG] errore generale refreshList:', e);
       listBox.textContent = 'Errore JS: ' + e.message;
     }
   }
   // click su Aggiorna → refreshList
   refreshBtn?.addEventListener('click', () => {
     console.log('[DEBUG] click Aggiorna OK');
     refreshList();
   });
   // carica subito all’apertura della dashboard
   refreshList();
 });

})(

 (window.mw && mw.hook) 
   ? (fn)=>mw.hook('wikipage.content').add(fn)
   : (fn)=>document.addEventListener('DOMContentLoaded', fn)

); </script>