Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: allow editing of start ts of active task log #3

Merged
merged 2 commits into from
Jul 19, 2024
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
29 changes: 17 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ brew install dhth/tap/hours
go install github.com/dhth/hours@latest
```

Or get the binaries directly from a
[release](https://github.com/dhth/hours/releases).

⚡️ Usage
---

Expand Down Expand Up @@ -181,20 +184,21 @@ hours gen --dbpath=/var/tmp/throwaway.db
---

```text
"hours" has 5 panes:
- Tasks List View Shows your tasks
- Task Management View Allows you to create/update tasks
- Task Log List View Shows your task log entries
- Inactive Tasks List View Shows inactive tasks
- Help View (this one)
"hours" has 6 views:
- Tasks List View Shows active tasks
- Task Management View Shows a form to create/update tasks
- Task Logs List View Shows your task logs
- Inactive Tasks List View Shows inactive tasks
- Task Log Entry View Shows a form to save/update a task log entry
- Help View

Keyboard Shortcuts

General

1 Switch to Tasks List View
2 Switch to Task Log List View
3 Switch to Inactive Task Log List View
2 Switch to Task Logs List View
3 Switch to Inactive Tasks List View
<tab> Go to next view/form entry
<shift+tab> Go to previous view/form entry
? Show help view
Expand All @@ -214,11 +218,11 @@ Task List View
s Toggle recording time on the currently selected task,
will open up a form to record a task log entry on
the second "s" keypress
<ctrl+s> Add a manual task log entry
<ctrl+s> Edit the currently active task log/Add a new manual task log entry
<ctrl+t> Go to currently tracked item
<ctrl+d> Deactivate task

Task Log List View
Task Logs List View

<ctrl+d> Delete task log entry
<ctrl+r> Refresh list
Expand All @@ -239,7 +243,8 @@ Task Log Entry View
Acknowledgements
---

`hours` is built using the TUI framework [bubbletea][1].
`hours` is built using [bubbletea][1], and is released using [goreleaser][2],
both of which are amazing tools.

