1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
This commit is contained in:
Chris Cummer 2018-07-11 17:47:05 -07:00
commit 35c2e088e0
9 changed files with 147 additions and 25 deletions

View File

@ -86,8 +86,8 @@
branch = "master"
[[constraint]]
branch = "master"
name = "github.com/darkSasori/todoist"
branch = "master"
[prune]
go-tests = true

View File

@ -208,6 +208,7 @@ wtf:
cityids:
- 3370352
- 1283240
WTF_OWM_API_KEY: [YOUR API KEY]
colors:
current: "lightblue"
enabled: true

View File

@ -21,7 +21,20 @@ wtf/jira/
## Keyboard Commands
None.
<span class="caption">Key:</span> `[return]` <br />
<span class="caption">Action:</span> Open the selected issue in the browser.
<span class="caption">Key:</span> `j` <br />
<span class="caption">Action:</span> Select the next item in the list.
<span class="caption">Key:</span> `k` <br />
<span class="caption">Action:</span> Select the previous item in the list.
<span class="caption">Key:</span> `↓` <br />
<span class="caption">Action:</span> Select the next item in the list.
<span class="caption">Key:</span> `↑` <br />
<span class="caption">Action:</span> Select the previous item in the list.
## Configuration

View File

@ -310,9 +310,11 @@ Key: j Action: Select the next item in the list.</description>
<guid>https://wtfutil.com/posts/modules/jira/</guid>
<description>Displays all Jira issues assigned to you for the specified project.
Source Code wtf/jira/ Required ENV Variables Key: WTF_JIRA_API_KEY Value: Your Jira API key.
Keyboard Commands None.
Configuration Single Jira Project jira:colors:rows:even:&amp;#34;lightblue&amp;#34;odd:&amp;#34;white&amp;#34;domain:&amp;#34;https://umbrellacorp.atlassian.net&amp;#34;email:&amp;#34;chriscummer@me.com&amp;#34;enabled:truejql:&amp;#34;issueType = Story&amp;#34;position:top:4left:1height:1width:2project:&amp;#34;ProjectA&amp;#34;refreshInterval:900username:&amp;#34;chris.cummer&amp;#34;verifyServerCertificate:true Multiple Jira Projects If you want to monitor multiple Jira projects, use the following configuration (note the difference in project):
jira:colors:rows:even:&amp;#34;lightblue&amp;#34;odd:&amp;#34;white&amp;#34;domain:&amp;#34;https://umbrellacorp.atlassian.net&amp;#34;email:&amp;#34;chriscummer@me.com&amp;#34;enabled:truejql:&amp;#34;issueType = Story&amp;#34;position:top:4left:1height:1width:2project:[&amp;#34;ProjectA&amp;#34;,&amp;#34;ProjectB&amp;#34;]refreshInterval:900username:&amp;#34;chris.cummer&amp;#34;verifyServerCertificate:true Attributes colors.rows.even Define the foreground color for even-numbered rows. Values: Any X11 color name.</description>
Keyboard Commands Key: [return] Action: Open the selected issue in the browser.
Key: j Action: Select the next item in the list.
Key: k Action: Select the previous item in the list.
Key: ↓ Action: Select the next item in the list.
Key: ↑ Action: Select the previous item in the list.</description>
</item>
<item>

View File

@ -310,9 +310,11 @@ Key: j Action: Select the next item in the list.</description>
<guid>https://wtfutil.com/posts/modules/jira/</guid>
<description>Displays all Jira issues assigned to you for the specified project.
Source Code wtf/jira/ Required ENV Variables Key: WTF_JIRA_API_KEY Value: Your Jira API key.
Keyboard Commands None.
Configuration Single Jira Project jira:colors:rows:even:&amp;#34;lightblue&amp;#34;odd:&amp;#34;white&amp;#34;domain:&amp;#34;https://umbrellacorp.atlassian.net&amp;#34;email:&amp;#34;chriscummer@me.com&amp;#34;enabled:truejql:&amp;#34;issueType = Story&amp;#34;position:top:4left:1height:1width:2project:&amp;#34;ProjectA&amp;#34;refreshInterval:900username:&amp;#34;chris.cummer&amp;#34;verifyServerCertificate:true Multiple Jira Projects If you want to monitor multiple Jira projects, use the following configuration (note the difference in project):
jira:colors:rows:even:&amp;#34;lightblue&amp;#34;odd:&amp;#34;white&amp;#34;domain:&amp;#34;https://umbrellacorp.atlassian.net&amp;#34;email:&amp;#34;chriscummer@me.com&amp;#34;enabled:truejql:&amp;#34;issueType = Story&amp;#34;position:top:4left:1height:1width:2project:[&amp;#34;ProjectA&amp;#34;,&amp;#34;ProjectB&amp;#34;]refreshInterval:900username:&amp;#34;chris.cummer&amp;#34;verifyServerCertificate:true Attributes colors.rows.even Define the foreground color for even-numbered rows. Values: Any X11 color name.</description>
Keyboard Commands Key: [return] Action: Open the selected issue in the browser.
Key: j Action: Select the next item in the list.
Key: k Action: Select the previous item in the list.
Key: ↓ Action: Select the next item in the list.
Key: ↑ Action: Select the previous item in the list.</description>
</item>
<item>

View File

