Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/controllers/edit_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) {
depends := requestBody.Depends
due := requestBody.Due
recur := requestBody.Recur
annotations := requestBody.Annotations

if taskID == "" {
http.Error(w, "taskID is required", http.StatusBadRequest)
Expand All @@ -64,7 +65,7 @@ func EditTaskHandler(w http.ResponseWriter, r *http.Request) {
Name: "Edit Task",
Execute: func() error {
logStore.AddLog("INFO", fmt.Sprintf("Editing task ID: %s", taskID), uuid, "Edit Task")
err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags, project, start, entry, wait, end, depends, due, recur)
err := tw.EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID, tags, project, start, entry, wait, end, depends, due, recur, annotations)
if err != nil {
logStore.AddLog("ERROR", fmt.Sprintf("Failed to edit task ID %s: %v", taskID, err), uuid, "Edit Task")
return err
Expand Down
29 changes: 15 additions & 14 deletions backend/models/request_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ type ModifyTaskRequestBody struct {
Tags []string `json:"tags"`
}
type EditTaskRequestBody struct {
Email string `json:"email"`
EncryptionSecret string `json:"encryptionSecret"`
UUID string `json:"UUID"`
TaskID string `json:"taskid"`
Description string `json:"description"`
Tags []string `json:"tags"`
Project string `json:"project"`
Start string `json:"start"`
Entry string `json:"entry"`
Wait string `json:"wait"`
End string `json:"end"`
Depends []string `json:"depends"`
Due string `json:"due"`
Recur string `json:"recur"`
Email string `json:"email"`
EncryptionSecret string `json:"encryptionSecret"`
UUID string `json:"UUID"`
TaskID string `json:"taskid"`
Description string `json:"description"`
Tags []string `json:"tags"`
Project string `json:"project"`
Start string `json:"start"`
Entry string `json:"entry"`
Wait string `json:"wait"`
End string `json:"end"`
Depends []string `json:"depends"`
Due string `json:"due"`
Recur string `json:"recur"`
Annotations []Annotation `json:"annotations"`
}
type CompleteTaskRequestBody struct {
Email string `json:"email"`
Expand Down
31 changes: 30 additions & 1 deletion backend/utils/tw/edit_task.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package tw

import (
"ccsync_backend/models"
"ccsync_backend/utils"
"encoding/json"
"fmt"
"os"
"strings"
)

func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string, start string, entry string, wait string, end string, depends []string, due string, recur string) error {
func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID string, tags []string, project string, start string, entry string, wait string, end string, depends []string, due string, recur string, annotations []models.Annotation) error {
if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil {
return fmt.Errorf("error deleting Taskwarrior data: %v", err)
}
Expand Down Expand Up @@ -119,6 +121,33 @@ func EditTaskInTaskwarrior(uuid, description, email, encryptionSecret, taskID st
}
}

// Handle annotations
if len(annotations) >= 0 {
output, err := utils.ExecCommandForOutputInDir(tempDir, "task", taskID, "export")
if err == nil {
var tasks []map[string]interface{}
if err := json.Unmarshal(output, &tasks); err == nil && len(tasks) > 0 {
if existingAnnotations, ok := tasks[0]["annotations"].([]interface{}); ok {
for _, ann := range existingAnnotations {
if annMap, ok := ann.(map[string]interface{}); ok {
if desc, ok := annMap["description"].(string); ok {
utils.ExecCommand("task", taskID, "denotate", desc)
}
}
}
}
}
}

for _, annotation := range annotations {
if annotation.Description != "" {
if err := utils.ExecCommand("task", taskID, "annotate", annotation.Description); err != nil {
return fmt.Errorf("failed to add annotation %s: %v", annotation.Description, err)
}
}
}
}

// Sync Taskwarrior again
if err := SyncTaskwarrior(tempDir); err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions backend/utils/tw/taskwarrior_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestSyncTaskwarrior(t *testing.T) {
}

func TestEditTaskInATaskwarrior(t *testing.T) {
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", nil, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "weekly")
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", nil, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "weekly", []models.Annotation{{Description: "test annotation"}})
if err != nil {
t.Errorf("EditTaskInTaskwarrior() failed: %v", err)
} else {
Expand All @@ -51,7 +51,7 @@ func TestAddTaskToTaskwarrior(t *testing.T) {
}

func TestAddTaskToTaskwarriorWithWaitDate(t *testing.T) {
err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "project", "H", "2025-03-03", "2025-03-04", "2025-03-04", "2025-03-04", "", nil, nil)
err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "project", "H", "2025-03-03", "2025-03-04", "2025-03-04", "2025-03-04", "", nil, []models.Annotation{})
if err != nil {
t.Errorf("AddTaskToTaskwarrior with wait date failed: %v", err)
} else {
Expand All @@ -78,7 +78,7 @@ func TestAddTaskWithTags(t *testing.T) {
}

func TestAddTaskToTaskwarriorWithWaitDateWithTags(t *testing.T) {
err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "project", "H", "2025-03-03", "2025-03-04", "2025-03-04", "2025-03-04", "", []string{"work", "important"}, nil)
err := AddTaskToTaskwarrior("email", "encryption_secret", "clientId", "description", "project", "H", "2025-03-03", "2025-03-04", "2025-03-04", "2025-03-04", "", []string{"work", "important"}, []models.Annotation{})
if err != nil {
t.Errorf("AddTaskToTaskwarrior with wait date failed: %v", err)
} else {
Expand All @@ -87,7 +87,7 @@ func TestAddTaskToTaskwarriorWithWaitDateWithTags(t *testing.T) {
}

func TestEditTaskWithTagAddition(t *testing.T) {
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "daily")
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "+important"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "daily", []models.Annotation{})
if err != nil {
t.Errorf("EditTaskInTaskwarrior with tag addition failed: %v", err)
} else {
Expand All @@ -96,7 +96,7 @@ func TestEditTaskWithTagAddition(t *testing.T) {
}

func TestEditTaskWithTagRemoval(t *testing.T) {
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "monthly")
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"-work", "-lowpriority"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "monthly", []models.Annotation{})
if err != nil {
t.Errorf("EditTaskInTaskwarrior with tag removal failed: %v", err)
} else {
Expand All @@ -105,7 +105,7 @@ func TestEditTaskWithTagRemoval(t *testing.T) {
}

func TestEditTaskWithMixedTagOperations(t *testing.T) {
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "yearly")
err := EditTaskInTaskwarrior("uuid", "description", "email", "encryptionSecret", "taskuuid", []string{"+urgent", "-work", "normal"}, "project", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-29T18:30:00.000Z", "2025-11-30T18:30:00.000Z", nil, "2025-12-01T18:30:00.000Z", "yearly", []models.Annotation{})
if err != nil {
t.Errorf("EditTaskInTaskwarrior with mixed tag operations failed: %v", err)
} else {
Expand Down
131 changes: 124 additions & 7 deletions frontend/src/components/HomeComponents/Tasks/TaskDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const TaskDialog = ({
onSaveDueDate,
onSaveDepends,
onSaveRecur,
onSaveAnnotations,
onMarkComplete,
onMarkDeleted,
isOverdue,
Expand Down Expand Up @@ -1230,14 +1231,130 @@ export const TaskDialog = ({
<TableRow>
<TableCell>Annotations:</TableCell>
<TableCell>
{task.annotations && task.annotations.length > 0 ? (
<span>
{task.annotations
.map((ann) => ann.description)
.join(', ')}
</span>
{editState.isEditingAnnotations ? (
<div>
<div className="flex items-center w-full">
<Input
type="text"
value={editState.annotationInput}
onChange={(e) => {
onUpdateState({
annotationInput: e.target.value,
});
}}
placeholder="Add an annotation (press enter to add)"
className="flex-grow mr-2"
onKeyDown={(e) => {
if (
e.key === 'Enter' &&
editState.annotationInput.trim()
) {
const newAnnotation = {
entry: new Date().toISOString(),
description: editState.annotationInput.trim(),
};
onUpdateState({
editedAnnotations: [
...editState.editedAnnotations,
newAnnotation,
],
annotationInput: '',
});
}
}}
/>
<Button
variant="ghost"
size="icon"
onClick={() => {
onSaveAnnotations(
task,
editState.editedAnnotations
);
onUpdateState({
isEditingAnnotations: false,
annotationInput: '',
});
}}
aria-label="Save annotations"
>
<CheckIcon className="h-4 w-4 text-green-500" />
</Button>
<Button
variant="ghost"
size="icon"
onClick={() => {
onUpdateState({
isEditingAnnotations: false,
editedAnnotations: task.annotations || [],
annotationInput: '',
});
}}
aria-label="Cancel editing annotations"
>
<XIcon className="h-4 w-4 text-red-500" />
</Button>
</div>
<div className="mt-2">
{editState.editedAnnotations != null &&
editState.editedAnnotations.length > 0 && (
<div>
<div className="flex flex-wrap gap-2 col-span-3">
{editState.editedAnnotations.map(
(annotation, index) => (
<Badge key={index}>
<span>{annotation.description}</span>
<button
type="button"
className="ml-2 text-red-500"
onClick={() =>
onUpdateState({
editedAnnotations:
editState.editedAnnotations.filter(
(a) => a !== annotation
),
})
}
>
</button>
</Badge>
)
)}
</div>
</div>
)}
</div>
</div>
) : (
<span>No Annotations</span>
<div className="flex items-center flex-wrap">
{task.annotations && task.annotations.length >= 1 ? (
task.annotations.map((annotation, index) => (
<Badge
key={index}
variant="secondary"
className="mr-2 mt-1"
>
{annotation.description}
</Badge>
))
) : (
<span>No Annotations</span>
)}
<Button
variant="ghost"
size="icon"
onClick={() =>
onUpdateState({
isEditingAnnotations: true,
editedAnnotations: task.annotations || [],
annotationInput: '',
})
}
>
<PencilIcon className="h-4 w-4 text-gray-500" />
</Button>
</div>
)}
</TableCell>
</TableRow>
Expand Down
Loading
Loading