Integrate tasktable

This commit is contained in:
Martin Pander
2026-02-26 22:49:00 +01:00
parent 9eda92503e
commit f6ce2e30dc
8 changed files with 778 additions and 109 deletions

View File

@@ -3,11 +3,11 @@ package pages
import (
"tasksquire/internal/common"
"tasksquire/internal/components/tasktable"
"tasksquire/internal/components/table"
"tasksquire/internal/taskwarrior"
tea "charm.land/bubbletea/v2"
// "charm.land/lipgloss/v2"
"charm.land/lipgloss/v2"
"charm.land/bubbles/v2/key"
)
@@ -22,7 +22,7 @@ type TaskPage struct {
tasks taskwarrior.Tasks
taskTable tasktable.Model
taskTable table.Model
// Details panel state
// detailsPanelActive bool
@@ -37,7 +37,7 @@ func NewTaskPage(com *common.Common, report *taskwarrior.Report) *TaskPage {
activeReport: report,
activeContext: com.TW.GetActiveContext(),
activeProject: "",
taskTable: tasktable.New(),
taskTable: table.New(),
// detailsPanelActive: false,
// detailsViewer: detailsviewer.New(com),
}
@@ -84,13 +84,13 @@ func (p *TaskPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return p, tea.Batch(cmds...)
case common.TaskMsg:
p.tasks = taskwarrior.Tasks(msg)
p.populateTaskTable(p.tasks)
// case UpdateReportMsg:
// p.activeReport = msg
// cmds = append(cmds, p.getTasks())
// case UpdateContextMsg:
// p.activeContext = msg
// p.common.TW.SetContext(msg)
// p.populateTaskTable(p.tasks)
// cmds = append(cmds, p.getTasks())
// case UpdateProjectMsg:
// p.activeProject = string(msg)
@@ -227,7 +227,7 @@ func (p *TaskPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// }
// }
//
// var cmd tea.Cmd
var cmd tea.Cmd
//
// // Route keyboard messages to details viewer when panel is active
// if p.detailsPanelActive {
@@ -238,15 +238,15 @@ func (p *TaskPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// cmds = append(cmds, viewerCmd)
// } else {
// // 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
// }
// }
p.taskTable, cmd = p.taskTable.Update(msg)
cmds = append(cmds, cmd)
if len(p.tasks) > 0 {
p.selectedTask = p.tasks[p.taskTable.Cursor()]
} else {
p.selectedTask = nil
}
// }
}
return p, tea.Batch(cmds...)
@@ -274,75 +274,99 @@ func (p *TaskPage) View() tea.View {
// )
// }
//
// func (p *TaskPage) populateTaskTable(tasks taskwarrior.Tasks) {
// if len(tasks) == 0 {
// return
// }
//
// // Build task tree for hierarchical display
// taskTree := taskwarrior.BuildTaskTree(tasks)
//
// // Use flattened tree list for display order
// orderedTasks := make(taskwarrior.Tasks, len(taskTree.FlatList))
// for i, node := range taskTree.FlatList {
// orderedTasks[i] = node.Task
// }
//
// selected := p.taskTable.Cursor()
//
// // Adjust cursor for tree ordering
// if p.selectedTask != nil {
// for i, task := range orderedTasks {
// if task.Uuid == p.selectedTask.Uuid {
// selected = i
// break
// }
// }
// }
// if selected > len(orderedTasks)-1 {
// selected = len(orderedTasks) - 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
func (p *TaskPage) populateTaskTable(tasks taskwarrior.Tasks) {
if len(tasks) == 0 {
return
}
selected := p.taskTable.Cursor()
// 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
// detailsHeight := max(min(baseHeight*2/5, baseHeight-10), 5)
// tableHeight = baseHeight - detailsHeight - 1 // -1 for spacing
// } else {
// tableHeight = baseHeight
tableHeight = baseHeight
// }
//
// p.taskTable = table.New(
// p.common,
// able.WithReport(p.activeReport),
// table.WithTasks(orderedTasks),
// table.WithTaskTree(taskTree),
// table.WithFocused(true),
// table.WithWidth(baseWidth),
// table.WithHeight(tableHeight),
// table.WithStyles(p.common.Styles.TableStyle),
// )
//
// if selected == 0 {
// selected = p.taskTable.Cursor()
// }
// if selected < len(orderedTasks) {
// p.taskTable.SetCursor(selected)
// } else {
// p.taskTable.SetCursor(len(p.tasks) - 1)
// }
numCols := len(p.activeReport.Columns)
taskRows := make([]table.Row, len(tasks))
taskStyles := make([]lipgloss.Style, len(tasks))
widths := make([]int, numCols)
for i, task := range tasks {
row := make(table.Row, numCols)
for j, colKey := range p.activeReport.Columns {
val := task.GetString(colKey)
row[j] = val
widths[j] = max(widths[j], lipgloss.Width(val))
}
taskRows[i] = row
taskStyles[i] = common.GetTaskTabelStyle(task, *p.common)
}
var columns []table.Column
for j, w := range widths {
title := p.activeReport.Labels[j]
width := 0
if w > 0 {
width = max(w, lipgloss.Width(title))
}
columns = append(columns, table.Column{
Title: title,
Width: width,
})
}
if len(columns) > 0 {
usedWidth := 0
for i := 0; i < len(columns)-1; i++ {
usedWidth += columns[i].Width + 1 // padding/border offset
}
remaining := p.taskTable.Width() - usedWidth - 1
lastIdx := len(columns) - 1
columns[lastIdx].Width = max(columns[lastIdx].Width, remaining)
}
p.taskTable = table.New(
table.WithColumns(columns),
table.WithRows(taskRows),
table.WithRowStyles(taskStyles),
table.WithFocused(true),
table.WithWidth(baseWidth),
table.WithHeight(tableHeight),
table.WithStyles(table.Styles{
Header: p.common.Styles.TableStyle.Header ,
Cell: p.common.Styles.TableStyle.Cell,
Selected: p.common.Styles.TableStyle.Selected,
}),
)
if selected == 0 {
selected = p.taskTable.Cursor()
}
if selected < len(tasks) {
p.taskTable.SetCursor(selected)
} 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 *TaskPage) getTasks() tea.Cmd {
return func() tea.Msg {
filters := []string{}