[1]: https://github.com/charmbracelet/bubbletea
[2]: https://www.youtube.com/watch?v=o244r1nyxac
[2]: https://github.com/goreleaser/goreleaser
4 changes: 2 additions & 2 deletions cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ func initDB(db *sql.DB) error {
// these init queries cannot be changed
// once hours is released; only further migrations
// can be added, which are run whenever hours
// sees a difference between the values in db_versions
// and latestDBVersion
// sees a difference between the values in db_versions
// and latestDBVersion
_, err := db.Exec(`
CREATE TABLE IF NOT EXISTS db_versions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
Expand Down
7 changes: 7 additions & 0 deletions internal/ui/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ LIMIT 1
}
}

func updateTLBeginTS(db *sql.DB, beginTS time.Time) tea.Cmd {
return func() tea.Msg {
err := updateTLBeginTSInDB(db, beginTS)
return tlBeginTSUpdatedMsg{beginTS, err}
}
}

func insertManualEntry(db *sql.DB, taskId int, beginTS time.Time, endTS time.Time, comment string) tea.Cmd {
return func() tea.Msg {
err := insertManualTLInDB(db, taskId, beginTS, endTS, comment)
Expand Down
19 changes: 8 additions & 11 deletions internal/ui/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package ui
import "fmt"

var (
helpText = fmt.Sprintf(`
%s
helpText = fmt.Sprintf(` %s
%s
%s

Expand All @@ -23,22 +22,20 @@ var (
`,
helpHeaderStyle.Render("\"hours\" Reference Manual"),
helpSectionStyle.Render(`
(scroll line by line with j/k/arrow keys or by half a page with <c-d>/<c-u>)

"hours" has 5 panes:
"hours" has 6 views:
- Tasks List View Shows active tasks
- Task Management View Shows a form to create/update tasks
- Task Log List View Shows your task log entries
- Task Logs List View Shows your task logs
- Inactive Tasks List View Shows inactive tasks
- Task Log Entry View Shows a form to save a task log entry (after you're done tracking time)
- Task Log Entry View Shows a form to save/update a task log entry
- Help View (this one)
`),
helpHeaderStyle.Render("Keyboard Shortcuts"),
helpHeaderStyle.Render("General"),
helpSectionStyle.Render(`
1 Switch to Tasks List View
2 Switch to Task Log List View
3 Switch to Inactive Task Log List View
2 Switch to Task Logs List View
3 Switch to Inactive Tasks List View
<tab> Go to next view/form entry
<shift+tab> Go to previous view/form entry
? Show help view
Expand All @@ -56,12 +53,12 @@ var (
a Add a task
u Update task details
s Start/stop recording time on a task; stopping will open up the "Task Log Entry View"
<ctrl+s> Add a manual task log entry
<ctrl+s> Edit the currently active task log/Add a new manual task log entry
<ctrl+x> Discard currently active recording
<ctrl+t> Go to currently tracked item
<ctrl+d> Deactivate task
`),
helpHeaderStyle.Render("Task Log List View"),
helpHeaderStyle.Render("Task Logs List View"),
helpSectionStyle.Render(`
<ctrl+d> Delete task log entry
`),
Expand Down
2 changes: 1 addition & 1 deletion internal/ui/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func InitialModel(db *sql.DB) model {
m.activeTasksList.SetShowHelp(false)
m.activeTasksList.Styles.Title = m.activeTasksList.Styles.Title.Foreground(lipgloss.Color(defaultBackgroundColor)).Background(lipgloss.Color(activeTaskListColor)).Bold(true)

m.taskLogList.Title = "Task Log (last 50)"
m.taskLogList.Title = "Task Logs (last 50)"
m.taskLogList.SetStatusBarItemName("entry", "entries")
m.taskLogList.SetFilteringEnabled(false)
m.taskLogList.DisableQuitKeybindings()
Expand Down
1 change: 1 addition & 0 deletions internal/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
activeTaskListView stateView = iota
taskLogView
inactiveTaskListView
editStartTsView
askForCommentView
manualTasklogEntryView
taskInputView
Expand Down
5 changes: 5 additions & 0 deletions internal/ui/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ type manualTaskLogInserted struct {
err error
}

type tlBeginTSUpdatedMsg struct {
beginTS time.Time
err error
}

type activeTaskLogDeletedMsg struct {
err error
}
Expand Down
26 changes: 23 additions & 3 deletions internal/ui/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
func insertNewTLInDB(db *sql.DB, taskId int, beginTs time.Time) error {

stmt, err := db.Prepare(`
INSERT INTO task_log (task_id, begin_ts, active)
VALUES (?, ?, ?);
`)
INSERT INTO task_log (task_id, begin_ts, active)
VALUES (?, ?, ?);
`)

if err != nil {
return err
Expand All @@ -27,6 +27,26 @@ func insertNewTLInDB(db *sql.DB, taskId int, beginTs time.Time) error {
return nil
}

func updateTLBeginTSInDB(db *sql.DB, beginTs time.Time) error {

stmt, err := db.Prepare(`
UPDATE task_log SET begin_ts=?
WHERE active is true;
`)

if err != nil {
return err
}
defer stmt.Close()

_, err = stmt.Exec(beginTs.UTC(), true)
if err != nil {
return err
}

return nil
}

func deleteActiveTLInDB(db *sql.DB) error {

stmt, err := db.Prepare(`
Expand Down
16 changes: 13 additions & 3 deletions internal/ui/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
defaultBackgroundColor = "#282828"
activeTaskListColor = "#fe8019"
inactiveTaskListColor = "#928374"
taskLogEntryColor = "#fabd2f"
taskLogListColor = "#b8bb26"
trackingColor = "#fabd2f"
activeTaskColor = "#8ec07c"
Expand All @@ -27,7 +28,7 @@ const (
helpMsgColor = "#83a598"
helpViewTitleColor = "#83a598"
helpHeaderColor = "#83a598"
helpSectionColor = "#fabd2f"
helpSectionColor = "#bdae93"
warningColor = "#fb4934"
)

Expand All @@ -45,11 +46,17 @@ var (
initialHelpMsgStyle = helpMsgStyle.
Foreground(lipgloss.Color(initialHelpMsgColor))

baseListStyle = lipgloss.NewStyle().PaddingTop(1).PaddingRight(2).PaddingLeft(1).PaddingBottom(1)
baseListStyle = lipgloss.NewStyle().PaddingTop(1).PaddingRight(2).PaddingBottom(1)

baseHeadingStyle = lipgloss.NewStyle().
Bold(true).
PaddingLeft(1).
PaddingRight(1).
Foreground(lipgloss.Color(defaultBackgroundColor))

viewPortStyle = lipgloss.NewStyle().
PaddingTop(1).
PaddingRight(2).
PaddingLeft(1).
PaddingBottom(1)

listStyle = baseListStyle
Expand All @@ -59,6 +66,9 @@ var (
Bold(true).
Background(lipgloss.Color(toolNameColor))

taskLogEntryHeadingStyle = baseHeadingStyle.
Background(lipgloss.Color(taskLogEntryColor))

formContextStyle = lipgloss.NewStyle().
Foreground(lipgloss.Color(formContextColor))

Expand Down
Loading