Skip to content

Commit

Permalink
feat: add synced worklog view
Browse files Browse the repository at this point in the history
  • Loading branch information
dhth committed May 14, 2024
1 parent 90e34c4 commit 5461305
Show file tree
Hide file tree
Showing 10 changed files with 206 additions and 71 deletions.
56 changes: 32 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,48 +92,56 @@ punchout \
```
punchout Reference Manual
punchout has 4 panes:
- Issues List View Shows you issues matching your JQL query
- Worklog List View Shows you your worklog entries; you sync these entries
to JIRA from here
- Worklog Entry View You enter/update a worklog entry from here
punchout has 5 panes:
- Issues List View Shows you issues matching your JQL query
- Worklog List View Shows you your worklog entries; you sync these entries
to JIRA from here
- Worklog Entry View You enter/update a worklog entry from here
- Synced Worklog Entry View You view the worklog entries synced to JIRA
- Help View (this one)
Keyboard Shortcuts
General
1 Switch to Issues List View
2 Switch to Worklog List View
<tab> Go to next view/form entry
<shift+tab> Go to previous view/form entry
? Show help view
1 Switch to Issues List View
2 Switch to Worklog List View
3 Switch to Synced Worklog List View
<tab> Go to next view/form entry
<shift+tab> Go to previous view/form entry
? Show help view
General List Controls
h/<Up> Move cursor up
k/<Down> Move cursor down
h<Left> Go to previous page
l<Right> Go to next page
/ Start filtering
h/<Up> Move cursor up
k/<Down> Move cursor down
h<Left> Go to previous page
l<Right> Go to next page
/ Start filtering
Issue List View
s Toggle recording time on the currently selected issue,
will open up a form to record a comment on the second
"s" keypress
<ctrl+s> Add manual worklog entry
s Toggle recording time on the currently selected issue,
will open up a form to record a comment on the second
"s" keypress
<ctrl+s> Add manual worklog entry
Worklog List View
<ctrl+s> Update worklog entry
<ctrl+d> Delete worklog entry
s Sync all visible entries to JIRA
<ctrl+r> Refresh list
<ctrl+s> Update worklog entry
<ctrl+d> Delete worklog entry
s Sync all visible entries to JIRA
<ctrl+r> Refresh list
Worklog Entry View
enter Save worklog entry
enter Save worklog entry
Synced Worklog Entry View
<ctrl+r> Refresh list
```

Acknowledgements
Expand Down
10 changes: 10 additions & 0 deletions ui/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ func fetchLogEntries(db *sql.DB) tea.Cmd {
}
}

func fetchSyncedLogEntries(db *sql.DB) tea.Cmd {
return func() tea.Msg {
entries, err := fetchSyncedEntries(db)
return SyncedLogEntriesFetchedMsg{
entries: entries,
err: err,
}
}
}

