MediaWiki:CommonDashboard.js: differenze tra le versioni
Nessun oggetto della modifica |
Nessun oggetto della modifica |
||
Riga 1: | Riga 1: | ||
// | // ============================================ | ||
window.toggleDashboardBox = function(id) { | // 🔧 CommonDashboard.js – versione pulita | ||
// ============================================ | |||
// 🔄 Apri/chiudi i box della dashboard | |||
window.toggleDashboardBox = function (id) { | |||
const box = document.getElementById(id); | const box = document.getElementById(id); | ||
if (box) { | if (box) { | ||
Riga 7: | Riga 11: | ||
}; | }; | ||
// Funzione per testare connessione API | // ▶️ Funzione per testare la connessione all'API OpenAI | ||
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 19: | Riga 23: | ||
} | } | ||
output.innerText = '⏳ Attendere...'; | output.innerText = '⏳ Attendere risposta da OpenAI...'; | ||
logActivity(`🚀 Test API avviato – Modello: <strong>${model}</strong>`); | |||
try { | try { | ||
Riga 39: | Riga 44: | ||
if (data.choices && data.choices.length > 0) { | if (data.choices && data.choices.length > 0) { | ||
output.innerText = "✅ Risposta:\n" + data.choices[0].message.content; | output.innerText = "✅ Risposta:\n" + data.choices[0].message.content; | ||
logActivity(`✅ | logActivity(`✅ Risposta ricevuta – Modello: <strong>${model}</strong>`); | ||
} else if (data.error) { | } else if (data.error) { | ||
output.innerText = "❌ Errore: " + data.error.message; | output.innerText = "❌ Errore: " + data.error.message; | ||
Riga 48: | Riga 53: | ||
} catch (e) { | } catch (e) { | ||
output.innerText = "🚫 Errore di rete o sintassi: " + e.message; | output.innerText = "🚫 Errore di rete o sintassi: " + e.message; | ||
logActivity(`❌ Errore di connessione: ${e.message}`); | |||
} | } | ||
}; | }; | ||
// | // 💾 Salvataggio simulato di file server | ||
window.saveFileChanges = function() { | window.saveFileChanges = function () { | ||
const selectedFile = document.getElementById("file-select").value; | const selectedFile = document.getElementById("file-select").value; | ||
const newContent = document.getElementById("file-preview").value; | const newContent = document.getElementById("file-preview").value; | ||
Riga 59: | Riga 65: | ||
}; | }; | ||
// | // 📄 Carica preview del file selezionato | ||
window.loadFilePreview = function(filename) { | window.loadFilePreview = function (filename) { | ||
const contentArea = document.getElementById("file-preview"); | const contentArea = document.getElementById("file-preview"); | ||
const fakeContents = { | const fakeContents = { | ||
Riga 70: | Riga 76: | ||
}; | }; | ||
// | // ➕ Apri/chiudi dialog per nuovo progetto | ||
window.openProjectDialog = function () { | window.openProjectDialog = function () { | ||
document.getElementById("newProjectDialog").style.display = "block"; | document.getElementById("newProjectDialog").style.display = "block"; | ||
}; | }; | ||
window.closeProjectDialog = function () { | window.closeProjectDialog = function () { | ||
document.getElementById("newProjectDialog").style.display = "none"; | document.getElementById("newProjectDialog").style.display = "none"; | ||
}; | }; | ||
// | // 📌 Aggiungi nuovo progetto alla tabella | ||
window.addNewProject = function () { | window.addNewProject = function () { | ||
const title = document.getElementById("newProjectTitle").value.trim(); | const title = document.getElementById("newProjectTitle").value.trim(); | ||
Riga 96: | Riga 100: | ||
table.appendChild(newRow); | table.appendChild(newRow); | ||
window.closeProjectDialog(); | window.closeProjectDialog(); | ||
logActivity(`📌 | logActivity(`📌 Progetto aggiunto: <strong>${title}</strong> – ${notes}`); | ||
}; | }; | ||
// | // 🧪 Console JS per test codice | ||
window.runTestCode = function () { | window.runTestCode = function () { | ||
const code = document.getElementById('codeArea').value; | const code = document.getElementById('codeArea').value; | ||
Riga 111: | Riga 115: | ||
}; | }; | ||
// | // 🧾 Registro attività – aggiungi messaggio | ||
window.logActivity = function (messaggio) { | window.logActivity = function (messaggio) { | ||
const contenitore = document.getElementById("activityLogContent"); | const contenitore = document.getElementById("activityLogContent"); | ||
Riga 131: | Riga 124: | ||
paragrafo.innerHTML = `<strong>[${ora}]</strong> ${messaggio}`; | paragrafo.innerHTML = `<strong>[${ora}]</strong> ${messaggio}`; | ||
contenitore.appendChild(paragrafo); | contenitore.appendChild(paragrafo); | ||
contenitore.scrollTop = contenitore.scrollHeight; | contenitore.scrollTop = contenitore.scrollHeight; | ||
}; | }; | ||
// | // 🧹 Pulizia del registro attività | ||
window.clearActivityLog = function () { | window.clearActivityLog = function () { | ||
const contenitore = document.getElementById("activityLogContent"); | const contenitore = document.getElementById("activityLogContent"); | ||
Riga 143: | Riga 134: | ||
}; | }; | ||
// | // 🪄 Inizializzazione automatica all'apertura | ||
document.addEventListener("DOMContentLoaded", function () { | |||
const fileSelect = document.getElementById("fileSelect"); | const fileSelect = document.getElementById("fileSelect"); | ||
if (fileSelect) { | |||
fileSelect.addEventListener("change", function () { | |||
const selected = this.value; | |||
window.loadFilePreview(selected); | |||
}); | |||
} | } | ||
}); | |||
Versione delle 14:21, 31 lug 2025
// ============================================
// 🔧 CommonDashboard.js – versione pulita
// ============================================
// 🔄 Apri/chiudi i box della dashboard
window.toggleDashboardBox = function (id) {
const box = document.getElementById(id);
if (box) {
box.style.display = (box.style.display === 'block') ? 'none' : 'block';
}
};
// ▶️ Funzione per testare la connessione all'API OpenAI
window.testAPIConnection = async function () {
const key = document.getElementById('api-key').value.trim();
const model = document.getElementById('model-select').value;
const prompt = document.getElementById('test-prompt').value;
const output = document.getElementById('api-result');
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}`);
}
};
// 💾 Salvataggio simulato di file server
window.saveFileChanges = function () {
const selectedFile = document.getElementById("file-select").value;
const newContent = document.getElementById("file-preview").value;
alert("💾 Modifiche salvate per: " + selectedFile + "\n(contenuto simulato)");
logActivity(`💾 File salvato: <strong>${selectedFile}</strong>`);
};
// 📄 Carica preview del file selezionato
window.loadFilePreview = function (filename) {
const contentArea = document.getElementById("file-preview");
const fakeContents = {
"common.css": "/* Contenuto di esempio per common.css */\nbody { background: #fff; }",
"common.js": "// Contenuto JS\nconsole.log('JS attivo');",
"LocalSettings.php": "<?php\n# Impostazioni locali di MediaWiki\n$wgSitename = 'Masticationpedia';"
};
contentArea.value = fakeContents[filename] || "Contenuto non disponibile.";
};
// ➕ Apri/chiudi dialog per nuovo progetto
window.openProjectDialog = function () {
document.getElementById("newProjectDialog").style.display = "block";
};
window.closeProjectDialog = function () {
document.getElementById("newProjectDialog").style.display = "none";
};
// 📌 Aggiungi nuovo progetto alla tabella
window.addNewProject = function () {
const title = document.getElementById("newProjectTitle").value.trim();
const notes = document.getElementById("newProjectNotes").value.trim();
if (!title) return;
const table = document.getElementById("projectRows");
const newRow = document.createElement("tr");
newRow.innerHTML = `
<td style="padding:0.5rem; border:1px solid #ccc;">${title}</td>
<td style="padding:0.5rem; border:1px solid #ccc; color:green; font-weight:bold;">✅ Completato</td>
<td style="padding:0.5rem; border:1px solid #ccc;">${new Date().toLocaleDateString("it-IT")}</td>
<td style="padding:0.5rem; border:1px solid #ccc;">${notes || '–'}</td>
`;
table.appendChild(newRow);
window.closeProjectDialog();
logActivity(`📌 Progetto aggiunto: <strong>${title}</strong> – ${notes}`);
};
// 🧪 Console JS per test codice
window.runTestCode = function () {
const code = document.getElementById('codeArea').value;
const output = document.getElementById('consoleOutput');
try {
const result = eval(code);
output.textContent = "✅ Output:\n" + result;
} catch (err) {
output.textContent = "❌ Errore:\n" + err;
}
};
// 🧾 Registro attività – aggiungi messaggio
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;
};
// 🧹 Pulizia del registro attività
window.clearActivityLog = function () {
const contenitore = document.getElementById("activityLogContent");
contenitore.innerHTML = "<em>Registro svuotato.</em><br>";
logActivity("🧹 Log svuotato manualmente.");
};
// 🪄 Inizializzazione automatica all'apertura
document.addEventListener("DOMContentLoaded", function () {
const fileSelect = document.getElementById("fileSelect");
if (fileSelect) {
fileSelect.addEventListener("change", function () {
const selected = this.value;
window.loadFilePreview(selected);
});
}
});