333 lines
11 KiB
HTML
333 lines
11 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>WebCounter - Controller</title>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.7.2/socket.io.js"></script>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
max-width: 800px;
|
|
margin: 0 auto;
|
|
padding: 20px;
|
|
background-color: #f5f5f5;
|
|
}
|
|
.container {
|
|
background: white;
|
|
padding: 30px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
|
|
}
|
|
h1 {
|
|
color: #333;
|
|
text-align: center;
|
|
margin-bottom: 30px;
|
|
}
|
|
.status {
|
|
padding: 10px;
|
|
border-radius: 5px;
|
|
margin-bottom: 20px;
|
|
text-align: center;
|
|
font-weight: bold;
|
|
}
|
|
.status.connected {
|
|
background-color: #d4edda;
|
|
color: #155724;
|
|
border: 1px solid #c3e6cb;
|
|
}
|
|
.status.disconnected {
|
|
background-color: #f8d7da;
|
|
color: #721c24;
|
|
border: 1px solid #f5c6cb;
|
|
}
|
|
.form-group {
|
|
margin-bottom: 20px;
|
|
}
|
|
label {
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
font-weight: bold;
|
|
color: #333;
|
|
}
|
|
input, textarea, select {
|
|
width: 100%;
|
|
padding: 10px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 5px;
|
|
font-size: 14px;
|
|
box-sizing: border-box;
|
|
}
|
|
textarea {
|
|
height: 100px;
|
|
resize: vertical;
|
|
font-family: monospace;
|
|
}
|
|
.btn {
|
|
padding: 12px 24px;
|
|
font-size: 16px;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
margin-right: 10px;
|
|
margin-bottom: 10px;
|
|
}
|
|
.btn-primary {
|
|
background-color: #007bff;
|
|
color: white;
|
|
}
|
|
.btn-primary:hover {
|
|
background-color: #0056b3;
|
|
}
|
|
.btn-success {
|
|
background-color: #28a745;
|
|
color: white;
|
|
}
|
|
.btn-success:hover {
|
|
background-color: #1e7e34;
|
|
}
|
|
.btn-warning {
|
|
background-color: #ffc107;
|
|
color: #212529;
|
|
}
|
|
.btn-warning:hover {
|
|
background-color: #e0a800;
|
|
}
|
|
.btn-danger {
|
|
background-color: #dc3545;
|
|
color: white;
|
|
}
|
|
.btn-danger:hover {
|
|
background-color: #c82333;
|
|
}
|
|
.quick-actions {
|
|
margin-top: 30px;
|
|
padding: 20px;
|
|
background-color: #f8f9fa;
|
|
border-radius: 5px;
|
|
}
|
|
.quick-actions h3 {
|
|
margin-top: 0;
|
|
color: #333;
|
|
}
|
|
.nav-link {
|
|
display: inline-block;
|
|
margin-top: 20px;
|
|
padding: 10px 20px;
|
|
background-color: #6c757d;
|
|
color: white;
|
|
text-decoration: none;
|
|
border-radius: 5px;
|
|
}
|
|
.nav-link:hover {
|
|
background-color: #5a6268;
|
|
}
|
|
.sent-events {
|
|
margin-top: 30px;
|
|
border: 1px solid #ddd;
|
|
border-radius: 5px;
|
|
padding: 20px;
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
background-color: #f9f9f9;
|
|
}
|
|
.sent-event {
|
|
background: white;
|
|
padding: 10px;
|
|
margin-bottom: 10px;
|
|
border-radius: 5px;
|
|
border-left: 4px solid #007bff;
|
|
box-shadow: 0 1px 3px rgba(0,0,0,0.1);
|
|
}
|
|
.sent-event-time {
|
|
color: #666;
|
|
font-size: 12px;
|
|
margin-bottom: 5px;
|
|
}
|
|
.sent-event-data {
|
|
font-family: monospace;
|
|
background-color: #f8f9fa;
|
|
padding: 5px;
|
|
border-radius: 3px;
|
|
word-break: break-all;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>WebCounter - Controller</h1>
|
|
<div id="status" class="status disconnected">Disconnected</div>
|
|
|
|
<form id="eventForm">
|
|
<div class="form-group">
|
|
<label for="eventType">Event Type:</label>
|
|
<select id="eventType">
|
|
<option value="message">Message</option>
|
|
<option value="notification">Notification</option>
|
|
<option value="update">Update</option>
|
|
<option value="alert">Alert</option>
|
|
<option value="custom">Custom</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="eventTitle">Title:</label>
|
|
<input type="text" id="eventTitle" placeholder="Enter event title">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="eventMessage">Message:</label>
|
|
<textarea id="eventMessage" placeholder="Enter event message or JSON data"></textarea>
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="eventPriority">Priority:</label>
|
|
<select id="eventPriority">
|
|
<option value="low">Low</option>
|
|
<option value="medium" selected>Medium</option>
|
|
<option value="high">High</option>
|
|
<option value="urgent">Urgent</option>
|
|
</select>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">Send Event</button>
|
|
<button type="button" class="btn btn-success" onclick="sendTestEvent()">Send Test Event</button>
|
|
</form>
|
|
|
|
<div class="quick-actions">
|
|
<h3>Quick Actions</h3>
|
|
<button class="btn btn-success" onclick="sendNotification('Success', 'Operation completed successfully!')">Success Notification</button>
|
|
<button class="btn btn-warning" onclick="sendNotification('Warning', 'Please check your input.')">Warning Notification</button>
|
|
<button class="btn btn-danger" onclick="sendNotification('Error', 'An error occurred!')">Error Notification</button>
|
|
<button class="btn btn-primary" onclick="sendCounterUpdate()">Counter Update</button>
|
|
</div>
|
|
|
|
<div class="sent-events">
|
|
<h3>Sent Events:</h3>
|
|
<div id="sentEvents"></div>
|
|
</div>
|
|
|
|
<a href="/" class="nav-link">← Back to Home</a>
|
|
</div>
|
|
|
|
<script>
|
|
// Connect to WebSocket server
|
|
const socket = io();
|
|
const statusDiv = document.getElementById('status');
|
|
const sentEventsDiv = document.getElementById('sentEvents');
|
|
let counter = 0;
|
|
|
|
// Connection status
|
|
socket.on('connect', function() {
|
|
statusDiv.textContent = 'Connected to server';
|
|
statusDiv.className = 'status connected';
|
|
console.log('Connected to server');
|
|
});
|
|
|
|
socket.on('disconnect', function() {
|
|
statusDiv.textContent = 'Disconnected from server';
|
|
statusDiv.className = 'status disconnected';
|
|
console.log('Disconnected from server');
|
|
});
|
|
|
|
// Handle form submission
|
|
document.getElementById('eventForm').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
sendEvent();
|
|
});
|
|
|
|
function sendEvent() {
|
|
const eventType = document.getElementById('eventType').value;
|
|
const eventTitle = document.getElementById('eventTitle').value;
|
|
const eventMessage = document.getElementById('eventMessage').value;
|
|
const eventPriority = document.getElementById('eventPriority').value;
|
|
|
|
let eventData;
|
|
|
|
if (eventType === 'custom') {
|
|
try {
|
|
eventData = JSON.parse(eventMessage);
|
|
} catch (e) {
|
|
eventData = { message: eventMessage };
|
|
}
|
|
} else {
|
|
eventData = {
|
|
type: eventType,
|
|
title: eventTitle,
|
|
message: eventMessage,
|
|
priority: eventPriority,
|
|
timestamp: new Date().toISOString()
|
|
};
|
|
}
|
|
|
|
socket.emit('send_event', eventData);
|
|
addSentEvent(eventData);
|
|
|
|
// Clear form
|
|
document.getElementById('eventTitle').value = '';
|
|
document.getElementById('eventMessage').value = '';
|
|
}
|
|
|
|
function sendTestEvent() {
|
|
const testEvent = {
|
|
type: 'test',
|
|
title: 'Test Event',
|
|
message: 'This is a test event from the controller',
|
|
priority: 'medium',
|
|
timestamp: new Date().toISOString()
|
|
};
|
|
|
|
socket.emit('send_event', testEvent);
|
|
addSentEvent(testEvent);
|
|
}
|
|
|
|
function sendNotification(type, message) {
|
|
const notification = {
|
|
type: 'notification',
|
|
title: type,
|
|
message: message,
|
|
priority: type.toLowerCase() === 'error' ? 'high' : 'medium',
|
|
timestamp: new Date().toISOString()
|
|
};
|
|
|
|
socket.emit('send_event', notification);
|
|
addSentEvent(notification);
|
|
}
|
|
|
|
function sendCounterUpdate() {
|
|
counter++;
|
|
const counterEvent = {
|
|
type: 'counter',
|
|
title: 'Counter Update',
|
|
message: `Counter value: ${counter}`,
|
|
counter: counter,
|
|
timestamp: new Date().toISOString()
|
|
};
|
|
|
|
socket.emit('send_event', counterEvent);
|
|
addSentEvent(counterEvent);
|
|
}
|
|
|
|
function addSentEvent(data) {
|
|
const eventDiv = document.createElement('div');
|
|
eventDiv.className = 'sent-event';
|
|
|
|
const timeDiv = document.createElement('div');
|
|
timeDiv.className = 'sent-event-time';
|
|
timeDiv.textContent = new Date().toLocaleTimeString();
|
|
|
|
const dataDiv = document.createElement('div');
|
|
dataDiv.className = 'sent-event-data';
|
|
dataDiv.textContent = JSON.stringify(data, null, 2);
|
|
|
|
eventDiv.appendChild(timeDiv);
|
|
eventDiv.appendChild(dataDiv);
|
|
|
|
sentEventsDiv.appendChild(eventDiv);
|
|
|
|
// Auto-scroll to bottom
|
|
sentEventsDiv.scrollTop = sentEventsDiv.scrollHeight;
|
|
}
|
|
</script>
|
|
</body>
|
|
</html> |