Add hostname editing feature to agent detail page
- Create enhanced agent detail template with all stats and hostname edit form
- Add UpdateHostname method to store for agent hostname updates
- Add UpdateAgentHostname handler in UI for web form submissions
- Add UpdateHostname endpoint in API handler for JSON requests
- Register new POST /agents/{id}/hostname route for hostname updates
- Improve agent detail page layout with Settings and Danger Zone sections
- Add error handling for missing agents and empty hostname values
This commit is contained in:
@@ -17,6 +17,7 @@ templ agentDetailContent(agent *store.AgentStats) {
|
||||
@AgentStatusBadge(agent.LastSeen)
|
||||
</div>
|
||||
|
||||
<!-- CPU Usage Card -->
|
||||
<div class="grid" style="grid-template-columns: 1fr;">
|
||||
<div class="card">
|
||||
<div class="card-title">CPU Usage</div>
|
||||
@@ -32,6 +33,7 @@ templ agentDetailContent(agent *store.AgentStats) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Memory and Disk Usage Cards -->
|
||||
<div class="grid" style="margin-top: 1.5rem;">
|
||||
<div class="card">
|
||||
<div class="card-title">Memory Usage</div>
|
||||
@@ -43,24 +45,49 @@ templ agentDetailContent(agent *store.AgentStats) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Agent Information and Settings -->
|
||||
<div class="card" style="margin-top: 1.5rem;">
|
||||
<div class="card-title">Agent Information</div>
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">Agent ID</span>
|
||||
<span class="metric-value" style="font-family: monospace; font-size: 0.875rem;">{ agent.ID }</span>
|
||||
</div>
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">Hostname</span>
|
||||
<span class="metric-value">{ agent.Hostname }</span>
|
||||
</div>
|
||||
<div class="metric-row">
|
||||
<span class="metric-label">Last Seen</span>
|
||||
<span class="metric-value">{ agent.LastSeen.Format("2006-01-02 15:04:05") }</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="btn-group" style="margin-top: 1.5rem;">
|
||||
<form method="POST" action={ templ.SafeURL(fmt.Sprintf("/api/agents/%s/delete", agent.ID)) } style="margin: 0;" onsubmit="return confirm('Are you sure you want to remove this agent?');">
|
||||
<!-- Hostname Settings -->
|
||||
<div class="card" style="margin-top: 1.5rem;">
|
||||
<div class="card-title">Settings</div>
|
||||
<form method="POST" action={ templ.SafeURL(fmt.Sprintf("/agents/%s/hostname", agent.ID)) } style="display: flex; flex-direction: column; gap: 1rem;">
|
||||
<div style="display: flex; flex-direction: column; gap: 0.5rem;">
|
||||
<label for="hostname" style="font-size: 0.875rem; font-weight: 500; color: #cbd5e1;">
|
||||
Hostname
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
id="hostname"
|
||||
name="hostname"
|
||||
value={ agent.Hostname }
|
||||
required
|
||||
style="padding: 0.5rem 0.75rem; background-color: #1e293b; border: 1px solid #475569; border-radius: 0.375rem; color: #e2e8f0; font-size: 0.875rem;"
|
||||
/>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary" style="align-self: flex-start;">
|
||||
Update Hostname
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Danger Zone -->
|
||||
<div class="card" style="margin-top: 1.5rem; border-left: 3px solid #ef4444;">
|
||||
<div class="card-title" style="color: #ef4444;">Danger Zone</div>
|
||||
<p style="margin: 0 0 1rem 0; color: #94a3b8; font-size: 0.875rem;">
|
||||
Deleting this agent will remove all its data and history.
|
||||
</p>
|
||||
<form method="POST" action={ templ.SafeURL(fmt.Sprintf("/api/agents/%s/delete", agent.ID)) } style="margin: 0;" onsubmit="return confirm('Are you sure you want to remove this agent? This action cannot be undone.');">
|
||||
<button type="submit" class="btn btn-danger">Delete Agent</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user