mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-28 13:27:33 +08:00
tasks.json structured CRUD: add /webui/api/tasks and task editor controls in audit page
This commit is contained in:
@@ -27,6 +27,10 @@ const resources = {
|
||||
retryTask: 'Retry',
|
||||
completeTask: 'Complete',
|
||||
ignoreTask: 'Ignore',
|
||||
taskCrud: 'Task CRUD',
|
||||
createTask: 'Create',
|
||||
updateTask: 'Update',
|
||||
deleteTask: 'Delete',
|
||||
error: 'Error',
|
||||
noTaskAudit: 'No task audit records',
|
||||
selectTask: 'Select a task from the left list',
|
||||
@@ -188,6 +192,10 @@ const resources = {
|
||||
retryTask: '重试',
|
||||
completeTask: '完成',
|
||||
ignoreTask: '忽略',
|
||||
taskCrud: '任务 CRUD',
|
||||
createTask: '新建',
|
||||
updateTask: '更新',
|
||||
deleteTask: '删除',
|
||||
error: '错误',
|
||||
noTaskAudit: '暂无任务审计记录',
|
||||
selectTask: '请从左侧选择任务',
|
||||
|
||||
@@ -32,6 +32,7 @@ const TaskAudit: React.FC = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [sourceFilter, setSourceFilter] = useState('all');
|
||||
const [statusFilter, setStatusFilter] = useState('all');
|
||||
const [draft, setDraft] = useState<any>({ id: '', content: '', priority: 'normal', status: 'todo', source: 'manual', due_at: '' });
|
||||
|
||||
const fetchData = async () => {
|
||||
setLoading(true);
|
||||
@@ -73,6 +74,21 @@ const TaskAudit: React.FC = () => {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
|
||||
const saveTask = async (action: 'create'|'update'|'delete') => {
|
||||
try {
|
||||
const url = `/webui/api/tasks${q}`;
|
||||
const payload: any = { action };
|
||||
if (action === 'create') payload.item = draft;
|
||||
if (action === 'update') { payload.id = draft.id; payload.item = draft; }
|
||||
if (action === 'delete') payload.id = draft.id;
|
||||
const r = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });
|
||||
if (!r.ok) throw new Error(await r.text());
|
||||
await fetchData();
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
};
|
||||
const selectedPretty = useMemo(() => selected ? JSON.stringify(selected, null, 2) : '', [selected]);
|
||||
|
||||
return (
|
||||
@@ -111,7 +127,7 @@ const TaskAudit: React.FC = () => {
|
||||
return (
|
||||
<button
|
||||
key={`${it.task_id || idx}-${it.time || idx}`}
|
||||
onClick={() => setSelected(it)}
|
||||
onClick={() => { setSelected(it); setDraft({ id: it.task_id || it.id || '', content: it.input_preview || it.content || '', priority: it.priority || 'normal', status: it.status || 'todo', source: it.source || 'manual', due_at: it.due_at || '' }); }}
|
||||
className={`w-full text-left px-3 py-2 border-b border-zinc-800/60 hover:bg-zinc-800/40 ${active ? 'bg-indigo-500/15' : ''}`}
|
||||
>
|
||||
<div className="text-sm font-medium text-zinc-100 truncate">{it.task_id || `task-${idx + 1}`}</div>
|
||||
@@ -134,6 +150,21 @@ const TaskAudit: React.FC = () => {
|
||||
<button onClick={()=>taskAction('ignore')} className="px-2 py-1 text-xs rounded bg-zinc-700 hover:bg-zinc-600">{t('ignoreTask')}</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="p-3 border border-zinc-800 rounded-lg bg-zinc-950/40 space-y-2">
|
||||
<div className="text-xs text-zinc-400 uppercase tracking-wider">{t('taskCrud')}</div>
|
||||
<input value={draft.id} onChange={(e)=>setDraft({ ...draft, id: e.target.value })} placeholder="id" className="w-full px-2 py-1 text-xs bg-zinc-900 border border-zinc-700 rounded" />
|
||||
<textarea value={draft.content} onChange={(e)=>setDraft({ ...draft, content: e.target.value })} placeholder="content" className="w-full px-2 py-1 text-xs bg-zinc-900 border border-zinc-700 rounded min-h-[70px]" />
|
||||
<div className="grid grid-cols-3 gap-2">
|
||||
<input value={draft.priority} onChange={(e)=>setDraft({ ...draft, priority: e.target.value })} placeholder="priority" className="px-2 py-1 text-xs bg-zinc-900 border border-zinc-700 rounded" />
|
||||
<input value={draft.status} onChange={(e)=>setDraft({ ...draft, status: e.target.value })} placeholder="status" className="px-2 py-1 text-xs bg-zinc-900 border border-zinc-700 rounded" />
|
||||
<input value={draft.source} onChange={(e)=>setDraft({ ...draft, source: e.target.value })} placeholder="source" className="px-2 py-1 text-xs bg-zinc-900 border border-zinc-700 rounded" />
|
||||
</div>
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<button onClick={()=>saveTask('create')} className="px-2 py-1 text-xs rounded bg-emerald-700/70 hover:bg-emerald-600">{t('createTask')}</button>
|
||||
<button onClick={()=>saveTask('update')} className="px-2 py-1 text-xs rounded bg-indigo-700/70 hover:bg-indigo-600">{t('updateTask')}</button>
|
||||
<button onClick={()=>saveTask('delete')} className="px-2 py-1 text-xs rounded bg-red-700/70 hover:bg-red-600">{t('deleteTask')}</button>
|
||||
</div>
|
||||
</div>
|
||||
{!selected ? (
|
||||
<div className="text-zinc-500">{t('selectTask')}</div>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user