Add pretty HTML dashboard for team tasks
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d1630e69b2
commit
32c2cc1381
1 changed files with 450 additions and 0 deletions
450
api/tasks/team/index.php
Normal file
450
api/tasks/team/index.php
Normal file
|
|
@ -0,0 +1,450 @@
|
|||
<?php
|
||||
require_once __DIR__ . '/../../helpers.php';
|
||||
|
||||
/**
|
||||
* Team Task Dashboard — pretty HTML view
|
||||
* GET /api/tasks/team/ or /api/tasks/team/index.php
|
||||
*/
|
||||
|
||||
// Grab filters from query string
|
||||
$botName = trim($_GET['BotName'] ?? '');
|
||||
$status = trim($_GET['Status'] ?? '');
|
||||
$assignedBy = trim($_GET['AssignedBy'] ?? '');
|
||||
|
||||
$validStatuses = ['active', 'paused', 'done', 'cancelled'];
|
||||
|
||||
try {
|
||||
$where = [];
|
||||
$params = [];
|
||||
|
||||
if ($botName !== '') {
|
||||
$where[] = "BotName = ?";
|
||||
$params[] = $botName;
|
||||
}
|
||||
if ($status !== '') {
|
||||
if (in_array($status, $validStatuses, true)) {
|
||||
$where[] = "Status = ?";
|
||||
$params[] = $status;
|
||||
}
|
||||
}
|
||||
if ($assignedBy !== '') {
|
||||
$where[] = "AssignedBy = ?";
|
||||
$params[] = $assignedBy;
|
||||
}
|
||||
|
||||
$whereClause = empty($where) ? '' : 'WHERE ' . implode(' AND ', $where);
|
||||
|
||||
$tasks = queryTimed("
|
||||
SELECT ID, BotName, Title, Status, Channel, StartedOn, PausedOn, CompletedOn, Notes, AssignedBy
|
||||
FROM TeamTasks
|
||||
$whereClause
|
||||
ORDER BY FIELD(Status, 'active', 'paused', 'done', 'cancelled'), StartedOn DESC
|
||||
", $params);
|
||||
|
||||
// Get unique bot names for filter dropdown
|
||||
$bots = queryTimed("SELECT DISTINCT BotName FROM TeamTasks ORDER BY BotName", []);
|
||||
|
||||
// Stats
|
||||
$stats = queryOne("SELECT
|
||||
COUNT(*) AS Total,
|
||||
SUM(Status = 'active') AS Active,
|
||||
SUM(Status = 'paused') AS Paused,
|
||||
SUM(Status = 'done') AS Done,
|
||||
SUM(Status = 'cancelled') AS Cancelled
|
||||
FROM TeamTasks", []);
|
||||
|
||||
} catch (Throwable $e) {
|
||||
$tasks = [];
|
||||
$bots = [];
|
||||
$stats = ['Total' => 0, 'Active' => 0, 'Paused' => 0, 'Done' => 0, 'Cancelled' => 0];
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
function statusBadge(string $status): string {
|
||||
$colors = [
|
||||
'active' => '#22c55e',
|
||||
'paused' => '#f59e0b',
|
||||
'done' => '#6b7280',
|
||||
'cancelled' => '#ef4444',
|
||||
];
|
||||
$icons = [
|
||||
'active' => '●',
|
||||
'paused' => '⏸',
|
||||
'done' => '✓',
|
||||
'cancelled' => '✕',
|
||||
];
|
||||
$color = $colors[$status] ?? '#6b7280';
|
||||
$icon = $icons[$status] ?? '';
|
||||
return "<span class=\"badge\" style=\"--badge-color: $color\">$icon " . htmlspecialchars($status) . "</span>";
|
||||
}
|
||||
|
||||
function timeAgo(string $datetime): string {
|
||||
if (empty($datetime)) return '—';
|
||||
$ts = strtotime($datetime);
|
||||
$diff = time() - $ts;
|
||||
if ($diff < 60) return 'just now';
|
||||
if ($diff < 3600) return floor($diff / 60) . 'm ago';
|
||||
if ($diff < 86400) return floor($diff / 3600) . 'h ago';
|
||||
if ($diff < 604800) return floor($diff / 86400) . 'd ago';
|
||||
return date('M j', $ts);
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Team Tasks — Payfrit</title>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: #0f172a;
|
||||
color: #e2e8f0;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.header {
|
||||
background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
|
||||
border-bottom: 1px solid #334155;
|
||||
padding: 24px 32px;
|
||||
}
|
||||
|
||||
.header h1 {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: #f8fafc;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.header p {
|
||||
color: #94a3b8;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.stats-bar {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
padding: 16px 32px;
|
||||
background: #1e293b;
|
||||
border-bottom: 1px solid #334155;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.stat {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
background: #0f172a;
|
||||
border-radius: 8px;
|
||||
border: 1px solid #334155;
|
||||
}
|
||||
|
||||
.stat-number {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
color: #f8fafc;
|
||||
}
|
||||
|
||||
.stat-label {
|
||||
font-size: 12px;
|
||||
color: #94a3b8;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
.filters {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 16px 32px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.filters label {
|
||||
font-size: 13px;
|
||||
color: #94a3b8;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.filters select, .filters a.btn {
|
||||
background: #1e293b;
|
||||
color: #e2e8f0;
|
||||
border: 1px solid #334155;
|
||||
padding: 6px 12px;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.filters select:hover, .filters a.btn:hover {
|
||||
border-color: #60a5fa;
|
||||
}
|
||||
|
||||
.filters a.btn {
|
||||
text-decoration: none;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.container {
|
||||
padding: 0 32px 32px;
|
||||
}
|
||||
|
||||
.task-table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.task-table th {
|
||||
text-align: left;
|
||||
padding: 10px 14px;
|
||||
font-size: 11px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.06em;
|
||||
color: #64748b;
|
||||
border-bottom: 1px solid #334155;
|
||||
background: #1e293b;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
}
|
||||
|
||||
.task-table td {
|
||||
padding: 12px 14px;
|
||||
font-size: 14px;
|
||||
border-bottom: 1px solid #1e293b;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.task-table tr:hover td {
|
||||
background: #1e293b;
|
||||
}
|
||||
|
||||
.task-table tr.status-done td {
|
||||
opacity: 0.6;
|
||||
}
|
||||
|
||||
.task-table tr.status-cancelled td {
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
.bot-name {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-weight: 600;
|
||||
color: #60a5fa;
|
||||
}
|
||||
|
||||
.bot-avatar {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
background: #334155;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 11px;
|
||||
font-weight: 700;
|
||||
color: #94a3b8;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.task-title {
|
||||
font-weight: 500;
|
||||
color: #f1f5f9;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.task-notes {
|
||||
font-size: 12px;
|
||||
color: #94a3b8;
|
||||
margin-top: 4px;
|
||||
max-width: 400px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
color: var(--badge-color);
|
||||
background: color-mix(in srgb, var(--badge-color) 15%, transparent);
|
||||
border: 1px solid color-mix(in srgb, var(--badge-color) 30%, transparent);
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 13px;
|
||||
color: #94a3b8;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.assigned-by {
|
||||
font-size: 13px;
|
||||
color: #94a3b8;
|
||||
}
|
||||
|
||||
.channel-tag {
|
||||
font-size: 12px;
|
||||
color: #60a5fa;
|
||||
background: rgba(96, 165, 250, 0.1);
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
text-align: center;
|
||||
padding: 64px 32px;
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
.empty-state p {
|
||||
font-size: 16px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.json-link {
|
||||
position: fixed;
|
||||
bottom: 16px;
|
||||
right: 16px;
|
||||
background: #1e293b;
|
||||
color: #94a3b8;
|
||||
border: 1px solid #334155;
|
||||
padding: 6px 14px;
|
||||
border-radius: 6px;
|
||||
font-size: 12px;
|
||||
text-decoration: none;
|
||||
font-family: monospace;
|
||||
}
|
||||
|
||||
.json-link:hover { color: #60a5fa; border-color: #60a5fa; }
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.header, .stats-bar, .filters, .container { padding-left: 16px; padding-right: 16px; }
|
||||
.task-table { font-size: 13px; }
|
||||
.task-table th, .task-table td { padding: 8px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h1>🚀 Team Tasks</h1>
|
||||
<p>Payfrit bot task tracker — real-time view of all team activity</p>
|
||||
</div>
|
||||
|
||||
<div class="stats-bar">
|
||||
<div class="stat">
|
||||
<div>
|
||||
<div class="stat-number"><?= (int)$stats['Total'] ?></div>
|
||||
<div class="stat-label">Total</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div>
|
||||
<div class="stat-number" style="color: #22c55e"><?= (int)$stats['Active'] ?></div>
|
||||
<div class="stat-label">Active</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div>
|
||||
<div class="stat-number" style="color: #f59e0b"><?= (int)$stats['Paused'] ?></div>
|
||||
<div class="stat-label">Paused</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div>
|
||||
<div class="stat-number" style="color: #6b7280"><?= (int)$stats['Done'] ?></div>
|
||||
<div class="stat-label">Done</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat">
|
||||
<div>
|
||||
<div class="stat-number" style="color: #ef4444"><?= (int)$stats['Cancelled'] ?></div>
|
||||
<div class="stat-label">Cancelled</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form class="filters" method="GET">
|
||||
<label>Filter:</label>
|
||||
<select name="BotName" onchange="this.form.submit()">
|
||||
<option value="">All Bots</option>
|
||||
<?php foreach ($bots as $b): ?>
|
||||
<option value="<?= htmlspecialchars($b['BotName']) ?>" <?= $botName === $b['BotName'] ? 'selected' : '' ?>>
|
||||
@<?= htmlspecialchars($b['BotName']) ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<select name="Status" onchange="this.form.submit()">
|
||||
<option value="">All Statuses</option>
|
||||
<?php foreach ($validStatuses as $s): ?>
|
||||
<option value="<?= $s ?>" <?= $status === $s ? 'selected' : '' ?>><?= ucfirst($s) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<?php if ($botName || $status || $assignedBy): ?>
|
||||
<a class="btn" href="?">Clear Filters</a>
|
||||
<?php endif; ?>
|
||||
</form>
|
||||
|
||||
<div class="container">
|
||||
<?php if (empty($tasks)): ?>
|
||||
<div class="empty-state">
|
||||
<p>No tasks found</p>
|
||||
<span>Tasks will appear here when bots register work via the API.</span>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<table class="task-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>Bot</th>
|
||||
<th>Task</th>
|
||||
<th>Status</th>
|
||||
<th>Assigned By</th>
|
||||
<th>Channel</th>
|
||||
<th>Started</th>
|
||||
<th>Completed</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($tasks as $t): ?>
|
||||
<tr class="status-<?= htmlspecialchars($t['Status']) ?>">
|
||||
<td style="color: #64748b; font-size: 12px;"><?= (int)$t['ID'] ?></td>
|
||||
<td>
|
||||
<span class="bot-name">
|
||||
<span class="bot-avatar"><?= strtoupper(substr($t['BotName'], 0, 1)) ?></span>
|
||||
@<?= htmlspecialchars($t['BotName']) ?>
|
||||
</span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="task-title"><?= htmlspecialchars($t['Title']) ?></div>
|
||||
<?php if (!empty($t['Notes'])): ?>
|
||||
<div class="task-notes"><?= htmlspecialchars($t['Notes']) ?></div>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td><?= statusBadge($t['Status']) ?></td>
|
||||
<td class="assigned-by"><?= !empty($t['AssignedBy']) ? '@' . htmlspecialchars($t['AssignedBy']) : '—' ?></td>
|
||||
<td><?= !empty($t['Channel']) ? '<span class="channel-tag">#' . htmlspecialchars($t['Channel']) . '</span>' : '—' ?></td>
|
||||
<td class="time" title="<?= htmlspecialchars($t['StartedOn'] ?? '') ?>"><?= timeAgo($t['StartedOn'] ?? '') ?></td>
|
||||
<td class="time" title="<?= htmlspecialchars($t['CompletedOn'] ?? '') ?>"><?= timeAgo($t['CompletedOn'] ?? '') ?></td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<a class="json-link" href="list.php" target="_blank">{ } JSON</a>
|
||||
|
||||
<?php if (isset($error)): ?>
|
||||
<script>console.error('Task dashboard error: <?= addslashes($error) ?>');</script>
|
||||
<?php endif; ?>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Reference in a new issue