add dashboard
This commit is contained in:
@@ -41,34 +41,22 @@ var defaultDashboardKeyMap = DashboardKeyMap{
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m DashboardKeyMap) ShortHelp() []key.Binding {
|
|
||||||
return []key.Binding{m.ScrollDown, m.ScrollUp, m.Quit, m.Help}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m DashboardKeyMap) FullHelp() [][]key.Binding {
|
|
||||||
return [][]key.Binding{
|
|
||||||
{m.SelectIssue, m.BackToList},
|
|
||||||
{m.ScrollUp, m.ScrollDown},
|
|
||||||
{m.Help, m.Quit},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd {
|
func (d *Model) handleKeyMsg(msg tea.KeyMsg) tea.Cmd {
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case key.Matches(msg, d.keyMap.Help):
|
case key.Matches(msg, d.keyMap.Help):
|
||||||
d.help.ShowAll = !d.help.ShowAll
|
d.helpBar.ToggleHelp()
|
||||||
case key.Matches(msg, d.keyMap.Quit):
|
case key.Matches(msg, d.keyMap.Quit):
|
||||||
return tea.Quit
|
return tea.Quit
|
||||||
case !d.focusedOnIssue && key.Matches(msg, d.keyMap.SelectIssue):
|
case d.IsFocusedOnList() && key.Matches(msg, d.keyMap.SelectIssue):
|
||||||
d.focusedOnIssue = true
|
d.FocusDetail()
|
||||||
case d.focusedOnIssue && key.Matches(msg, d.keyMap.BackToList):
|
case d.IsFocusedOnDetail() && key.Matches(msg, d.keyMap.BackToList):
|
||||||
d.focusedOnIssue = false
|
d.FocusList()
|
||||||
case d.focusedOnIssue && key.Matches(msg, d.keyMap.ScrollUp):
|
case d.IsFocusedOnDetail() && key.Matches(msg, d.keyMap.ScrollUp):
|
||||||
d.issueView.Viewport.ScrollUp(1)
|
d.issueDetail.ScrollUp(1)
|
||||||
case d.focusedOnIssue && key.Matches(msg, d.keyMap.ScrollDown):
|
case d.IsFocusedOnDetail() && key.Matches(msg, d.keyMap.ScrollDown):
|
||||||
d.issueView.Viewport.ScrollDown(1)
|
d.issueDetail.ScrollDown(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
|
|||||||
@@ -1,26 +1,69 @@
|
|||||||
package dashboard
|
package dashboard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/tui/views/issue"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/charmbracelet/bubbles/help"
|
|
||||||
"github.com/charmbracelet/bubbles/list"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Model struct {
|
type Model struct {
|
||||||
help help.Model
|
header Header
|
||||||
issueView issue.Model
|
issueList IssueList
|
||||||
issueList list.Model
|
issueDetail IssueDetail
|
||||||
|
helpBar HelpBar
|
||||||
keyMap DashboardKeyMap
|
keyMap DashboardKeyMap
|
||||||
svc *service.Services
|
svc *service.Services
|
||||||
focusedOnIssue bool
|
width int
|
||||||
|
height int
|
||||||
|
focusedPane int // 0 = list, 1 = detail
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListIssue struct {
|
func NewDashboard(svc *service.Services) *Model {
|
||||||
models.Issue
|
m := &Model{
|
||||||
|
header: NewHeader("Project Manager Dashboard"),
|
||||||
|
keyMap: defaultDashboardKeyMap,
|
||||||
|
svc: svc,
|
||||||
|
width: 80,
|
||||||
|
height: 24,
|
||||||
|
focusedPane: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
m.issueList = NewIssueList(svc, 0, 0)
|
||||||
|
m.issueDetail = NewIssueDetail()
|
||||||
|
m.helpBar = NewHelpBar(m.keyMap)
|
||||||
|
|
||||||
|
if selected := m.issueList.SelectedItem(); selected.ID != "" {
|
||||||
|
m.issueDetail.SetIssue(selected.Issue)
|
||||||
|
}
|
||||||
|
|
||||||
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i ListIssue) Title() string { return i.Issue.Title }
|
func (m *Model) Init() tea.Cmd {
|
||||||
func (i ListIssue) Description() string { return i.Issue.Description }
|
return nil
|
||||||
func (i ListIssue) FilterValue() string { return i.Issue.ID + " " + i.Issue.Title }
|
}
|
||||||
|
|
||||||
|
func (m *Model) IsFocusedOnList() bool {
|
||||||
|
return m.focusedPane == 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) IsFocusedOnDetail() bool {
|
||||||
|
return m.focusedPane == 1
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) FocusList() {
|
||||||
|
m.focusedPane = 0
|
||||||
|
m.issueDetail.SetFocused(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) FocusDetail() {
|
||||||
|
m.focusedPane = 1
|
||||||
|
m.issueDetail.SetFocused(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) ToggleFocus() {
|
||||||
|
if m.focusedPane == 0 {
|
||||||
|
m.FocusDetail()
|
||||||
|
} else {
|
||||||
|
m.FocusList()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,60 +1,34 @@
|
|||||||
package dashboard
|
package dashboard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/tui/styles"
|
|
||||||
"github.com/charmbracelet/bubbles/list"
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (d Model) Update(m tea.Msg) (tea.Model, tea.Cmd) {
|
func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
switch msg := m.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
if d.issueList.FilterState() == list.Filtering {
|
if m.issueList.FilterState() == 1 {
|
||||||
break
|
cmd, _ := m.issueList.Update(msg)
|
||||||
|
return m, cmd
|
||||||
}
|
}
|
||||||
cmd := d.handleKeyMsg(msg)
|
|
||||||
|
cmd := m.handleKeyMsg(msg)
|
||||||
if cmd != nil {
|
if cmd != nil {
|
||||||
return d, cmd
|
return m, cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
case tea.WindowSizeMsg:
|
case tea.WindowSizeMsg:
|
||||||
d.updateSizes(msg.Width, msg.Height)
|
m.width = msg.Width
|
||||||
|
m.height = msg.Height
|
||||||
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmd tea.Cmd
|
cmd, changed := m.issueList.Update(msg)
|
||||||
oldIndex := d.issueList.Index()
|
if changed {
|
||||||
d.issueList, cmd = d.issueList.Update(m)
|
if selected := m.issueList.SelectedItem(); selected.ID != "" {
|
||||||
|
m.issueDetail.SetIssue(selected.Issue)
|
||||||
if d.issueList.Index() != oldIndex {
|
}
|
||||||
d.updateIssueView()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return d, cmd
|
return m, cmd
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Model) updateIssueView() {
|
|
||||||
if item, ok := d.issueList.SelectedItem().(ListIssue); ok {
|
|
||||||
d.issueView.ID = item.ID
|
|
||||||
d.issueView.Title = item.Issue.Title
|
|
||||||
d.issueView.Description = item.Issue.Description
|
|
||||||
d.issueView.Status = string(item.Issue.Status)
|
|
||||||
d.issueView.IssueType = string(item.Issue.IssueType)
|
|
||||||
|
|
||||||
content := fmt.Sprintf("ID: %s\nTitle: %s\nDescription: %s\nStatus: %s\nType: %s",
|
|
||||||
d.issueView.ID, d.issueView.Title, d.issueView.Description, d.issueView.Status, d.issueView.IssueType)
|
|
||||||
|
|
||||||
d.issueView.Viewport.SetContent(content)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *Model) updateSizes(width, height int) {
|
|
||||||
listWidth := width / 2
|
|
||||||
issueWidth := width - listWidth
|
|
||||||
|
|
||||||
w, h := styles.AppStyle.GetFrameSize()
|
|
||||||
d.issueList.SetSize(listWidth-w, height-h)
|
|
||||||
d.issueView.SetSize(issueWidth, height-h)
|
|
||||||
d.issueView.Viewport.Width = issueWidth
|
|
||||||
d.issueView.Viewport.Height = height - h
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,73 +1,36 @@
|
|||||||
package dashboard
|
package dashboard
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/help"
|
|
||||||
"github.com/charmbracelet/bubbles/list"
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
|
||||||
"github.com/charmbracelet/lipgloss"
|
|
||||||
|
|
||||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/tui/styles"
|
"github.com/LazyBachelor/LazyPM/pkg/tui/styles"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/tui/views/issue"
|
"github.com/charmbracelet/lipgloss"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewDashboard(svc *service.Services) Model {
|
func (m *Model) View() string {
|
||||||
|
if m.width == 0 || m.height == 0 {
|
||||||
issues, err := svc.Beads.AllIssues(context.Background())
|
return "Loading..."
|
||||||
|
|
||||||
listIssues := []ListIssue{}
|
|
||||||
for _, issue := range issues {
|
|
||||||
listIssues = append(listIssues, ListIssue{Issue: issue})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
m.helpBar.SetWidth(m.width)
|
||||||
listIssues = []ListIssue{}
|
|
||||||
}
|
|
||||||
|
|
||||||
items := make([]list.Item, len(listIssues))
|
header := m.header.View(m.width)
|
||||||
for i, issue := range listIssues {
|
headerHeight := m.header.Height()
|
||||||
items[i] = issue
|
|
||||||
}
|
|
||||||
|
|
||||||
issueList := list.New(items, IssueListDelegate{}, 0, 0)
|
bottomView := m.helpBar.View()
|
||||||
|
bottomHeight := m.helpBar.Height()
|
||||||
|
|
||||||
issueList.Title = "Issues"
|
contentHeight := m.height - headerHeight - bottomHeight
|
||||||
issueList.Styles.Title = styles.TitleStyle
|
|
||||||
issueList.SetShowHelp(false)
|
|
||||||
|
|
||||||
issueView := issue.NewIssueView(issue.Model{})
|
totalContentWidth := m.width - 1
|
||||||
|
listWidth := totalContentWidth * styles.ListViewRatio / 100
|
||||||
|
detailWidth := totalContentWidth - listWidth
|
||||||
|
|
||||||
m := Model{
|
m.issueList.SetSize(listWidth, contentHeight)
|
||||||
help: help.New(),
|
m.issueDetail.SetSize(detailWidth, contentHeight)
|
||||||
issueView: issueView,
|
|
||||||
issueList: issueList,
|
|
||||||
keyMap: defaultDashboardKeyMap,
|
|
||||||
svc: svc,
|
|
||||||
}
|
|
||||||
|
|
||||||
m.updateIssueView()
|
listView := m.issueList.View()
|
||||||
|
detailView := m.issueDetail.View()
|
||||||
|
|
||||||
return m
|
content := lipgloss.JoinHorizontal(lipgloss.Left, listView, detailView)
|
||||||
}
|
|
||||||
|
return lipgloss.JoinVertical(lipgloss.Left, header, content, bottomView)
|
||||||
func (d Model) Init() tea.Cmd {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d Model) View() string {
|
|
||||||
issueView := d.issueView.View()
|
|
||||||
|
|
||||||
if d.focusedOnIssue {
|
|
||||||
issueView = styles.FocusedIssueStyle.Render(issueView)
|
|
||||||
} else {
|
|
||||||
issueView = styles.IssueStyle.Render(issueView)
|
|
||||||
}
|
|
||||||
|
|
||||||
help := d.help.View(d.keyMap)
|
|
||||||
|
|
||||||
str := lipgloss.JoinHorizontal(lipgloss.Left, styles.AppStyle.Render(d.issueList.View()), issueView) + "\n" + help
|
|
||||||
|
|
||||||
return str
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,6 @@ import (
|
|||||||
"github.com/LazyBachelor/LazyPM/pkg/tui/views/dashboard"
|
"github.com/LazyBachelor/LazyPM/pkg/tui/views/dashboard"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewDashboardView(svc *service.Services) dashboard.Model {
|
func NewDashboardView(svc *service.Services) *dashboard.Model {
|
||||||
return dashboard.NewDashboard(svc)
|
return dashboard.NewDashboard(svc)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user