Dashboard Masticationpedia: differenze tra le versioni
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> | ||
<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 = '<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; | |||
} | |||
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 = '<em style="color:#777;">Nessun file salvato.</em>'; | |||
return; | |||
} | |||
console.log('[DEBUG] files =', j.files.length); | |||
listBox.innerHTML = j.files.map(f => ` | |||
<div style="display:flex;justify-content:space-between;gap:8px;border-bottom:1px dashed #eee;padding:4px 0;"> | |||
<span>${f.name} <span style="color:#888;">(${f.size} B)</span></span> | |||
<button class="mpOpen" data-name="${f.name}">Apri</button> | |||
</div> | |||
`).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> | </script> | ||
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>