Add things
This commit is contained in:
@ -30,6 +30,8 @@ type TimeEditorPage struct {
|
||||
selectedProject string
|
||||
currentField int
|
||||
totalFields int
|
||||
uuid string // Preserved UUID tag
|
||||
track string // Preserved track tag (if present)
|
||||
}
|
||||
|
||||
type timeEditorProjectSelectedMsg struct {
|
||||
@ -37,9 +39,19 @@ type timeEditorProjectSelectedMsg struct {
|
||||
}
|
||||
|
||||
func NewTimeEditorPage(com *common.Common, interval *timewarrior.Interval) *TimeEditorPage {
|
||||
// Extract project from tags if it exists
|
||||
projects := com.TW.GetProjects()
|
||||
selectedProject, remainingTags := extractProjectFromTags(interval.Tags, projects)
|
||||
// Extract special tags (uuid, project, track) and display tags
|
||||
uuid, selectedProject, track, displayTags := extractSpecialTags(interval.Tags)
|
||||
|
||||
// If UUID exists, fetch the task and add its title to display tags
|
||||
if uuid != "" {
|
||||
tasks := com.TW.GetTasks(nil, "uuid:"+uuid)
|
||||
if len(tasks) > 0 {
|
||||
taskTitle := tasks[0].Description
|
||||
// Add to display tags if not already present
|
||||
// Note: formatTags() will handle quoting for display, so we store the raw title
|
||||
displayTags = ensureTagPresent(displayTags, taskTitle)
|
||||
}
|
||||
}
|
||||
|
||||
// Create project picker with onCreate support for new projects
|
||||
projectItemProvider := func() []list.Item {
|
||||
@ -99,7 +111,7 @@ func NewTimeEditorPage(com *common.Common, interval *timewarrior.Interval) *Time
|
||||
|
||||
tagsInput := autocomplete.New(tagCombinations, 3, 10)
|
||||
tagsInput.SetPlaceholder("Space separated, use \"\" for tags with spaces")
|
||||
tagsInput.SetValue(formatTags(remainingTags)) // Use remaining tags (without project)
|
||||
tagsInput.SetValue(formatTags(displayTags)) // Use display tags only (no uuid, project, track)
|
||||
tagsInput.SetWidth(50)
|
||||
|
||||
p := &TimeEditorPage{
|
||||
@ -113,6 +125,8 @@ func NewTimeEditorPage(com *common.Common, interval *timewarrior.Interval) *Time
|
||||
selectedProject: selectedProject,
|
||||
currentField: 0,
|
||||
totalFields: 5, // Now 5 fields: project, tags, start, end, adjust
|
||||
uuid: uuid,
|
||||
track: track,
|
||||
}
|
||||
|
||||
return p
|
||||
@ -365,23 +379,27 @@ func (p *TimeEditorPage) saveInterval() {
|
||||
p.interval.Start = p.startEditor.GetValueString()
|
||||
p.interval.End = p.endEditor.GetValueString()
|
||||
|
||||
// Parse tags from input
|
||||
tags := parseTags(p.tagsInput.GetValue())
|
||||
// Parse display tags from input
|
||||
displayTags := parseTags(p.tagsInput.GetValue())
|
||||
|
||||
// Add project to tags if not already present
|
||||
if p.selectedProject != "" {
|
||||
projectTag := "project:" + p.selectedProject
|
||||
projectExists := false
|
||||
for _, tag := range tags {
|
||||
if tag == projectTag {
|
||||
projectExists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !projectExists {
|
||||
tags = append([]string{projectTag}, tags...) // Prepend project tag
|
||||
}
|
||||
// Reconstruct full tags array by combining special tags and display tags
|
||||
var tags []string
|
||||
|
||||
// Add preserved special tags first
|
||||
if p.uuid != "" {
|
||||
tags = append(tags, "uuid:"+p.uuid)
|
||||
}
|
||||
if p.track != "" {
|
||||
tags = append(tags, p.track)
|
||||
}
|
||||
|
||||
// Add project tag
|
||||
if p.selectedProject != "" {
|
||||
tags = append(tags, "project:"+p.selectedProject)
|
||||
}
|
||||
|
||||
// Add display tags (user-entered tags from the input field)
|
||||
tags = append(tags, displayTags...)
|
||||
|
||||
p.interval.Tags = tags
|
||||
|
||||
@ -427,30 +445,39 @@ func formatTags(tags []string) string {
|
||||
return strings.Join(formatted, " ")
|
||||
}
|
||||
|
||||
// extractSpecialTags separates special tags (uuid, project, track) from display tags
|
||||
// Returns uuid, project, track as separate strings, and displayTags for user editing
|
||||
func extractSpecialTags(tags []string) (uuid, project, track string, displayTags []string) {
|
||||
for _, tag := range tags {
|
||||
if strings.HasPrefix(tag, "uuid:") {
|
||||
uuid = strings.TrimPrefix(tag, "uuid:")
|
||||
} else if strings.HasPrefix(tag, "project:") {
|
||||
project = strings.TrimPrefix(tag, "project:")
|
||||
} else if tag == "track" {
|
||||
track = tag
|
||||
} else {
|
||||
displayTags = append(displayTags, tag)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// extractProjectFromTags finds and removes the first tag that matches a known project
|
||||
// Returns the found project (or empty string) and the remaining tags
|
||||
// This is kept for backward compatibility but now uses extractSpecialTags internally
|
||||
func extractProjectFromTags(tags []string, projects []string) (string, []string) {
|
||||
projectSet := make(map[string]bool)
|
||||
for _, p := range projects {
|
||||
projectSet[p] = true
|
||||
}
|
||||
_, project, _, remaining := extractSpecialTags(tags)
|
||||
return project, remaining
|
||||
}
|
||||
|
||||
var foundProject string
|
||||
var remaining []string
|
||||
|
||||
for _, tag := range tags {
|
||||
// Check if this tag is a project tag (format: "project:projectname")
|
||||
if strings.HasPrefix(tag, "project:") {
|
||||
projectName := strings.TrimPrefix(tag, "project:")
|
||||
if foundProject == "" && projectSet[projectName] {
|
||||
foundProject = projectName // First matching project
|
||||
continue // Don't add to remaining tags
|
||||
}
|
||||
// ensureTagPresent adds a tag to the list if not already present
|
||||
func ensureTagPresent(tags []string, tag string) []string {
|
||||
for _, t := range tags {
|
||||
if t == tag {
|
||||
return tags // Already present
|
||||
}
|
||||
remaining = append(remaining, tag)
|
||||
}
|
||||
|
||||
return foundProject, remaining
|
||||
return append(tags, tag)
|
||||
}
|
||||
|
||||
// filterTagCombinationsByProject filters tag combinations to only show those
|
||||
|
||||
Reference in New Issue
Block a user