193 lines
8.2 KiB
HTML
193 lines
8.2 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 toggle-btn"
|
|
data-agent="{{.Name}}"
|
|
data-active="{{.Status}}">
|
|
{{if .Status}}
|
|
<i class="fas fa-pause"></i> Pause Agent
|
|
{{else}}
|
|
<i class="fas fa-play"></i> Start Agent
|
|
{{end}}
|
|
</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 listener for delete button
|
|
document.querySelectorAll('[data-action="delete"]').forEach(button => {
|
|
button.addEventListener('htmx:afterRequest', function(event) {
|
|
handleActionResponse(event, this);
|
|
});
|
|
});
|
|
|
|
// Handle toggle button
|
|
const toggleButton = document.querySelector('.toggle-btn');
|
|
if (toggleButton) {
|
|
toggleButton.addEventListener('click', function() {
|
|
const agent = this.getAttribute('data-agent');
|
|
const isActive = this.getAttribute('data-active') === "true";
|
|
const endpoint = isActive ? `/pause/${agent}` : `/start/${agent}`;
|
|
|
|
// Add animation
|
|
this.style.animation = 'pulse 0.5s';
|
|
|
|
// Create a new XMLHttpRequest
|
|
const xhr = new XMLHttpRequest();
|
|
xhr.open('PUT', endpoint);
|
|
xhr.setRequestHeader('Content-Type', 'application/json');
|
|
|
|
xhr.onload = () => {
|
|
// Clear animation
|
|
this.style.animation = '';
|
|
|
|
if (xhr.status === 200) {
|
|
try {
|
|
const response = JSON.parse(xhr.responseText);
|
|
|
|
if (response.status === "ok") {
|
|
// Toggle the button state
|
|
const newState = !isActive;
|
|
this.setAttribute('data-active', newState.toString());
|
|
|
|
// Update button text and icon
|
|
if (newState) {
|
|
this.innerHTML = '<i class="fas fa-pause"></i> Pause Agent';
|
|
} else {
|
|
this.innerHTML = '<i class="fas fa-play"></i> Start Agent';
|
|
}
|
|
|
|
// Show success toast
|
|
const action = isActive ? 'pause' : 'start';
|
|
showToast(`Agent "${agent}" ${action}ed successfully`, 'success');
|
|
|
|
} else if (response.error) {
|
|
// Show error toast
|
|
showToast(`Error: ${response.error}`, 'error');
|
|
}
|
|
} catch (e) {
|
|
// Handle parsing error
|
|
showToast("Invalid response format", 'error');
|
|
console.error("Error parsing response:", e);
|
|
}
|
|
} else {
|
|
// Handle HTTP error
|
|
showToast(`Server error: ${xhr.status}`, 'error');
|
|
}
|
|
};
|
|
|
|
xhr.onerror = () => {
|
|
// Clear animation
|
|
this.style.animation = '';
|
|
showToast("Network error occurred", 'error');
|
|
console.error("Network error occurred");
|
|
};
|
|
|
|
// Send the request
|
|
xhr.send(JSON.stringify({}));
|
|
});
|
|
}
|
|
|
|
// Set current date for timestamp
|
|
const now = new Date("2025-03-04T20:52:02Z");
|
|
document.getElementById('current-date').textContent = now.toISOString().split('T')[0];
|
|
});
|
|
|
|
// Function to handle API responses for delete action
|
|
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 '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> |