feat: add workspace discoverability and multi-project task support
This commit is contained in:
parent
4b3781c9cc
commit
a9df1a25a5
26
README.md
26
README.md
|
|
@ -365,6 +365,32 @@ See [`.env.example`](.env.example) for the complete list. Key variables:
|
||||||
> OPENCLAW_MEMORY_DIR=/home/you/clawd-agents
|
> OPENCLAW_MEMORY_DIR=/home/you/clawd-agents
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
|
### Workspace Creation Flow
|
||||||
|
|
||||||
|
To add a new workspace/client instance in the UI:
|
||||||
|
|
||||||
|
1. Open `Workspaces` from the left navigation.
|
||||||
|
2. Expand `Show Create Client Instance`.
|
||||||
|
3. Fill tenant/workspace fields (`slug`, `display_name`, optional ports/gateway owner).
|
||||||
|
4. Click `Create + Queue`.
|
||||||
|
5. Approve/run the generated provisioning job in the same panel.
|
||||||
|
|
||||||
|
`Workspaces` and `Super Admin` currently point to the same provisioning control plane.
|
||||||
|
|
||||||
|
### Projects and Ticket Prefixes
|
||||||
|
|
||||||
|
Mission Control supports multi-project task organization per workspace:
|
||||||
|
|
||||||
|
- Create/manage projects via Task Board → `Projects`.
|
||||||
|
- Each project has its own ticket prefix and counter.
|
||||||
|
- New tasks receive project-scoped ticket refs like `PA-001`, `PA-002`.
|
||||||
|
- Task board supports filtering by project.
|
||||||
|
|
||||||
|
### Memory Scope Clarification
|
||||||
|
|
||||||
|
- **Agent profile → Memory tab**: per-agent working memory stored in Mission Control DB (`working_memory`).
|
||||||
|
- **Memory Browser page**: workspace/local filesystem memory tree under `OPENCLAW_MEMORY_DIR`.
|
||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,8 @@ function ContentRouter({ tab }: { tab: string }) {
|
||||||
return <OfficePanel />
|
return <OfficePanel />
|
||||||
case 'super-admin':
|
case 'super-admin':
|
||||||
return <SuperAdminPanel />
|
return <SuperAdminPanel />
|
||||||
|
case 'workspaces':
|
||||||
|
return <SuperAdminPanel />
|
||||||
default:
|
default:
|
||||||
return <Dashboard />
|
return <Dashboard />
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ import { logger } from '@/lib/logger';
|
||||||
/**
|
/**
|
||||||
* GET /api/agents/[id]/memory - Get agent's working memory
|
* GET /api/agents/[id]/memory - Get agent's working memory
|
||||||
*
|
*
|
||||||
* Working memory is stored as WORKING.md content in the database
|
* Working memory is stored in the agents.working_memory DB column.
|
||||||
* Each agent has their own working memory space for temporary notes
|
* This endpoint is per-agent scratchpad memory (not the global Memory Browser filesystem view).
|
||||||
*/
|
*/
|
||||||
export async function GET(
|
export async function GET(
|
||||||
request: NextRequest,
|
request: NextRequest,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,177 @@
|
||||||
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
|
import { getDatabase } from '@/lib/db'
|
||||||
|
import { requireRole } from '@/lib/auth'
|
||||||
|
import { mutationLimiter } from '@/lib/rate-limit'
|
||||||
|
import { logger } from '@/lib/logger'
|
||||||
|
|
||||||
|
function normalizePrefix(input: string): string {
|
||||||
|
const normalized = input.trim().toUpperCase().replace(/[^A-Z0-9]/g, '')
|
||||||
|
return normalized.slice(0, 12)
|
||||||
|
}
|
||||||
|
|
||||||
|
function toProjectId(raw: string): number {
|
||||||
|
const id = Number.parseInt(raw, 10)
|
||||||
|
return Number.isFinite(id) ? id : NaN
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
const auth = requireRole(request, 'viewer')
|
||||||
|
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
||||||
|
|
||||||
|
try {
|
||||||
|
const db = getDatabase()
|
||||||
|
const workspaceId = auth.user.workspace_id ?? 1
|
||||||
|
const { id } = await params
|
||||||
|
const projectId = toProjectId(id)
|
||||||
|
if (Number.isNaN(projectId)) return NextResponse.json({ error: 'Invalid project ID' }, { status: 400 })
|
||||||
|
|
||||||
|
const project = db.prepare(`
|
||||||
|
SELECT id, workspace_id, name, slug, description, ticket_prefix, ticket_counter, status, created_at, updated_at
|
||||||
|
FROM projects
|
||||||
|
WHERE id = ? AND workspace_id = ?
|
||||||
|
`).get(projectId, workspaceId)
|
||||||
|
if (!project) return NextResponse.json({ error: 'Project not found' }, { status: 404 })
|
||||||
|
|
||||||
|
return NextResponse.json({ project })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error({ err: error }, 'GET /api/projects/[id] error')
|
||||||
|
return NextResponse.json({ error: 'Failed to fetch project' }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function PATCH(
|
||||||
|
request: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
const auth = requireRole(request, 'operator')
|
||||||
|
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
||||||
|
|
||||||
|
const rateCheck = mutationLimiter(request)
|
||||||
|
if (rateCheck) return rateCheck
|
||||||
|
|
||||||
|
try {
|
||||||
|
const db = getDatabase()
|
||||||
|
const workspaceId = auth.user.workspace_id ?? 1
|
||||||
|
const { id } = await params
|
||||||
|
const projectId = toProjectId(id)
|
||||||
|
if (Number.isNaN(projectId)) return NextResponse.json({ error: 'Invalid project ID' }, { status: 400 })
|
||||||
|
|
||||||
|
const current = db.prepare(`SELECT * FROM projects WHERE id = ? AND workspace_id = ?`).get(projectId, workspaceId) as any
|
||||||
|
if (!current) return NextResponse.json({ error: 'Project not found' }, { status: 404 })
|
||||||
|
if (current.slug === 'general' && current.workspace_id === workspaceId && current.id === projectId) {
|
||||||
|
const body = await request.json()
|
||||||
|
if (body?.status === 'archived') {
|
||||||
|
return NextResponse.json({ error: 'Default project cannot be archived' }, { status: 400 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = await request.json()
|
||||||
|
const updates: string[] = []
|
||||||
|
const paramsList: Array<string | number | null> = []
|
||||||
|
|
||||||
|
if (typeof body?.name === 'string') {
|
||||||
|
const name = body.name.trim()
|
||||||
|
if (!name) return NextResponse.json({ error: 'Project name cannot be empty' }, { status: 400 })
|
||||||
|
updates.push('name = ?')
|
||||||
|
paramsList.push(name)
|
||||||
|
}
|
||||||
|
if (typeof body?.description === 'string') {
|
||||||
|
updates.push('description = ?')
|
||||||
|
paramsList.push(body.description.trim() || null)
|
||||||
|
}
|
||||||
|
if (typeof body?.ticket_prefix === 'string' || typeof body?.ticketPrefix === 'string') {
|
||||||
|
const raw = String(body.ticket_prefix ?? body.ticketPrefix)
|
||||||
|
const prefix = normalizePrefix(raw)
|
||||||
|
if (!prefix) return NextResponse.json({ error: 'Invalid ticket prefix' }, { status: 400 })
|
||||||
|
const conflict = db.prepare(`
|
||||||
|
SELECT id FROM projects
|
||||||
|
WHERE workspace_id = ? AND ticket_prefix = ? AND id != ?
|
||||||
|
`).get(workspaceId, prefix, projectId)
|
||||||
|
if (conflict) return NextResponse.json({ error: 'Ticket prefix already in use' }, { status: 409 })
|
||||||
|
updates.push('ticket_prefix = ?')
|
||||||
|
paramsList.push(prefix)
|
||||||
|
}
|
||||||
|
if (typeof body?.status === 'string') {
|
||||||
|
const status = body.status === 'archived' ? 'archived' : 'active'
|
||||||
|
updates.push('status = ?')
|
||||||
|
paramsList.push(status)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (updates.length === 0) return NextResponse.json({ error: 'No fields to update' }, { status: 400 })
|
||||||
|
|
||||||
|
updates.push('updated_at = unixepoch()')
|
||||||
|
db.prepare(`
|
||||||
|
UPDATE projects
|
||||||
|
SET ${updates.join(', ')}
|
||||||
|
WHERE id = ? AND workspace_id = ?
|
||||||
|
`).run(...paramsList, projectId, workspaceId)
|
||||||
|
|
||||||
|
const project = db.prepare(`
|
||||||
|
SELECT id, workspace_id, name, slug, description, ticket_prefix, ticket_counter, status, created_at, updated_at
|
||||||
|
FROM projects
|
||||||
|
WHERE id = ? AND workspace_id = ?
|
||||||
|
`).get(projectId, workspaceId)
|
||||||
|
|
||||||
|
return NextResponse.json({ project })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error({ err: error }, 'PATCH /api/projects/[id] error')
|
||||||
|
return NextResponse.json({ error: 'Failed to update project' }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function DELETE(
|
||||||
|
request: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
const auth = requireRole(request, 'admin')
|
||||||
|
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
||||||
|
|
||||||
|
const rateCheck = mutationLimiter(request)
|
||||||
|
if (rateCheck) return rateCheck
|
||||||
|
|
||||||
|
try {
|
||||||
|
const db = getDatabase()
|
||||||
|
const workspaceId = auth.user.workspace_id ?? 1
|
||||||
|
const { id } = await params
|
||||||
|
const projectId = toProjectId(id)
|
||||||
|
if (Number.isNaN(projectId)) return NextResponse.json({ error: 'Invalid project ID' }, { status: 400 })
|
||||||
|
|
||||||
|
const current = db.prepare(`SELECT * FROM projects WHERE id = ? AND workspace_id = ?`).get(projectId, workspaceId) as any
|
||||||
|
if (!current) return NextResponse.json({ error: 'Project not found' }, { status: 404 })
|
||||||
|
if (current.slug === 'general') {
|
||||||
|
return NextResponse.json({ error: 'Default project cannot be deleted' }, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const mode = new URL(request.url).searchParams.get('mode') || 'archive'
|
||||||
|
if (mode !== 'delete') {
|
||||||
|
db.prepare(`UPDATE projects SET status = 'archived', updated_at = unixepoch() WHERE id = ? AND workspace_id = ?`).run(projectId, workspaceId)
|
||||||
|
return NextResponse.json({ success: true, mode: 'archive' })
|
||||||
|
}
|
||||||
|
|
||||||
|
const fallback = db.prepare(`
|
||||||
|
SELECT id FROM projects
|
||||||
|
WHERE workspace_id = ? AND slug = 'general'
|
||||||
|
LIMIT 1
|
||||||
|
`).get(workspaceId) as { id: number } | undefined
|
||||||
|
if (!fallback) return NextResponse.json({ error: 'Default project missing' }, { status: 500 })
|
||||||
|
|
||||||
|
const tx = db.transaction(() => {
|
||||||
|
db.prepare(`
|
||||||
|
UPDATE tasks
|
||||||
|
SET project_id = ?
|
||||||
|
WHERE workspace_id = ? AND project_id = ?
|
||||||
|
`).run(fallback.id, workspaceId, projectId)
|
||||||
|
|
||||||
|
db.prepare(`DELETE FROM projects WHERE id = ? AND workspace_id = ?`).run(projectId, workspaceId)
|
||||||
|
})
|
||||||
|
tx()
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, mode: 'delete' })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error({ err: error }, 'DELETE /api/projects/[id] error')
|
||||||
|
return NextResponse.json({ error: 'Failed to delete project' }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
||||||
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
|
import { getDatabase } from '@/lib/db'
|
||||||
|
import { requireRole } from '@/lib/auth'
|
||||||
|
import { logger } from '@/lib/logger'
|
||||||
|
|
||||||
|
function formatTicketRef(prefix?: string | null, num?: number | null): string | undefined {
|
||||||
|
if (!prefix || typeof num !== 'number' || !Number.isFinite(num) || num <= 0) return undefined
|
||||||
|
return `${prefix}-${String(num).padStart(3, '0')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: NextRequest,
|
||||||
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
const auth = requireRole(request, 'viewer')
|
||||||
|
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
||||||
|
|
||||||
|
try {
|
||||||
|
const db = getDatabase()
|
||||||
|
const workspaceId = auth.user.workspace_id ?? 1
|
||||||
|
const { id } = await params
|
||||||
|
const projectId = Number.parseInt(id, 10)
|
||||||
|
if (!Number.isFinite(projectId)) {
|
||||||
|
return NextResponse.json({ error: 'Invalid project ID' }, { status: 400 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const project = db.prepare(`
|
||||||
|
SELECT id, workspace_id, name, slug, description, ticket_prefix, ticket_counter, status, created_at, updated_at
|
||||||
|
FROM projects
|
||||||
|
WHERE id = ? AND workspace_id = ?
|
||||||
|
`).get(projectId, workspaceId)
|
||||||
|
if (!project) return NextResponse.json({ error: 'Project not found' }, { status: 404 })
|
||||||
|
|
||||||
|
const tasks = db.prepare(`
|
||||||
|
SELECT t.*, p.name as project_name, p.ticket_prefix as project_prefix
|
||||||
|
FROM tasks t
|
||||||
|
LEFT JOIN projects p ON p.id = t.project_id AND p.workspace_id = t.workspace_id
|
||||||
|
WHERE t.workspace_id = ? AND t.project_id = ?
|
||||||
|
ORDER BY t.created_at DESC
|
||||||
|
`).all(workspaceId, projectId)
|
||||||
|
|
||||||
|
return NextResponse.json({
|
||||||
|
project,
|
||||||
|
tasks: tasks.map((task: any) => ({
|
||||||
|
...task,
|
||||||
|
tags: task.tags ? JSON.parse(task.tags) : [],
|
||||||
|
metadata: task.metadata ? JSON.parse(task.metadata) : {},
|
||||||
|
ticket_ref: formatTicketRef(task.project_prefix, task.project_ticket_no),
|
||||||
|
}))
|
||||||
|
})
|
||||||
|
} catch (error) {
|
||||||
|
logger.error({ err: error }, 'GET /api/projects/[id]/tasks error')
|
||||||
|
return NextResponse.json({ error: 'Failed to fetch project tasks' }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
import { NextRequest, NextResponse } from 'next/server'
|
||||||
|
import { getDatabase } from '@/lib/db'
|
||||||
|
import { requireRole } from '@/lib/auth'
|
||||||
|
import { mutationLimiter } from '@/lib/rate-limit'
|
||||||
|
import { logger } from '@/lib/logger'
|
||||||
|
|
||||||
|
function slugify(input: string): string {
|
||||||
|
return input
|
||||||
|
.trim()
|
||||||
|
.toLowerCase()
|
||||||
|
.replace(/[^a-z0-9]+/g, '-')
|
||||||
|
.replace(/^-+|-+$/g, '')
|
||||||
|
.slice(0, 64)
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizePrefix(input: string): string {
|
||||||
|
const normalized = input.trim().toUpperCase().replace(/[^A-Z0-9]/g, '')
|
||||||
|
return normalized.slice(0, 12)
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function GET(request: NextRequest) {
|
||||||
|
const auth = requireRole(request, 'viewer')
|
||||||
|
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
||||||
|
|
||||||
|
try {
|
||||||
|
const db = getDatabase()
|
||||||
|
const workspaceId = auth.user.workspace_id ?? 1
|
||||||
|
const includeArchived = new URL(request.url).searchParams.get('includeArchived') === '1'
|
||||||
|
|
||||||
|
const projects = db.prepare(`
|
||||||
|
SELECT id, workspace_id, name, slug, description, ticket_prefix, ticket_counter, status, created_at, updated_at
|
||||||
|
FROM projects
|
||||||
|
WHERE workspace_id = ?
|
||||||
|
${includeArchived ? '' : "AND status = 'active'"}
|
||||||
|
ORDER BY name COLLATE NOCASE ASC
|
||||||
|
`).all(workspaceId)
|
||||||
|
|
||||||
|
return NextResponse.json({ projects })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error({ err: error }, 'GET /api/projects error')
|
||||||
|
return NextResponse.json({ error: 'Failed to fetch projects' }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function POST(request: NextRequest) {
|
||||||
|
const auth = requireRole(request, 'operator')
|
||||||
|
if ('error' in auth) return NextResponse.json({ error: auth.error }, { status: auth.status })
|
||||||
|
|
||||||
|
const rateCheck = mutationLimiter(request)
|
||||||
|
if (rateCheck) return rateCheck
|
||||||
|
|
||||||
|
try {
|
||||||
|
const db = getDatabase()
|
||||||
|
const workspaceId = auth.user.workspace_id ?? 1
|
||||||
|
const body = await request.json()
|
||||||
|
|
||||||
|
const name = String(body?.name || '').trim()
|
||||||
|
const description = typeof body?.description === 'string' ? body.description.trim() : ''
|
||||||
|
const prefixInput = String(body?.ticket_prefix || body?.ticketPrefix || '').trim()
|
||||||
|
const slugInput = String(body?.slug || '').trim()
|
||||||
|
|
||||||
|
if (!name) return NextResponse.json({ error: 'Project name is required' }, { status: 400 })
|
||||||
|
|
||||||
|
const slug = slugInput ? slugify(slugInput) : slugify(name)
|
||||||
|
const ticketPrefix = normalizePrefix(prefixInput || name.slice(0, 5))
|
||||||
|
if (!slug) return NextResponse.json({ error: 'Invalid project slug' }, { status: 400 })
|
||||||
|
if (!ticketPrefix) return NextResponse.json({ error: 'Invalid ticket prefix' }, { status: 400 })
|
||||||
|
|
||||||
|
const exists = db.prepare(`
|
||||||
|
SELECT id FROM projects
|
||||||
|
WHERE workspace_id = ? AND (slug = ? OR ticket_prefix = ?)
|
||||||
|
LIMIT 1
|
||||||
|
`).get(workspaceId, slug, ticketPrefix) as { id: number } | undefined
|
||||||
|
if (exists) {
|
||||||
|
return NextResponse.json({ error: 'Project slug or ticket prefix already exists' }, { status: 409 })
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = db.prepare(`
|
||||||
|
INSERT INTO projects (workspace_id, name, slug, description, ticket_prefix, status, created_at, updated_at)
|
||||||
|
VALUES (?, ?, ?, ?, ?, 'active', unixepoch(), unixepoch())
|
||||||
|
`).run(workspaceId, name, slug, description || null, ticketPrefix)
|
||||||
|
|
||||||
|
const project = db.prepare(`
|
||||||
|
SELECT id, workspace_id, name, slug, description, ticket_prefix, ticket_counter, status, created_at, updated_at
|
||||||
|
FROM projects
|
||||||
|
WHERE id = ?
|
||||||
|
`).get(Number(result.lastInsertRowid))
|
||||||
|
|
||||||
|
return NextResponse.json({ project }, { status: 201 })
|
||||||
|
} catch (error) {
|
||||||
|
logger.error({ err: error }, 'POST /api/projects error')
|
||||||
|
return NextResponse.json({ error: 'Failed to create project' }, { status: 500 })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,20 @@ import { mutationLimiter } from '@/lib/rate-limit';
|
||||||
import { logger } from '@/lib/logger';
|
import { logger } from '@/lib/logger';
|
||||||
import { validateBody, updateTaskSchema } from '@/lib/validation';
|
import { validateBody, updateTaskSchema } from '@/lib/validation';
|
||||||
|
|
||||||
|
function formatTicketRef(prefix?: string | null, num?: number | null): string | undefined {
|
||||||
|
if (!prefix || typeof num !== 'number' || !Number.isFinite(num) || num <= 0) return undefined
|
||||||
|
return `${prefix}-${String(num).padStart(3, '0')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapTaskRow(task: any): Task & { tags: string[]; metadata: Record<string, unknown> } {
|
||||||
|
return {
|
||||||
|
...task,
|
||||||
|
tags: task.tags ? JSON.parse(task.tags) : [],
|
||||||
|
metadata: task.metadata ? JSON.parse(task.metadata) : {},
|
||||||
|
ticket_ref: formatTicketRef(task.project_prefix, task.project_ticket_no),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function hasAegisApproval(
|
function hasAegisApproval(
|
||||||
db: ReturnType<typeof getDatabase>,
|
db: ReturnType<typeof getDatabase>,
|
||||||
taskId: number,
|
taskId: number,
|
||||||
|
|
@ -40,7 +54,12 @@ export async function GET(
|
||||||
return NextResponse.json({ error: 'Invalid task ID' }, { status: 400 });
|
return NextResponse.json({ error: 'Invalid task ID' }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const stmt = db.prepare('SELECT * FROM tasks WHERE id = ? AND workspace_id = ?');
|
const stmt = db.prepare(`
|
||||||
|
SELECT t.*, p.name as project_name, p.ticket_prefix as project_prefix
|
||||||
|
FROM tasks t
|
||||||
|
LEFT JOIN projects p ON p.id = t.project_id AND p.workspace_id = t.workspace_id
|
||||||
|
WHERE t.id = ? AND t.workspace_id = ?
|
||||||
|
`);
|
||||||
const task = stmt.get(taskId, workspaceId) as Task;
|
const task = stmt.get(taskId, workspaceId) as Task;
|
||||||
|
|
||||||
if (!task) {
|
if (!task) {
|
||||||
|
|
@ -48,11 +67,7 @@ export async function GET(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse JSON fields
|
// Parse JSON fields
|
||||||
const taskWithParsedData = {
|
const taskWithParsedData = mapTaskRow(task);
|
||||||
...task,
|
|
||||||
tags: task.tags ? JSON.parse(task.tags) : [],
|
|
||||||
metadata: task.metadata ? JSON.parse(task.metadata) : {}
|
|
||||||
};
|
|
||||||
|
|
||||||
return NextResponse.json({ task: taskWithParsedData });
|
return NextResponse.json({ task: taskWithParsedData });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -101,6 +116,7 @@ export async function PUT(
|
||||||
description,
|
description,
|
||||||
status,
|
status,
|
||||||
priority,
|
priority,
|
||||||
|
project_id,
|
||||||
assigned_to,
|
assigned_to,
|
||||||
due_date,
|
due_date,
|
||||||
estimated_hours,
|
estimated_hours,
|
||||||
|
|
@ -114,6 +130,7 @@ export async function PUT(
|
||||||
// Build dynamic update query
|
// Build dynamic update query
|
||||||
const fieldsToUpdate = [];
|
const fieldsToUpdate = [];
|
||||||
const updateParams: any[] = [];
|
const updateParams: any[] = [];
|
||||||
|
let nextProjectTicketNo: number | null = null;
|
||||||
|
|
||||||
if (title !== undefined) {
|
if (title !== undefined) {
|
||||||
fieldsToUpdate.push('title = ?');
|
fieldsToUpdate.push('title = ?');
|
||||||
|
|
@ -137,6 +154,36 @@ export async function PUT(
|
||||||
fieldsToUpdate.push('priority = ?');
|
fieldsToUpdate.push('priority = ?');
|
||||||
updateParams.push(priority);
|
updateParams.push(priority);
|
||||||
}
|
}
|
||||||
|
if (project_id !== undefined) {
|
||||||
|
const project = db.prepare(`
|
||||||
|
SELECT id FROM projects
|
||||||
|
WHERE id = ? AND workspace_id = ? AND status = 'active'
|
||||||
|
`).get(project_id, workspaceId) as { id: number } | undefined
|
||||||
|
if (!project) {
|
||||||
|
return NextResponse.json({ error: 'Project not found or archived' }, { status: 400 })
|
||||||
|
}
|
||||||
|
if (project_id !== currentTask.project_id) {
|
||||||
|
db.prepare(`
|
||||||
|
UPDATE projects
|
||||||
|
SET ticket_counter = ticket_counter + 1, updated_at = unixepoch()
|
||||||
|
WHERE id = ? AND workspace_id = ?
|
||||||
|
`).run(project_id, workspaceId)
|
||||||
|
const row = db.prepare(`
|
||||||
|
SELECT ticket_counter FROM projects
|
||||||
|
WHERE id = ? AND workspace_id = ?
|
||||||
|
`).get(project_id, workspaceId) as { ticket_counter: number } | undefined
|
||||||
|
if (!row || !row.ticket_counter) {
|
||||||
|
return NextResponse.json({ error: 'Failed to allocate project ticket number' }, { status: 500 })
|
||||||
|
}
|
||||||
|
nextProjectTicketNo = row.ticket_counter
|
||||||
|
}
|
||||||
|
fieldsToUpdate.push('project_id = ?');
|
||||||
|
updateParams.push(project_id);
|
||||||
|
if (nextProjectTicketNo !== null) {
|
||||||
|
fieldsToUpdate.push('project_ticket_no = ?');
|
||||||
|
updateParams.push(nextProjectTicketNo);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (assigned_to !== undefined) {
|
if (assigned_to !== undefined) {
|
||||||
fieldsToUpdate.push('assigned_to = ?');
|
fieldsToUpdate.push('assigned_to = ?');
|
||||||
updateParams.push(assigned_to);
|
updateParams.push(assigned_to);
|
||||||
|
|
@ -224,6 +271,10 @@ export async function PUT(
|
||||||
changes.push(`priority: ${currentTask.priority} → ${priority}`);
|
changes.push(`priority: ${currentTask.priority} → ${priority}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (project_id !== undefined && project_id !== currentTask.project_id) {
|
||||||
|
changes.push(`project: ${currentTask.project_id || 'none'} → ${project_id}`);
|
||||||
|
}
|
||||||
|
|
||||||
// Log activity if there were meaningful changes
|
// Log activity if there were meaningful changes
|
||||||
if (changes.length > 0) {
|
if (changes.length > 0) {
|
||||||
db_helpers.logActivity(
|
db_helpers.logActivity(
|
||||||
|
|
@ -247,14 +298,13 @@ export async function PUT(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch updated task
|
// Fetch updated task
|
||||||
const updatedTask = db
|
const updatedTask = db.prepare(`
|
||||||
.prepare('SELECT * FROM tasks WHERE id = ? AND workspace_id = ?')
|
SELECT t.*, p.name as project_name, p.ticket_prefix as project_prefix
|
||||||
.get(taskId, workspaceId) as Task;
|
FROM tasks t
|
||||||
const parsedTask = {
|
LEFT JOIN projects p ON p.id = t.project_id AND p.workspace_id = t.workspace_id
|
||||||
...updatedTask,
|
WHERE t.id = ? AND t.workspace_id = ?
|
||||||
tags: updatedTask.tags ? JSON.parse(updatedTask.tags) : [],
|
`).get(taskId, workspaceId) as Task;
|
||||||
metadata: updatedTask.metadata ? JSON.parse(updatedTask.metadata) : {}
|
const parsedTask = mapTaskRow(updatedTask);
|
||||||
};
|
|
||||||
|
|
||||||
// Broadcast to SSE clients
|
// Broadcast to SSE clients
|
||||||
eventBus.broadcast('task.updated', parsedTask);
|
eventBus.broadcast('task.updated', parsedTask);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,43 @@ import { mutationLimiter } from '@/lib/rate-limit';
|
||||||
import { logger } from '@/lib/logger';
|
import { logger } from '@/lib/logger';
|
||||||
import { validateBody, createTaskSchema, bulkUpdateTaskStatusSchema } from '@/lib/validation';
|
import { validateBody, createTaskSchema, bulkUpdateTaskStatusSchema } from '@/lib/validation';
|
||||||
|
|
||||||
|
function formatTicketRef(prefix?: string | null, num?: number | null): string | undefined {
|
||||||
|
if (!prefix || typeof num !== 'number' || !Number.isFinite(num) || num <= 0) return undefined
|
||||||
|
return `${prefix}-${String(num).padStart(3, '0')}`
|
||||||
|
}
|
||||||
|
|
||||||
|
function mapTaskRow(task: any): Task & { tags: string[]; metadata: Record<string, unknown> } {
|
||||||
|
return {
|
||||||
|
...task,
|
||||||
|
tags: task.tags ? JSON.parse(task.tags) : [],
|
||||||
|
metadata: task.metadata ? JSON.parse(task.metadata) : {},
|
||||||
|
ticket_ref: formatTicketRef(task.project_prefix, task.project_ticket_no),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resolveProjectId(db: ReturnType<typeof getDatabase>, workspaceId: number, requestedProjectId?: number): number {
|
||||||
|
if (typeof requestedProjectId === 'number' && Number.isFinite(requestedProjectId)) {
|
||||||
|
const project = db.prepare(`
|
||||||
|
SELECT id FROM projects
|
||||||
|
WHERE id = ? AND workspace_id = ? AND status = 'active'
|
||||||
|
LIMIT 1
|
||||||
|
`).get(requestedProjectId, workspaceId) as { id: number } | undefined
|
||||||
|
if (project) return project.id
|
||||||
|
}
|
||||||
|
|
||||||
|
const fallback = db.prepare(`
|
||||||
|
SELECT id FROM projects
|
||||||
|
WHERE workspace_id = ? AND status = 'active'
|
||||||
|
ORDER BY CASE WHEN slug = 'general' THEN 0 ELSE 1 END, id ASC
|
||||||
|
LIMIT 1
|
||||||
|
`).get(workspaceId) as { id: number } | undefined
|
||||||
|
|
||||||
|
if (!fallback) {
|
||||||
|
throw new Error('No active project available in workspace')
|
||||||
|
}
|
||||||
|
return fallback.id
|
||||||
|
}
|
||||||
|
|
||||||
function hasAegisApproval(db: ReturnType<typeof getDatabase>, taskId: number, workspaceId: number): boolean {
|
function hasAegisApproval(db: ReturnType<typeof getDatabase>, taskId: number, workspaceId: number): boolean {
|
||||||
const review = db.prepare(`
|
const review = db.prepare(`
|
||||||
SELECT status FROM quality_reviews
|
SELECT status FROM quality_reviews
|
||||||
|
|
@ -18,7 +55,7 @@ function hasAegisApproval(db: ReturnType<typeof getDatabase>, taskId: number, wo
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GET /api/tasks - List all tasks with optional filtering
|
* GET /api/tasks - List all tasks with optional filtering
|
||||||
* Query params: status, assigned_to, priority, limit, offset
|
* Query params: status, assigned_to, priority, project_id, limit, offset
|
||||||
*/
|
*/
|
||||||
export async function GET(request: NextRequest) {
|
export async function GET(request: NextRequest) {
|
||||||
const auth = requireRole(request, 'viewer');
|
const auth = requireRole(request, 'viewer');
|
||||||
|
|
@ -33,40 +70,48 @@ export async function GET(request: NextRequest) {
|
||||||
const status = searchParams.get('status');
|
const status = searchParams.get('status');
|
||||||
const assigned_to = searchParams.get('assigned_to');
|
const assigned_to = searchParams.get('assigned_to');
|
||||||
const priority = searchParams.get('priority');
|
const priority = searchParams.get('priority');
|
||||||
|
const projectIdParam = Number.parseInt(searchParams.get('project_id') || '', 10);
|
||||||
const limit = Math.min(parseInt(searchParams.get('limit') || '50'), 200);
|
const limit = Math.min(parseInt(searchParams.get('limit') || '50'), 200);
|
||||||
const offset = parseInt(searchParams.get('offset') || '0');
|
const offset = parseInt(searchParams.get('offset') || '0');
|
||||||
|
|
||||||
// Build dynamic query
|
// Build dynamic query
|
||||||
let query = 'SELECT * FROM tasks WHERE workspace_id = ?';
|
let query = `
|
||||||
|
SELECT t.*, p.name as project_name, p.ticket_prefix as project_prefix
|
||||||
|
FROM tasks t
|
||||||
|
LEFT JOIN projects p
|
||||||
|
ON p.id = t.project_id AND p.workspace_id = t.workspace_id
|
||||||
|
WHERE t.workspace_id = ?
|
||||||
|
`;
|
||||||
const params: any[] = [workspaceId];
|
const params: any[] = [workspaceId];
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
query += ' AND status = ?';
|
query += ' AND t.status = ?';
|
||||||
params.push(status);
|
params.push(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assigned_to) {
|
if (assigned_to) {
|
||||||
query += ' AND assigned_to = ?';
|
query += ' AND t.assigned_to = ?';
|
||||||
params.push(assigned_to);
|
params.push(assigned_to);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priority) {
|
if (priority) {
|
||||||
query += ' AND priority = ?';
|
query += ' AND t.priority = ?';
|
||||||
params.push(priority);
|
params.push(priority);
|
||||||
}
|
}
|
||||||
|
|
||||||
query += ' ORDER BY created_at DESC LIMIT ? OFFSET ?';
|
if (Number.isFinite(projectIdParam)) {
|
||||||
|
query += ' AND t.project_id = ?';
|
||||||
|
params.push(projectIdParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
query += ' ORDER BY t.created_at DESC LIMIT ? OFFSET ?';
|
||||||
params.push(limit, offset);
|
params.push(limit, offset);
|
||||||
|
|
||||||
const stmt = db.prepare(query);
|
const stmt = db.prepare(query);
|
||||||
const tasks = stmt.all(...params) as Task[];
|
const tasks = stmt.all(...params) as Task[];
|
||||||
|
|
||||||
// Parse JSON fields
|
// Parse JSON fields
|
||||||
const tasksWithParsedData = tasks.map(task => ({
|
const tasksWithParsedData = tasks.map(mapTaskRow);
|
||||||
...task,
|
|
||||||
tags: task.tags ? JSON.parse(task.tags) : [],
|
|
||||||
metadata: task.metadata ? JSON.parse(task.metadata) : {}
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Get total count for pagination
|
// Get total count for pagination
|
||||||
let countQuery = 'SELECT COUNT(*) as total FROM tasks WHERE workspace_id = ?';
|
let countQuery = 'SELECT COUNT(*) as total FROM tasks WHERE workspace_id = ?';
|
||||||
|
|
@ -83,6 +128,10 @@ export async function GET(request: NextRequest) {
|
||||||
countQuery += ' AND priority = ?';
|
countQuery += ' AND priority = ?';
|
||||||
countParams.push(priority);
|
countParams.push(priority);
|
||||||
}
|
}
|
||||||
|
if (Number.isFinite(projectIdParam)) {
|
||||||
|
countQuery += ' AND project_id = ?';
|
||||||
|
countParams.push(projectIdParam);
|
||||||
|
}
|
||||||
const countRow = db.prepare(countQuery).get(...countParams) as { total: number };
|
const countRow = db.prepare(countQuery).get(...countParams) as { total: number };
|
||||||
|
|
||||||
return NextResponse.json({ tasks: tasksWithParsedData, total: countRow.total, page: Math.floor(offset / limit) + 1, limit });
|
return NextResponse.json({ tasks: tasksWithParsedData, total: countRow.total, page: Math.floor(offset / limit) + 1, limit });
|
||||||
|
|
@ -115,6 +164,7 @@ export async function POST(request: NextRequest) {
|
||||||
description,
|
description,
|
||||||
status = 'inbox',
|
status = 'inbox',
|
||||||
priority = 'medium',
|
priority = 'medium',
|
||||||
|
project_id,
|
||||||
assigned_to,
|
assigned_to,
|
||||||
created_by = user?.username || 'system',
|
created_by = user?.username || 'system',
|
||||||
due_date,
|
due_date,
|
||||||
|
|
@ -130,19 +180,33 @@ export async function POST(request: NextRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = Math.floor(Date.now() / 1000);
|
const now = Math.floor(Date.now() / 1000);
|
||||||
|
const createTaskTx = db.transaction(() => {
|
||||||
|
const resolvedProjectId = resolveProjectId(db, workspaceId, project_id)
|
||||||
|
db.prepare(`
|
||||||
|
UPDATE projects
|
||||||
|
SET ticket_counter = ticket_counter + 1, updated_at = unixepoch()
|
||||||
|
WHERE id = ? AND workspace_id = ?
|
||||||
|
`).run(resolvedProjectId, workspaceId)
|
||||||
|
const row = db.prepare(`
|
||||||
|
SELECT ticket_counter FROM projects
|
||||||
|
WHERE id = ? AND workspace_id = ?
|
||||||
|
`).get(resolvedProjectId, workspaceId) as { ticket_counter: number } | undefined
|
||||||
|
if (!row || !row.ticket_counter) throw new Error('Failed to allocate project ticket number')
|
||||||
|
|
||||||
const stmt = db.prepare(`
|
const insertStmt = db.prepare(`
|
||||||
INSERT INTO tasks (
|
INSERT INTO tasks (
|
||||||
title, description, status, priority, assigned_to, created_by,
|
title, description, status, priority, project_id, project_ticket_no, assigned_to, created_by,
|
||||||
created_at, updated_at, due_date, estimated_hours, tags, metadata, workspace_id
|
created_at, updated_at, due_date, estimated_hours, tags, metadata, workspace_id
|
||||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
`);
|
`)
|
||||||
|
|
||||||
const dbResult = stmt.run(
|
const dbResult = insertStmt.run(
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
status,
|
status,
|
||||||
priority,
|
priority,
|
||||||
|
resolvedProjectId,
|
||||||
|
row.ticket_counter,
|
||||||
assigned_to,
|
assigned_to,
|
||||||
created_by,
|
created_by,
|
||||||
now,
|
now,
|
||||||
|
|
@ -152,9 +216,11 @@ export async function POST(request: NextRequest) {
|
||||||
JSON.stringify(tags),
|
JSON.stringify(tags),
|
||||||
JSON.stringify(metadata),
|
JSON.stringify(metadata),
|
||||||
workspaceId
|
workspaceId
|
||||||
);
|
)
|
||||||
|
return Number(dbResult.lastInsertRowid)
|
||||||
|
})
|
||||||
|
|
||||||
const taskId = dbResult.lastInsertRowid as number;
|
const taskId = createTaskTx()
|
||||||
|
|
||||||
// Log activity
|
// Log activity
|
||||||
db_helpers.logActivity('task_created', 'task', taskId, created_by, `Created task: ${title}`, {
|
db_helpers.logActivity('task_created', 'task', taskId, created_by, `Created task: ${title}`, {
|
||||||
|
|
@ -183,12 +249,14 @@ export async function POST(request: NextRequest) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch the created task
|
// Fetch the created task
|
||||||
const createdTask = db.prepare('SELECT * FROM tasks WHERE id = ? AND workspace_id = ?').get(taskId, workspaceId) as Task;
|
const createdTask = db.prepare(`
|
||||||
const parsedTask = {
|
SELECT t.*, p.name as project_name, p.ticket_prefix as project_prefix
|
||||||
...createdTask,
|
FROM tasks t
|
||||||
tags: JSON.parse(createdTask.tags || '[]'),
|
LEFT JOIN projects p
|
||||||
metadata: JSON.parse(createdTask.metadata || '{}')
|
ON p.id = t.project_id AND p.workspace_id = t.workspace_id
|
||||||
};
|
WHERE t.id = ? AND t.workspace_id = ?
|
||||||
|
`).get(taskId, workspaceId) as Task;
|
||||||
|
const parsedTask = mapTaskRow(createdTask);
|
||||||
|
|
||||||
// Broadcast to SSE clients
|
// Broadcast to SSE clients
|
||||||
eventBus.broadcast('task.created', parsedTask);
|
eventBus.broadcast('task.created', parsedTask);
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ export function HeaderBar() {
|
||||||
alerts: 'Alert Rules',
|
alerts: 'Alert Rules',
|
||||||
gateways: 'Gateway Manager',
|
gateways: 'Gateway Manager',
|
||||||
users: 'Users',
|
users: 'Users',
|
||||||
|
workspaces: 'Workspaces',
|
||||||
'gateway-config': 'Gateway Config',
|
'gateway-config': 'Gateway Config',
|
||||||
settings: 'Settings',
|
settings: 'Settings',
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,7 @@ const navGroups: NavGroup[] = [
|
||||||
{ id: 'gateways', label: 'Gateways', icon: <GatewaysIcon />, priority: false },
|
{ id: 'gateways', label: 'Gateways', icon: <GatewaysIcon />, priority: false },
|
||||||
{ id: 'gateway-config', label: 'Config', icon: <GatewayConfigIcon />, priority: false, requiresGateway: true },
|
{ id: 'gateway-config', label: 'Config', icon: <GatewayConfigIcon />, priority: false, requiresGateway: true },
|
||||||
{ id: 'integrations', label: 'Integrations', icon: <IntegrationsIcon />, priority: false },
|
{ id: 'integrations', label: 'Integrations', icon: <IntegrationsIcon />, priority: false },
|
||||||
|
{ id: 'workspaces', label: 'Workspaces', icon: <SuperAdminIcon />, priority: false },
|
||||||
{ id: 'super-admin', label: 'Super Admin', icon: <SuperAdminIcon />, priority: false },
|
{ id: 'super-admin', label: 'Super Admin', icon: <SuperAdminIcon />, priority: false },
|
||||||
{ id: 'settings', label: 'Settings', icon: <SettingsIcon />, priority: false },
|
{ id: 'settings', label: 'Settings', icon: <SettingsIcon />, priority: false },
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -669,7 +669,10 @@ export function TasksTab({ agent }: { agent: Agent }) {
|
||||||
<Link href={`/tasks?taskId=${task.id}`} className="font-medium text-foreground hover:text-primary transition-colors">
|
<Link href={`/tasks?taskId=${task.id}`} className="font-medium text-foreground hover:text-primary transition-colors">
|
||||||
{task.title}
|
{task.title}
|
||||||
</Link>
|
</Link>
|
||||||
<div className="text-xs text-muted-foreground mt-1">Task #{task.id}</div>
|
<div className="text-xs text-muted-foreground mt-1">
|
||||||
|
{task.ticket_ref || `Task #${task.id}`}
|
||||||
|
{task.project_name ? ` · ${task.project_name}` : ''}
|
||||||
|
</div>
|
||||||
{task.description && (
|
{task.description && (
|
||||||
<p className="text-foreground/80 text-sm mt-1">{task.description}</p>
|
<p className="text-foreground/80 text-sm mt-1">{task.description}</p>
|
||||||
)}
|
)}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,11 @@ interface Task {
|
||||||
tags?: string[]
|
tags?: string[]
|
||||||
metadata?: any
|
metadata?: any
|
||||||
aegisApproved?: boolean
|
aegisApproved?: boolean
|
||||||
|
project_id?: number
|
||||||
|
project_ticket_no?: number
|
||||||
|
project_name?: string
|
||||||
|
project_prefix?: string
|
||||||
|
ticket_ref?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Agent {
|
interface Agent {
|
||||||
|
|
@ -50,6 +55,14 @@ interface Comment {
|
||||||
replies?: Comment[]
|
replies?: Comment[]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface Project {
|
||||||
|
id: number
|
||||||
|
name: string
|
||||||
|
slug: string
|
||||||
|
ticket_prefix: string
|
||||||
|
status: 'active' | 'archived'
|
||||||
|
}
|
||||||
|
|
||||||
const statusColumns = [
|
const statusColumns = [
|
||||||
{ key: 'inbox', title: 'Inbox', color: 'bg-secondary text-foreground' },
|
{ key: 'inbox', title: 'Inbox', color: 'bg-secondary text-foreground' },
|
||||||
{ key: 'assigned', title: 'Assigned', color: 'bg-blue-500/20 text-blue-400' },
|
{ key: 'assigned', title: 'Assigned', color: 'bg-blue-500/20 text-blue-400' },
|
||||||
|
|
@ -72,11 +85,14 @@ export function TaskBoardPanel() {
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
const [agents, setAgents] = useState<Agent[]>([])
|
const [agents, setAgents] = useState<Agent[]>([])
|
||||||
|
const [projects, setProjects] = useState<Project[]>([])
|
||||||
|
const [projectFilter, setProjectFilter] = useState<string>('all')
|
||||||
const [loading, setLoading] = useState(true)
|
const [loading, setLoading] = useState(true)
|
||||||
const [error, setError] = useState<string | null>(null)
|
const [error, setError] = useState<string | null>(null)
|
||||||
const [aegisMap, setAegisMap] = useState<Record<number, boolean>>({})
|
const [aegisMap, setAegisMap] = useState<Record<number, boolean>>({})
|
||||||
const [draggedTask, setDraggedTask] = useState<Task | null>(null)
|
const [draggedTask, setDraggedTask] = useState<Task | null>(null)
|
||||||
const [showCreateModal, setShowCreateModal] = useState(false)
|
const [showCreateModal, setShowCreateModal] = useState(false)
|
||||||
|
const [showProjectManager, setShowProjectManager] = useState(false)
|
||||||
const [editingTask, setEditingTask] = useState<Task | null>(null)
|
const [editingTask, setEditingTask] = useState<Task | null>(null)
|
||||||
const dragCounter = useRef(0)
|
const dragCounter = useRef(0)
|
||||||
const selectedTaskIdFromUrl = Number.parseInt(searchParams.get('taskId') || '', 10)
|
const selectedTaskIdFromUrl = Number.parseInt(searchParams.get('taskId') || '', 10)
|
||||||
|
|
@ -103,23 +119,31 @@ export function TaskBoardPanel() {
|
||||||
aegisApproved: Boolean(aegisMap[t.id])
|
aegisApproved: Boolean(aegisMap[t.id])
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Fetch tasks and agents
|
// Fetch tasks, agents, and projects
|
||||||
const fetchData = useCallback(async () => {
|
const fetchData = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
setError(null)
|
setError(null)
|
||||||
|
|
||||||
const [tasksResponse, agentsResponse] = await Promise.all([
|
const tasksQuery = new URLSearchParams()
|
||||||
fetch('/api/tasks'),
|
if (projectFilter !== 'all') {
|
||||||
fetch('/api/agents')
|
tasksQuery.set('project_id', projectFilter)
|
||||||
|
}
|
||||||
|
const tasksUrl = tasksQuery.toString() ? `/api/tasks?${tasksQuery.toString()}` : '/api/tasks'
|
||||||
|
|
||||||
|
const [tasksResponse, agentsResponse, projectsResponse] = await Promise.all([
|
||||||
|
fetch(tasksUrl),
|
||||||
|
fetch('/api/agents'),
|
||||||
|
fetch('/api/projects')
|
||||||
])
|
])
|
||||||
|
|
||||||
if (!tasksResponse.ok || !agentsResponse.ok) {
|
if (!tasksResponse.ok || !agentsResponse.ok || !projectsResponse.ok) {
|
||||||
throw new Error('Failed to fetch data')
|
throw new Error('Failed to fetch data')
|
||||||
}
|
}
|
||||||
|
|
||||||
const tasksData = await tasksResponse.json()
|
const tasksData = await tasksResponse.json()
|
||||||
const agentsData = await agentsResponse.json()
|
const agentsData = await agentsResponse.json()
|
||||||
|
const projectsData = await projectsResponse.json()
|
||||||
|
|
||||||
const tasksList = tasksData.tasks || []
|
const tasksList = tasksData.tasks || []
|
||||||
const taskIds = tasksList.map((task: Task) => task.id)
|
const taskIds = tasksList.map((task: Task) => task.id)
|
||||||
|
|
@ -146,12 +170,13 @@ export function TaskBoardPanel() {
|
||||||
storeSetTasks(tasksList)
|
storeSetTasks(tasksList)
|
||||||
setAegisMap(newAegisMap)
|
setAegisMap(newAegisMap)
|
||||||
setAgents(agentsData.agents || [])
|
setAgents(agentsData.agents || [])
|
||||||
|
setProjects(projectsData.projects || [])
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError(err instanceof Error ? err.message : 'An error occurred')
|
setError(err instanceof Error ? err.message : 'An error occurred')
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}, [storeSetTasks])
|
}, [projectFilter, storeSetTasks])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchData()
|
fetchData()
|
||||||
|
|
@ -321,8 +346,28 @@ export function TaskBoardPanel() {
|
||||||
<div className="h-full flex flex-col">
|
<div className="h-full flex flex-col">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<div className="flex justify-between items-center p-4 border-b border-border flex-shrink-0">
|
<div className="flex justify-between items-center p-4 border-b border-border flex-shrink-0">
|
||||||
|
<div className="flex items-center gap-3">
|
||||||
<h2 className="text-xl font-bold text-foreground">Task Board</h2>
|
<h2 className="text-xl font-bold text-foreground">Task Board</h2>
|
||||||
|
<select
|
||||||
|
value={projectFilter}
|
||||||
|
onChange={(e) => setProjectFilter(e.target.value)}
|
||||||
|
className="h-9 px-3 bg-surface-1 text-foreground border border-border rounded-md text-sm"
|
||||||
|
>
|
||||||
|
<option value="all">All Projects</option>
|
||||||
|
{projects.map((project) => (
|
||||||
|
<option key={project.id} value={String(project.id)}>
|
||||||
|
{project.name} ({project.ticket_prefix})
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
|
<button
|
||||||
|
onClick={() => setShowProjectManager(true)}
|
||||||
|
className="px-4 py-2 bg-secondary text-muted-foreground rounded-md hover:bg-surface-2 transition-smooth text-sm font-medium"
|
||||||
|
>
|
||||||
|
Projects
|
||||||
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={() => setShowCreateModal(true)}
|
onClick={() => setShowCreateModal(true)}
|
||||||
className="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-smooth text-sm font-medium"
|
className="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-smooth text-sm font-medium"
|
||||||
|
|
@ -403,6 +448,11 @@ export function TaskBoardPanel() {
|
||||||
{task.title}
|
{task.title}
|
||||||
</h4>
|
</h4>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
|
{task.ticket_ref && (
|
||||||
|
<span className="text-[10px] px-2 py-0.5 rounded bg-primary/20 text-primary">
|
||||||
|
{task.ticket_ref}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
{task.aegisApproved && (
|
{task.aegisApproved && (
|
||||||
<span className="text-[10px] px-2 py-0.5 rounded bg-emerald-700 text-emerald-100">
|
<span className="text-[10px] px-2 py-0.5 rounded bg-emerald-700 text-emerald-100">
|
||||||
Aegis Approved
|
Aegis Approved
|
||||||
|
|
@ -439,6 +489,12 @@ export function TaskBoardPanel() {
|
||||||
<span className="font-medium">{formatTaskTimestamp(task.created_at)}</span>
|
<span className="font-medium">{formatTaskTimestamp(task.created_at)}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{task.project_name && (
|
||||||
|
<div className="text-xs text-muted-foreground mt-1">
|
||||||
|
Project: {task.project_name}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
{task.tags && task.tags.length > 0 && (
|
{task.tags && task.tags.length > 0 && (
|
||||||
<div className="flex flex-wrap gap-1 mt-2">
|
<div className="flex flex-wrap gap-1 mt-2">
|
||||||
{task.tags.slice(0, 3).map((tag, index) => (
|
{task.tags.slice(0, 3).map((tag, index) => (
|
||||||
|
|
@ -490,6 +546,7 @@ export function TaskBoardPanel() {
|
||||||
<TaskDetailModal
|
<TaskDetailModal
|
||||||
task={selectedTask}
|
task={selectedTask}
|
||||||
agents={agents}
|
agents={agents}
|
||||||
|
projects={projects}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setSelectedTask(null)
|
setSelectedTask(null)
|
||||||
updateTaskUrl(null)
|
updateTaskUrl(null)
|
||||||
|
|
@ -507,6 +564,7 @@ export function TaskBoardPanel() {
|
||||||
{showCreateModal && (
|
{showCreateModal && (
|
||||||
<CreateTaskModal
|
<CreateTaskModal
|
||||||
agents={agents}
|
agents={agents}
|
||||||
|
projects={projects}
|
||||||
onClose={() => setShowCreateModal(false)}
|
onClose={() => setShowCreateModal(false)}
|
||||||
onCreated={fetchData}
|
onCreated={fetchData}
|
||||||
/>
|
/>
|
||||||
|
|
@ -517,10 +575,18 @@ export function TaskBoardPanel() {
|
||||||
<EditTaskModal
|
<EditTaskModal
|
||||||
task={editingTask}
|
task={editingTask}
|
||||||
agents={agents}
|
agents={agents}
|
||||||
|
projects={projects}
|
||||||
onClose={() => setEditingTask(null)}
|
onClose={() => setEditingTask(null)}
|
||||||
onUpdated={() => { fetchData(); setEditingTask(null) }}
|
onUpdated={() => { fetchData(); setEditingTask(null) }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{showProjectManager && (
|
||||||
|
<ProjectManagerModal
|
||||||
|
onClose={() => setShowProjectManager(false)}
|
||||||
|
onChanged={fetchData}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
@ -529,16 +595,21 @@ export function TaskBoardPanel() {
|
||||||
function TaskDetailModal({
|
function TaskDetailModal({
|
||||||
task,
|
task,
|
||||||
agents,
|
agents,
|
||||||
|
projects,
|
||||||
onClose,
|
onClose,
|
||||||
onUpdate,
|
onUpdate,
|
||||||
onEdit
|
onEdit
|
||||||
}: {
|
}: {
|
||||||
task: Task
|
task: Task
|
||||||
agents: Agent[]
|
agents: Agent[]
|
||||||
|
projects: Project[]
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
onUpdate: () => void
|
onUpdate: () => void
|
||||||
onEdit: (task: Task) => void
|
onEdit: (task: Task) => void
|
||||||
}) {
|
}) {
|
||||||
|
const resolvedProjectName =
|
||||||
|
task.project_name ||
|
||||||
|
projects.find((project) => project.id === task.project_id)?.name
|
||||||
const [comments, setComments] = useState<Comment[]>([])
|
const [comments, setComments] = useState<Comment[]>([])
|
||||||
const [loadingComments, setLoadingComments] = useState(false)
|
const [loadingComments, setLoadingComments] = useState(false)
|
||||||
const [commentText, setCommentText] = useState('')
|
const [commentText, setCommentText] = useState('')
|
||||||
|
|
@ -722,6 +793,18 @@ function TaskDetailModal({
|
||||||
|
|
||||||
{activeTab === 'details' && (
|
{activeTab === 'details' && (
|
||||||
<div id="tabpanel-details" role="tabpanel" aria-label="Details" className="grid grid-cols-2 gap-4 text-sm mt-4">
|
<div id="tabpanel-details" role="tabpanel" aria-label="Details" className="grid grid-cols-2 gap-4 text-sm mt-4">
|
||||||
|
{task.ticket_ref && (
|
||||||
|
<div>
|
||||||
|
<span className="text-muted-foreground">Ticket:</span>
|
||||||
|
<span className="text-foreground ml-2 font-mono">{task.ticket_ref}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{resolvedProjectName && (
|
||||||
|
<div>
|
||||||
|
<span className="text-muted-foreground">Project:</span>
|
||||||
|
<span className="text-foreground ml-2">{resolvedProjectName}</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div>
|
<div>
|
||||||
<span className="text-muted-foreground">Status:</span>
|
<span className="text-muted-foreground">Status:</span>
|
||||||
<span className="text-foreground ml-2">{task.status}</span>
|
<span className="text-foreground ml-2">{task.status}</span>
|
||||||
|
|
@ -897,10 +980,12 @@ function TaskDetailModal({
|
||||||
// Create Task Modal Component (placeholder)
|
// Create Task Modal Component (placeholder)
|
||||||
function CreateTaskModal({
|
function CreateTaskModal({
|
||||||
agents,
|
agents,
|
||||||
|
projects,
|
||||||
onClose,
|
onClose,
|
||||||
onCreated
|
onCreated
|
||||||
}: {
|
}: {
|
||||||
agents: Agent[]
|
agents: Agent[]
|
||||||
|
projects: Project[]
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
onCreated: () => void
|
onCreated: () => void
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -908,6 +993,7 @@ function CreateTaskModal({
|
||||||
title: '',
|
title: '',
|
||||||
description: '',
|
description: '',
|
||||||
priority: 'medium' as Task['priority'],
|
priority: 'medium' as Task['priority'],
|
||||||
|
project_id: projects[0]?.id ? String(projects[0].id) : '',
|
||||||
assigned_to: '',
|
assigned_to: '',
|
||||||
tags: '',
|
tags: '',
|
||||||
})
|
})
|
||||||
|
|
@ -923,6 +1009,7 @@ function CreateTaskModal({
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
...formData,
|
...formData,
|
||||||
|
project_id: formData.project_id ? Number(formData.project_id) : undefined,
|
||||||
tags: formData.tags ? formData.tags.split(',').map(t => t.trim()) : [],
|
tags: formData.tags ? formData.tags.split(',').map(t => t.trim()) : [],
|
||||||
assigned_to: formData.assigned_to || undefined
|
assigned_to: formData.assigned_to || undefined
|
||||||
})
|
})
|
||||||
|
|
@ -989,6 +1076,23 @@ function CreateTaskModal({
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="create-project" className="block text-sm text-muted-foreground mb-1">Project</label>
|
||||||
|
<select
|
||||||
|
id="create-project"
|
||||||
|
value={formData.project_id}
|
||||||
|
onChange={(e) => setFormData(prev => ({ ...prev, project_id: e.target.value }))}
|
||||||
|
className="w-full bg-surface-1 text-foreground border border-border rounded-md px-3 py-2 focus:outline-none focus:ring-1 focus:ring-primary/50"
|
||||||
|
>
|
||||||
|
{projects.map(project => (
|
||||||
|
<option key={project.id} value={String(project.id)}>
|
||||||
|
{project.name} ({project.ticket_prefix})
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="create-assignee" className="block text-sm text-muted-foreground mb-1">Assign to</label>
|
<label htmlFor="create-assignee" className="block text-sm text-muted-foreground mb-1">Assign to</label>
|
||||||
<select
|
<select
|
||||||
|
|
@ -1005,7 +1109,6 @@ function CreateTaskModal({
|
||||||
))}
|
))}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="create-tags" className="block text-sm text-muted-foreground mb-1">Tags (comma-separated)</label>
|
<label htmlFor="create-tags" className="block text-sm text-muted-foreground mb-1">Tags (comma-separated)</label>
|
||||||
|
|
@ -1045,11 +1148,13 @@ function CreateTaskModal({
|
||||||
function EditTaskModal({
|
function EditTaskModal({
|
||||||
task,
|
task,
|
||||||
agents,
|
agents,
|
||||||
|
projects,
|
||||||
onClose,
|
onClose,
|
||||||
onUpdated
|
onUpdated
|
||||||
}: {
|
}: {
|
||||||
task: Task
|
task: Task
|
||||||
agents: Agent[]
|
agents: Agent[]
|
||||||
|
projects: Project[]
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
onUpdated: () => void
|
onUpdated: () => void
|
||||||
}) {
|
}) {
|
||||||
|
|
@ -1058,6 +1163,7 @@ function EditTaskModal({
|
||||||
description: task.description || '',
|
description: task.description || '',
|
||||||
priority: task.priority,
|
priority: task.priority,
|
||||||
status: task.status,
|
status: task.status,
|
||||||
|
project_id: task.project_id ? String(task.project_id) : (projects[0]?.id ? String(projects[0].id) : ''),
|
||||||
assigned_to: task.assigned_to || '',
|
assigned_to: task.assigned_to || '',
|
||||||
tags: task.tags ? task.tags.join(', ') : '',
|
tags: task.tags ? task.tags.join(', ') : '',
|
||||||
})
|
})
|
||||||
|
|
@ -1073,6 +1179,7 @@ function EditTaskModal({
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
...formData,
|
...formData,
|
||||||
|
project_id: formData.project_id ? Number(formData.project_id) : undefined,
|
||||||
tags: formData.tags ? formData.tags.split(',').map(t => t.trim()) : [],
|
tags: formData.tags ? formData.tags.split(',').map(t => t.trim()) : [],
|
||||||
assigned_to: formData.assigned_to || undefined
|
assigned_to: formData.assigned_to || undefined
|
||||||
})
|
})
|
||||||
|
|
@ -1156,6 +1263,22 @@ function EditTaskModal({
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label htmlFor="edit-project" className="block text-sm text-muted-foreground mb-1">Project</label>
|
||||||
|
<select
|
||||||
|
id="edit-project"
|
||||||
|
value={formData.project_id}
|
||||||
|
onChange={(e) => setFormData(prev => ({ ...prev, project_id: e.target.value }))}
|
||||||
|
className="w-full bg-surface-1 text-foreground border border-border rounded-md px-3 py-2 focus:outline-none focus:ring-1 focus:ring-primary/50"
|
||||||
|
>
|
||||||
|
{projects.map(project => (
|
||||||
|
<option key={project.id} value={String(project.id)}>
|
||||||
|
{project.name} ({project.ticket_prefix})
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<label htmlFor="edit-assignee" className="block text-sm text-muted-foreground mb-1">Assign to</label>
|
<label htmlFor="edit-assignee" className="block text-sm text-muted-foreground mb-1">Assign to</label>
|
||||||
<select
|
<select
|
||||||
|
|
@ -1206,3 +1329,165 @@ function EditTaskModal({
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ProjectManagerModal({
|
||||||
|
onClose,
|
||||||
|
onChanged
|
||||||
|
}: {
|
||||||
|
onClose: () => void
|
||||||
|
onChanged: () => Promise<void>
|
||||||
|
}) {
|
||||||
|
const [projects, setProjects] = useState<Project[]>([])
|
||||||
|
const [loading, setLoading] = useState(true)
|
||||||
|
const [error, setError] = useState<string | null>(null)
|
||||||
|
const [form, setForm] = useState({ name: '', ticket_prefix: '', description: '' })
|
||||||
|
|
||||||
|
const load = useCallback(async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true)
|
||||||
|
const response = await fetch('/api/projects?includeArchived=1')
|
||||||
|
const data = await response.json()
|
||||||
|
if (!response.ok) throw new Error(data.error || 'Failed to load projects')
|
||||||
|
setProjects(data.projects || [])
|
||||||
|
setError(null)
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Failed to load projects')
|
||||||
|
} finally {
|
||||||
|
setLoading(false)
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
load()
|
||||||
|
}, [load])
|
||||||
|
|
||||||
|
const createProject = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault()
|
||||||
|
if (!form.name.trim()) return
|
||||||
|
try {
|
||||||
|
const response = await fetch('/api/projects', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
name: form.name,
|
||||||
|
ticket_prefix: form.ticket_prefix,
|
||||||
|
description: form.description
|
||||||
|
})
|
||||||
|
})
|
||||||
|
const data = await response.json()
|
||||||
|
if (!response.ok) throw new Error(data.error || 'Failed to create project')
|
||||||
|
setForm({ name: '', ticket_prefix: '', description: '' })
|
||||||
|
await load()
|
||||||
|
await onChanged()
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Failed to create project')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const archiveProject = async (project: Project) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/projects/${project.id}`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ status: project.status === 'active' ? 'archived' : 'active' })
|
||||||
|
})
|
||||||
|
const data = await response.json()
|
||||||
|
if (!response.ok) throw new Error(data.error || 'Failed to update project')
|
||||||
|
await load()
|
||||||
|
await onChanged()
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Failed to update project')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteProject = async (project: Project) => {
|
||||||
|
if (!confirm(`Delete project "${project.name}"? Existing tasks will be moved to General.`)) return
|
||||||
|
try {
|
||||||
|
const response = await fetch(`/api/projects/${project.id}?mode=delete`, { method: 'DELETE' })
|
||||||
|
const data = await response.json()
|
||||||
|
if (!response.ok) throw new Error(data.error || 'Failed to delete project')
|
||||||
|
await load()
|
||||||
|
await onChanged()
|
||||||
|
} catch (err) {
|
||||||
|
setError(err instanceof Error ? err.message : 'Failed to delete project')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const dialogRef = useFocusTrap(onClose)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="fixed inset-0 bg-black/60 backdrop-blur-sm flex items-center justify-center z-50 p-4" onClick={(e) => { if (e.target === e.currentTarget) onClose() }}>
|
||||||
|
<div ref={dialogRef} role="dialog" aria-modal="true" aria-labelledby="projects-title" className="bg-card border border-border rounded-lg max-w-2xl w-full max-h-[90vh] overflow-y-auto">
|
||||||
|
<div className="p-6 space-y-4">
|
||||||
|
<div className="flex items-center justify-between">
|
||||||
|
<h3 id="projects-title" className="text-xl font-bold text-foreground">Project Management</h3>
|
||||||
|
<button onClick={onClose} className="text-muted-foreground hover:text-foreground text-2xl">×</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{error && <div className="text-sm text-red-400 bg-red-500/10 border border-red-500/20 rounded p-2">{error}</div>}
|
||||||
|
|
||||||
|
<form onSubmit={createProject} className="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={form.name}
|
||||||
|
onChange={(e) => setForm((prev) => ({ ...prev, name: e.target.value }))}
|
||||||
|
placeholder="Project name"
|
||||||
|
className="bg-surface-1 text-foreground border border-border rounded-md px-3 py-2"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={form.ticket_prefix}
|
||||||
|
onChange={(e) => setForm((prev) => ({ ...prev, ticket_prefix: e.target.value }))}
|
||||||
|
placeholder="Ticket prefix (e.g. PA)"
|
||||||
|
className="bg-surface-1 text-foreground border border-border rounded-md px-3 py-2"
|
||||||
|
/>
|
||||||
|
<button type="submit" className="bg-primary text-primary-foreground rounded-md px-3 py-2 hover:bg-primary/90">
|
||||||
|
Add Project
|
||||||
|
</button>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={form.description}
|
||||||
|
onChange={(e) => setForm((prev) => ({ ...prev, description: e.target.value }))}
|
||||||
|
placeholder="Description (optional)"
|
||||||
|
className="md:col-span-3 bg-surface-1 text-foreground border border-border rounded-md px-3 py-2"
|
||||||
|
/>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{loading ? (
|
||||||
|
<div className="text-sm text-muted-foreground">Loading projects...</div>
|
||||||
|
) : (
|
||||||
|
<div className="space-y-2">
|
||||||
|
{projects.map((project) => (
|
||||||
|
<div key={project.id} className="flex items-center justify-between border border-border rounded-md p-3">
|
||||||
|
<div>
|
||||||
|
<div className="text-sm font-medium text-foreground">{project.name}</div>
|
||||||
|
<div className="text-xs text-muted-foreground">{project.ticket_prefix} · {project.slug} · {project.status}</div>
|
||||||
|
</div>
|
||||||
|
<div className="flex gap-2">
|
||||||
|
{project.slug !== 'general' && (
|
||||||
|
<>
|
||||||
|
<button
|
||||||
|
onClick={() => archiveProject(project)}
|
||||||
|
className="px-3 py-1 text-xs rounded border border-border hover:bg-secondary"
|
||||||
|
>
|
||||||
|
{project.status === 'active' ? 'Archive' : 'Activate'}
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
onClick={() => deleteProject(project)}
|
||||||
|
className="px-3 py-1 text-xs rounded border border-red-500/30 text-red-400 hover:bg-red-500/10"
|
||||||
|
>
|
||||||
|
Delete
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,11 @@ export interface Task {
|
||||||
description?: string
|
description?: string
|
||||||
status: 'inbox' | 'assigned' | 'in_progress' | 'review' | 'quality_review' | 'done'
|
status: 'inbox' | 'assigned' | 'in_progress' | 'review' | 'quality_review' | 'done'
|
||||||
priority: 'low' | 'medium' | 'high' | 'urgent'
|
priority: 'low' | 'medium' | 'high' | 'urgent'
|
||||||
|
project_id?: number
|
||||||
|
project_ticket_no?: number
|
||||||
|
project_name?: string
|
||||||
|
project_prefix?: string
|
||||||
|
ticket_ref?: string
|
||||||
assigned_to?: string
|
assigned_to?: string
|
||||||
created_by: string
|
created_by: string
|
||||||
created_at: number
|
created_at: number
|
||||||
|
|
|
||||||
|
|
@ -164,6 +164,11 @@ export interface Task {
|
||||||
description?: string;
|
description?: string;
|
||||||
status: 'inbox' | 'assigned' | 'in_progress' | 'review' | 'quality_review' | 'done';
|
status: 'inbox' | 'assigned' | 'in_progress' | 'review' | 'quality_review' | 'done';
|
||||||
priority: 'low' | 'medium' | 'high' | 'urgent';
|
priority: 'low' | 'medium' | 'high' | 'urgent';
|
||||||
|
project_id?: number;
|
||||||
|
project_ticket_no?: number;
|
||||||
|
project_name?: string;
|
||||||
|
project_prefix?: string;
|
||||||
|
ticket_ref?: string;
|
||||||
assigned_to?: string;
|
assigned_to?: string;
|
||||||
created_by: string;
|
created_by: string;
|
||||||
created_at: number;
|
created_at: number;
|
||||||
|
|
|
||||||
|
|
@ -676,6 +676,83 @@ const migrations: Migration[] = [
|
||||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_webhook_deliveries_workspace_id ON webhook_deliveries(workspace_id)`)
|
db.exec(`CREATE INDEX IF NOT EXISTS idx_webhook_deliveries_workspace_id ON webhook_deliveries(workspace_id)`)
|
||||||
db.exec(`CREATE INDEX IF NOT EXISTS idx_token_usage_workspace_id ON token_usage(workspace_id)`)
|
db.exec(`CREATE INDEX IF NOT EXISTS idx_token_usage_workspace_id ON token_usage(workspace_id)`)
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: '024_projects_support',
|
||||||
|
up: (db) => {
|
||||||
|
db.exec(`
|
||||||
|
CREATE TABLE IF NOT EXISTS projects (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
workspace_id INTEGER NOT NULL DEFAULT 1,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
slug TEXT NOT NULL,
|
||||||
|
description TEXT,
|
||||||
|
ticket_prefix TEXT NOT NULL,
|
||||||
|
ticket_counter INTEGER NOT NULL DEFAULT 0,
|
||||||
|
status TEXT NOT NULL DEFAULT 'active',
|
||||||
|
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
||||||
|
updated_at INTEGER NOT NULL DEFAULT (unixepoch()),
|
||||||
|
UNIQUE(workspace_id, slug),
|
||||||
|
UNIQUE(workspace_id, ticket_prefix)
|
||||||
|
)
|
||||||
|
`)
|
||||||
|
db.exec(`CREATE INDEX IF NOT EXISTS idx_projects_workspace_status ON projects(workspace_id, status)`)
|
||||||
|
|
||||||
|
const taskCols = db.prepare(`PRAGMA table_info(tasks)`).all() as Array<{ name: string }>
|
||||||
|
if (!taskCols.some((c) => c.name === 'project_id')) {
|
||||||
|
db.exec(`ALTER TABLE tasks ADD COLUMN project_id INTEGER`)
|
||||||
|
}
|
||||||
|
if (!taskCols.some((c) => c.name === 'project_ticket_no')) {
|
||||||
|
db.exec(`ALTER TABLE tasks ADD COLUMN project_ticket_no INTEGER`)
|
||||||
|
}
|
||||||
|
db.exec(`CREATE INDEX IF NOT EXISTS idx_tasks_workspace_project ON tasks(workspace_id, project_id)`)
|
||||||
|
|
||||||
|
const workspaceRows = db.prepare(`SELECT id FROM workspaces ORDER BY id ASC`).all() as Array<{ id: number }>
|
||||||
|
const ensureDefaultProject = db.prepare(`
|
||||||
|
INSERT OR IGNORE INTO projects (workspace_id, name, slug, description, ticket_prefix, ticket_counter, status, created_at, updated_at)
|
||||||
|
VALUES (?, 'General', 'general', 'Default project for uncategorized tasks', 'TASK', 0, 'active', unixepoch(), unixepoch())
|
||||||
|
`)
|
||||||
|
const getDefaultProject = db.prepare(`
|
||||||
|
SELECT id, ticket_counter FROM projects
|
||||||
|
WHERE workspace_id = ? AND slug = 'general'
|
||||||
|
LIMIT 1
|
||||||
|
`)
|
||||||
|
const setTaskProject = db.prepare(`
|
||||||
|
UPDATE tasks SET project_id = ?
|
||||||
|
WHERE workspace_id = ? AND (project_id IS NULL OR project_id = 0)
|
||||||
|
`)
|
||||||
|
const listProjectTasks = db.prepare(`
|
||||||
|
SELECT id FROM tasks
|
||||||
|
WHERE workspace_id = ? AND project_id = ?
|
||||||
|
ORDER BY created_at ASC, id ASC
|
||||||
|
`)
|
||||||
|
const setTaskNo = db.prepare(`UPDATE tasks SET project_ticket_no = ? WHERE id = ?`)
|
||||||
|
const setProjectCounter = db.prepare(`UPDATE projects SET ticket_counter = ?, updated_at = unixepoch() WHERE id = ?`)
|
||||||
|
|
||||||
|
for (const workspace of workspaceRows) {
|
||||||
|
ensureDefaultProject.run(workspace.id)
|
||||||
|
const defaultProject = getDefaultProject.get(workspace.id) as { id: number; ticket_counter: number } | undefined
|
||||||
|
if (!defaultProject) continue
|
||||||
|
|
||||||
|
setTaskProject.run(defaultProject.id, workspace.id)
|
||||||
|
|
||||||
|
const projectRows = db.prepare(`
|
||||||
|
SELECT id FROM projects
|
||||||
|
WHERE workspace_id = ?
|
||||||
|
ORDER BY id ASC
|
||||||
|
`).all(workspace.id) as Array<{ id: number }>
|
||||||
|
|
||||||
|
for (const project of projectRows) {
|
||||||
|
const tasks = listProjectTasks.all(workspace.id, project.id) as Array<{ id: number }>
|
||||||
|
let counter = 0
|
||||||
|
for (const task of tasks) {
|
||||||
|
counter += 1
|
||||||
|
setTaskNo.run(counter, task.id)
|
||||||
|
}
|
||||||
|
setProjectCounter.run(counter, project.id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ export const createTaskSchema = z.object({
|
||||||
description: z.string().max(5000).optional(),
|
description: z.string().max(5000).optional(),
|
||||||
status: z.enum(['inbox', 'assigned', 'in_progress', 'review', 'quality_review', 'done']).default('inbox'),
|
status: z.enum(['inbox', 'assigned', 'in_progress', 'review', 'quality_review', 'done']).default('inbox'),
|
||||||
priority: z.enum(['critical', 'high', 'medium', 'low']).default('medium'),
|
priority: z.enum(['critical', 'high', 'medium', 'low']).default('medium'),
|
||||||
|
project_id: z.number().int().positive().optional(),
|
||||||
assigned_to: z.string().max(100).optional(),
|
assigned_to: z.string().max(100).optional(),
|
||||||
created_by: z.string().max(100).optional(),
|
created_by: z.string().max(100).optional(),
|
||||||
due_date: z.number().optional(),
|
due_date: z.number().optional(),
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,11 @@ export interface Task {
|
||||||
description?: string
|
description?: string
|
||||||
status: 'inbox' | 'assigned' | 'in_progress' | 'review' | 'quality_review' | 'done'
|
status: 'inbox' | 'assigned' | 'in_progress' | 'review' | 'quality_review' | 'done'
|
||||||
priority: 'low' | 'medium' | 'high' | 'critical' | 'urgent'
|
priority: 'low' | 'medium' | 'high' | 'critical' | 'urgent'
|
||||||
|
project_id?: number
|
||||||
|
project_ticket_no?: number
|
||||||
|
project_name?: string
|
||||||
|
project_prefix?: string
|
||||||
|
ticket_ref?: string
|
||||||
assigned_to?: string
|
assigned_to?: string
|
||||||
created_by: string
|
created_by: string
|
||||||
created_at: number
|
created_at: number
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue