Compare commits
No commits in common. "c7798c5784e3acb9cb15c0f5b7d7a6e911ac4c2f" and "e1df2dea3b9397ce934b09349dfc38e2986aa989" have entirely different histories.
c7798c5784
...
e1df2dea3b
25
mite/mite.go
25
mite/mite.go
@ -51,10 +51,8 @@ type Project struct {
|
|||||||
func (p Project) String() string {
|
func (p Project) String() string {
|
||||||
return fmt.Sprintf("%d: %s (%s)", p.ID, p.Name, p.CustomerName)
|
return fmt.Sprintf("%d: %s (%s)", p.ID, p.Name, p.CustomerName)
|
||||||
}
|
}
|
||||||
func (p Project) GetID() int { return p.ID }
|
func (p Project) GetID() int { return p.ID }
|
||||||
func (p Project) GetName() string {
|
func (p Project) GetName() string { return p.Name + " (" + p.CustomerName + ")" }
|
||||||
return p.Name + " (" + p.CustomerName + ")"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a APIClient) GetProjects() (Projects, error) {
|
func (a APIClient) GetProjects() (Projects, error) {
|
||||||
// GET /projects.json
|
// GET /projects.json
|
||||||
@ -240,9 +238,7 @@ type requestAddTimeEntry struct {
|
|||||||
} `json:"time_entry"`
|
} `json:"time_entry"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type apiPostTimeEntry timeEntryHolder
|
func (a APIClient) AddTimeEntry(date string, minutes int, notes string, projectId, serviceId int) error {
|
||||||
|
|
||||||
func (a APIClient) AddTimeEntry(date string, minutes int, notes string, projectId, serviceId int) (int, error) {
|
|
||||||
// POST /time_entries.json
|
// POST /time_entries.json
|
||||||
// {
|
// {
|
||||||
// "time_entry": {
|
// "time_entry": {
|
||||||
@ -258,10 +254,8 @@ func (a APIClient) AddTimeEntry(date string, minutes int, notes string, projectI
|
|||||||
req.RequestTimeEntryHolder.ProjectID = projectId
|
req.RequestTimeEntryHolder.ProjectID = projectId
|
||||||
req.RequestTimeEntryHolder.ServiceID = serviceId
|
req.RequestTimeEntryHolder.ServiceID = serviceId
|
||||||
|
|
||||||
res := apiPostTimeEntry{}
|
err := a.post("/time_entries.json", req)
|
||||||
|
return err
|
||||||
err := a.post("/time_entries.json", req, &res)
|
|
||||||
return res.TimeEntry.ID, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type apiTimeTrackerEntry struct {
|
type apiTimeTrackerEntry struct {
|
||||||
@ -404,9 +398,9 @@ func (a APIClient) patch(path string, data any) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a APIClient) post(path string, dataIn any, dataOut any) error {
|
func (a APIClient) post(path string, data any) error {
|
||||||
|
|
||||||
b, err := json.Marshal(dataIn)
|
b, err := json.Marshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -427,11 +421,6 @@ func (a APIClient) post(path string, dataIn any, dataOut any) error {
|
|||||||
return fmt.Errorf("expected 2XX, got %d", resp.StatusCode)
|
return fmt.Errorf("expected 2XX, got %d", resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.NewDecoder(resp.Body).Decode(&dataOut)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@ func (m model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
projectID := m.formData.form.GetString("project")
|
projectID := m.formData.form.GetString("project")
|
||||||
description := m.formData.form.GetString("description")
|
description := m.formData.form.GetString("description")
|
||||||
minutes := m.formData.form.GetString("minutes")
|
minutes := m.formData.form.GetString("minutes")
|
||||||
tracker := m.formData.form.GetBool("tracker")
|
|
||||||
|
|
||||||
minutesInt, err1 := strconv.ParseInt(minutes, 10, 64)
|
minutesInt, err1 := strconv.ParseInt(minutes, 10, 64)
|
||||||
serviceIDInt, err2 := strconv.ParseInt(serviceID, 10, 64)
|
serviceIDInt, err2 := strconv.ParseInt(serviceID, 10, 64)
|
||||||
@ -46,27 +45,14 @@ func (m model) updateForm(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
m.tuiMode = MODE_CAL
|
m.tuiMode = MODE_CAL
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
id, err := m.miteAPI.AddTimeEntry(m.dest.Format(time.DateOnly), int(minutesInt), description, int(projectIDInt), int(serviceIDInt))
|
err := m.miteAPI.AddTimeEntry(m.dest.Format(time.DateOnly), int(minutesInt), description, int(projectIDInt), int(serviceIDInt))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.statusBarMessage = err.Error()
|
m.statusBarMessage = err.Error()
|
||||||
m.tuiMode = MODE_CAL
|
m.tuiMode = MODE_CAL
|
||||||
} else {
|
} else {
|
||||||
if tracker {
|
m.statusBarMessage = "Successfully logged time"
|
||||||
_, _, err = m.miteAPI.StartTimeTracker(id)
|
m.tuiMode = MODE_CAL
|
||||||
if err != nil {
|
return m, m.fetchMiteData()
|
||||||
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()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,51 +101,38 @@ func (m model) buildForm() *huh.Form {
|
|||||||
Key("project").
|
Key("project").
|
||||||
Title("Project").
|
Title("Project").
|
||||||
Options(projOptions...).
|
Options(projOptions...).
|
||||||
Height(6)
|
Height(10)
|
||||||
|
|
||||||
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(
|
form := huh.NewForm(
|
||||||
huh.NewGroup(
|
huh.NewGroup(
|
||||||
pl,
|
pl,
|
||||||
sl,
|
sl,
|
||||||
description,
|
|
||||||
),
|
),
|
||||||
huh.NewGroup(
|
huh.NewGroup(
|
||||||
minutes,
|
huh.NewText().
|
||||||
confirmTracker,
|
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"),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return form
|
return form
|
||||||
|
Loading…
x
Reference in New Issue
Block a user