add task system and task model for viewing task details

This commit is contained in:
Robin Olsen
2026-02-12 20:40:55 +01:00
parent da8ab0833e
commit 183f13895b
7 changed files with 234 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package tasks
import (
"context"
"github.com/LazyBachelor/LazyPM/internal/service"
tea "github.com/charmbracelet/bubbletea"
)
func (t *Task) IntroduceTask() error {
_, err := tea.NewProgram(t.aboutScreen, tea.WithAltScreen()).Run()
return err
}
func (t *Task) StartInterface(ctx context.Context, cfg service.Config) error {
return t.interfaceType.Run(ctx, cfg)
}
func (t *Task) StartQuestionnaire() error {
_, err := tea.NewProgram(t.questionnaire, tea.WithAltScreen()).Run()
return err
}

45
cmd/survey/tasks/task.go Normal file
View File

@@ -0,0 +1,45 @@
// task.go
package tasks
import (
"context"
"errors"
"github.com/LazyBachelor/LazyPM/internal/service"
tea "github.com/charmbracelet/bubbletea"
)
func NewTask(interfaceType Interface, aboutScreen tea.Model, questionnaire tea.Model) *Task {
return &Task{
interfaceType: interfaceType,
aboutScreen: aboutScreen,
questionnaire: questionnaire,
}
}
func (t *Task) SetValidateFunc(fn ValidateFunc) {
t.validateFunc = fn
}
func (t *Task) SetDbStateFunc(fn DbStateFunc) {
t.dbStateFunc = fn
}
func (t *Task) SetInterface(interfaceType Interface) {
t.interfaceType = interfaceType
}
func (t *Task) Validate(ctx context.Context, svc *service.Services) (bool, error) {
if t.validateFunc == nil {
return false, errors.New("validateFunc is not set")
}
return t.validateFunc(ctx, svc)
}
func (t *Task) MigrateToTask(ctx context.Context, svc *service.Services, task *Task) error {
t = task
if t.dbStateFunc == nil {
return errors.New("dbStateFunc is not set")
}
return t.dbStateFunc(ctx, svc)
}

29
cmd/survey/tasks/types.go Normal file
View File

@@ -0,0 +1,29 @@
package tasks
import (
"context"
"github.com/LazyBachelor/LazyPM/internal/service"
tea "github.com/charmbracelet/bubbletea"
)
type Interface interface {
Run(context.Context, service.Config) error
}
type ValidateFunc func(context.Context, *service.Services) (ok bool, err error)
type DbStateFunc func(context.Context, *service.Services) error
type Task struct {
interfaceType Interface
aboutScreen tea.Model
questionnaire tea.Model
validateFunc ValidateFunc
dbStateFunc DbStateFunc
}
type TaskList struct {
Todo []*Task
Done []*Task
}