|
|
| 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> |
| (function(hook){ | | document.addEventListener('DOMContentLoaded', () => { |
| // Esegui sia con DOM standard sia con il ricarico di MediaWiki
| | const refreshBtn = document.getElementById('mpChatRefresh'); |
| hook(() => {
| | const listBox = document.getElementById('mpSavedList'); |
| const refreshBtn = document.getElementById('mpChatRefresh');
| | const answerBox = document.getElementById('mpChatAnswer'); |
| const listBox = document.getElementById('mpSavedList');
| | const projectSel = document.getElementById('mpChatProject'); |
| 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(){
| | async function refreshList(){ |
| console.log('[DEBUG] refreshList() start');
| | if (!listBox) return; |
| if (!listBox) { console.warn('[DEBUG] listBox #mpSavedList assente'); return; }
| | listBox.innerHTML = '<em style="color:#777;">Aggiorno…</em>'; |
| listBox.innerHTML = '<em style="color:#777;">Aggiorno…</em>';
| | const prj = currentProject(); |
| | | try { |
| const prj = currentProject();
| | const r = await fetch('/dashboard/api/list_saved_output.php?project=' + encodeURIComponent(prj) + '&sub=output', { cache:'no-store' }); |
| console.log('[DEBUG] project =', prj);
| | const txt = await r.text(); |
| | | let j; |
| try {
| | try { j = JSON.parse(txt); } |
| const url = '/dashboard/api/list_saved_output.php?project=' + encodeURIComponent(prj) + '&sub=output';
| | catch(e){ |
| console.log('[DEBUG] fetch URL =', url);
| | 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); |
| const r = await fetch(url, { cache:'no-store' });
| | return; |
| 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;
| |
| }
| |
|
| |
|
| if (!j.ok) {
| | if (!j.ok) { listBox.textContent = 'Errore: ' + (j.error || ''); return; } |
| console.error('[DEBUG] ok=false:', j);
| | if (!j.files || !j.files.length) { listBox.innerHTML = '<em style="color:#777;">Nessun file salvato.</em>'; return; } |
| listBox.textContent = 'Errore: ' + (j.error || 'sconosciuto');
| |
| return;
| |
| }
| |
|
| |
|
| if (!j.files || !j.files.length) {
| | listBox.innerHTML = j.files.map(f => ` |
| console.log('[DEBUG] nessun file');
| | <div style="display:flex;justify-content:space-between;gap:8px;border-bottom:1px dashed #eee;padding:4px 0;"> |
| listBox.innerHTML = '<em style="color:#777;">Nessun file salvato.</em>'; | | <span>${f.name} <span style="color:#888;">(${f.size} B)</span></span> |
| return; | | <button class="mpOpen" data-name="${f.name}">Apri</button> |
| } | | </div> |
| | `).join(''); |
|
| |
|
| console.log('[DEBUG] files =', j.files.length);
| | listBox.querySelectorAll('.mpOpen').forEach(btn => { |
| listBox.innerHTML = j.files.map(f => `
| | btn.addEventListener('click', async () => { |
| <div style="display:flex;justify-content:space-between;gap:8px;border-bottom:1px dashed #eee;padding:4px 0;">
| | const name = btn.getAttribute('data-name'); |
| <span>${f.name} <span style="color:#888;">(${f.size} B)</span></span>
| | try { |
| <button class="mpOpen" data-name="${f.name}">Apri</button>
| | const rr = await fetch('/dashboard/api/read_saved_output.php', { |
| </div>
| | method:'POST', |
| `).join('');
| | headers:{'Content-Type':'application/json'}, |
| | | body: JSON.stringify({ project: prj, file: name }) |
| // wiring del bottone Apri (carica contenuto nel box Risposta)
| | }); |
| listBox.querySelectorAll('.mpOpen').forEach(btn => {
| | const jj = await rr.json(); |
| btn.addEventListener('click', async () => {
| | if (!jj.ok) { alert('Errore lettura: ' + (jj.error||'')); return; } |
| const name = btn.getAttribute('data-name');
| | if (answerBox) answerBox.textContent = jj.content || ''; |
| console.log('[DEBUG] click Apri:', name);
| | } catch (e) { |
| try {
| | alert('Errore apertura file: ' + e.message); |
| 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);
| | } catch (e) { |
| listBox.textContent = 'Errore JS: ' + e.message;
| | listBox.textContent = 'Errore JS: ' + e.message; |
| } | | console.error(e); |
| } | | } |
| | } |
|
| |
|
| // click su Aggiorna → refreshList
| | refreshBtn && refreshBtn.addEventListener('click', refreshList); |
| refreshBtn?.addEventListener('click', () => {
| | // carica subito l'elenco alla prima apertura |
| console.log('[DEBUG] click Aggiorna OK');
| | refreshList(); |
| refreshList();
| | }); |
| });
| | </script> |
|
| |
|
| // carica subito all’apertura della dashboard
| | </html> |
| refreshList();
| |
| });
| |
| })(
| |
| (window.mw && mw.hook)
| |
| ? (fn)=>mw.hook('wikipage.content').add(fn)
| |
| : (fn)=>document.addEventListener('DOMContentLoaded', fn)
| |
| );
| |
| </script> | |
🔧 Dashboard Operativa – Masticationpedia
Centro di comando per progetti, API, file e backup
Connessione API (protetta dal server)
ChatGPT plus – Generazione capitoli
Trascina qui file (solo elenco, non inviati)
🗂️ File salvati (output/)
Nessun file elencato. Clicca “Aggiorna”.
📁 Carica File GPT
📘 Registro attività:
Registro avviato...