/**
* Env Config View
* Manage and edit .env file content with local SQLite version history & restore capabilities.
*/
const EnvConfigView = {
currentContent: '',
history: [],
selectedPreview: null,
async render() {
const container = document.getElementById('view-container');
container.innerHTML = `
Nessuna versione registrata nello storico. Salva una modifica per iniziare l'archiviazione.
`;
}
return this.history.map((h, idx) => {
const isCurrentVersion = idx === 0;
const formattedDate = App.formatDateTime ? App.formatDateTime(h.created_at) : h.created_at;
return `
#${h.id}
${isCurrentVersion ? `Attuale ` : ''}
${formattedDate}
${App.escapeHtml(h.agent_name || 'Agente')} : ${App.escapeHtml(h.note || 'Modifica senza nota')}
๐๏ธ Anteprima
${!isCurrentVersion ? `
๐ Ripristina
` : ''}
`;
}).join('');
},
bindEvents() {
const saveBtn = document.getElementById('env-save-btn');
const reloadBtn = document.getElementById('env-reload-btn');
const editorTextarea = document.getElementById('env-editor-content');
const noteInput = document.getElementById('env-note-input');
if (saveBtn) {
saveBtn.addEventListener('click', async () => {
const content = editorTextarea.value;
const note = noteInput.value.trim();
try {
saveBtn.disabled = true;
saveBtn.textContent = 'Salvataggio...';
const res = await App.api('/api/config/env', {
method: 'POST',
body: JSON.stringify({ content, note })
});
Toast.success(res.message || 'File .env aggiornato con successo!');
if (noteInput) noteInput.value = '';
this.currentContent = content;
this.history = res.history || [];
// Re-render history panel
const historyListDiv = document.getElementById('env-history-list');
if (historyListDiv) {
historyListDiv.innerHTML = this.renderHistoryList();
this.bindHistoryEvents();
}
} catch (err) {
Toast.error('Errore salvataggio file .env: ' + err.message);
} finally {
saveBtn.disabled = false;
saveBtn.innerHTML = '