Files
LocalAGI/webui/views/settings.html
Ettore Di Giacinto d714c4f80b Page restyling
2025-03-03 23:08:58 +01:00

138 lines
5.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<title>Agent settings {{.Name}}</title>
{{template "views/partials/header"}}
</head>
<body>
{{template "views/partials/menu"}}
<!-- Toast for notifications -->
<div id="toast" class="toast">
<span id="toast-message"></span>
</div>
<div class="container">
<header class="text-center mb-8">
<h1 class="text-3xl md:text-5xl font-bold">Agent settings - {{.Name}}</h1>
</header>
<div class="max-w-4xl mx-auto">
<div class="section-box">
<h2>Agent Control</h2>
<div class="button-container">
<button
class="action-btn start-btn"
hx-put="/start/{{.Name}}"
hx-swap="none"
data-action="start"
data-agent="{{.Name}}">
<i class="fas fa-play"></i> Start Agent
</button>
<button
class="action-btn pause-btn"
hx-put="/pause/{{.Name}}"
hx-swap="none"
data-action="pause"
data-agent="{{.Name}}">
<i class="fas fa-pause"></i> Pause Agent
</button>
</div>
</div>
<div class="section-box">
<h2>Export Data</h2>
<p class="mb-4">Export your agent configuration for backup or transfer.</p>
<button
class="action-btn"
onclick="window.location.href='/settings/export/{{.Name}}'">
<i class="fas fa-file-export"></i> Export Configuration
</button>
</div>
<div class="section-box">
<h2>Danger Zone</h2>
<p class="mb-4">Permanently delete this agent and all associated data. This action cannot be undone.</p>
<button
class="action-btn"
style="background: linear-gradient(135deg, #ff4545, var(--secondary)); color: white;"
hx-delete="/delete/{{.Name}}"
hx-swap="none"
data-action="delete"
data-agent="{{.Name}}">
<i class="fas fa-trash-alt"></i> Delete Agent
</button>
</div>
<div class="user-info">
<span>Agent: {{.Name}}</span>
<span class="timestamp">Last modified: <span id="current-date"></span></span>
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
// Add event listeners for action buttons (Start, Pause)
document.querySelectorAll('[data-action]').forEach(button => {
button.addEventListener('htmx:afterRequest', function(event) {
handleActionResponse(event, this);
});
});
// Set current date for timestamp
const now = new Date();
document.getElementById('current-date').textContent = now.toISOString().split('T')[0];
});
// Function to handle API responses for all actions
function handleActionResponse(event, button) {
const xhr = event.detail.xhr;
const action = button.getAttribute('data-action');
const agent = button.getAttribute('data-agent');
if (xhr.status === 200) {
try {
const response = JSON.parse(xhr.responseText);
if (response.status === "ok") {
// Action successful
let message = "";
switch(action) {
case 'start':
message = `Agent "${agent}" started successfully`;
break;
case 'pause':
message = `Agent "${agent}" paused successfully`;
break;
case 'delete':
message = `Agent "${agent}" deleted successfully`;
// Redirect to agent list page after short delay for delete
setTimeout(() => {
window.location.href = "/agents";
}, 2000);
break;
default:
message = "Operation completed successfully";
}
// Show success message
showToast(message, 'success');
} else if (response.error) {
// Show error message
showToast(`Error: ${response.error}`, 'error');
}
} catch (e) {
// Handle JSON parsing error
showToast("Invalid response format", 'error');
}
} else {
// Handle HTTP error
showToast(`Server error: ${xhr.status}`, 'error');
}
}
</script>
</body>
</html>