Initial commit - Shopfloor Dashboard

- Node.js Express server with MySQL integration
- Real-time event dashboard with live updates
- GE Aerospace branding and design
- Auto-refresh every 10 seconds (AJAX)
- Shows current and upcoming events (48 hour window)
- Connection status monitoring
- Optimized for TV display

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
cproudlock
2025-10-21 16:17:45 -04:00
commit 6a9bb8c7a4
11 changed files with 2760 additions and 0 deletions

59
.gitignore vendored Normal file
View File

@@ -0,0 +1,59 @@
# Node.js
node_modules/
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# Environment variables
.env
.env.local
.env.*.local
# Logs
logs/
*.log
# Runtime data
pids/
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov/
# Coverage directory used by tools like istanbul
coverage/
# nyc test coverage
.nyc_output/
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# IDE
.vscode/
.idea/
*.swp
*.swo
*~
# OS
.DS_Store
Thumbs.db
# Temporary files
tmp/
temp/

192
README.md Normal file
View File

@@ -0,0 +1,192 @@
# Shopfloor Dashboard
GE Aerospace West Jefferson shopfloor events and notifications dashboard.
## Overview
Real-time display dashboard for showing current and upcoming events on the shopfloor. Designed for TV displays with large, readable text and GE Aerospace branding.
## Features
- **Live Data Updates**: Auto-refreshes every 10 seconds via AJAX (no page reload)
- **48-Hour Window**: Shows current events and upcoming events within next 48 hours
- **Real-Time Clock**: Always-on clock display
- **Connection Monitoring**: Visual indicator shows live connection status
- **GE Aerospace Branding**: Official colors, fonts, and logo
## Technology Stack
- **Backend**: Node.js with Express
- **Database**: MySQL 5.6
- **Frontend**: Vanilla JavaScript (no frameworks)
- **Styling**: Custom CSS with GE Aerospace brand colors
## Installation
### Prerequisites
- Node.js 16+ and npm
- MySQL 5.6+ database
- Access to ShopDB database
### Setup
```bash
# Install dependencies
npm install
# Set environment variables (optional)
export DB_HOST=localhost
export DB_PORT=3306
export DB_USER=570005354
export DB_PASS=570005354
export DB_NAME=shopdb
export PORT=3001
# Start the server
npm start
# Or for development with auto-restart
npm run dev
```
## Configuration
Environment variables:
| Variable | Default | Description |
|----------|---------|-------------|
| `PORT` | 3000 | Server port |
| `DB_HOST` | localhost | Database host |
| `DB_PORT` | 3306 | Database port |
| `DB_USER` | 570005354 | Database username |
| `DB_PASS` | 570005354 | Database password |
| `DB_NAME` | shopdb | Database name |
## Usage
### Access the Dashboard
Open your browser to:
```
http://localhost:3001
```
### API Endpoints
**Get Notifications:**
```
GET /api/notifications
```
Returns current and upcoming events in JSON format.
**Health Check:**
```
GET /health
```
Returns server status.
## Display on TV
1. Open the dashboard URL in a web browser (Chrome recommended)
2. Press F11 for fullscreen mode
3. Dashboard will auto-refresh every 10 seconds
4. Connection status indicator shows "LIVE" when connected
## Project Structure
```
shopfloor-dashboard/
├── server.js # Express server
├── package.json # Dependencies
├── public/
│ ├── index.html # Dashboard UI
│ └── ge-aerospace-logo.svg
├── .gitignore
└── README.md
```
## Database Schema
Queries the `notifications` table in ShopDB:
```sql
SELECT notificationid, notification, starttime, endtime,
ticketnumber, link, isactive
FROM notifications
WHERE isactive = 1
AND (conditions for current/upcoming)
ORDER BY starttime ASC
```
## Design
### Colors (GE Aerospace Brand)
- **Deep Navy**: `#00003d` (background)
- **Sky Blue**: `#4181ff` (accents, clock)
- **Avionics Green**: `#0ad64f` (live indicator)
- **Tungsten**: `#eaeaea` (secondary text)
### Typography
- **Font**: Inter (sans-serif)
- **Sizes**: Large for TV readability (38px-48px headers)
## Development
```bash
# Install dev dependencies
npm install
# Run with auto-restart
npm run dev
# The server will restart automatically when you edit files
```
## Deployment
For production deployment:
1. Use a process manager (PM2, systemd)
2. Set environment variables
3. Configure reverse proxy (nginx/Apache) if needed
4. Enable SSL/TLS for secure connections
### Example with PM2:
```bash
npm install -g pm2
pm2 start server.js --name shopfloor-dashboard
pm2 save
pm2 startup
```
## Troubleshooting
**Port already in use:**
```bash
# Use a different port
PORT=3001 npm start
```
**Can't connect to database:**
- Verify MySQL is running
- Check credentials in environment variables
- Ensure database exists and user has permissions
**Dashboard not updating:**
- Check browser console for errors
- Verify `/api/notifications` endpoint returns data
- Check network connectivity
## License
Internal GE Aerospace project - West Jefferson facility
## Support
Contact: IT Support - West Jefferson

