Page restyling
This commit is contained in:
@@ -5,79 +5,6 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Agent List</title>
|
||||
{{template "views/partials/header"}}
|
||||
<style>
|
||||
.button-container {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.section-box {
|
||||
background-color: rgba(30, 41, 59, 0.8);
|
||||
border-radius: 8px;
|
||||
padding: 20px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
.alert {
|
||||
padding: 10px 15px;
|
||||
border-radius: 4px;
|
||||
margin: 10px 0;
|
||||
display: none;
|
||||
}
|
||||
.alert-success {
|
||||
background-color: rgba(16, 185, 129, 0.2);
|
||||
border: 1px solid #10b981;
|
||||
color: #10b981;
|
||||
}
|
||||
.alert-error {
|
||||
background-color: rgba(239, 68, 68, 0.2);
|
||||
border: 1px solid #ef4444;
|
||||
color: #ef4444;
|
||||
}
|
||||
.toast {
|
||||
position: fixed;
|
||||
top: 20px;
|
||||
right: 20px;
|
||||
max-width: 350px;
|
||||
padding: 15px;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
|
||||
z-index: 1000;
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s ease;
|
||||
}
|
||||
.toast-success {
|
||||
background-color: #10b981;
|
||||
color: white;
|
||||
}
|
||||
.toast-error {
|
||||
background-color: #ef4444;
|
||||
color: white;
|
||||
}
|
||||
.toast-visible {
|
||||
opacity: 1;
|
||||
}
|
||||
.action-btn {
|
||||
background-color: #374151;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 6px 12px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.3s;
|
||||
}
|
||||
.start-btn {
|
||||
background-color: #10b981;
|
||||
}
|
||||
.start-btn:hover {
|
||||
background-color: #059669;
|
||||
}
|
||||
.pause-btn {
|
||||
background-color: #f59e0b;
|
||||
}
|
||||
.pause-btn:hover {
|
||||
background-color: #d97706;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body class="bg-gray-900 p-4 text-white font-sans">
|
||||
{{template "views/partials/menu"}}
|
||||
@@ -88,217 +15,172 @@
|
||||
|
||||
<div class="max-w-6xl mx-auto">
|
||||
<header class="text-center mb-8">
|
||||
<h1 class="text-3xl md:text-5xl font-bold">Smart Agent List</h1>
|
||||
<h1 class="text-4xl md:text-6xl font-bold text-primary">Smart Agent List</h1>
|
||||
</header>
|
||||
<div class="button-container">
|
||||
<div class="button-container justify-center mb-6">
|
||||
<a href="/create" class="bg-green-500 hover:bg-green-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out">
|
||||
Add New Agent
|
||||
</a>
|
||||
<button id="toggle-import" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out ml-4">
|
||||
Import Agent
|
||||
</button>
|
||||
</div>
|
||||
<section class="flex flex-col">
|
||||
<div class="overflow-x-auto">
|
||||
<div class="py-2 align-middle inline-block min-w-full">
|
||||
<div class="shadow overflow-hidden border-b border-gray-700 rounded-lg">
|
||||
<table class="min-w-full divide-y divide-gray-700">
|
||||
<thead class="bg-gray-700">
|
||||
<tr>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-400 uppercase tracking-wider">
|
||||
Name
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-400 uppercase tracking-wider">
|
||||
Status
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3 text-center">
|
||||
<span class="sr-only">Talk</span>
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3 text-center">
|
||||
<span class="sr-only">Start</span>
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3 text-center">
|
||||
<span class="sr-only">Stop</span>
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3 text-center">
|
||||
<span class="sr-only">Settings</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-gray-800 divide-y divide-gray-700">
|
||||
<!-- Dynamic agent rows go here -->
|
||||
{{ $status := .Status }}
|
||||
{{ range .Agents }}
|
||||
<tr hx-ext="sse" data-agent-name="{{.}}">
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-300">{{.}}</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-300">
|
||||
Online: {{ index $status . }}
|
||||
<a href="/status/{{.}}" class="text-indigo-500 hover:text-indigo-400">
|
||||
<i class="fas fa-info"></i> Status
|
||||
</a>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
|
||||
<a href="/talk/{{.}}" class="text-indigo-500 hover:text-indigo-400">
|
||||
<i class="fas fa-comments"></i> Talk
|
||||
</a>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
|
||||
<button class="action-btn start-btn"
|
||||
hx-put="/start/{{.}}"
|
||||
hx-swap="none"
|
||||
hx-ext="json-enc"
|
||||
data-action="start"
|
||||
data-agent="{{.}}">
|
||||
Start
|
||||
</button>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
|
||||
<button class="action-btn pause-btn"
|
||||
hx-put="/pause/{{.}}"
|
||||
hx-swap="none"
|
||||
hx-ext="json-enc"
|
||||
data-action="pause"
|
||||
data-agent="{{.}}">
|
||||
Pause
|
||||
</button>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-center text-sm font-medium">
|
||||
<a href="/settings/{{.}}" class="text-indigo-500 hover:text-indigo-400">
|
||||
<i class="fas fa-cog"></i> Settings
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{{ end }}
|
||||
<!-- Repeat for each agent -->
|
||||
</tbody>
|
||||
</table>
|
||||
<section id="import-section" class="hidden mb-8">
|
||||
<div class="section-box">
|
||||
<h2 class="text-2xl font-bold mb-4">Import Agent</h2>
|
||||
<!-- Response Messages Container -->
|
||||
<div id="response-container">
|
||||
<!-- Success Alert -->
|
||||
<div id="success-alert" class="alert alert-success">
|
||||
Agent imported successfully! The page will refresh in a moment.
|
||||
</div>
|
||||
<!-- Error Alert -->
|
||||
<div id="error-alert" class="alert alert-error">
|
||||
<span id="error-message">Error importing agent.</span>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
<footer class="mt-8 text-center">
|
||||
|
||||
<!-- File Upload Form -->
|
||||
<div class="section-box">
|
||||
<h2 class="text-2xl font-bold mb-4">Import Agent</h2>
|
||||
|
||||
<!-- Response Messages Container -->
|
||||
<div id="response-container">
|
||||
<!-- Success Alert -->
|
||||
<div id="success-alert" class="alert alert-success">
|
||||
Agent imported successfully! The page will refresh in a moment.
|
||||
</div>
|
||||
|
||||
<!-- Error Alert -->
|
||||
<div id="error-alert" class="alert alert-error">
|
||||
<span id="error-message">Error importing agent.</span>
|
||||
</div>
|
||||
<form id='import-form' hx-encoding='multipart/form-data' hx-post='/settings/import' hx-target="#response-container" hx-swap="none">
|
||||
<div class="mb-4">
|
||||
<label for="file" class="block text-gray-300 mb-2">Select Agent File:</label>
|
||||
<input type='file' name='file' id='file' class="bg-gray-700 text-white rounded p-2 w-full">
|
||||
</div>
|
||||
|
||||
<form id='import-form' hx-encoding='multipart/form-data' hx-post='/settings/import' hx-target="#response-container" hx-swap="none">
|
||||
<div class="mb-4">
|
||||
<label for="file" class="block text-gray-300 mb-2">Select Agent File:</label>
|
||||
<input type='file' name='file' id='file' class="bg-gray-700 text-white rounded p-2 w-full">
|
||||
</div>
|
||||
<div class="flex items-center">
|
||||
<button id="import-button" type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out">
|
||||
Import Agent
|
||||
</button>
|
||||
<progress id='progress' value='0' max='100' class="ml-4"></progress>
|
||||
</div>
|
||||
</form>
|
||||
<div class="flex items-center">
|
||||
<button id="import-button" type="submit" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded transition duration-300 ease-in-out">
|
||||
Import Agent
|
||||
</button>
|
||||
<progress id='progress' value='0' max='100' class="ml-4"></progress>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</section>
|
||||
<section class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
|
||||
{{ $status := .Status }}
|
||||
{{ range .Agents }}
|
||||
<div class="card relative flex flex-col items-center text-center p-6 bg-gray-800 rounded-lg shadow-md">
|
||||
<img src="/public/agent_{{.}}.png" alt="{{.}}" class="w-24 h-24 rounded-full mb-4">
|
||||
<h2 class="text-xl font-bold mb-2">{{.}}</h2>
|
||||
<p class="text-gray-400 mb-4">Online: {{ index $status . }}</p>
|
||||
<div class="flex justify-center space-x-4">
|
||||
<a href="/status/{{.}}" class="text-indigo-500 hover:text-indigo-400">
|
||||
<i class="fas fa-info-circle"></i> Status
|
||||
</a>
|
||||
<a href="/talk/{{.}}" class="text-indigo-500 hover:text-indigo-400">
|
||||
<i class="fas fa-comments"></i> Talk
|
||||
</a>
|
||||
<button class="action-btn start-btn" hx-put="/start/{{.}}" hx-swap="none" hx-ext="json-enc" data-action="start" data-agent="{{.}}">
|
||||
Start
|
||||
</button>
|
||||
<button class="action-btn pause-btn" hx-put="/pause/{{.}}" hx-swap="none" hx-ext="json-enc" data-action="pause" data-agent="{{.}}">
|
||||
Pause
|
||||
</button>
|
||||
<a href="/settings/{{.}}" class="text-indigo-500 hover:text-indigo-400">
|
||||
<i class="fas fa-cog"></i> Settings
|
||||
</a>
|
||||
</div>
|
||||
|
||||
</footer>
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
</section>
|
||||
<footer class="mt-8 text-center">
|
||||
<p>© 2025 Smart Agent List. All rights reserved.</p>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Handle import form submission
|
||||
document.getElementById('import-form').addEventListener('htmx:afterRequest', function(event) {
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const importSection = document.getElementById('import-section');
|
||||
const toggleImport = document.getElementById('toggle-import');
|
||||
|
||||
// Toggle import section visibility
|
||||
toggleImport.addEventListener('click', function() {
|
||||
importSection.classList.toggle('hidden');
|
||||
});
|
||||
|
||||
// Handle import form submission
|
||||
document.getElementById('import-form').addEventListener('htmx:afterRequest', function(event) {
|
||||
const xhr = event.detail.xhr;
|
||||
const successAlert = document.getElementById('success-alert');
|
||||
const errorAlert = document.getElementById('error-alert');
|
||||
const errorMessage = document.getElementById('error-message');
|
||||
|
||||
// Hide both alerts initially
|
||||
successAlert.style.display = 'none';
|
||||
errorAlert.style.display = 'none';
|
||||
|
||||
if (xhr.status === 200) {
|
||||
try {
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
|
||||
if (response.status === "ok") {
|
||||
// Show success message
|
||||
successAlert.style.display = 'block';
|
||||
|
||||
// Refresh the page after a short delay
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2000);
|
||||
} else if (response.error) {
|
||||
// Show error message
|
||||
errorMessage.textContent = response.error;
|
||||
errorAlert.style.display = 'block';
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle parsing error
|
||||
errorMessage.textContent = "Invalid response format";
|
||||
errorAlert.style.display = 'block';
|
||||
}
|
||||
} else {
|
||||
// Handle HTTP error
|
||||
errorMessage.textContent = "Server error: " + xhr.status;
|
||||
errorAlert.style.display = 'block';
|
||||
}
|
||||
});
|
||||
|
||||
// Add event listeners for Start and Pause buttons
|
||||
document.querySelectorAll('.action-btn').forEach(button => {
|
||||
button.addEventListener('htmx:afterRequest', function(event) {
|
||||
const xhr = event.detail.xhr;
|
||||
const successAlert = document.getElementById('success-alert');
|
||||
const errorAlert = document.getElementById('error-alert');
|
||||
const errorMessage = document.getElementById('error-message');
|
||||
|
||||
// Hide both alerts initially
|
||||
successAlert.style.display = 'none';
|
||||
errorAlert.style.display = 'none';
|
||||
const action = this.getAttribute('data-action');
|
||||
const agent = this.getAttribute('data-agent');
|
||||
|
||||
if (xhr.status === 200) {
|
||||
try {
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
|
||||
if (response.status === "ok") {
|
||||
// Show success message
|
||||
successAlert.style.display = 'block';
|
||||
// Show success toast
|
||||
showToast(`Agent "${agent}" ${action === 'start' ? 'started' : 'paused'} successfully`, 'success');
|
||||
|
||||
// Refresh the page after a short delay
|
||||
setTimeout(() => {
|
||||
window.location.reload();
|
||||
}, 2000);
|
||||
// Update the status cell if needed
|
||||
updateAgentStatus(agent, action === 'start' ? true : false);
|
||||
} else if (response.error) {
|
||||
// Show error message
|
||||
errorMessage.textContent = response.error;
|
||||
errorAlert.style.display = 'block';
|
||||
// Show error toast
|
||||
showToast(`Error: ${response.error}`, 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle parsing error
|
||||
errorMessage.textContent = "Invalid response format";
|
||||
errorAlert.style.display = 'block';
|
||||
showToast("Invalid response format", 'error');
|
||||
}
|
||||
} else {
|
||||
// Handle HTTP error
|
||||
errorMessage.textContent = "Server error: " + xhr.status;
|
||||
errorAlert.style.display = 'block';
|
||||
showToast(`Server error: ${xhr.status}`, 'error');
|
||||
}
|
||||
});
|
||||
|
||||
// Add event listeners for Start and Pause buttons
|
||||
document.querySelectorAll('.action-btn').forEach(button => {
|
||||
button.addEventListener('htmx:afterRequest', function(event) {
|
||||
const xhr = event.detail.xhr;
|
||||
const action = this.getAttribute('data-action');
|
||||
const agent = this.getAttribute('data-agent');
|
||||
|
||||
if (xhr.status === 200) {
|
||||
try {
|
||||
const response = JSON.parse(xhr.responseText);
|
||||
|
||||
if (response.status === "ok") {
|
||||
// Show success toast
|
||||
showToast(`Agent "${agent}" ${action === 'start' ? 'started' : 'paused'} successfully`, 'success');
|
||||
|
||||
// Update the status cell if needed
|
||||
updateAgentStatus(agent, action === 'start' ? true : false);
|
||||
} else if (response.error) {
|
||||
// Show error toast
|
||||
showToast(`Error: ${response.error}`, 'error');
|
||||
}
|
||||
} catch (e) {
|
||||
// Handle parsing error
|
||||
showToast("Invalid response format", 'error');
|
||||
}
|
||||
} else {
|
||||
// Handle HTTP error
|
||||
showToast(`Server error: ${xhr.status}`, 'error');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Function to update agent status in the UI
|
||||
function updateAgentStatus(agentName, isOnline) {
|
||||
// Find the row for this agent
|
||||
const rows = document.querySelectorAll('tr[data-agent-name]');
|
||||
rows.forEach(row => {
|
||||
if (row.getAttribute('data-agent-name') === agentName) {
|
||||
// Find status cell (second cell in the row)
|
||||
const statusCell = row.querySelector('td:nth-child(2)');
|
||||
if (statusCell) {
|
||||
// Update the "Online:" text
|
||||
const statusText = statusCell.firstChild;
|
||||
statusText.textContent = `Online: ${isOnline}`;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
// Function to update agent status in the UI
|
||||
function updateAgentStatus(agentName, isOnline) {
|
||||
// Find the card for this agent
|
||||
const cards = document.querySelectorAll('.card');
|
||||
cards.forEach(card => {
|
||||
const agentTitle = card.querySelector('h2').textContent;
|
||||
if (agentTitle === agentName) {
|
||||
// Update the "Online:" text
|
||||
const statusText = card.querySelector('p');
|
||||
statusText.textContent = `Online: ${isOnline}`;
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user