576 lines
20 KiB
HTML
576 lines
20 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>SPORE UI</title>
|
|
<style>
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
|
|
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
|
min-height: 100vh;
|
|
padding: 2rem;
|
|
color: white;
|
|
}
|
|
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
}
|
|
|
|
.header {
|
|
text-align: center;
|
|
margin-bottom: 3rem;
|
|
}
|
|
|
|
h1 {
|
|
font-size: 3rem;
|
|
margin-bottom: 1rem;
|
|
font-weight: 700;
|
|
text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
|
|
}
|
|
|
|
p {
|
|
font-size: 1.2rem;
|
|
opacity: 0.9;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.status {
|
|
background: rgba(255, 255, 255, 0.2);
|
|
padding: 1rem 2rem;
|
|
border-radius: 50px;
|
|
font-weight: 500;
|
|
display: inline-block;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.cluster-section {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
border-radius: 20px;
|
|
backdrop-filter: blur(10px);
|
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
padding: 2rem;
|
|
margin-bottom: 2rem;
|
|
}
|
|
|
|
.cluster-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 1.5rem;
|
|
}
|
|
|
|
.cluster-title {
|
|
font-size: 1.5rem;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.refresh-btn {
|
|
background: rgba(255, 255, 255, 0.2);
|
|
border: 1px solid rgba(255, 255, 255, 0.3);
|
|
color: white;
|
|
padding: 0.5rem 1rem;
|
|
border-radius: 8px;
|
|
cursor: pointer;
|
|
font-size: 0.9rem;
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.refresh-btn:hover {
|
|
background: rgba(255, 255, 255, 0.3);
|
|
transform: translateY(-2px);
|
|
}
|
|
|
|
.refresh-btn:active {
|
|
transform: translateY(0);
|
|
}
|
|
|
|
.members-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
|
gap: 1rem;
|
|
}
|
|
|
|
.member-card {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
border: 1px solid rgba(255, 255, 255, 0.2);
|
|
border-radius: 12px;
|
|
padding: 1.5rem;
|
|
transition: all 0.3s ease;
|
|
cursor: pointer;
|
|
position: relative;
|
|
}
|
|
|
|
.member-card::before {
|
|
content: '';
|
|
position: absolute;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
bottom: 0;
|
|
background: rgba(255, 255, 255, 0.05);
|
|
border-radius: 12px;
|
|
opacity: 0;
|
|
transition: opacity 0.3s ease;
|
|
pointer-events: none;
|
|
}
|
|
|
|
.member-card:hover::before {
|
|
opacity: 1;
|
|
}
|
|
|
|
.member-card:hover {
|
|
transform: translateY(-4px);
|
|
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
.member-card.expanded {
|
|
background: rgba(255, 255, 255, 0.15);
|
|
border-color: rgba(255, 255, 255, 0.4);
|
|
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
|
|
transform: scale(1.02);
|
|
}
|
|
|
|
.member-card.expanded:hover {
|
|
transform: none;
|
|
}
|
|
|
|
.member-card.expanded .expand-icon {
|
|
transform: rotate(180deg);
|
|
}
|
|
|
|
.member-header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-start;
|
|
margin-bottom: 1rem;
|
|
}
|
|
|
|
.member-info {
|
|
flex: 1;
|
|
}
|
|
|
|
.expand-icon {
|
|
font-size: 1.2rem;
|
|
opacity: 0.7;
|
|
transition: transform 0.3s ease;
|
|
}
|
|
|
|
.member-card.expanded .expand-icon {
|
|
transform: rotate(90deg);
|
|
}
|
|
|
|
.member-details {
|
|
display: none;
|
|
opacity: 0;
|
|
margin-top: 0;
|
|
padding-top: 0;
|
|
border-top: 1px solid transparent;
|
|
transition: opacity 0.3s ease;
|
|
}
|
|
|
|
.member-card.expanded .member-details {
|
|
display: block;
|
|
opacity: 1;
|
|
margin-top: 1rem;
|
|
padding-top: 1rem;
|
|
border-top: 1px solid rgba(255, 255, 255, 0.2);
|
|
}
|
|
|
|
.detail-row {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
margin-bottom: 0.5rem;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.detail-label {
|
|
opacity: 0.7;
|
|
font-weight: 500;
|
|
}
|
|
|
|
.detail-value {
|
|
font-family: 'Courier New', monospace;
|
|
opacity: 0.9;
|
|
}
|
|
|
|
.api-endpoints {
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.api-endpoints h4 {
|
|
margin-bottom: 0.5rem;
|
|
font-size: 0.9rem;
|
|
opacity: 0.8;
|
|
}
|
|
|
|
.endpoint-item {
|
|
background: rgba(255, 255, 255, 0.1);
|
|
padding: 0.5rem;
|
|
border-radius: 6px;
|
|
margin-bottom: 0.5rem;
|
|
font-size: 0.8rem;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
|
|
.loading-details {
|
|
text-align: center;
|
|
padding: 1rem;
|
|
opacity: 0.7;
|
|
font-size: 0.9rem;
|
|
}
|
|
|
|
.member-name {
|
|
font-size: 1.2rem;
|
|
font-weight: 600;
|
|
margin-bottom: 0.5rem;
|
|
color: #fff;
|
|
}
|
|
|
|
.member-ip {
|
|
font-size: 0.9rem;
|
|
opacity: 0.8;
|
|
margin-bottom: 0.5rem;
|
|
font-family: 'Courier New', monospace;
|
|
}
|
|
|
|
.member-status {
|
|
display: inline-block;
|
|
padding: 0.25rem 0.75rem;
|
|
border-radius: 20px;
|
|
font-size: 0.8rem;
|
|
font-weight: 500;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
}
|
|
|
|
.status-online {
|
|
background: rgba(76, 175, 80, 0.3);
|
|
color: #4caf50;
|
|
border: 1px solid rgba(76, 175, 80, 0.5);
|
|
}
|
|
|
|
.status-offline {
|
|
background: rgba(244, 67, 54, 0.3);
|
|
color: #f44336;
|
|
border: 1px solid rgba(244, 67, 54, 0.5);
|
|
}
|
|
|
|
.loading {
|
|
text-align: center;
|
|
padding: 2rem;
|
|
opacity: 0.7;
|
|
}
|
|
|
|
.error {
|
|
background: rgba(244, 67, 54, 0.2);
|
|
border: 1px solid rgba(244, 67, 54, 0.3);
|
|
color: #ffcdd2;
|
|
padding: 1rem;
|
|
border-radius: 8px;
|
|
margin-top: 1rem;
|
|
}
|
|
|
|
.empty-state {
|
|
text-align: center;
|
|
padding: 2rem;
|
|
opacity: 0.7;
|
|
}
|
|
|
|
.empty-state-icon {
|
|
font-size: 3rem;
|
|
margin-bottom: 1rem;
|
|
opacity: 0.5;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<div class="header">
|
|
<h1>SPORE UI</h1>
|
|
<div class="status">🚀 Cluster Online</div>
|
|
</div>
|
|
|
|
<div class="cluster-section">
|
|
<div class="cluster-header">
|
|
<div class="cluster-title">🌐 Cluster Members</div>
|
|
<button class="refresh-btn" onclick="refreshClusterMembers()">
|
|
🔄 Refresh
|
|
</button>
|
|
</div>
|
|
|
|
<div id="cluster-members-container">
|
|
<div class="loading">
|
|
<div>Loading cluster members...</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
// Frontend API client - calls our Express backend
|
|
class FrontendApiClient {
|
|
constructor() {
|
|
this.baseUrl = ''; // Same origin as the current page
|
|
}
|
|
|
|
async getClusterMembers() {
|
|
try {
|
|
const response = await fetch('/api/cluster/members', {
|
|
method: 'GET',
|
|
headers: {
|
|
'Accept': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
return await response.json();
|
|
} catch (error) {
|
|
throw new Error(`Request failed: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
async getNodeStatus(ip) {
|
|
try {
|
|
// Create a proxy endpoint that forwards the request to the specific node
|
|
const response = await fetch(`/api/node/status/${encodeURIComponent(ip)}`, {
|
|
method: 'GET',
|
|
headers: {
|
|
'Accept': 'application/json'
|
|
}
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP ${response.status}: ${response.statusText}`);
|
|
}
|
|
|
|
return await response.json();
|
|
} catch (error) {
|
|
throw new Error(`Request failed: ${error.message}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Global client instance
|
|
const client = new FrontendApiClient();
|
|
|
|
// Function to refresh cluster members
|
|
async function refreshClusterMembers() {
|
|
const container = document.getElementById('cluster-members-container');
|
|
|
|
// Show loading state
|
|
container.innerHTML = `
|
|
<div class="loading">
|
|
<div>Loading cluster members...</div>
|
|
</div>
|
|
`;
|
|
|
|
try {
|
|
const response = await client.getClusterMembers();
|
|
console.log(response);
|
|
displayClusterMembers(response.members);
|
|
} catch (error) {
|
|
console.error('Failed to fetch cluster members:', error);
|
|
container.innerHTML = `
|
|
<div class="error">
|
|
<strong>Error loading cluster members:</strong><br>
|
|
${error.message}
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
// Function to load detailed node information
|
|
async function loadNodeDetails(card, memberIp) {
|
|
console.log('Loading node details for IP:', memberIp);
|
|
const memberDetails = card.querySelector('.member-details');
|
|
console.log('Member details element:', memberDetails);
|
|
|
|
try {
|
|
console.log('Fetching node status...');
|
|
const nodeStatus = await client.getNodeStatus(memberIp);
|
|
console.log('Node status received:', nodeStatus);
|
|
displayNodeDetails(memberDetails, nodeStatus);
|
|
} catch (error) {
|
|
console.error('Failed to load node details:', error);
|
|
memberDetails.innerHTML = `
|
|
<div class="error">
|
|
<strong>Error loading node details:</strong><br>
|
|
${error.message}
|
|
</div>
|
|
`;
|
|
}
|
|
}
|
|
|
|
// Function to display node details
|
|
function displayNodeDetails(container, nodeStatus) {
|
|
container.innerHTML = `
|
|
<div class="detail-row">
|
|
<span class="detail-label">Free Heap:</span>
|
|
<span class="detail-value">${Math.round(nodeStatus.freeHeap / 1024)}KB</span>
|
|
</div>
|
|
<div class="detail-row">
|
|
<span class="detail-label">Chip ID:</span>
|
|
<span class="detail-value">${nodeStatus.chipId}</span>
|
|
</div>
|
|
<div class="detail-row">
|
|
<span class="detail-label">SDK Version:</span>
|
|
<span class="detail-value">${nodeStatus.sdkVersion}</span>
|
|
</div>
|
|
<div class="detail-row">
|
|
<span class="detail-label">CPU Frequency:</span>
|
|
<span class="detail-value">${nodeStatus.cpuFreqMHz}MHz</span>
|
|
</div>
|
|
<div class="detail-row">
|
|
<span class="detail-label">Flash Size:</span>
|
|
<span class="detail-value">${Math.round(nodeStatus.flashChipSize / 1024)}KB</span>
|
|
</div>
|
|
<div class="api-endpoints">
|
|
<h4>Available API Endpoints:</h4>
|
|
${nodeStatus.api ? nodeStatus.api.map(endpoint =>
|
|
`<div class="endpoint-item">${endpoint.method === 1 ? 'GET' : 'POST'} ${endpoint.uri}</div>`
|
|
).join('') : '<div class="endpoint-item">No API endpoints available</div>'}
|
|
</div>
|
|
`;
|
|
}
|
|
|
|
// Function to display cluster members
|
|
function displayClusterMembers(members) {
|
|
const container = document.getElementById('cluster-members-container');
|
|
|
|
if (!members || members.length === 0) {
|
|
container.innerHTML = `
|
|
<div class="empty-state">
|
|
<div class="empty-state-icon">🌐</div>
|
|
<div>No cluster members found</div>
|
|
<div style="font-size: 0.9rem; margin-top: 0.5rem; opacity: 0.7;">
|
|
The cluster might be empty or not yet discovered
|
|
</div>
|
|
</div>
|
|
`;
|
|
return;
|
|
}
|
|
|
|
const membersHTML = members.map(member => {
|
|
const statusClass = member.status === 'active' ? 'status-online' : 'status-offline';
|
|
const statusText = member.status === 'active' ? 'Online' : 'Offline';
|
|
const statusIcon = member.status === 'active' ? '🟢' : '🔴';
|
|
|
|
return `
|
|
<div class="member-card" data-member-ip="${member.ip}">
|
|
<div class="member-header">
|
|
<div class="member-info">
|
|
<div class="member-name">${member.hostname || 'Unknown Device'}</div>
|
|
<div class="member-ip">${member.ip || 'No IP'}</div>
|
|
<div class="member-status ${statusClass}">
|
|
${statusIcon} ${statusText}
|
|
</div>
|
|
</div>
|
|
<div class="expand-icon">▶️</div>
|
|
</div>
|
|
<div class="member-details">
|
|
<div class="loading-details">Loading detailed information...</div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
}).join('');
|
|
|
|
container.innerHTML = membersHTML;
|
|
|
|
// Add event listeners for expand/collapse
|
|
console.log('Setting up event listeners for', members.length, 'member cards');
|
|
|
|
// Small delay to ensure DOM is ready
|
|
setTimeout(() => {
|
|
document.querySelectorAll('.member-card').forEach((card, index) => {
|
|
const expandIcon = card.querySelector('.expand-icon');
|
|
const memberDetails = card.querySelector('.member-details');
|
|
const memberIp = card.dataset.memberIp;
|
|
|
|
console.log(`Setting up card ${index} with IP: ${memberIp}`);
|
|
|
|
// Make the entire card clickable
|
|
card.addEventListener('click', async (e) => {
|
|
// Don't trigger if clicking on the expand icon (to avoid double-triggering)
|
|
if (e.target === expandIcon) {
|
|
return;
|
|
}
|
|
|
|
console.log('Card clicked for IP:', memberIp);
|
|
|
|
const isExpanding = !card.classList.contains('expanded');
|
|
console.log('Is expanding:', isExpanding);
|
|
|
|
if (isExpanding) {
|
|
// Expanding - fetch detailed status
|
|
console.log('Starting to expand...');
|
|
await loadNodeDetails(card, memberIp);
|
|
card.classList.add('expanded');
|
|
expandIcon.classList.add('expanded');
|
|
console.log('Card expanded successfully');
|
|
} else {
|
|
// Collapsing
|
|
console.log('Collapsing...');
|
|
card.classList.remove('expanded');
|
|
expandIcon.classList.remove('expanded');
|
|
console.log('Card collapsed successfully');
|
|
}
|
|
});
|
|
|
|
// Keep the expand icon click handler for visual feedback
|
|
if (expandIcon) {
|
|
expandIcon.addEventListener('click', async (e) => {
|
|
e.stopPropagation();
|
|
console.log('Expand icon clicked for IP:', memberIp);
|
|
|
|
const isExpanding = !card.classList.contains('expanded');
|
|
console.log('Is expanding:', isExpanding);
|
|
|
|
if (isExpanding) {
|
|
// Expanding - fetch detailed status
|
|
console.log('Starting to expand...');
|
|
await loadNodeDetails(card, memberIp);
|
|
card.classList.add('expanded');
|
|
expandIcon.classList.add('expanded');
|
|
console.log('Card expanded successfully');
|
|
} else {
|
|
// Collapsing
|
|
console.log('Collapsing...');
|
|
card.classList.remove('expanded');
|
|
expandIcon.classList.remove('expanded');
|
|
console.log('Card collapsed successfully');
|
|
}
|
|
});
|
|
|
|
console.log(`Event listener added for expand icon on card ${index}`);
|
|
} else {
|
|
console.error(`No expand icon found for card ${index}`);
|
|
}
|
|
|
|
console.log(`Event listener added for card ${index}`);
|
|
});
|
|
}, 100);
|
|
}
|
|
|
|
// Load cluster members when page loads
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
refreshClusterMembers();
|
|
});
|
|
|
|
// Auto-refresh every 30 seconds
|
|
setInterval(refreshClusterMembers, 30000);
|
|
</script>
|
|
</body>
|
|
</html> |