74
api_notifications.php Normal file
View File

@@ -0,0 +1,74 @@
<?php
/**
* API Endpoint - Fetch Live Notifications
* Returns JSON data for AJAX updates
*/
header('Content-Type: application/json');
require_once 'db_config.php';
try {
// Get current time and 48 hours from now
$now = date('Y-m-d H:i:s');
$future = date('Y-m-d H:i:s', strtotime('+48 hours'));
// Fetch active notifications within the next 48 hours
$pdo = getDbConnection();
$sql = "SELECT notificationid, notification, starttime, endtime, ticketnumber, link, isactive
FROM notifications
WHERE isactive = 1
AND (
(starttime <= :future AND (endtime IS NULL OR endtime >= :now))
OR (starttime BETWEEN :now2 AND :future2)
)
ORDER BY starttime ASC";
$stmt = $pdo->prepare($sql);
$stmt->execute([
':now' => $now,
':now2' => $now,
':future' => $future,
':future2' => $future
]);
$notifications = $stmt->fetchAll();
// Categorize notifications
$currentEvents = [];
$upcomingEvents = [];
foreach ($notifications as $notification) {
$start = strtotime($notification['starttime']);
$end = $notification['endtime'] ? strtotime($notification['endtime']) : null;
$nowTimestamp = time();
if ($start <= $nowTimestamp && ($end === null || $end >= $nowTimestamp)) {
$currentEvents[] = $notification;
} else {
$upcomingEvents[] = $notification;
}
}
// Return JSON response
echo json_encode([
'success' => true,
'timestamp' => date('Y-m-d H:i:s'),
'current' => $currentEvents,
'upcoming' => $upcomingEvents
], JSON_PRETTY_PRINT);
} catch (PDOException $e) {
http_response_code(500);
echo json_encode([
'success' => false,
'error' => 'Database error: ' . $e->getMessage()
]);
} catch (Exception $e) {
http_response_code(500);
echo json_encode([
'success' => false,
'error' => 'Server error: ' . $e->getMessage()
]);
}
?>

33
db_config.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
/**
* Database Configuration for Shopfloor Dashboard
* Connects to ShopDB MySQL database
*/
// Database configuration
define('DB_HOST', 'mysql'); // Docker container name
define('DB_PORT', '3306');
define('DB_NAME', 'shopdb');
define('DB_USER', '570005354');
define('DB_PASS', '570005354');
/**
* Get database connection
* @return PDO Database connection object
*/
function getDbConnection() {
try {
$dsn = "mysql:host=" . DB_HOST . ";port=" . DB_PORT . ";dbname=" . DB_NAME . ";charset=utf8mb4";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$pdo = new PDO($dsn, DB_USER, DB_PASS, $options);
return $pdo;
} catch (PDOException $e) {
die("Database Connection Failed: " . htmlspecialchars($e->getMessage()));
}
}
?>

8
ge-aerospace-logo.svg Normal file

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.3 KiB

469
index.php Normal file
View File

@@ -0,0 +1,469 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopfloor Dashboard - Events & Notifications</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: #00003d; /* GE Aerospace Deep Navy */
color: #fff;
overflow-x: hidden;
}
.container {
max-width: 1920px;
margin: 0 auto;
padding: 30px 40px;
padding-bottom: 100px;
}
.header {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 40px;
margin-bottom: 40px;
border-bottom: 2px solid #4181ff; /* GE Sky Blue */
padding-bottom: 25px;
}
.logo-container {
display: flex;
align-items: center;
}
.logo-container img {
height: 100px;
width: auto;
}
.header-center {
text-align: center;
display: flex;
flex-direction: column;
gap: 8px;
}
.location-title {
font-size: 18px;
font-weight: 600;
color: #eaeaea; /* GE Tungsten */
text-transform: uppercase;
letter-spacing: 2px;
}
.header-center h1 {
font-size: 48px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 2px;
color: #fff;
}
.clock {
font-size: 36px;
font-weight: 600;
letter-spacing: 1px;
color: #4181ff; /* GE Sky Blue */
text-align: right;
}
.connection-status {
position: fixed;
top: 20px;
right: 20px;
padding: 12px 20px;
border-radius: 6px;
font-size: 18px;
font-weight: 700;
z-index: 1000;
display: flex;
align-items: center;
gap: 10px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.connection-status.connected {
background: #0ad64f; /* GE Avionics Green */
color: #00003d;
}
.connection-status.disconnected {
background: #dc3545;
animation: blink 1s infinite;
}
@keyframes blink {
0%, 50% { opacity: 1; }
51%, 100% { opacity: 0.5; }
}
.status-dot {
width: 12px;
height: 12px;
border-radius: 50%;
background: #00003d;
}
.events-section {
margin-bottom: 40px;
}
.section-title {
font-size: 42px;
font-weight: 800;
margin-bottom: 25px;
padding: 15px 25px;
border-radius: 8px;
display: inline-block;
text-transform: uppercase;
letter-spacing: 1px;
}
.section-title.current {
background: #dc3545;
color: #fff;
box-shadow: 0 4px 20px rgba(220, 53, 69, 0.4);
}
.section-title.upcoming {
background: #4181ff; /* GE Sky Blue */
color: #fff;
box-shadow: 0 4px 20px rgba(65, 129, 255, 0.4);
}
.event-card {
background: #fff;
color: #000;
padding: 30px 40px;
margin-bottom: 20px;
border-radius: 8px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
border-left: 8px solid;
transition: all 0.3s ease;
}
.event-card.current {
border-left-color: #dc3545;
animation: pulse 2s infinite;
}
.event-card.upcoming {
border-left-color: #4181ff; /* GE Sky Blue */
}
@keyframes pulse {
0%, 100% {
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
50% {
box-shadow: 0 6px 30px rgba(220, 53, 69, 0.5);
}
}
.event-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
gap: 20px;
}
.event-title {
font-size: 38px;
font-weight: 700;
flex: 1;
color: #00003d; /* GE Deep Navy for text */
}
.event-ticket {
font-size: 32px;
font-weight: 700;
background: #00003d; /* GE Deep Navy */
color: #fff;
padding: 10px 25px;
border-radius: 6px;
white-space: nowrap;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.event-time {
font-size: 26px;
color: #666;
font-weight: 400;
}
.event-time strong {
color: #00003d; /* GE Deep Navy */
font-weight: 700;
}
.no-events {
text-align: center;
font-size: 36px;
font-weight: 600;
padding: 80px 40px;
background: rgba(234, 234, 234, 0.1);
border-radius: 8px;
margin-top: 30px;
color: #eaeaea; /* GE Tungsten */
}
.footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.8);
text-align: center;
padding: 15px;
font-size: 22px;
z-index: 999;
font-weight: 500;
}
.loading {
text-align: center;
font-size: 36px;
font-weight: 600;
padding: 80px 40px;
background: rgba(234, 234, 234, 0.1);
border-radius: 8px;
margin-top: 30px;
}
.error-message {
background: #dc3545;
color: #fff;
padding: 40px;
border-radius: 8px;
text-align: center;
font-size: 32px;
font-weight: 700;
margin: 30px 0;
}
</style>
</head>
<body>
<div class="connection-status connected" id="connectionStatus">
<div class="status-dot"></div>
<span>LIVE</span>
</div>
<div class="container">
<div class="header">
<div class="logo-container">
<img src="ge-aerospace-logo.svg" alt="GE Aerospace">
</div>
<div class="header-center">
<div class="location-title">West Jefferson</div>
<h1>Shopfloor Events</h1>
</div>
<div class="clock" id="clock"></div>
</div>
<div id="eventsContainer">
<div class="loading"> Loading events...</div>
</div>
</div>
<div class="footer">
Last updated: <span id="lastUpdate">--:--:--</span> | Refreshing every 10 seconds
</div>
<script>
let isConnected = true;
let updateInterval;
let clockInterval;
// Update clock
function updateClock() {
const now = new Date();
const timeString = now.toLocaleString('en-US', {
weekday: 'short',
month: 'short',
day: 'numeric',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
document.getElementById('clock').textContent = timeString;
}
// Update connection status indicator
function setConnectionStatus(connected) {
isConnected = connected;
const statusEl = document.getElementById('connectionStatus');
if (connected) {
statusEl.className = 'connection-status connected';
statusEl.innerHTML = '<div class="status-dot"></div><span>LIVE</span>';
} else {
statusEl.className = 'connection-status disconnected';
statusEl.innerHTML = '<div class="status-dot"></div><span>RECONNECTING...</span>';
}
}
// Format date/time for display
function formatDateTime(datetime) {
const date = new Date(datetime);
return date.toLocaleString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true
});
}
// Render events on the page
function renderEvents(data) {
const container = document.getElementById('eventsContainer');
let html = '';
// Current Events
if (data.current && data.current.length > 0) {
html += '<div class="events-section">';
html += '<div class="section-title current">🔴 CURRENT EVENTS</div>';
data.current.forEach(event => {
html += `
<div class="event-card current">
<div class="event-header">
<div class="event-title">${escapeHtml(event.notification)}</div>
${event.ticketnumber ? `<div class="event-ticket">Ticket: ${escapeHtml(event.ticketnumber)}</div>` : ''}
</div>
<div class="event-time">
<strong>Started:</strong> ${formatDateTime(event.starttime)}
${event.endtime ? `<br><strong>Ends:</strong> ${formatDateTime(event.endtime)}` : '<br><strong>Status:</strong> Ongoing (no end time)'}
</div>
</div>
`;
});
html += '</div>';
}
// Upcoming Events
if (data.upcoming && data.upcoming.length > 0) {
html += '<div class="events-section">';
html += '<div class="section-title upcoming">⚠️ UPCOMING (Next 48 Hours)</div>';
data.upcoming.forEach(event => {
html += `
<div class="event-card upcoming">
<div class="event-header">
<div class="event-title">${escapeHtml(event.notification)}</div>
${event.ticketnumber ? `<div class="event-ticket">Ticket: ${escapeHtml(event.ticketnumber)}</div>` : ''}
</div>
<div class="event-time">
<strong>Starts:</strong> ${formatDateTime(event.starttime)}
${event.endtime ? `<br><strong>Ends:</strong> ${formatDateTime(event.endtime)}` : ''}
</div>
</div>
`;
});
html += '</div>';
}
// No events message
if ((!data.current || data.current.length === 0) && (!data.upcoming || data.upcoming.length === 0)) {
html += '<div class="no-events">✅ No scheduled events for the next 48 hours</div>';
}
container.innerHTML = html;
}
// Escape HTML to prevent XSS
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// Fetch notifications from API
async function fetchNotifications() {
try {
const response = await fetch('api_notifications.php');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (data.success) {
renderEvents(data);
updateLastUpdateTime();
setConnectionStatus(true);
} else {
throw new Error(data.error || 'Unknown error');
}
} catch (error) {
console.error('Error fetching notifications:', error);
setConnectionStatus(false);
// Show error message if first load
const container = document.getElementById('eventsContainer');
if (container.querySelector('.loading')) {
container.innerHTML = `
<div class="error-message">
⚠️ Unable to load events<br>
<span style="font-size: 24px; margin-top: 10px; display: block;">Retrying...</span>
</div>
`;
}
}
}
// Update last update time
function updateLastUpdateTime() {
const now = new Date();
const timeString = now.toLocaleTimeString('en-US');
document.getElementById('lastUpdate').textContent = timeString;
}
// Initialize dashboard
function init() {
// Start clock
updateClock();
clockInterval = setInterval(updateClock, 1000);
// Initial data fetch
fetchNotifications();
// Set up automatic refresh every 10 seconds
updateInterval = setInterval(fetchNotifications, 10000);
}
// Handle page visibility changes (pause updates when hidden)
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
clearInterval(updateInterval);
clearInterval(clockInterval);
} else {
init();
}
});
// Start the dashboard
init();
</script>
</body>
</html>

1335
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

20
package.json Normal file
View File

@@ -0,0 +1,20 @@
{
"name": "shopfloor-dashboard",
"version": "1.0.0",
"description": "GE Aerospace Shopfloor Events Dashboard",
"main": "server.js",
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js"
},
"keywords": ["dashboard", "events", "notifications"],
"author": "GE Aerospace - West Jefferson",
"license": "ISC",
"dependencies": {
"express": "^4.18.2",
"mysql2": "^3.6.5"
},
"devDependencies": {
"nodemon": "^3.0.2"
}
}

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 9.3 KiB

469
public/index.html Normal file
View File

@@ -0,0 +1,469 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shopfloor Dashboard - Events & Notifications</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&display=swap" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
background: #00003d; /* GE Aerospace Deep Navy */
color: #fff;
overflow-x: hidden;
}
.container {
max-width: 1920px;
margin: 0 auto;
padding: 30px 40px;
padding-bottom: 100px;
}
.header {
display: grid;
grid-template-columns: auto 1fr auto;
align-items: center;
gap: 40px;
margin-bottom: 40px;
border-bottom: 2px solid #4181ff; /* GE Sky Blue */
padding-bottom: 25px;
}
.logo-container {
display: flex;
align-items: center;
}
.logo-container img {
height: 100px;
width: auto;
}
.header-center {
text-align: center;
display: flex;
flex-direction: column;
gap: 8px;
}
.location-title {
font-size: 18px;
font-weight: 600;
color: #eaeaea; /* GE Tungsten */
text-transform: uppercase;
letter-spacing: 2px;
}
.header-center h1 {
font-size: 48px;
font-weight: 700;
text-transform: uppercase;
letter-spacing: 2px;
color: #fff;
}
.clock {
font-size: 36px;
font-weight: 600;
letter-spacing: 1px;
color: #4181ff; /* GE Sky Blue */
text-align: right;
}
.connection-status {
position: fixed;
top: 20px;
right: 20px;
padding: 12px 20px;
border-radius: 6px;
font-size: 18px;
font-weight: 700;
z-index: 1000;
display: flex;
align-items: center;
gap: 10px;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.connection-status.connected {
background: #0ad64f; /* GE Avionics Green */
color: #00003d;
}
.connection-status.disconnected {
background: #dc3545;
animation: blink 1s infinite;
}
@keyframes blink {
0%, 50% { opacity: 1; }
51%, 100% { opacity: 0.5; }
}
.status-dot {
width: 12px;
height: 12px;
border-radius: 50%;
background: #00003d;
}
.events-section {
margin-bottom: 40px;
}
.section-title {
font-size: 42px;
font-weight: 800;
margin-bottom: 25px;
padding: 15px 25px;
border-radius: 8px;
display: inline-block;
text-transform: uppercase;
letter-spacing: 1px;
}
.section-title.current {
background: #dc3545;
color: #fff;
box-shadow: 0 4px 20px rgba(220, 53, 69, 0.4);
}
.section-title.upcoming {
background: #4181ff; /* GE Sky Blue */
color: #fff;
box-shadow: 0 4px 20px rgba(65, 129, 255, 0.4);
}
.event-card {
background: #fff;
color: #000;
padding: 30px 40px;
margin-bottom: 20px;
border-radius: 8px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
border-left: 8px solid;
transition: all 0.3s ease;
}
.event-card.current {
border-left-color: #dc3545;
animation: pulse 2s infinite;
}
.event-card.upcoming {
border-left-color: #4181ff; /* GE Sky Blue */
}
@keyframes pulse {
0%, 100% {
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}
50% {
box-shadow: 0 6px 30px rgba(220, 53, 69, 0.5);
}
}
.event-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 20px;
gap: 20px;
}
.event-title {
font-size: 38px;
font-weight: 700;
flex: 1;
color: #00003d; /* GE Deep Navy for text */
}
.event-ticket {
font-size: 32px;
font-weight: 700;
background: #00003d; /* GE Deep Navy */
color: #fff;
padding: 10px 25px;
border-radius: 6px;
white-space: nowrap;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.event-time {
font-size: 26px;
color: #666;
font-weight: 400;
}
.event-time strong {
color: #00003d; /* GE Deep Navy */
font-weight: 700;
}
.no-events {
text-align: center;
font-size: 36px;
font-weight: 600;
padding: 80px 40px;
background: rgba(234, 234, 234, 0.1);
border-radius: 8px;
margin-top: 30px;
color: #eaeaea; /* GE Tungsten */
}
.footer {
position: fixed;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.8);
text-align: center;
padding: 15px;
font-size: 22px;
z-index: 999;
font-weight: 500;
}
.loading {
text-align: center;
font-size: 36px;
font-weight: 600;
padding: 80px 40px;
background: rgba(234, 234, 234, 0.1);
border-radius: 8px;
margin-top: 30px;
}
.error-message {
background: #dc3545;
color: #fff;
padding: 40px;
border-radius: 8px;
text-align: center;
font-size: 32px;
font-weight: 700;
margin: 30px 0;
}
</style>
</head>
<body>
<div class="connection-status connected" id="connectionStatus">
<div class="status-dot"></div>
<span>LIVE</span>
</div>
<div class="container">
<div class="header">
<div class="logo-container">
<img src="ge-aerospace-logo.svg" alt="GE Aerospace">
</div>
<div class="header-center">
<div class="location-title">West Jefferson</div>
<h1>Shopfloor Events</h1>
</div>
<div class="clock" id="clock"></div>
</div>
<div id="eventsContainer">
<div class="loading">⏳ Loading events...</div>
</div>
</div>
<div class="footer">
Last updated: <span id="lastUpdate">--:--:--</span> | Refreshing every 10 seconds
</div>
<script>
let isConnected = true;
let updateInterval;
let clockInterval;
// Update clock
function updateClock() {
const now = new Date();
const timeString = now.toLocaleString('en-US', {
weekday: 'short',
month: 'short',
day: 'numeric',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
second: '2-digit'
});
document.getElementById('clock').textContent = timeString;
}
// Update connection status indicator
function setConnectionStatus(connected) {
isConnected = connected;
const statusEl = document.getElementById('connectionStatus');
if (connected) {
statusEl.className = 'connection-status connected';
statusEl.innerHTML = '<div class="status-dot"></div><span>LIVE</span>';
} else {
statusEl.className = 'connection-status disconnected';
statusEl.innerHTML = '<div class="status-dot"></div><span>RECONNECTING...</span>';
}
}
// Format date/time for display
function formatDateTime(datetime) {
const date = new Date(datetime);
return date.toLocaleString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true
});
}
// Render events on the page
function renderEvents(data) {
const container = document.getElementById('eventsContainer');
let html = '';
// Current Events
if (data.current && data.current.length > 0) {
html += '<div class="events-section">';
html += '<div class="section-title current">🔴 CURRENT EVENTS</div>';
data.current.forEach(event => {
html += `
<div class="event-card current">
<div class="event-header">
<div class="event-title">${escapeHtml(event.notification)}</div>
${event.ticketnumber ? `<div class="event-ticket">Ticket: ${escapeHtml(event.ticketnumber)}</div>` : ''}
</div>
<div class="event-time">
<strong>Started:</strong> ${formatDateTime(event.starttime)}
${event.endtime ? `<br><strong>Ends:</strong> ${formatDateTime(event.endtime)}` : '<br><strong>Status:</strong> Ongoing (no end time)'}
</div>
</div>
`;
});
html += '</div>';
}
// Upcoming Events
if (data.upcoming && data.upcoming.length > 0) {
html += '<div class="events-section">';
html += '<div class="section-title upcoming">⚠️ UPCOMING (Next 48 Hours)</div>';
data.upcoming.forEach(event => {
html += `
<div class="event-card upcoming">
<div class="event-header">
<div class="event-title">${escapeHtml(event.notification)}</div>
${event.ticketnumber ? `<div class="event-ticket">Ticket: ${escapeHtml(event.ticketnumber)}</div>` : ''}
</div>
<div class="event-time">
<strong>Starts:</strong> ${formatDateTime(event.starttime)}
${event.endtime ? `<br><strong>Ends:</strong> ${formatDateTime(event.endtime)}` : ''}
</div>
</div>
`;
});
html += '</div>';
}
// No events message
if ((!data.current || data.current.length === 0) && (!data.upcoming || data.upcoming.length === 0)) {
html += '<div class="no-events">✅ No scheduled events for the next 48 hours</div>';
}
container.innerHTML = html;
}
// Escape HTML to prevent XSS
function escapeHtml(text) {
const div = document.createElement('div');
div.textContent = text;
return div.innerHTML;
}
// Fetch notifications from API
async function fetchNotifications() {
try {
const response = await fetch('/api/notifications');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (data.success) {
renderEvents(data);
updateLastUpdateTime();
setConnectionStatus(true);
} else {
throw new Error(data.error || 'Unknown error');
}
} catch (error) {
console.error('Error fetching notifications:', error);
setConnectionStatus(false);
// Show error message if first load
const container = document.getElementById('eventsContainer');
if (container.querySelector('.loading')) {
container.innerHTML = `
<div class="error-message">
⚠️ Unable to load events<br>
<span style="font-size: 24px; margin-top: 10px; display: block;">Retrying...</span>
</div>
`;
}
}
}
// Update last update time
function updateLastUpdateTime() {
const now = new Date();
const timeString = now.toLocaleTimeString('en-US');
document.getElementById('lastUpdate').textContent = timeString;
}
// Initialize dashboard
function init() {
// Start clock
updateClock();
clockInterval = setInterval(updateClock, 1000);
// Initial data fetch
fetchNotifications();
// Set up automatic refresh every 10 seconds
updateInterval = setInterval(fetchNotifications, 10000);
}
// Handle page visibility changes (pause updates when hidden)
document.addEventListener('visibilitychange', function() {
if (document.hidden) {
clearInterval(updateInterval);
clearInterval(clockInterval);
} else {
init();
}
});
// Start the dashboard
init();
</script>
</body>
</html>

