Add things
This commit is contained in:
135
pages/report.go
135
pages/report.go
@ -3,13 +3,13 @@ package pages
|
||||
|
||||
import (
|
||||
"tasksquire/common"
|
||||
"tasksquire/components/detailsviewer"
|
||||
"tasksquire/components/table"
|
||||
"tasksquire/taskwarrior"
|
||||
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
|
||||
// "github.com/charmbracelet/bubbles/table"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
type ReportPage struct {
|
||||
@ -25,6 +25,10 @@ type ReportPage struct {
|
||||
|
||||
taskTable table.Model
|
||||
|
||||
// Details panel state
|
||||
detailsPanelActive bool
|
||||
detailsViewer *detailsviewer.DetailsViewer
|
||||
|
||||
subpage common.Component
|
||||
}
|
||||
|
||||
@ -38,11 +42,13 @@ func NewReportPage(com *common.Common, report *taskwarrior.Report) *ReportPage {
|
||||
// }
|
||||
|
||||
p := &ReportPage{
|
||||
common: com,
|
||||
activeReport: report,
|
||||
activeContext: com.TW.GetActiveContext(),
|
||||
activeProject: "",
|
||||
taskTable: table.New(com),
|
||||
common: com,
|
||||
activeReport: report,
|
||||
activeContext: com.TW.GetActiveContext(),
|
||||
activeProject: "",
|
||||
taskTable: table.New(com),
|
||||
detailsPanelActive: false,
|
||||
detailsViewer: detailsviewer.New(com),
|
||||
}
|
||||
|
||||
return p
|
||||
@ -51,8 +57,39 @@ func NewReportPage(com *common.Common, report *taskwarrior.Report) *ReportPage {
|
||||
func (p *ReportPage) SetSize(width int, height int) {
|
||||
p.common.SetSize(width, height)
|
||||
|
||||
p.taskTable.SetWidth(width - p.common.Styles.Base.GetHorizontalFrameSize())
|
||||
p.taskTable.SetHeight(height - p.common.Styles.Base.GetVerticalFrameSize())
|
||||
baseHeight := height - p.common.Styles.Base.GetVerticalFrameSize()
|
||||
baseWidth := width - p.common.Styles.Base.GetHorizontalFrameSize()
|
||||
|
||||
var tableHeight int
|
||||
if p.detailsPanelActive {
|
||||
// Allocate 60% for table, 40% for details panel
|
||||
// Minimum 5 lines for details, minimum 10 lines for table
|
||||
detailsHeight := max(min(baseHeight*2/5, baseHeight-10), 5)
|
||||
tableHeight = baseHeight - detailsHeight - 1 // -1 for spacing
|
||||
|
||||
// Set component size (component handles its own border/padding)
|
||||
p.detailsViewer.SetSize(baseWidth, detailsHeight)
|
||||
} else {
|
||||
tableHeight = baseHeight
|
||||
}
|
||||
|
||||
p.taskTable.SetWidth(baseWidth)
|
||||
p.taskTable.SetHeight(tableHeight)
|
||||
}
|
||||
|
||||
// Helper functions
|
||||
func max(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (p *ReportPage) Init() tea.Cmd {
|
||||
@ -91,6 +128,14 @@ func (p *ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case UpdatedTasksMsg:
|
||||
cmds = append(cmds, p.getTasks())
|
||||
case tea.KeyMsg:
|
||||
// Handle ESC when details panel is active
|
||||
if p.detailsPanelActive && key.Matches(msg, p.common.Keymap.Back) {
|
||||
p.detailsPanelActive = false
|
||||
p.detailsViewer.Blur()
|
||||
p.SetSize(p.common.Width(), p.common.Height())
|
||||
return p, nil
|
||||
}
|
||||
|
||||
switch {
|
||||
case key.Matches(msg, p.common.Keymap.Quit):
|
||||
return p, tea.Quit
|
||||
@ -155,28 +200,63 @@ func (p *ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
return p, p.getTasks()
|
||||
}
|
||||
case key.Matches(msg, p.common.Keymap.ViewDetails):
|
||||
if p.selectedTask != nil {
|
||||
// Toggle details panel
|
||||
p.detailsPanelActive = !p.detailsPanelActive
|
||||
if p.detailsPanelActive {
|
||||
p.detailsViewer.SetTask(p.selectedTask)
|
||||
p.detailsViewer.Focus()
|
||||
} else {
|
||||
p.detailsViewer.Blur()
|
||||
}
|
||||
p.SetSize(p.common.Width(), p.common.Height())
|
||||
return p, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cmd tea.Cmd
|
||||
p.taskTable, cmd = p.taskTable.Update(msg)
|
||||
cmds = append(cmds, cmd)
|
||||
|
||||
if p.tasks != nil && len(p.tasks) > 0 {
|
||||
p.selectedTask = p.tasks[p.taskTable.Cursor()]
|
||||
// Route keyboard messages to details viewer when panel is active
|
||||
if p.detailsPanelActive {
|
||||
var viewerCmd tea.Cmd
|
||||
var viewerModel tea.Model
|
||||
viewerModel, viewerCmd = p.detailsViewer.Update(msg)
|
||||
p.detailsViewer = viewerModel.(*detailsviewer.DetailsViewer)
|
||||
cmds = append(cmds, viewerCmd)
|
||||
} else {
|
||||
p.selectedTask = nil
|
||||
// Route to table when details panel not active
|
||||
p.taskTable, cmd = p.taskTable.Update(msg)
|
||||
cmds = append(cmds, cmd)
|
||||
|
||||
if p.tasks != nil && len(p.tasks) > 0 {
|
||||
p.selectedTask = p.tasks[p.taskTable.Cursor()]
|
||||
} else {
|
||||
p.selectedTask = nil
|
||||
}
|
||||
}
|
||||
|
||||
return p, tea.Batch(cmds...)
|
||||
}
|
||||
|
||||
func (p *ReportPage) View() string {
|
||||
// return p.common.Styles.Main.Render(p.taskTable.View()) + "\n"
|
||||
if p.tasks == nil || len(p.tasks) == 0 {
|
||||
return p.common.Styles.Base.Render("No tasks found")
|
||||
}
|
||||
return p.taskTable.View()
|
||||
|
||||
tableView := p.taskTable.View()
|
||||
|
||||
if !p.detailsPanelActive {
|
||||
return tableView
|
||||
}
|
||||
|
||||
// Combine table and details panel vertically
|
||||
return lipgloss.JoinVertical(
|
||||
lipgloss.Left,
|
||||
tableView,
|
||||
p.detailsViewer.View(),
|
||||
)
|
||||
}
|
||||
|
||||
func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
|
||||
@ -197,13 +277,27 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
|
||||
selected = len(tasks) - 1
|
||||
}
|
||||
|
||||
// Calculate proper dimensions based on whether details panel is active
|
||||
baseHeight := p.common.Height() - p.common.Styles.Base.GetVerticalFrameSize()
|
||||
baseWidth := p.common.Width() - p.common.Styles.Base.GetHorizontalFrameSize()
|
||||
|
||||
var tableHeight int
|
||||
if p.detailsPanelActive {
|
||||
// Allocate 60% for table, 40% for details panel
|
||||
// Minimum 5 lines for details, minimum 10 lines for table
|
||||
detailsHeight := max(min(baseHeight*2/5, baseHeight-10), 5)
|
||||
tableHeight = baseHeight - detailsHeight - 1 // -1 for spacing
|
||||
} else {
|
||||
tableHeight = baseHeight
|
||||
}
|
||||
|
||||
p.taskTable = table.New(
|
||||
p.common,
|
||||
table.WithReport(p.activeReport),
|
||||
table.WithTasks(tasks),
|
||||
table.WithFocused(true),
|
||||
table.WithWidth(p.common.Width()-p.common.Styles.Base.GetVerticalFrameSize()),
|
||||
table.WithHeight(p.common.Height()-p.common.Styles.Base.GetHorizontalFrameSize()-1),
|
||||
table.WithWidth(baseWidth),
|
||||
table.WithHeight(tableHeight),
|
||||
table.WithStyles(p.common.Styles.TableStyle),
|
||||
)
|
||||
|
||||
@ -215,6 +309,11 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
|
||||
} else {
|
||||
p.taskTable.SetCursor(len(p.tasks) - 1)
|
||||
}
|
||||
|
||||
// Refresh details content if panel is active
|
||||
if p.detailsPanelActive && p.selectedTask != nil {
|
||||
p.detailsViewer.SetTask(p.selectedTask)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ReportPage) getTasks() tea.Cmd {
|
||||
|
||||
Reference in New Issue
Block a user