lots of changes and reducing dependency imports
This commit is contained in:
@@ -78,14 +78,14 @@ func renderHeaders(cols []TableColumn) string {
|
||||
}
|
||||
|
||||
func NewIssueList(app *service.App, width, height int) IssueList {
|
||||
issues, err := app.Issues.AllIssues(context.Background())
|
||||
issues, err := app.Issues.SearchIssues(context.Background(), "", models.IssueFilter{})
|
||||
if err != nil {
|
||||
return IssueList{}
|
||||
}
|
||||
|
||||
listIssues := []ListIssue{}
|
||||
for _, issue := range issues {
|
||||
listIssues = append(listIssues, ListIssue{Issue: issue})
|
||||
listIssues = append(listIssues, ListIssue{Issue: *issue})
|
||||
}
|
||||
|
||||
items := make([]list.Item, len(listIssues))
|
||||
@@ -111,11 +111,11 @@ func NewIssueList(app *service.App, width, height int) IssueList {
|
||||
}
|
||||
}
|
||||
|
||||
func NewIssueListFromIssues(app *service.App, issues []models.Issue, width, height int) IssueList {
|
||||
func NewIssueListFromIssues(app *service.App, issues []*models.Issue, width, height int) IssueList {
|
||||
// for making an IssueList from a pre-existing list of issues.
|
||||
listIssues := make([]list.Item, len(issues))
|
||||
for i, issue := range issues {
|
||||
listIssues[i] = ListIssue{Issue: issue}
|
||||
listIssues[i] = ListIssue{Issue: *issue}
|
||||
}
|
||||
l := list.New(listIssues, NewIssueListDelegate(width), width, height)
|
||||
l.SetShowTitle(false)
|
||||
@@ -134,9 +134,9 @@ func NewIssueListFromIssues(app *service.App, issues []models.Issue, width, heig
|
||||
}
|
||||
}
|
||||
|
||||
func OpenAndInProgressOnly(issues []models.Issue) []models.Issue {
|
||||
func OpenAndInProgressOnly(issues []*models.Issue) []*models.Issue {
|
||||
// used to display open & in-progress issues in the first window in the dashboard
|
||||
out := make([]models.Issue, 0, len(issues))
|
||||
out := make([]*models.Issue, 0, len(issues))
|
||||
for _, issue := range issues {
|
||||
if issue.Status == models.StatusOpen || issue.Status == models.StatusInProgress {
|
||||
out = append(out, issue)
|
||||
@@ -146,9 +146,9 @@ func OpenAndInProgressOnly(issues []models.Issue) []models.Issue {
|
||||
return out
|
||||
}
|
||||
|
||||
func ClosedOnly(issues []models.Issue) []models.Issue {
|
||||
func ClosedOnly(issues []*models.Issue) []*models.Issue {
|
||||
// used to display issues in the second window in the dashboard
|
||||
out := make([]models.Issue, 0, len(issues))
|
||||
out := make([]*models.Issue, 0, len(issues))
|
||||
for _, issue := range issues {
|
||||
if issue.Status == models.StatusClosed {
|
||||
out = append(out, issue)
|
||||
@@ -158,7 +158,7 @@ func ClosedOnly(issues []models.Issue) []models.Issue {
|
||||
return out
|
||||
}
|
||||
|
||||
func sortByPriorityDesc(issues []models.Issue) {
|
||||
func sortByPriorityDesc(issues []*models.Issue) {
|
||||
// sorts issues by priority, highest first.
|
||||
sort.Slice(issues, func(i, j int) bool {
|
||||
return issues[i].Priority > issues[j].Priority
|
||||
@@ -248,10 +248,10 @@ func (l IssueList) FilterState() list.FilterState {
|
||||
return l.list.FilterState()
|
||||
}
|
||||
|
||||
func (l *IssueList) SetIssues(issues []models.Issue) tea.Cmd {
|
||||
func (l *IssueList) SetIssues(issues []*models.Issue) tea.Cmd {
|
||||
listIssues := make([]list.Item, len(issues))
|
||||
for i, issue := range issues {
|
||||
listIssues[i] = ListIssue{Issue: issue}
|
||||
listIssues[i] = ListIssue{Issue: *issue}
|
||||
}
|
||||
return l.list.SetItems(listIssues)
|
||||
}
|
||||
|
||||
@@ -3,15 +3,15 @@ package dashboard
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||
"github.com/charmbracelet/bubbles/textarea"
|
||||
"github.com/charmbracelet/bubbles/textinput"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type ValidationFeedbackMsg struct {
|
||||
Feedback task.ValidationFeedback
|
||||
Feedback models.ValidationFeedback
|
||||
}
|
||||
|
||||
type Model struct {
|
||||
@@ -24,9 +24,9 @@ type Model struct {
|
||||
app *service.App
|
||||
width int
|
||||
height int
|
||||
focusedWindow int // 0 = main (display issues), 1 = closed issues
|
||||
focusedWindow int // 0 = main (display issues), 1 = closed issues
|
||||
focusedPaneMain int // 0 = list, 1 = detail
|
||||
focusedPaneClosed int
|
||||
focusedPaneClosed int
|
||||
editingTitle bool // true while we are editing a title
|
||||
titleInput textinput.Model
|
||||
editingIssueID string
|
||||
@@ -42,18 +42,18 @@ type Model struct {
|
||||
deleteConfirmIndex int
|
||||
|
||||
choosingStatus bool // true while choosing a status
|
||||
statusIssueID string
|
||||
choosingPriority bool // true while choosing a priority
|
||||
priorityIssueID string
|
||||
choosingType bool // true while choosing a type
|
||||
typeIssueID string
|
||||
feedbackChan chan task.ValidationFeedback
|
||||
quitChan chan bool
|
||||
currentFeedback task.ValidationFeedback
|
||||
showComplete bool
|
||||
statusIssueID string
|
||||
choosingPriority bool // true while choosing a priority
|
||||
priorityIssueID string
|
||||
choosingType bool // true while choosing a type
|
||||
typeIssueID string
|
||||
feedbackChan chan models.ValidationFeedback
|
||||
quitChan chan bool
|
||||
currentFeedback models.ValidationFeedback
|
||||
showComplete bool
|
||||
}
|
||||
|
||||
func NewDashboard(app *service.App, feedbackChan chan task.ValidationFeedback, quitChan chan bool) *Model {
|
||||
func NewDashboard(app *service.App, feedbackChan chan models.ValidationFeedback, quitChan chan bool) *Model {
|
||||
m := &Model{
|
||||
header: NewHeader("Project Manager Dashboard"),
|
||||
keyMap: defaultDashboardKeyMap,
|
||||
@@ -67,7 +67,7 @@ func NewDashboard(app *service.App, feedbackChan chan task.ValidationFeedback, q
|
||||
quitChan: quitChan,
|
||||
}
|
||||
|
||||
allIssues, _ := app.Issues.AllIssues(context.Background())
|
||||
allIssues, _ := app.Issues.SearchIssues(context.Background(), "", models.IssueFilter{})
|
||||
m.issueList = NewIssueListFromIssues(app, OpenAndInProgressOnly(allIssues), 0, 0)
|
||||
m.issueDetail = NewIssueDetail()
|
||||
m.closedIssueList = NewIssueListFromIssues(app, ClosedOnly(allIssues), 0, 0)
|
||||
|
||||
@@ -113,7 +113,7 @@ func (m *Model) refreshIssueListsAndSelectIssue(issueID string) tea.Cmd {
|
||||
/* update handler for issueTitleUpdatedMsg, issueDescriptionUpdatedMsg, and issueStatusUpdatedMsg to avoid using nearly identical code for refreshing the issue lists and updating the detail view
|
||||
Fetch all issues, update both lists, set the detail view for the given issue, and return a command to select that issue. Returns nil if fetch fails.
|
||||
*/
|
||||
issues, err := m.app.Issues.AllIssues(context.Background())
|
||||
issues, err := m.app.Issues.SearchIssues(context.Background(), "", models.IssueFilter{})
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@@ -121,7 +121,7 @@ func (m *Model) refreshIssueListsAndSelectIssue(issueID string) tea.Cmd {
|
||||
closedSetCmd := m.closedIssueList.SetIssues(ClosedOnly(issues))
|
||||
for _, issue := range issues {
|
||||
if issue.ID == issueID {
|
||||
m.issueDetail.SetIssue(issue)
|
||||
m.issueDetail.SetIssue(*issue)
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -184,7 +184,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if msg.Err != nil || msg.Issue == nil {
|
||||
return m, nil
|
||||
}
|
||||
issues, err := m.app.Issues.AllIssues(context.Background())
|
||||
issues, err := m.app.Issues.SearchIssues(context.Background(), "", models.IssueFilter{})
|
||||
if err != nil {
|
||||
return m, nil
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
for _, issue := range issues {
|
||||
// Prefer an issue that matches the created issue's title when ID is not yet known.
|
||||
if issue.Title == msg.Issue.Title {
|
||||
selectedIssue = &issue
|
||||
selectedIssue = issue
|
||||
break
|
||||
}
|
||||
}
|
||||
@@ -211,7 +211,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if msg.Err != nil {
|
||||
return m, nil
|
||||
}
|
||||
issues, err := m.app.Issues.AllIssues(context.Background())
|
||||
issues, err := m.app.Issues.SearchIssues(context.Background(), "", models.IssueFilter{})
|
||||
if err != nil {
|
||||
return m, nil
|
||||
}
|
||||
@@ -226,7 +226,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
|
||||
// Determine which list to use for the next selection.
|
||||
var targetIssues []models.Issue
|
||||
var targetIssues []*models.Issue
|
||||
if m.focusedWindow == 0 {
|
||||
targetIssues = openIssues
|
||||
if len(targetIssues) == 0 && len(closedIssues) > 0 {
|
||||
@@ -254,7 +254,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
newIndex = len(targetIssues) - 1
|
||||
}
|
||||
selectedIssue := targetIssues[newIndex]
|
||||
m.issueDetail.SetIssue(selectedIssue)
|
||||
m.issueDetail.SetIssue(*selectedIssue)
|
||||
return m, tea.Sequence(setItemsCmd, closedSetCmd, func() tea.Msg {
|
||||
return selectIssueMsg{IssueID: selectedIssue.ID}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user