93
server.js Normal file
View File

@@ -0,0 +1,93 @@
const express = require('express');
const mysql = require('mysql2');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3000;
// Database connection pool
const pool = mysql.createPool({
host: process.env.DB_HOST || 'localhost',
port: process.env.DB_PORT || 3306,
user: process.env.DB_USER || '570005354',
password: process.env.DB_PASS || '570005354',
database: process.env.DB_NAME || 'shopdb',
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
});
// Promisify for async/await
const promisePool = pool.promise();
// Serve static files
app.use(express.static('public'));
// API endpoint to get notifications
app.get('/api/notifications', async (req, res) => {
try {
const now = new Date();
const future = new Date(now.getTime() + (48 * 60 * 60 * 1000)); // 48 hours from now
const [rows] = await promisePool.query(
`SELECT notificationid, notification, starttime, endtime, ticketnumber, link, isactive
FROM notifications
WHERE isactive = 1
AND (
(starttime <= ? AND (endtime IS NULL OR endtime >= ?))
OR (starttime BETWEEN ? AND ?)
)
ORDER BY starttime ASC`,
[future, now, now, future]
);
// Categorize notifications
const currentEvents = [];
const upcomingEvents = [];
rows.forEach(notification => {
const start = new Date(notification.starttime);
const end = notification.endtime ? new Date(notification.endtime) : null;
if (start <= now && (end === null || end >= now)) {
currentEvents.push(notification);
} else {
upcomingEvents.push(notification);
}
});
res.json({
success: true,
timestamp: new Date().toISOString(),
current: currentEvents,
upcoming: upcomingEvents
});
} catch (error) {
console.error('Database error:', error);
res.status(500).json({
success: false,
error: 'Database error: ' + error.message
});
}
});
// Health check endpoint
app.get('/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString() });
});
// Start server
app.listen(PORT, () => {
console.log(`Shopfloor Dashboard running on port ${PORT}`);
console.log(`Access at: http://localhost:${PORT}`);
});
// Graceful shutdown
process.on('SIGTERM', () => {
console.log('SIGTERM signal received: closing HTTP server');
pool.end(() => {
console.log('Database pool closed');
process.exit(0);
});
});