Skip to content
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ jobs:
ghcr.io/ccextractor/frontend:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
VITE_BACKEND_URL=http://localhost:8000
VITE_FRONTEND_URL=http://localhost:80
VITE_CONTAINER_ORIGIN=http://localhost:8080

build-and-push-backend:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/frontend-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- "main"
pull_request:
branches:
- "*"
- ["main", "dev"]
jobs:
prettier:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- "main"
pull_request:
branches:
- "*"
- ["main", "dev"]

jobs:
gofmt:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
- "main"
pull_request:
branches:
- "*"
- ["main", "dev"]
jobs:
prettier:
runs-on: ubuntu-latest
Expand Down
51 changes: 51 additions & 0 deletions backend/controllers/modify_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,54 @@ func ModifyTaskHandler(w http.ResponseWriter, r *http.Request) {
}
http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)
}
func TogglePinHandler(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
http.Error(w, "Invalid request method; POST required", http.StatusMethodNotAllowed)
return
}

var payload struct {
Email string `json:"email"`
EncryptionSecret string `json:"encryptionSecret"`
UserUUID string `json:"UUID"`
TaskUUID string `json:"taskuuid"`
TaskID string `json:"taskid"`
IsPinned *bool `json:"isPinned"`
}

if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
http.Error(w, fmt.Sprintf("invalid JSON: %v", err), http.StatusBadRequest)
return
}

taskUUID := payload.TaskUUID
if taskUUID == "" {
taskUUID = payload.TaskID
}

if taskUUID == "" {
http.Error(w, "missing task identifier (taskuuid/taskid)", http.StatusBadRequest)
return
}
if payload.Email == "" || payload.EncryptionSecret == "" || payload.UserUUID == "" {
http.Error(w, "missing email, encryptionSecret or UUID", http.StatusBadRequest)
return
}

isPinned := false
if payload.IsPinned != nil {
isPinned = *payload.IsPinned
}

if err := ModifyTaskPinStatus(payload.Email, payload.EncryptionSecret, payload.UserUUID, taskUUID, isPinned); err != nil {
fmt.Printf("TogglePinHandler error: %v\n", err)
http.Error(w, fmt.Sprintf("failed to update pin: %v", err), http.StatusInternalServerError)
return
}

w.WriteHeader(http.StatusOK)
}
func ModifyTaskPinStatus(email, encryptionSecret, userUUID, taskUUID string, isPinned bool) error {
return tw.ModifyTaskPin(email, encryptionSecret, userUUID, taskUUID, isPinned)
}

2 changes: 1 addition & 1 deletion backend/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func main() {
mux.Handle("/modify-task", rateLimitedHandler(http.HandlerFunc(controllers.ModifyTaskHandler)))
mux.Handle("/complete-task", rateLimitedHandler(http.HandlerFunc(controllers.CompleteTaskHandler)))
mux.Handle("/delete-task", rateLimitedHandler(http.HandlerFunc(controllers.DeleteTaskHandler)))

mux.Handle("/toggle-pin", rateLimitedHandler(http.HandlerFunc(controllers.TogglePinHandler)))
mux.HandleFunc("/ws", controllers.WebSocketHandler)

go controllers.JobStatusManager()
Expand Down
1 change: 1 addition & 0 deletions backend/models/request_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type ModifyTaskRequestBody struct {
Status string `json:"status"`
Due string `json:"due"`
Tags []string `json:"tags"`
IsPinned bool `json:"isPinned"`
}
type EditTaskRequestBody struct {
Email string `json:"email"`
Expand Down
1 change: 1 addition & 0 deletions backend/models/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ type Task struct {
RType string `json:"rtype"`
Recur string `json:"recur"`
Annotations []Annotation `json:"annotations"`
IsPinned bool `json:"isPinned"`
}
1 change: 1 addition & 0 deletions backend/utils/tw/add_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func AddTaskToTaskwarrior(email, encryptionSecret, uuid, description, project, p

// Sync Taskwarrior again
if err := SyncTaskwarrior(tempDir); err != nil {
fmt.Print("Sync after adding task failed")
return err
}

Expand Down
59 changes: 57 additions & 2 deletions backend/utils/tw/modify_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ func ModifyTaskInTaskwarrior(uuid, description, project, priority, status, due,
}

// escapedStatus := fmt.Sprintf(`status:%s`, strings.ReplaceAll(status, `"`, `\"`))
if status == "completed" {
switch status {
case "completed":
utils.ExecCommand("task", taskID, "done", "rc.confirmation=off")
} else if status == "deleted" {
case "deleted":
utils.ExecCommand("task", taskID, "delete", "rc.confirmation=off")
}

Expand Down Expand Up @@ -93,3 +94,57 @@ func ModifyTaskInTaskwarrior(uuid, description, project, priority, status, due,

return nil
}

/*
func ModifyTaskPin(uuid string, isPinned bool) error {
var tagAction string
if isPinned {
tagAction = "+pinned" // Add the tag
} else {
tagAction = "-pinned" // Remove the tag
}

// This runs: task <uuid> modify +pinned
cmd := exec.Command("task", uuid, "modify", tagAction)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("taskwarrior error: %s", string(output))
}
return nil
}
*/
func ModifyTaskPin(email, encryptionSecret, uuid, taskuuid string, isPinned bool) error {
if err := utils.ExecCommand("rm", "-rf", "/root/.task"); err != nil {
return fmt.Errorf("error deleting Taskwarrior data: %v", err)
}

tempDir, err := os.MkdirTemp("", "taskwarrior-"+email)
if err != nil {
return fmt.Errorf("failed to create temporary directory: %v", err)
}
defer os.RemoveAll(tempDir)

origin := os.Getenv("CONTAINER_ORIGIN")
if err := SetTaskwarriorConfig(tempDir, encryptionSecret, origin, uuid); err != nil {
return err
}

if err := SyncTaskwarrior(tempDir); err != nil {
return err
}

tagAction := "+pinned"
if !isPinned {
tagAction = "-pinned"
}

if err := utils.ExecCommandInDir(tempDir, "task", taskuuid, "modify", tagAction); err != nil {
return fmt.Errorf("failed to modify task pin: %v", err)
}

if err := SyncTaskwarrior(tempDir); err != nil {
return err
}

return nil
}
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
depends_on:
- backend
env_file:
- ./.frontend.env
- ./frontend/.env
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:80"]
interval: 30s
Expand All @@ -28,7 +28,7 @@ services:
depends_on:
- syncserver
env_file:
- ./.backend.env
- ./backend/.env
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
interval: 30s
Expand Down
Loading