func deleteLogEntry(db *sql.DB, id int) tea.Cmd {
return func() tea.Msg {
err := deleteEntry(db, id)
Expand Down
56 changes: 32 additions & 24 deletions ui/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,61 @@ var (
%s
%s
%s
%s
%s
%s
`,
helpHeaderStyle.Render("punchout Reference Manual"),
helpSectionStyle.Render(`
(scroll line by line with j/k/arrow keys or by half a page with <c-d>/<c-u>)
punchout has 4 panes:
- Issues List View Shows you issues matching your JQL query
- Worklog List View Shows you your worklog entries; you sync these entries
to JIRA from here
- Worklog Entry View You enter/update a worklog entry from here
punchout has 5 panes:
- Issues List View Shows you issues matching your JQL query
- Worklog List View Shows you your worklog entries; you sync these entries
to JIRA from here
- Worklog Entry View You enter/update a worklog entry from here
- Synced Worklog Entry View You view the worklog entries synced to JIRA
- Help View (this one)
`),
helpHeaderStyle.Render("Keyboard Shortcuts"),
helpHeaderStyle.Render("General"),
helpSectionStyle.Render(`
1 Switch to Issues List View
2 Switch to Worklog List View
<tab> Go to next view/form entry
<shift+tab> Go to previous view/form entry
? Show help view
1 Switch to Issues List View
2 Switch to Worklog List View
3 Switch to Synced Worklog List View
<tab> Go to next view/form entry
<shift+tab> Go to previous view/form entry
? Show help view
`),
helpHeaderStyle.Render("General List Controls"),
helpSectionStyle.Render(`
h/<Up> Move cursor up
k/<Down> Move cursor down
h<Left> Go to previous page
l<Right> Go to next page
/ Start filtering
h/<Up> Move cursor up
k/<Down> Move cursor down
h<Left> Go to previous page
l<Right> Go to next page
/ Start filtering
`),
helpHeaderStyle.Render("Issue List View"),
helpSectionStyle.Render(`
s Toggle recording time on the currently selected issue,
will open up a form to record a comment on the second
"s" keypress
<ctrl+s> Add manual worklog entry
s Toggle recording time on the currently selected issue,
will open up a form to record a comment on the second
"s" keypress
<ctrl+s> Add manual worklog entry
`),
helpHeaderStyle.Render("Worklog List View"),
helpSectionStyle.Render(`
<ctrl+s> Update worklog entry
<ctrl+d> Delete worklog entry
s Sync all visible entries to JIRA
<ctrl+r> Refresh list
<ctrl+s> Update worklog entry
<ctrl+d> Delete worklog entry
s Sync all visible entries to JIRA
<ctrl+r> Refresh list
`),
helpHeaderStyle.Render("Worklog Entry View"),
helpSectionStyle.Render(`
enter Save worklog entry
enter Save worklog entry
`),
helpHeaderStyle.Render("Synced Worklog Entry View"),
helpSectionStyle.Render(`
<ctrl+r> Refresh list
`),
)
)
11 changes: 11 additions & 0 deletions ui/initial.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
func InitialModel(db *sql.DB, jiraClient *jira.Client, jql string, jiraTimeDeltaMins int) model {
var stackItems []list.Item
var worklogListItems []list.Item
var syncedWorklogListItems []list.Item

itemDel := newItemDelegate()

Expand Down Expand Up @@ -40,6 +41,7 @@ func InitialModel(db *sql.DB, jiraClient *jira.Client, jql string, jiraTimeDelta
jql: jql,
issueList: list.New(stackItems, itemDel, listWidth, 0),
worklogList: list.New(worklogListItems, itemDel, listWidth, 0),
syncedWorklogList: list.New(syncedWorklogListItems, itemDel, listWidth, 0),
jiraTimeDeltaMins: jiraTimeDeltaMins,
showHelpIndicator: true,
trackingInputs: trackingInputs,
Expand All @@ -61,5 +63,14 @@ func InitialModel(db *sql.DB, jiraClient *jira.Client, jql string, jiraTimeDelta
m.worklogList.Styles.Title.Background(lipgloss.Color("#fe8019"))
m.worklogList.Styles.Title.Bold(true)

m.syncedWorklogList.Title = "Synced Worklog Entries (from local db)"
m.syncedWorklogList.SetStatusBarItemName("entry", "entries")
m.syncedWorklogList.SetFilteringEnabled(false)
m.syncedWorklogList.DisableQuitKeybindings()
m.syncedWorklogList.SetShowHelp(false)
m.syncedWorklogList.Styles.Title.Foreground(lipgloss.Color("#282828"))
m.syncedWorklogList.Styles.Title.Background(lipgloss.Color("#fe8019"))
m.syncedWorklogList.Styles.Title.Bold(true)

return m
}
45 changes: 24 additions & 21 deletions ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type StateView uint
const (
IssueListView StateView = iota
WorklogView
SyncedWorklogView
AskForCommentView
ManualWorklogEntryView
HelpView
Expand All @@ -55,27 +56,29 @@ const (
)

type model struct {
activeView StateView
lastView StateView
db *sql.DB
jiraClient *jira.Client
jql string
issueList list.Model
worklogList list.Model
trackingInputs []textinput.Model
trackingFocussedField trackingFocussedField
helpVP viewport.Model
helpVPReady bool
lastChange DBChange
changesLocked bool
activeIssue string
worklogSaveType worklogSaveType
message string
errorMessage string
messages []string
jiraTimeDeltaMins int
showHelpIndicator bool
terminalHeight int
activeView StateView
lastView StateView
db *sql.DB
jiraClient *jira.Client
jql string
issueList list.Model
worklogList list.Model
syncedWorklogList list.Model
syncedWLEntriesFetched bool
trackingInputs []textinput.Model
trackingFocussedField trackingFocussedField
helpVP viewport.Model
helpVPReady bool
lastChange DBChange
changesLocked bool
activeIssue string
worklogSaveType worklogSaveType
message string
errorMessage string
messages []string
jiraTimeDeltaMins int
showHelpIndicator bool
terminalHeight int
}

func (m model) Init() tea.Cmd {
Expand Down
5 changes: 5 additions & 0 deletions ui/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type LogEntriesFetchedMsg struct {
err error
}

type SyncedLogEntriesFetchedMsg struct {
entries []SyncedWorklogEntry
err error
}

type LogEntriesDeletedMsg struct {
err error
}
Expand Down
22 changes: 22 additions & 0 deletions ui/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ type WorklogEntry struct {
Error error
}

type SyncedWorklogEntry struct {
Id int
IssueKey string
BeginTS time.Time
EndTS time.Time
Comment string
}

func (entry WorklogEntry) Title() string {
return entry.Comment
}
Expand All @@ -83,3 +91,17 @@ func (entry WorklogEntry) Description() string {
)
}
func (entry WorklogEntry) FilterValue() string { return entry.IssueKey }

func (entry SyncedWorklogEntry) Title() string {
return entry.Comment
}
func (entry SyncedWorklogEntry) Description() string {
minsSpent := int(entry.EndTS.Sub(entry.BeginTS).Minutes())
minsSpentStr := fmt.Sprintf("spent %d mins", minsSpent)
return fmt.Sprintf("%s%s%s",
RightPadTrim(entry.IssueKey, int(listWidth/4)),
RightPadTrim("started: "+entry.BeginTS.Format("Mon, 3:04pm"), int(listWidth/4)),
RightPadTrim(minsSpentStr, int(listWidth/4)),
)
}
func (entry SyncedWorklogEntry) FilterValue() string { return entry.IssueKey }
Loading

0 comments on commit 5461305

Please sign in to comment.