@ -148,7 +148,20 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<h2 id="keyboard-commands">Keyboard Commands</h2>
<p>None.</p>
<p><span class="caption">Key:</span> <code>[return]</code> <br />
<span class="caption">Action:</span> Open the selected issue in the browser.</p>
<p><span class="caption">Key:</span> <code>j</code> <br />
<span class="caption">Action:</span> Select the next item in the list.</p>
<p><span class="caption">Key:</span> <code>k</code> <br />
<span class="caption">Action:</span> Select the previous item in the list.</p>
<p><span class="caption">Key:</span> <code></code> <br />
<span class="caption">Action:</span> Select the next item in the list.</p>
<p><span class="caption">Key:</span> <code></code> <br />
<span class="caption">Action:</span> Select the previous item in the list.</p>
<h2 id="configuration">Configuration</h2>

View File

@ -156,7 +156,11 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<span class="caption">Action:</span> Show the previous project.</p>
<p><span class="caption">Key:</span> <code></code> <br />
<<<<<<< HEAD
<span class="caption">Action:</span←> Show the previous project.</p>
=======
<span class="caption">Action:</span> Show the previous project.</p>
>>>>>>> baustinanki-make-jira-interactable
<p><span class="caption">Key:</span> <code>l</code> <br />
<span class="caption">Action:</span> Show the next project.</p>

View File

@ -3,18 +3,24 @@ package jira
import (
"fmt"
"github.com/gdamore/tcell"
"github.com/senorprogrammer/wtf/wtf"
)
type Widget struct {
wtf.TextWidget
result *SearchResult
selected int
}
func NewWidget() *Widget {
widget := Widget{
TextWidget: wtf.NewTextWidget(" Jira ", "jira", false),
TextWidget: wtf.NewTextWidget(" Jira ", "jira", true),
}
widget.unselect()
widget.View.SetInputCapture(widget.keyboardIntercept)
return &widget
}
@ -29,38 +35,71 @@ func (widget *Widget) Refresh() {
widget.UpdateRefreshedAt()
var content string
if err != nil {
widget.result = nil
widget.View.SetWrap(true)
widget.View.SetTitle(widget.Name)
content = err.Error()
widget.View.SetText(err.Error())
} else {
widget.View.SetWrap(false)
widget.View.SetTitle(
fmt.Sprintf(
"%s- [green]%s[white]",
widget.Name,
wtf.Config.UString("wtf.mods.jira.project"),
),
)
content = widget.contentFrom(searchResult)
widget.result = searchResult
}
widget.View.SetText(content)
widget.display()
}
/* -------------------- Unexported Functions -------------------- */
func (widget *Widget) display() {
if widget.result == nil {
return
}
widget.View.SetWrap(false)
widget.View.SetTitle(
fmt.Sprintf(
"%s- [green]%s[white]",
widget.Name,
wtf.Config.UString("wtf.mods.jira.project"),
),
)
widget.View.SetText(fmt.Sprintf("%s", widget.contentFrom(widget.result)))
}
func (widget *Widget) next() {
widget.selected++
if widget.result != nil && widget.selected >= len(widget.result.Issues) {
widget.selected = 0
}
}
func (widget *Widget) prev() {
widget.selected--
if widget.selected < 0 && widget.result != nil {
widget.selected = len(widget.result.Issues) - 1
}
}
func (widget *Widget) openItem() {
sel := widget.selected
if sel >= 0 && widget.result != nil && sel < len(widget.result.Issues) {
issue := &widget.result.Issues[widget.selected]
wtf.OpenFile(wtf.Config.UString("wtf.mods.jira.domain") + "/browse/" + issue.Key)
}
}
func (widget *Widget) unselect() {
widget.selected = -1
}
func (widget *Widget) contentFrom(searchResult *SearchResult) string {
str := " [red]Assigned Issues[white]\n"
for idx, issue := range searchResult.Issues {
str = str + fmt.Sprintf(
" [%s]%-6s[white] [green]%-10s[%s] %s\n",
" [%s]%-6s[white] [green]%-10s [%s]%s\n",
widget.issueTypeColor(&issue),
issue.IssueFields.IssueType.Name,
issue.Key,
wtf.RowColor("jira", idx),
widget.rowColor(idx),
issue.IssueFields.Summary,
)
}
@ -68,6 +107,15 @@ func (widget *Widget) contentFrom(searchResult *SearchResult) string {
return str
}
func (widget *Widget) rowColor(idx int) string {
if widget.View.HasFocus() && (idx == widget.selected) {
foreColor := wtf.Config.UString("wtf.mods.jira.colors.highlight.fore", "black")
backColor := wtf.Config.UString("wtf.mods.jira.colors.highlight.back", "white")
return fmt.Sprintf("%s:%s", foreColor, backColor)
}
return wtf.RowColor("jira", idx)
}
func (widget *Widget) issueTypeColor(issue *Issue) string {
switch issue.IssueFields.IssueType.Name {
case "Bug":
@ -98,3 +146,42 @@ func getProjects() []string {
}
return ret
}
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
switch string(event.Rune()) {
case "j":
// Select the next item down
widget.next()
widget.display()
return nil
case "k":
// Select the next item up
widget.prev()
widget.display()
return nil
}
switch event.Key() {
case tcell.KeyDown:
// Select the next item down
widget.next()
widget.display()
return nil
case tcell.KeyEnter:
widget.openItem()
return nil
case tcell.KeyEsc:
// Unselect the current row
widget.unselect()
widget.display()
return event
case tcell.KeyUp:
// Select the next item up
widget.prev()
widget.display()
return nil
default:
// Pass it along
return event
}
}

View File

@ -48,7 +48,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
}
if widget.APIKey == "" {
logger.Log("loading weather WTF_OWM_API_KEY key from config")
logger.Log("loading weather API key from config")
widget.APIKey = wtf.Config.UString(fmt.Sprintf("wtf.mods.%s.apiKey", configKey), "")
}