[WIP] Task editing

This commit is contained in:
Martin
2024-05-24 06:51:06 +02:00
parent fe00170a5c
commit 1086b19765
7 changed files with 334 additions and 16 deletions

View File

@ -1,6 +1,8 @@
// TODO: update table every second (to show correct relative time)
package pages
import (
"strings"
"tasksquire/common"
"tasksquire/taskwarrior"
@ -161,7 +163,7 @@ func (p *ReportPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
cmds = append(cmds, cmd)
if p.tasks != nil && len(p.tasks) > 0 {
p.selectedTask = (*taskwarrior.Task)(p.tasks[p.taskTable.Cursor()])
p.selectedTask = p.tasks[p.taskTable.Cursor()]
} else {
p.selectedTask = nil
}
@ -185,6 +187,7 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
columnSizes := make([]int, nCols)
fullRows := make([]table.Row, len(tasks))
rows := make([]table.Row, len(tasks))
descIndex := -1
for i, task := range tasks {
if p.selectedTask != nil && task.Uuid == p.selectedTask.Uuid {
@ -193,6 +196,9 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
row := table.Row{}
for i, col := range p.activeReport.Columns {
if strings.Contains(col, "description") {
descIndex = i
}
field := task.GetString(col)
columnSizes[i] = max(columnSizes[i], len(field))
row = append(row, field)
@ -211,12 +217,24 @@ func (p *ReportPage) populateTaskTable(tasks taskwarrior.Tasks) {
rows[i] = row
}
combinedSize := 0
for i, label := range p.activeReport.Labels {
if columnSizes[i] == 0 {
continue
}
columns = append(columns, table.Column{Title: label, Width: max(columnSizes[i], len(label))})
width := max(columnSizes[i], len(label))
columns = append(columns, table.Column{Title: label, Width: width})
if i == descIndex {
descIndex = len(columns) - 1
continue
}
combinedSize += width
}
if descIndex >= 0 {
columns[descIndex].Width = p.taskTable.Width() - combinedSize - 14
}
if selected == 0 {

View File

@ -105,6 +105,7 @@ func NewTaskEditorPage(common *common.Common, task taskwarrior.Task) *TaskEditor
huh.NewMultiSelect[string]().
Options(huh.NewOptions(tagOptions...)...).
// Key("tags").
Title("Tags").
Value(&p.task.Tags),
@ -245,6 +246,8 @@ func (p *TaskEditorPage) updateTasksCmd() tea.Msg {
if p.additionalProject != "" {
p.task.Project = p.additionalProject
}
// tags := p.form.Get("tags").([]string)
// p.task.Tags = tags
p.common.TW.ImportTask(&p.task)
return UpdatedTasksMsg{}
}