# Tasks: Add Custom Fields ## Backend Tasks ### 1. Create CustomField and TaskCustomValue models - [x] Create `backend/app/models/custom_field.py` with CustomField model - [x] Create `backend/app/models/task_custom_value.py` with TaskCustomValue model - [x] Update `backend/app/models/__init__.py` to export new models - [x] Create Alembic migration for new tables - **驗證**: Migration 成功執行,tables 建立正確 ### 2. Create Custom Fields API endpoints - [x] Create `backend/app/api/custom_fields/router.py` - [x] Implement `POST /api/projects/{project_id}/custom-fields` - 新增欄位 - [x] Implement `GET /api/projects/{project_id}/custom-fields` - 列出欄位 - [x] Implement `PUT /api/custom-fields/{field_id}` - 更新欄位 - [x] Implement `DELETE /api/custom-fields/{field_id}` - 刪除欄位 - [x] Add permission checks (only project owner/manager can manage fields) - [x] Register router in main.py - **驗證**: API endpoints 可正常呼叫,權限檢查正確 ### 3. Implement formula calculation engine - [x] Create `backend/app/services/formula_service.py` - [x] Implement formula parsing (extract field references) - [x] Implement formula validation (detect circular references) - [x] Implement formula calculation - [x] Add unit tests for formula service - **驗證**: 公式計算正確,循環引用被拒絕 ### 4. Integrate custom values with Tasks API - [x] Modify `TaskCreate` schema to accept `custom_values` - [x] Modify `TaskUpdate` schema to accept `custom_values` - [x] Modify `TaskResponse` schema to include `custom_values` - [x] Update `create_task` endpoint to save custom values - [x] Update `update_task` endpoint to save custom values - [x] Update `get_task` endpoint to return custom values - [x] Trigger formula recalculation on value change - **驗證**: 任務 CRUD 包含自定義欄位值 ### 5. Add backend tests - [x] Test custom field CRUD operations - [x] Test permission checks - [x] Test formula calculation - [x] Test task integration with custom values - **驗證**: 所有測試通過 (20/20 tests passed) ## Frontend Tasks ### 6. Create Custom Fields management UI - [x] Create `frontend/src/pages/ProjectSettings.tsx` or extend existing - [x] Create `frontend/src/components/CustomFieldEditor.tsx` - 欄位編輯表單 - [x] Create `frontend/src/components/CustomFieldList.tsx` - 欄位列表 - [x] Add custom fields API service in `frontend/src/services/customFields.ts` - **驗證**: 可在專案設定中管理自定義欄位 ### 7. Dynamic field rendering in Task forms - [x] Create `frontend/src/components/CustomFieldInput.tsx` - 動態欄位輸入 - [x] Integrate into TaskDetailModal.tsx - [x] Integrate into task creation form - [x] Handle different field types (text, number, dropdown, date, person) - [x] Display formula fields as read-only - **驗證**: 任務表單正確顯示和儲存自定義欄位 ### 8. Display custom fields in task views - [x] Add custom field columns to List view - [x] Display custom field values in Kanban cards (optional, configurable) - [x] Add column visibility toggle for custom fields - **驗證**: 自定義欄位值在各視角中正確顯示 ## Task Dependencies ``` [1] Models -> [2] API -> [4] Task Integration -> [5] Tests \ [3] Formula Engine / [6] Management UI -> [7] Task Forms -> [8] View Display ``` - Tasks 1-5 (Backend) 可平行於 Tasks 6-8 (Frontend) 開發 - Task 2 完成後 Task 6 可開始(需要 API) - Task 4 完成後 Task 7 可開始(需要 Task API 支援 custom values)