mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-574: Change display of Jira columns.
- Single-word status is now shown - All columns are now of equal width - Issue type and issue status columns are now trimmed to a certain max length (7 and 14 characters, respectively).
This commit is contained in:
parent
c3a54de181
commit
35797d2db6
@ -2,7 +2,6 @@ package jira
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/rivo/tview"
|
||||
"github.com/wtfutil/wtf/utils"
|
||||
"github.com/wtfutil/wtf/view"
|
||||
@ -68,26 +67,35 @@ func (widget *Widget) openItem() {
|
||||
}
|
||||
}
|
||||
|
||||
const MaxIssueTypeLength = 7
|
||||
const MaxStatusNameLength = 14
|
||||
|
||||
func (widget *Widget) content() (string, string, bool) {
|
||||
if widget.err != nil {
|
||||
return widget.CommonSettings().Title, widget.err.Error(), true
|
||||
}
|
||||
|
||||
title := fmt.Sprintf("%s- [green]%s[white]", widget.CommonSettings().Title, widget.settings.projects)
|
||||
|
||||
str := " [red]Assigned Issues[white]\n"
|
||||
|
||||
if widget.result == nil || len(widget.result.Issues) == 0 {
|
||||
return title, "No results to display", false
|
||||
}
|
||||
|
||||
longestIssueTypeLength, longestKeyLength, longestStatusNameLength := getLongestColumnLengths(widget.result.Issues)
|
||||
|
||||
for idx, issue := range widget.result.Issues {
|
||||
row := fmt.Sprintf(
|
||||
`[%s] [%s]%-6s[white] [green]%-10s[white] [yellow][%s][white] [%s]%s`,
|
||||
`[%s] [%s]%-*s[white] [green]%-*s[white] [yellow]%-*s[white] [%s]%s`,
|
||||
widget.RowColor(idx),
|
||||
widget.issueTypeColor(&issue),
|
||||
issue.IssueFields.IssueType.Name,
|
||||
longestIssueTypeLength+1,
|
||||
trimToMaxLength(issue.IssueFields.IssueType.Name, MaxIssueTypeLength),
|
||||
longestKeyLength+1,
|
||||
issue.Key,
|
||||
issue.IssueFields.IssueStatus.IName,
|
||||
longestStatusNameLength+1,
|
||||
trimToMaxLength(issue.IssueFields.IssueStatus.IName, MaxStatusNameLength),
|
||||
widget.RowColor(idx),
|
||||
issue.IssueFields.Summary,
|
||||
)
|
||||
@ -98,6 +106,38 @@ func (widget *Widget) content() (string, string, bool) {
|
||||
return title, str, false
|
||||
}
|
||||
|
||||
func getLongestColumnLengths(issues []Issue) (int, int, int) {
|
||||
longestIssueTypeLength := 0
|
||||
longestKeyLength := 0
|
||||
longestStatusNameLength := 0
|
||||
for _, issue := range issues {
|
||||
issueTypeLength := len(issue.IssueFields.IssueType.Name)
|
||||
if issueTypeLength > longestIssueTypeLength {
|
||||
longestIssueTypeLength = issueTypeLength
|
||||
}
|
||||
|
||||
issueKeyLength := len(issue.Key)
|
||||
if issueKeyLength > longestKeyLength {
|
||||
longestKeyLength = len("WTF-XXX") // issueKeyLength
|
||||
}
|
||||
|
||||
statusNameLength := len(issue.IssueFields.IssueStatus.IName)
|
||||
if statusNameLength > longestStatusNameLength {
|
||||
longestStatusNameLength = statusNameLength
|
||||
}
|
||||
}
|
||||
|
||||
if longestIssueTypeLength > MaxIssueTypeLength {
|
||||
longestIssueTypeLength = MaxIssueTypeLength
|
||||
}
|
||||
|
||||
if longestStatusNameLength > MaxStatusNameLength {
|
||||
longestStatusNameLength = MaxStatusNameLength
|
||||
}
|
||||
|
||||
return longestIssueTypeLength, longestKeyLength, longestStatusNameLength
|
||||
}
|
||||
|
||||
func (widget *Widget) issueTypeColor(issue *Issue) string {
|
||||
switch issue.IssueFields.IssueType.Name {
|
||||
case "Bug":
|
||||
@ -110,3 +150,11 @@ func (widget *Widget) issueTypeColor(issue *Issue) string {
|
||||
return "white"
|
||||
}
|
||||
}
|
||||
|
||||
func trimToMaxLength(text string, maxLength int) string {
|
||||
if len(text) <= maxLength {
|
||||
return text
|
||||
} else {
|
||||
return text[:maxLength]
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user