Files
grepo-remote/templates/dashboard.html
2026-04-19 19:51:02 +00:00

529 lines
16 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Grepolis Remote</title>
<style>
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
font-family: 'Segoe UI', sans-serif;
background: #1a1a2e;
color: #e0e0e0;
min-height: 100vh;
}
header {
background: #16213e;
border-bottom: 2px solid #c8a44a;
padding: 12px 24px;
display: flex;
align-items: center;
gap: 16px;
}
header h1 {
font-size: 1.3rem;
color: #c8a44a;
letter-spacing: 1px;
}
#connection-status {
margin-left: auto;
font-size: 0.8rem;
padding: 4px 10px;
border-radius: 12px;
background: #333;
}
#connection-status.online { background: #1a4a1a; color: #6fcf6f; }
#connection-status.offline { background: #4a1a1a; color: #cf6f6f; }
.layout {
display: grid;
grid-template-columns: 320px 1fr;
grid-template-rows: auto 1fr;
gap: 0;
height: calc(100vh - 57px);
}
/* ---- Town list (left panel) ---- */
#town-panel {
grid-row: 1 / 3;
background: #16213e;
border-right: 1px solid #2a2a4a;
overflow-y: auto;
padding: 12px;
}
#town-panel h2 {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 1px;
color: #888;
margin-bottom: 10px;
padding-bottom: 6px;
border-bottom: 1px solid #2a2a4a;
}
.town-card {
background: #0f3460;
border: 1px solid #2a2a6a;
border-radius: 6px;
padding: 10px;
margin-bottom: 8px;
cursor: pointer;
transition: border-color 0.15s;
}
.town-card:hover { border-color: #c8a44a; }
.town-card.selected { border-color: #c8a44a; background: #1a4070; }
.town-card .town-name { font-weight: 600; font-size: 0.95rem; color: #c8a44a; }
.town-card .town-meta { font-size: 0.72rem; color: #888; margin-top: 2px; }
.town-card .town-res {
display: flex; gap: 8px;
margin-top: 6px; font-size: 0.78rem;
}
.res-item { display: flex; align-items: center; gap: 3px; }
.res-icon { width: 12px; height: 12px; border-radius: 2px; }
.res-wood { background: #8B6914; }
.res-stone { background: #888; }
.res-iron { background: #5588aa; }
.res-pop { background: #88aa55; }
.town-stale { opacity: 0.5; }
/* ---- Command panel (top right) ---- */
#command-panel {
padding: 16px 20px;
background: #1a1a2e;
border-bottom: 1px solid #2a2a4a;
}
#command-panel h2 {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 1px;
color: #888;
margin-bottom: 12px;
}
.command-form {
display: flex;
flex-wrap: wrap;
gap: 10px;
align-items: flex-end;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: 0.72rem; color: #aaa; text-transform: uppercase; letter-spacing: 0.5px; }
select, input[type=number] {
background: #0f3460;
border: 1px solid #2a2a6a;
color: #e0e0e0;
padding: 7px 10px;
border-radius: 4px;
font-size: 0.85rem;
min-width: 140px;
}
select:focus, input:focus { outline: none; border-color: #c8a44a; }
.btn {
padding: 8px 18px;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 0.85rem;
font-weight: 600;
letter-spacing: 0.5px;
transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-gold { background: #c8a44a; color: #1a1a2e; }
.btn-danger { background: #8b2222; color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 0.75rem; }
#no-town-selected {
color: #666;
font-size: 0.85rem;
padding: 8px 0;
}
/* Build queue preview */
#build-queue-preview {
margin-top: 10px;
font-size: 0.78rem;
color: #aaa;
}
#build-queue-preview span {
background: #0f3460;
border: 1px solid #2a4a6a;
border-radius: 3px;
padding: 2px 7px;
margin-right: 4px;
display: inline-block;
margin-bottom: 4px;
}
/* ---- Command log (bottom right) ---- */
#log-panel {
padding: 16px 20px;
overflow-y: auto;
background: #1a1a2e;
}
#log-panel h2 {
font-size: 0.75rem;
text-transform: uppercase;
letter-spacing: 1px;
color: #888;
margin-bottom: 10px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 0.8rem;
}
th {
text-align: left;
color: #888;
font-weight: 500;
padding: 4px 8px;
border-bottom: 1px solid #2a2a4a;
white-space: nowrap;
}
td {
padding: 5px 8px;
border-bottom: 1px solid #1e1e3a;
vertical-align: middle;
}
tr:hover td { background: #1e1e40; }
.status-badge {
padding: 2px 8px;
border-radius: 10px;
font-size: 0.7rem;
font-weight: 600;
text-transform: uppercase;
white-space: nowrap;
}
.status-pending { background: #3a3a00; color: #cccc00; }
.status-executing { background: #003a4a; color: #00ccee; }
.status-done { background: #003a00; color: #00cc66; }
.status-failed { background: #4a0000; color: #ee4444; }
.status-cancelled { background: #2a2a2a; color: #888; }
#empty-log { color: #444; font-size: 0.85rem; padding: 12px 0; }
</style>
</head>
<body>
<header>
<h1>⚔️ Grepolis Remote</h1>
<div id="connection-status">Connecting…</div>
</header>
<div class="layout">
<!-- Left: Town list -->
<div id="town-panel">
<h2>Towns</h2>
<div id="town-list"><p style="color:#444;font-size:0.8rem;">Waiting for data from home PC…</p></div>
</div>
<!-- Top right: Command panel -->
<div id="command-panel">
<h2>Send Command</h2>
<div id="no-town-selected">← Select a town first</div>
<div id="command-form-wrap" style="display:none">
<div class="command-form">
<div class="form-group">
<label>Command Type</label>
<select id="cmd-type" onchange="onCmdTypeChange()">
<option value="build">Build / Upgrade</option>
<option value="recruit">Recruit Troops</option>
</select>
</div>
<!-- Build options -->
<div class="form-group" id="build-options">
<label>Building</label>
<select id="building-select">
<option value="main">Senate (main)</option>
<option value="storage">Warehouse (storage)</option>
<option value="farm">Farm</option>
<option value="academy">Academy</option>
<option value="temple">Temple</option>
<option value="barracks">Barracks</option>
<option value="docks">Docks</option>
<option value="market">Marketplace</option>
<option value="hide">Cave (hide)</option>
<option value="lumber">Lumber mill</option>
<option value="stoner">Quarry (stoner)</option>
<option value="ironer">Ironer</option>
<option value="wall">City Wall</option>
</select>
</div>
<!-- Recruit options -->
<div class="form-group" id="recruit-options" style="display:none">
<label>Unit</label>
<select id="unit-select">
<optgroup label="Land">
<option value="sword">Swordsman</option>
<option value="slinger">Slinger</option>
<option value="archer">Archer</option>
<option value="hoplite">Hoplite</option>
<option value="rider">Rider</option>
<option value="chariot">Chariot</option>
<option value="catapult">Catapult</option>
</optgroup>
<optgroup label="Naval">
<option value="big_transporter">Big Transporter</option>
<option value="small_transporter">Small Transporter</option>
<option value="bireme">Bireme</option>
<option value="attack_ship">Attack Ship</option>
<option value="trireme">Trireme</option>
<option value="colonize_ship">Colony Ship</option>
</optgroup>
<optgroup label="Mythical">
<option value="medusa">Medusa</option>
<option value="zyklop">Cyclops</option>
<option value="harpy">Harpy</option>
<option value="pegasus">Pegasus</option>
<option value="minotaur">Minotaur</option>
<option value="manticore">Manticore</option>
<option value="cerberus">Cerberus</option>
<option value="hydra">Hydra</option>
<option value="sea_monster">Sea Monster</option>
</optgroup>
</select>
</div>
<div class="form-group" id="amount-group" style="display:none">
<label>Amount</label>
<input type="number" id="recruit-amount" value="1" min="1" max="9999" style="width:80px;">
</div>
<button class="btn btn-gold" onclick="sendCommand()">Send ⚡</button>
</div>
<div id="build-queue-preview"></div>
</div>
</div>
<!-- Bottom right: Command log -->
<div id="log-panel">
<h2>Command Log</h2>
<div id="log-content">
<p id="empty-log">No commands sent yet.</p>
</div>
</div>
</div>
<script>
// ================================================================
// State
// ================================================================
let towns = [];
let selectedTownId = null;
const POLL_INTERVAL = 4000;
// ================================================================
// Polling
// ================================================================
async function fetchTowns() {
try {
const res = await fetch('/dashboard/towns');
towns = await res.json();
renderTowns();
updateConnectionStatus(true);
} catch (e) {
updateConnectionStatus(false);
}
}
async function fetchLog() {
try {
const res = await fetch('/dashboard/commands');
const cmds = await res.json();
renderLog(cmds);
} catch (e) {}
}
function updateConnectionStatus(online) {
const el = document.getElementById('connection-status');
if (online) {
el.textContent = '● Online';
el.className = 'online';
} else {
el.textContent = '● Offline';
el.className = 'offline';
}
}
// ================================================================
// Render towns
// ================================================================
function renderTowns() {
const container = document.getElementById('town-list');
if (!towns.length) {
container.innerHTML = '<p style="color:#444;font-size:0.8rem;">No towns received yet.</p>';
return;
}
const now = Date.now();
container.innerHTML = towns.map(t => {
const updatedMs = new Date(t.updated_at + 'Z').getTime();
const ageMin = Math.round((now - updatedMs) / 60000);
const stale = ageMin > 3;
const selected = t.town_id === selectedTownId ? 'selected' : '';
return `
<div class="town-card ${selected} ${stale ? 'town-stale' : ''}"
onclick="selectTown('${t.town_id}')">
<div class="town-name">${t.town_name}</div>
<div class="town-meta">${t.points} pts · ${t.god || 'No god'} · ${ageMin}m ago</div>
<div class="town-res">
<div class="res-item"><div class="res-icon res-wood"></div>${fmt(t.resources.wood)}</div>
<div class="res-item"><div class="res-icon res-stone"></div>${fmt(t.resources.stone)}</div>
<div class="res-item"><div class="res-icon res-iron"></div>${fmt(t.resources.iron)}</div>
<div class="res-item"><div class="res-icon res-pop"></div>${fmt(t.resources.population)}</div>
</div>
</div>`;
}).join('');
}
function fmt(n) {
if (n >= 1000) return (n / 1000).toFixed(1) + 'k';
return n;
}
// ================================================================
// Town selection
// ================================================================
function selectTown(id) {
selectedTownId = id;
renderTowns();
document.getElementById('no-town-selected').style.display = 'none';
document.getElementById('command-form-wrap').style.display = 'block';
renderBuildQueuePreview();
}
function getSelectedTown() {
return towns.find(t => t.town_id === selectedTownId);
}
function renderBuildQueuePreview() {
const town = getSelectedTown();
const el = document.getElementById('build-queue-preview');
if (!town || !town.build_queue || !town.build_queue.length) {
el.innerHTML = '<span style="color:#444">Build queue: empty</span>';
return;
}
const items = town.build_queue.map(o =>
`<span>${o.building_type || o.name || JSON.stringify(o)}</span>`
).join('');
el.innerHTML = `<div style="margin-top:6px;color:#888;font-size:0.72rem;text-transform:uppercase;letter-spacing:0.5px;margin-bottom:4px;">Current queue</div>${items}`;
}
// ================================================================
// Form logic
// ================================================================
function onCmdTypeChange() {
const type = document.getElementById('cmd-type').value;
document.getElementById('build-options').style.display = type === 'build' ? '' : 'none';
document.getElementById('recruit-options').style.display = type === 'recruit' ? '' : 'none';
document.getElementById('amount-group').style.display = type === 'recruit' ? '' : 'none';
}
// ================================================================
// Send command
// ================================================================
async function sendCommand() {
const town = getSelectedTown();
if (!town) return alert('Select a town first.');
const type = document.getElementById('cmd-type').value;
let payload = {};
if (type === 'build') {
payload = { building_id: document.getElementById('building-select').value };
} else {
payload = {
unit_id: document.getElementById('unit-select').value,
amount: parseInt(document.getElementById('recruit-amount').value) || 1,
};
}
try {
const res = await fetch('/dashboard/commands', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
town_id: town.town_id,
town_name: town.town_name,
type,
payload
})
});
const data = await res.json();
if (data.ok) {
fetchLog();
} else {
alert('Error: ' + JSON.stringify(data));
}
} catch (e) {
alert('Failed to send command: ' + e);
}
}
// ================================================================
// Command log
// ================================================================
function renderLog(cmds) {
const el = document.getElementById('log-content');
if (!cmds.length) {
el.innerHTML = '<p id="empty-log">No commands sent yet.</p>';
return;
}
const rows = cmds.map(cmd => {
const p = typeof cmd.payload === 'string' ? JSON.parse(cmd.payload) : cmd.payload;
const desc = cmd.type === 'build'
? `Build: ${p.building_id}`
: `Recruit: ${p.amount}x ${p.unit_id}`;
const statusClass = `status-${cmd.status}`;
const cancelBtn = cmd.status === 'pending'
? `<button class="btn btn-danger btn-sm" onclick="cancelCommand(${cmd.id})">✕</button>`
: '';
return `<tr>
<td style="color:#888;font-size:0.7rem">#${cmd.id}</td>
<td>${cmd.town_name || cmd.town_id}</td>
<td>${desc}</td>
<td><span class="status-badge ${statusClass}">${cmd.status}</span></td>
<td style="color:#666;font-size:0.72rem">${cmd.result_msg || ''}</td>
<td>${cancelBtn}</td>
</tr>`;
}).join('');
el.innerHTML = `<table>
<thead><tr>
<th>#</th><th>Town</th><th>Command</th><th>Status</th><th>Result</th><th></th>
</tr></thead>
<tbody>${rows}</tbody>
</table>`;
}
async function cancelCommand(id) {
await fetch(`/dashboard/commands/${id}`, { method: 'DELETE' });
fetchLog();
}
// ================================================================
// Boot
// ================================================================
fetchTowns();
fetchLog();
setInterval(fetchTowns, POLL_INTERVAL);
setInterval(fetchLog, POLL_INTERVAL);
</script>
</body>
</html>