Add the ability to start the tracker when submitting an entry
All checks were successful
CI / test (push) Successful in 1m1s
All checks were successful
CI / test (push) Successful in 1m1s
This commit is contained in:
parent
6116e89aac
commit
c7798c5784
@ -35,6 +35,7 @@ func (m model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
projectID := m.formData.form.GetString("project")
|
||||
description := m.formData.form.GetString("description")
|
||||
minutes := m.formData.form.GetString("minutes")
|
||||
tracker := m.formData.form.GetBool("tracker")
|
||||
|
||||
minutesInt, err1 := strconv.ParseInt(minutes, 10, 64)
|
||||
serviceIDInt, err2 := strconv.ParseInt(serviceID, 10, 64)
|
||||
@ -45,14 +46,27 @@ func (m model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.tuiMode = MODE_CAL
|
||||
} else {
|
||||
|
||||
err := m.miteAPI.AddTimeEntry(m.dest.Format(time.DateOnly), int(minutesInt), description, int(projectIDInt), int(serviceIDInt))
|
||||
id, err := m.miteAPI.AddTimeEntry(m.dest.Format(time.DateOnly), int(minutesInt), description, int(projectIDInt), int(serviceIDInt))
|
||||
if err != nil {
|
||||
m.statusBarMessage = err.Error()
|
||||
m.tuiMode = MODE_CAL
|
||||
} else {
|
||||
m.statusBarMessage = "Successfully logged time"
|
||||
m.tuiMode = MODE_CAL
|
||||
return m, m.fetchMiteData()
|
||||
if tracker {
|
||||
_, _, err = m.miteAPI.StartTimeTracker(id)
|
||||
if err != nil {
|
||||
m.statusBarMessage = err.Error()
|
||||
m.tuiMode = MODE_CAL
|
||||
} else {
|
||||
m.statusBarMessage = "Successfully logged time and started tracker"
|
||||
m.tuiMode = MODE_CAL
|
||||
return m, m.fetchMiteData()
|
||||
}
|
||||
} else {
|
||||
|
||||
m.statusBarMessage = "Successfully logged time"
|
||||
m.tuiMode = MODE_CAL
|
||||
return m, m.fetchMiteData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -101,38 +115,51 @@ func (m model) buildForm() *huh.Form {
|
||||
Key("project").
|
||||
Title("Project").
|
||||
Options(projOptions...).
|
||||
Height(10)
|
||||
Height(6)
|
||||
|
||||
description := huh.NewText().
|
||||
Key("description").
|
||||
Title("description").
|
||||
Validate(func(s string) error {
|
||||
if s == "" {
|
||||
return errors.New("must enter a description")
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
defMinutes := "0"
|
||||
minutes := huh.NewInput().
|
||||
Key("minutes").
|
||||
CharLimit(5).
|
||||
Validate(
|
||||
func(s string) error {
|
||||
h, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if h < 0 {
|
||||
return errors.New("must be positive")
|
||||
}
|
||||
return err
|
||||
}).
|
||||
Title("Minutes").
|
||||
Value(&defMinutes)
|
||||
|
||||
confirmTracker := huh.NewConfirm().
|
||||
Key("tracker").
|
||||
Affirmative("Yes").
|
||||
Negative("No").
|
||||
Title("Start tracker")
|
||||
|
||||
form := huh.NewForm(
|
||||
huh.NewGroup(
|
||||
pl,
|
||||
sl,
|
||||
description,
|
||||
),
|
||||
huh.NewGroup(
|
||||
huh.NewText().
|
||||
Key("description").
|
||||
Title("description").
|
||||
Validate(func(s string) error {
|
||||
if s == "" {
|
||||
return errors.New("must enter a description")
|
||||
}
|
||||
return nil
|
||||
}),
|
||||
huh.NewInput().
|
||||
Key("minutes").
|
||||
CharLimit(5).
|
||||
Validate(
|
||||
func(s string) error {
|
||||
h, err := strconv.ParseInt(s, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if h < 0 {
|
||||
return errors.New("must be positive")
|
||||
}
|
||||
return err
|
||||
}).
|
||||
Title("Minutes"),
|
||||
minutes,
|
||||
confirmTracker,
|
||||
),
|
||||
)
|
||||
return form
|
||||
|
Loading…
x
Reference in New Issue
Block a user