1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Merge pull request #591 from lesteenman/WTF-574-change-jira-status-layout

WTF-574: Change display of Jira columns.
This commit is contained in:
Chris Cummer 2019-09-02 16:03:00 -07:00 committed by GitHub
commit d0095f9e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,7 +2,6 @@ package jira
import (
"fmt"
"github.com/rivo/tview"
"github.com/wtfutil/wtf/utils"
"github.com/wtfutil/wtf/view"
@ -69,26 +68,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,
)
@ -99,6 +107,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":
@ -111,3 +151,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]
}
}