mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
commit
d5056bc3fc
@ -66,17 +66,17 @@ func listTickets(pag ...string) (*TicketArray, error) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newTickets(ticketStatus string) ([]Ticket, error) {
|
func newTickets(ticketStatus string) (*TicketArray, error) {
|
||||||
newTickets := []Ticket{}
|
newTicketArray := &TicketArray{}
|
||||||
tickets, err := listTickets()
|
tickets, err := listTickets()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
for _, Ticket := range tickets.Tickets {
|
for _, Ticket := range tickets.Tickets {
|
||||||
if Ticket.Status == ticketStatus && Ticket.Status != "closed" && Ticket.Status != "solved" {
|
if Ticket.Status == ticketStatus && Ticket.Status != "closed" && Ticket.Status != "solved" {
|
||||||
newTickets = append(newTickets, Ticket)
|
newTicketArray.Tickets = append(newTicketArray.Tickets, Ticket)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newTickets, nil
|
return newTicketArray, nil
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,9 @@ import (
|
|||||||
|
|
||||||
type Widget struct {
|
type Widget struct {
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
|
result *TicketArray
|
||||||
|
selected int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget() *Widget {
|
func NewWidget() *Widget {
|
||||||
@ -26,36 +29,46 @@ func NewWidget() *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
ticketStatus := wtf.Config.UString("wtf.mods.zendesk.status")
|
ticketStatus := wtf.Config.UString("wtf.mods.zendesk.status")
|
||||||
tickets, err := newTickets(ticketStatus)
|
ticketArray, err := newTickets(ticketStatus)
|
||||||
|
ticketArray.Count = len(ticketArray.Tickets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
|
} else {
|
||||||
|
widget.result = ticketArray
|
||||||
}
|
}
|
||||||
widget.UpdateRefreshedAt()
|
widget.UpdateRefreshedAt()
|
||||||
|
|
||||||
widget.View.SetTitle(fmt.Sprintf("%s (%d)", widget.Name, len(tickets)))
|
widget.display()
|
||||||
widget.View.SetText(widget.textContent(tickets))
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func (widget *Widget) display() {
|
||||||
|
widget.View.SetTitle(fmt.Sprintf("%s (%d)", widget.Name, widget.result.Count))
|
||||||
|
widget.View.SetText(widget.textContent(widget.result.Tickets))
|
||||||
|
}
|
||||||
|
|
||||||
func (widget *Widget) textContent(items []Ticket) string {
|
func (widget *Widget) textContent(items []Ticket) string {
|
||||||
if len(items) == 0 {
|
if len(items) == 0 {
|
||||||
return fmt.Sprintf("No unassigned tickets in queue - woop!!")
|
return fmt.Sprintf("No unassigned tickets in queue - woop!!")
|
||||||
}
|
}
|
||||||
|
|
||||||
str := ""
|
str := ""
|
||||||
for _, data := range items {
|
for idx, data := range items {
|
||||||
str = str + widget.format(data)
|
str = str + widget.format(data, idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) format(ticket Ticket) string {
|
func (widget *Widget) format(ticket Ticket, idx int) string {
|
||||||
var str string
|
var str string
|
||||||
requesterName := widget.parseRequester(ticket)
|
requesterName := widget.parseRequester(ticket)
|
||||||
str = fmt.Sprintf(" [green]%d - %s\n %s\n\n", ticket.Id, requesterName, ticket.Subject)
|
textColor := wtf.Config.UString("wtf.colors.background", "green")
|
||||||
|
if idx == widget.selected {
|
||||||
|
textColor = wtf.Config.UString("wtf.colors.background", "orange")
|
||||||
|
}
|
||||||
|
str = fmt.Sprintf(" [%s:]%d - %s\n %s\n\n", textColor, ticket.Id, requesterName, ticket.Subject)
|
||||||
return str
|
return str
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,21 +85,71 @@ func (widget *Widget) parseRequester(ticket Ticket) interface{} {
|
|||||||
return fromName
|
return fromName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) next() {
|
||||||
|
widget.selected++
|
||||||
|
if widget.result != nil && widget.selected >= len(widget.result.Tickets) {
|
||||||
|
widget.selected = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) prev() {
|
||||||
|
widget.selected--
|
||||||
|
if widget.selected < 0 && widget.result != nil {
|
||||||
|
widget.selected = len(widget.result.Tickets) - 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (widget *Widget) openTicket() {
|
func (widget *Widget) openTicket() {
|
||||||
wtf.OpenFile("https://" + subdomain + ".zendesk.com")
|
sel := widget.selected
|
||||||
|
if sel >= 0 && widget.result != nil && sel < len(widget.result.Tickets) {
|
||||||
|
issue := &widget.result.Tickets[widget.selected]
|
||||||
|
ticketUrl := fmt.Sprintf("https://%s.zendesk.com/agent/tickets/%d", subdomain, issue.Id)
|
||||||
|
wtf.OpenFile(ticketUrl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (widget *Widget) unselect() {
|
||||||
|
widget.selected = -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
func (widget *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
||||||
switch string(event.Rune()) {
|
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
|
||||||
|
|
||||||
case "f":
|
case "f":
|
||||||
widget.openTicket()
|
widget.openTicket()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
switch event.Key() {
|
switch event.Key() {
|
||||||
|
/* case tcell.KeyDown:
|
||||||
|
// Select the next item down
|
||||||
|
widget.next()
|
||||||
|
widget.display()
|
||||||
|
return nil */
|
||||||
case tcell.KeyEnter:
|
case tcell.KeyEnter:
|
||||||
widget.openTicket()
|
widget.openTicket()
|
||||||
return nil
|
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:
|
default:
|
||||||
|
// Pass it along
|
||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user