mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* WTF-730 Fix missing color key config error Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-730 Add Subheading color formatting to modules Users can now set a `subheading` color in their config to change the color of subheadings in widget display. Defaults to `red`. Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-730 Fix oustanding color issues Clean up missing color config changes not addressed in earlier commits. Signed-off-by: Chris Cummer <chriscummer@me.com> * Remove unused dependency Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-730 Base cleanup Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-730 Fix a few bugs related to color config changes Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-730 Fix issues with PagerDuty subheading display Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-730 Fix bug with Todo list colour rendering Signed-off-by: Chris Cummer <chriscummer@me.com>
106 lines
2.8 KiB
Go
106 lines
2.8 KiB
Go
package zendesk
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/rivo/tview"
|
|
"github.com/wtfutil/wtf/utils"
|
|
"github.com/wtfutil/wtf/view"
|
|
)
|
|
|
|
// A Widget represents a Zendesk widget
|
|
type Widget struct {
|
|
view.KeyboardWidget
|
|
view.ScrollableWidget
|
|
|
|
result *TicketArray
|
|
settings *Settings
|
|
err error
|
|
}
|
|
|
|
// NewWidget creates a new instance of a widget
|
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
|
widget := Widget{
|
|
KeyboardWidget: view.NewKeyboardWidget(app, pages, settings.common),
|
|
ScrollableWidget: view.NewScrollableWidget(app, settings.common),
|
|
|
|
settings: settings,
|
|
}
|
|
|
|
widget.SetRenderFunction(widget.Render)
|
|
widget.initializeKeyboardControls()
|
|
widget.View.SetInputCapture(widget.InputCapture)
|
|
|
|
widget.KeyboardWidget.SetView(widget.View)
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
ticketArray, err := widget.newTickets()
|
|
ticketArray.Count = len(ticketArray.Tickets)
|
|
widget.err = err
|
|
widget.result = ticketArray
|
|
widget.Render()
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) Render() {
|
|
widget.Redraw(widget.content)
|
|
}
|
|
|
|
func (widget *Widget) content() (string, string, bool) {
|
|
title := fmt.Sprintf("%s (%d)", widget.CommonSettings().Title, widget.result.Count)
|
|
if widget.err != nil {
|
|
return title, widget.err.Error(), true
|
|
}
|
|
|
|
items := widget.result.Tickets
|
|
if len(items) == 0 {
|
|
return title, "No unassigned tickets in queue - woop!!", false
|
|
}
|
|
|
|
str := ""
|
|
for idx, data := range items {
|
|
str += widget.format(data, idx)
|
|
}
|
|
|
|
return title, str, false
|
|
}
|
|
|
|
func (widget *Widget) format(ticket Ticket, idx int) string {
|
|
textColor := widget.settings.common.Colors.Background
|
|
if idx == widget.GetSelected() {
|
|
textColor = widget.settings.common.Colors.BorderTheme.Focused
|
|
}
|
|
|
|
requesterName := widget.parseRequester(ticket)
|
|
str := fmt.Sprintf(" [%s:]%d - %s\n %s\n\n", textColor, ticket.Id, requesterName, ticket.Subject)
|
|
return str
|
|
}
|
|
|
|
// this is a nasty means of extracting the actual name of the requester from the Via interface of the Ticket.
|
|
// very very open to improvements on this
|
|
func (widget *Widget) parseRequester(ticket Ticket) interface{} {
|
|
viaMap := ticket.Via
|
|
via := viaMap.(map[string]interface{})
|
|
source := via["source"]
|
|
fromMap, _ := source.(map[string]interface{})
|
|
from := fromMap["from"]
|
|
fromValMap := from.(map[string]interface{})
|
|
fromName := fromValMap["name"]
|
|
return fromName
|
|
}
|
|
|
|
func (widget *Widget) openTicket() {
|
|
sel := widget.GetSelected()
|
|
if sel >= 0 && widget.result != nil && sel < len(widget.result.Tickets) {
|
|
issue := &widget.result.Tickets[sel]
|
|
ticketURL := fmt.Sprintf("https://%s.zendesk.com/agent/tickets/%d", widget.settings.subdomain, issue.Id)
|
|
utils.OpenFile(ticketURL)
|
|
}
|
|
}
|