Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | <script> import { onMount, onDestroy } from "svelte"; import KanbanBoard from "../components/opc/KanbanBoard.svelte"; import TaskModal from "../components/opc/TaskModal.svelte"; import AgentPanel from "../components/opc/AgentPanel.svelte"; import { getTasks, getAgents } from "../lib/opc-api.js"; import * as opcWs from "../lib/opc-ws.js"; let tasks = $state([]); let agents = $state([]); let loading = $state(true); let showTaskModal = $state(false); let editingTask = $state(null); let showAgentPanel = $state( typeof localStorage !== 'undefined' ? localStorage.getItem('opc_showAgentPanel') !== 'false' : true ); let unsubscribe = null; // Persist agent panel visibility $effect(() => { if (typeof localStorage !== 'undefined') { localStorage.setItem('opc_showAgentPanel', showAgentPanel); } }); async function loadData() { loading = true; try { const [tasksRes, agentsRes] = await Promise.all([ getTasks(), getAgents() ]); tasks = tasksRes.items || []; agents = agentsRes.items || []; } catch (e) { console.error("Failed to load data:", e); } finally { loading = false; } } function handleWebSocketMessage(message) { if (message.type === "task_update") { const { task_id, action, data } = message; if (action === "created") { tasks = [...tasks, data]; } else if (action === "updated" || action === "moved") { tasks = tasks.map(t => t.id === task_id ? data : t); } else if (action === "deleted") { tasks = tasks.filter(t => t.id !== task_id); } } else if (message.type === "agent_execution") { // Could show agent status in UI console.log("Agent execution update:", message); } } function handleCreateTask() { editingTask = null; showTaskModal = true; } function handleEditTask(task) { editingTask = task; showTaskModal = true; } function handleDeleteTask(taskId) { tasks = tasks.filter(t => t.id !== taskId); } function handleAssignTask(taskId, assignedTo, assignedType) { const task = tasks.find(t => t.id === taskId); if (task) { task.assigned_to = assignedTo; task.assigned_type = assignedType; tasks = [...tasks]; } } function handleTaskMoved(taskId, newStatus) { const task = tasks.find(t => t.id === taskId); if (task) { task.status = newStatus; tasks = [...tasks]; } } function handleModalClose() { showTaskModal = false; editingTask = null; } function handleModalSave() { loadData(); } onMount(() => { loadData(); // Connect WebSocket opcWs.connect(); unsubscribe = opcWs.subscribe(handleWebSocketMessage); }); onDestroy(() => { if (unsubscribe) { unsubscribe(); } opcWs.disconnect(); }); </script> <div class="space-y-6 h-full flex flex-col"> <!-- Header --> <div class="flex items-center justify-between"> <div> <h1 class="text-2xl font-bold text-surface-900 dark:text-surface-100"> OPC Management </h1> <p class="text-surface-600 dark:text-surface-400 mt-1"> Manage your tasks with AI agents </p> </div> <div class="flex gap-2"> <button onclick={() => showAgentPanel = !showAgentPanel} class="px-4 py-2 bg-surface-200 dark:bg-surface-700 text-surface-900 dark:text-surface-100 rounded-lg hover:bg-surface-300 dark:hover:bg-surface-600 flex items-center gap-2" > <span>🤖</span> <span>{showAgentPanel ? "Hide" : "Show"} Agents</span> </button> <button onclick={handleCreateTask} class="px-4 py-2 bg-primary-600 text-white rounded-lg hover:bg-primary-700 flex items-center gap-2" > <span>➕</span> <span>New Task</span> </button> </div> </div> <!-- Stats --> <div class="grid grid-cols-1 md:grid-cols-4 gap-4"> <div class="bg-white dark:bg-surface-800 rounded-lg p-4 border border-surface-200 dark:border-surface-700"> <div class="text-sm text-surface-600 dark:text-surface-400">Total Tasks</div> <div class="text-2xl font-bold text-surface-900 dark:text-surface-100 mt-1"> {tasks.length} </div> </div> <div class="bg-white dark:bg-surface-800 rounded-lg p-4 border border-surface-200 dark:border-surface-700"> <div class="text-sm text-surface-600 dark:text-surface-400">Parking Lot</div> <div class="text-2xl font-bold text-slate-600 dark:text-slate-400 mt-1"> {tasks.filter(t => t.status === "parking_lot").length} </div> </div> <div class="bg-white dark:bg-surface-800 rounded-lg p-4 border border-surface-200 dark:border-surface-700"> <div class="text-sm text-surface-600 dark:text-surface-400">In Progress</div> <div class="text-2xl font-bold text-blue-600 dark:text-blue-400 mt-1"> {tasks.filter(t => t.status === "in_progress").length} </div> </div> <div class="bg-white dark:bg-surface-800 rounded-lg p-4 border border-surface-200 dark:border-surface-700"> <div class="text-sm text-surface-600 dark:text-surface-400">Done</div> <div class="text-2xl font-bold text-emerald-600 dark:text-emerald-400 mt-1"> {tasks.filter(t => t.status === "done").length} </div> </div> </div> <!-- Kanban Board --> {#if loading} <div class="flex-1 flex items-center justify-center"> <div class="text-surface-600 dark:text-surface-400">Loading...</div> </div> {:else} <div class="flex-1 overflow-hidden"> <KanbanBoard {tasks} {agents} onEdit={handleEditTask} onDelete={handleDeleteTask} onAssign={handleAssignTask} onTaskMoved={handleTaskMoved} /> </div> {/if} <!-- Agent Panel --> {#if showAgentPanel} <div class="mt-6"> <AgentPanel /> </div> {/if} </div> <!-- Task Modal --> {#if showTaskModal} <TaskModal task={editingTask} {agents} onClose={handleModalClose} onSave={handleModalSave} /> {/if} |