MediaWiki:CommonDashboard.js: differenze tra le versioni
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
Riga 1: | Riga 1: | ||
// ============================================ | // ============================================ | ||
// 🔧 CommonDashboard.js – versione GPT-4o + | // 🔧 CommonDashboard.js – versione GPT-4o + Lettura file reale | ||
// ============================================ | |||
// ============================================ | |||
// 📘 INTRODUZIONE | |||
// ============================================ | // ============================================ | ||
window.toggleDashboardBox = function (id) { | window.toggleDashboardBox = function (id) { | ||
const box = document.getElementById(id); | const box = document.getElementById(id); | ||
if (box) box.style.display = box.style.display === "block" ? "none" : "block"; | if (box) { | ||
box.style.display = box.style.display === "block" ? "none" : "block"; | |||
} | |||
}; | }; | ||
// | // ============================================ | ||
// ⚙️ CONNESSIONE API | |||
// ============================================ | |||
window.testAPIConnection = async function () { | window.testAPIConnection = async function () { | ||
const key = document.getElementById('api-key').value.trim(); | const key = document.getElementById('api-key').value.trim(); | ||
Riga 55: | Riga 63: | ||
}; | }; | ||
// 📂 | // ============================================ | ||
// 📂 ACCESSO FILE SERVER | |||
// ============================================ | |||
document.querySelector('#readFileBtn')?.addEventListener('click', async () => { | document.querySelector('#readFileBtn')?.addEventListener('click', async () => { | ||
const filenameInput = document.querySelector('#readFileName'); | const filenameInput = document.querySelector('#readFileName'); | ||
Riga 67: | Riga 78: | ||
try { | try { | ||
const | const endpoint = "/dashboard/api/read_file.php"; | ||
const response = await fetch(`${endpoint}?filename=${encodeURIComponent(filename)}`); | |||
const data = await response.json(); | const data = await response.json(); | ||
Riga 83: | Riga 95: | ||
}); | }); | ||
// | // ============================================ | ||
// 📊 STATO PROGETTI | |||
// ============================================ | |||
// (Da completare nel prossimo step) | |||
// | // ============================================ | ||
// 🧪 STRUMENTI DI TEST | |||
// ============================================ | |||
// (Da completare nel prossimo step) | |||
// | // ============================================ | ||
// 🧾 REGISTRO ATTIVITÀ | |||
// ============================================ | |||
window.logActivity = function (messaggio) { | window.logActivity = function (messaggio) { | ||
const contenitore = document.getElementById("activityLogContent"); | const contenitore = document.getElementById("activityLogContent"); | ||
Riga 134: | Riga 122: | ||
}; | }; | ||
window.clearActivityLog = function () { | window.clearActivityLog = function () { | ||
const contenitore = document.getElementById("activityLogContent"); | const contenitore = document.getElementById("activityLogContent"); | ||
Riga 141: | Riga 128: | ||
}; | }; | ||
// | // ============================================ | ||
// 🧠 CARICA IN OPENAI | |||
// ============================================ | |||
// (Da completare nel prossimo step) | |||
Versione delle 15:24, 1 ago 2025
// ============================================
// 🔧 CommonDashboard.js – versione GPT-4o + Lettura file reale
// ============================================
// ============================================
// 📘 INTRODUZIONE
// ============================================
window.toggleDashboardBox = function (id) {
const box = document.getElementById(id);
if (box) {
box.style.display = box.style.display === "block" ? "none" : "block";
}
};
// ============================================
// ⚙️ CONNESSIONE API
// ============================================
window.testAPIConnection = async function () {
const key = document.getElementById('api-key').value.trim();
const prompt = document.getElementById('test-prompt').value;
const output = document.getElementById('api-result');
const model = "gpt-4o-2024-05-13";
if (!key || !prompt) {
output.innerText = '⚠️ Inserisci una chiave valida e un prompt.';
return;
}
output.innerText = '⏳ Attendere risposta da OpenAI...';
logActivity(`🚀 Test API avviato – Modello: <strong>${model}</strong>`);
try {
const response = await fetch("https://api.openai.com/v1/chat/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer " + key
},
body: JSON.stringify({
model: model,
messages: [{ role: "user", content: prompt }],
temperature: 0.7
})
});
const data = await response.json();
if (data.choices && data.choices.length > 0) {
output.innerText = "✅ Risposta:\n" + data.choices[0].message.content;
logActivity(`✅ Risposta ricevuta – Modello: <strong>${model}</strong>`);
} else if (data.error) {
output.innerText = "❌ Errore: " + data.error.message;
logActivity(`❌ Errore API: ${data.error.message}`);
} else {
output.innerText = "❌ Nessuna risposta ricevuta.";
}
} catch (e) {
output.innerText = "🚫 Errore di rete o sintassi: " + e.message;
logActivity(`❌ Errore di connessione: ${e.message}`);
}
};
// ============================================
// 📂 ACCESSO FILE SERVER
// ============================================
document.querySelector('#readFileBtn')?.addEventListener('click', async () => {
const filenameInput = document.querySelector('#readFileName');
const fileContentDiv = document.querySelector('#readFileResult');
const filename = filenameInput.value.trim();
if (!filename) {
fileContentDiv.innerHTML = '<span style="color:red;">⚠️ Inserisci un nome di file.</span>';
return;
}
try {
const endpoint = "/dashboard/api/read_file.php";
const response = await fetch(`${endpoint}?filename=${encodeURIComponent(filename)}`);
const data = await response.json();
if (data.status === 'success') {
fileContentDiv.innerHTML = `<pre style="background:#f4f4f4;border:1px solid #ccc;padding:8px;max-height:400px;overflow:auto;font-size:14px;">${data.content}</pre>`;
logActivity(`📂 File letto: <strong>${filename}</strong>`);
} else {
fileContentDiv.innerHTML = `<span style="color:red;">❌ Errore: ${data.message}</span>`;
logActivity(`❌ Errore lettura file: ${data.message}`);
}
} catch (error) {
fileContentDiv.innerHTML = `<span style="color:red;">❌ Errore di connessione.</span>`;
console.error('Errore JS:', error);
}
});
// ============================================
// 📊 STATO PROGETTI
// ============================================
// (Da completare nel prossimo step)
// ============================================
// 🧪 STRUMENTI DI TEST
// ============================================
// (Da completare nel prossimo step)
// ============================================
// 🧾 REGISTRO ATTIVITÀ
// ============================================
window.logActivity = function (messaggio) {
const contenitore = document.getElementById("activityLogContent");
if (!contenitore) return;
const ora = new Date().toLocaleTimeString("it-IT");
const paragrafo = document.createElement("p");
paragrafo.innerHTML = `<strong>[${ora}]</strong> ${messaggio}`;
contenitore.appendChild(paragrafo);
contenitore.scrollTop = contenitore.scrollHeight;
};
window.clearActivityLog = function () {
const contenitore = document.getElementById("activityLogContent");
contenitore.innerHTML = "<em>Registro svuotato.</em><br>";
logActivity("🧹 Log svuotato manualmente.");
};
// ============================================
// 🧠 CARICA IN OPENAI
// ============================================
// (Da completare nel prossimo step)