1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/jira/widget.go
Chris Cummer 037c90db85 Widget#focus now a thing
Widgets can inform whether or not they should get tab focus.

Widgets that provide additional functionality should return true.

Widgets that have no extra capability should return false.

This allows the FocusTracker to only tab through and focus on widgets
for which it provides value.
2018-04-28 23:41:51 -07:00

90 lines
1.7 KiB
Go

package jira
import (
"fmt"
"time"
"github.com/olebedev/config"
"github.com/senorprogrammer/wtf/wtf"
)
// Config is a pointer to the global config object
var Config *config.Config
type Widget struct {
wtf.TextWidget
}
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget("JIRA", "jira", false),
}
return &widget
}
/* -------------------- Exported Functions -------------------- */
func (widget *Widget) Refresh() {
if widget.Disabled() {
return
}
searchResult, err := IssuesFor(Config.UString("wtf.mods.jira.username"))
widget.View.Clear()
if err != nil {
widget.View.SetWrap(true)
widget.View.SetTitle(fmt.Sprintf(" %s ", widget.Name))
fmt.Fprintf(widget.View, "%v", err)
} else {
widget.View.SetWrap(false)
widget.View.SetTitle(
fmt.Sprintf(
" %s: [green]%s[white] ",
widget.Name,
Config.UString("wtf.mods.jira.project"),
),
)
fmt.Fprintf(widget.View, "%s", widget.contentFrom(searchResult))
}
widget.RefreshedAt = time.Now()
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) contentFrom(searchResult *SearchResult) string {
str := " [red]Assigned Issues[white]\n"
for _, issue := range searchResult.Issues {
str = str + fmt.Sprintf(
" [%s]%-6s[white] [green]%-10s[white] %s\n",
widget.issueTypeColor(&issue),
issue.IssueFields.IssueType.Name,
issue.Key,
issue.IssueFields.Summary,
)
}
return str
}
func (widget *Widget) issueTypeColor(issue *Issue) string {
var color string
switch issue.IssueFields.IssueType.Name {
case "Bug":
color = "red"
case "Story":
color = "blue"
case "Task":
color = "orange"
default:
color = "white"
}
return color
}