Creata pagina con "// Funzione per aprire e chiudere i box nella dashboard window.toggleDashboardBox = function(id) { const box = document.getElementById(id); if (box) { box.style.display = (box.style.display === 'block') ? 'none' : 'block'; } }; // Funzione per testare connessione API window.testAPIConnection = async function () { const key = document.getElementById('api-key').value.trim(); const model = document.getElementById('model-select').value; const prompt = docume..."
 
Nessun oggetto della modifica
Riga 141: Riga 141:
   contenitore.innerHTML = "<em>Registro svuotato.</em><br>";
   contenitore.innerHTML = "<em>Registro svuotato.</em><br>";
   logActivity("🧹 Log svuotato manualmente.");
   logActivity("🧹 Log svuotato manualmente.");
};
window.uploadToOpenAI = async function () {
  const log = document.getElementById("activityLogContent");
  try {
    const response = await fetch("/oauth/sync_to_openai.php");
    const result = await response.text();
    logActivity(`🔄 File trasferito a OpenAI → ${result}`);
  } catch (err) {
    logActivity(`❌ Errore sincronizzazione: ${err.message}`);
  }
};
};

Versione delle 22:04, 30 lug 2025

// Funzione per aprire e chiudere i box nella dashboard
window.toggleDashboardBox = function(id) {
  const box = document.getElementById(id);
  if (box) {
    box.style.display = (box.style.display === 'block') ? 'none' : 'block';
  }
};

// Funzione per testare connessione API
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...';

  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(`✅ Test API riuscito – 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;
  }
};

// Funzione mock per salvataggio
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>`);
};

// Funzione per anteprima file simulata
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.";
};

// Funzione per aprire popup nuovo progetto
window.openProjectDialog = function () {
  document.getElementById("newProjectDialog").style.display = "block";
};

// Funzione per chiudere popup nuovo progetto
window.closeProjectDialog = function () {
  document.getElementById("newProjectDialog").style.display = "none";
};

// Funzione per aggiungere nuovo progetto
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(`📌 Nuovo progetto aggiunto: <strong>${title}</strong> – ${notes}`);
};

// Mini console per testare codice JS
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;
  }
};

// Inizializzazione automatica dei comportamenti al caricamento
document.addEventListener("DOMContentLoaded", function () {
  const fileSelect = document.getElementById("fileSelect");
  if (fileSelect) {
    fileSelect.addEventListener("change", function () {
      const selected = this.value;
      window.loadFilePreview(selected);
    });
  }
});

// Funzione per scrivere nel 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);

  // Scorrimento automatico verso il basso
  contenitore.scrollTop = contenitore.scrollHeight;
};

// Funzione per pulire il registro
window.clearActivityLog = function () {
  const contenitore = document.getElementById("activityLogContent");
  contenitore.innerHTML = "<em>Registro svuotato.</em><br>";
  logActivity("🧹 Log svuotato manualmente.");
};

window.uploadToOpenAI = async function () {
  const log = document.getElementById("activityLogContent");

  try {
    const response = await fetch("/oauth/sync_to_openai.php");
    const result = await response.text();
    logActivity(`🔄 File trasferito a OpenAI → ${result}`);
  } catch (err) {
    logActivity(`❌ Errore sincronizzazione: ${err.message}`);
  }
};