mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge pull request #590 from Seanstoppable/errtidy
Refactor a number of widgets to display client errors
This commit is contained in:
commit
03733084e6
@ -15,6 +15,7 @@ type Widget struct {
|
|||||||
|
|
||||||
monitors []datadog.Monitor
|
monitors []datadog.Monitor
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
@ -37,10 +38,12 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
|
widget.err = nil
|
||||||
monitors, monitorErr := widget.Monitors()
|
monitors, monitorErr := widget.Monitors()
|
||||||
|
|
||||||
if monitorErr != nil {
|
if monitorErr != nil {
|
||||||
widget.monitors = nil
|
widget.monitors = nil
|
||||||
|
widget.err = monitorErr
|
||||||
widget.SetItemCount(0)
|
widget.SetItemCount(0)
|
||||||
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, monitorErr.Error(), true })
|
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, monitorErr.Error(), true })
|
||||||
return
|
return
|
||||||
@ -73,6 +76,12 @@ func (widget *Widget) content() (string, string, bool) {
|
|||||||
triggeredMonitors := widget.monitors
|
triggeredMonitors := widget.monitors
|
||||||
var str string
|
var str string
|
||||||
|
|
||||||
|
title := widget.CommonSettings().Title
|
||||||
|
|
||||||
|
if widget.err != nil {
|
||||||
|
return title, widget.err.Error(), true
|
||||||
|
}
|
||||||
|
|
||||||
if len(triggeredMonitors) > 0 {
|
if len(triggeredMonitors) > 0 {
|
||||||
str += fmt.Sprintf(
|
str += fmt.Sprintf(
|
||||||
" %s\n",
|
" %s\n",
|
||||||
@ -93,7 +102,7 @@ func (widget *Widget) content() (string, string, bool) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return widget.CommonSettings().Title, str, false
|
return title, str, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) openItem() {
|
func (widget *Widget) openItem() {
|
||||||
|
@ -31,6 +31,11 @@ func (widget *Widget) display() {
|
|||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
title := widget.settings.common.Title
|
title := widget.settings.common.Title
|
||||||
calEvents := widget.calEvents
|
calEvents := widget.calEvents
|
||||||
|
|
||||||
|
if widget.err != nil {
|
||||||
|
return title, widget.err.Error(), true
|
||||||
|
}
|
||||||
|
|
||||||
if (calEvents == nil) || (len(calEvents) == 0) {
|
if (calEvents == nil) || (len(calEvents) == 0) {
|
||||||
return title, "No calendar events", false
|
return title, "No calendar events", false
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ type Widget struct {
|
|||||||
app *tview.Application
|
app *tview.Application
|
||||||
calEvents []*CalEvent
|
calEvents []*CalEvent
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
@ -45,8 +46,10 @@ func (widget *Widget) Refresh() {
|
|||||||
func (widget *Widget) fetchAndDisplayEvents() {
|
func (widget *Widget) fetchAndDisplayEvents() {
|
||||||
calEvents, err := widget.Fetch()
|
calEvents, err := widget.Fetch()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
widget.err = err
|
||||||
widget.calEvents = []*CalEvent{}
|
widget.calEvents = []*CalEvent{}
|
||||||
} else {
|
} else {
|
||||||
|
widget.err = nil
|
||||||
widget.calEvents = calEvents
|
widget.calEvents = calEvents
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,13 +9,17 @@ func (widget *Widget) display() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := widget.CommonSettings().Title
|
||||||
|
if widget.err != nil {
|
||||||
|
return title, widget.err.Error(), true
|
||||||
|
}
|
||||||
|
|
||||||
project := widget.currentGerritProject()
|
project := widget.currentGerritProject()
|
||||||
if project == nil {
|
if project == nil {
|
||||||
return widget.CommonSettings().Title, "Gerrit project data is unavailable", true
|
return title, "Gerrit project data is unavailable", true
|
||||||
}
|
}
|
||||||
|
|
||||||
title := fmt.Sprintf("%s- %s", widget.CommonSettings().Title, widget.title(project))
|
title = fmt.Sprintf("%s- %s", widget.CommonSettings().Title, widget.title(project))
|
||||||
|
|
||||||
_, _, width, _ := widget.View.GetRect()
|
_, _, width, _ := widget.View.GetRect()
|
||||||
str := widget.settings.common.SigilStr(len(widget.GerritProjects), widget.Idx, width) + "\n"
|
str := widget.settings.common.SigilStr(len(widget.GerritProjects), widget.Idx, width) + "\n"
|
||||||
|
@ -23,6 +23,7 @@ type Widget struct {
|
|||||||
|
|
||||||
selected int
|
selected int
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -76,14 +77,16 @@ func (widget *Widget) Refresh() {
|
|||||||
}
|
}
|
||||||
gerrit, err := glb.NewClient(gerritUrl, httpClient)
|
gerrit, err := glb.NewClient(gerritUrl, httpClient)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
|
widget.err = err
|
||||||
return
|
widget.gerrit = nil
|
||||||
}
|
widget.GerritProjects = nil
|
||||||
widget.gerrit = gerrit
|
} else {
|
||||||
widget.GerritProjects = widget.buildProjectCollection(widget.settings.projects)
|
widget.err = nil
|
||||||
|
widget.gerrit = gerrit
|
||||||
for _, project := range widget.GerritProjects {
|
widget.GerritProjects = widget.buildProjectCollection(widget.settings.projects)
|
||||||
project.Refresh(widget.settings.username)
|
for _, project := range widget.GerritProjects {
|
||||||
|
project.Refresh(widget.settings.username)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.display()
|
widget.display()
|
||||||
|
@ -14,6 +14,7 @@ type Widget struct {
|
|||||||
|
|
||||||
settings *Settings
|
settings *Settings
|
||||||
cells []*sheets.ValueRange
|
cells []*sheets.ValueRange
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
||||||
@ -29,7 +30,8 @@ func NewWidget(app *tview.Application, settings *Settings) *Widget {
|
|||||||
/* -------------------- Exported Functions -------------------- */
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
cells, _ := widget.Fetch()
|
cells, err := widget.Fetch()
|
||||||
|
widget.err = err
|
||||||
widget.cells = cells
|
widget.cells = cells
|
||||||
|
|
||||||
widget.Redraw(widget.content)
|
widget.Redraw(widget.content)
|
||||||
@ -38,8 +40,13 @@ func (widget *Widget) Refresh() {
|
|||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
|
title := widget.CommonSettings().Title
|
||||||
|
if widget.err != nil {
|
||||||
|
return title, widget.err.Error(), true
|
||||||
|
}
|
||||||
|
|
||||||
if widget.cells == nil {
|
if widget.cells == nil {
|
||||||
return widget.CommonSettings().Title, "error 1", false
|
return title, "No cells", false
|
||||||
}
|
}
|
||||||
|
|
||||||
res := ""
|
res := ""
|
||||||
@ -49,5 +56,5 @@ func (widget *Widget) content() (string, string, bool) {
|
|||||||
res += fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, widget.cells[i].Values[0][0])
|
res += fmt.Sprintf("%s\t[%s]%s\n", cells[i], widget.settings.colors.values, widget.cells[i].Values[0][0])
|
||||||
}
|
}
|
||||||
|
|
||||||
return widget.CommonSettings().Title, res, false
|
return title, res, false
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ type Widget struct {
|
|||||||
|
|
||||||
stories []Story
|
stories []Story
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
|
||||||
@ -43,25 +44,22 @@ func (widget *Widget) Refresh() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
storyIds, err := GetStories(widget.settings.storyType)
|
storyIds, err := GetStories(widget.settings.storyType)
|
||||||
if storyIds == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
widget.Redraw(func() (string, string, bool) { return widget.CommonSettings().Title, err.Error(), true })
|
widget.err = err
|
||||||
return
|
widget.stories = nil
|
||||||
}
|
widget.SetItemCount(0)
|
||||||
var stories []Story
|
} else {
|
||||||
for idx := 0; idx < widget.settings.numberOfStories; idx++ {
|
var stories []Story
|
||||||
story, e := GetStory(storyIds[idx])
|
for idx := 0; idx < widget.settings.numberOfStories; idx++ {
|
||||||
if e == nil {
|
story, e := GetStory(storyIds[idx])
|
||||||
stories = append(stories, story)
|
if e == nil {
|
||||||
|
stories = append(stories, story)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
widget.stories = stories
|
||||||
|
widget.SetItemCount(len(stories))
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.stories = stories
|
|
||||||
widget.SetItemCount(len(stories))
|
|
||||||
|
|
||||||
widget.Render()
|
widget.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,6 +72,11 @@ func (widget *Widget) Render() {
|
|||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
title := fmt.Sprintf("%s - %s stories", widget.CommonSettings().Title, widget.settings.storyType)
|
title := fmt.Sprintf("%s - %s stories", widget.CommonSettings().Title, widget.settings.storyType)
|
||||||
|
|
||||||
|
if widget.err != nil {
|
||||||
|
return title, widget.err.Error(), true
|
||||||
|
}
|
||||||
|
|
||||||
stories := widget.stories
|
stories := widget.stories
|
||||||
if stories == nil || len(stories) == 0 {
|
if stories == nil || len(stories) == 0 {
|
||||||
return title, "No stories to display", false
|
return title, "No stories to display", false
|
||||||
|
@ -46,11 +46,12 @@ func (widget *Widget) Refresh() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
widget.err = err
|
widget.err = err
|
||||||
widget.result = nil
|
widget.result = nil
|
||||||
return
|
widget.SetItemCount(0)
|
||||||
|
} else {
|
||||||
|
widget.err = nil
|
||||||
|
widget.result = searchResult
|
||||||
|
widget.SetItemCount(len(searchResult.Issues))
|
||||||
}
|
}
|
||||||
widget.err = nil
|
|
||||||
widget.result = searchResult
|
|
||||||
widget.SetItemCount(len(searchResult.Issues))
|
|
||||||
widget.Render()
|
widget.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
widget.initializeKeyboardControls()
|
widget.initializeKeyboardControls()
|
||||||
widget.View.SetInputCapture(widget.InputCapture)
|
widget.View.SetInputCapture(widget.InputCapture)
|
||||||
|
|
||||||
widget.SetDisplayFunction(widget.display)
|
widget.SetDisplayFunction(widget.Refresh)
|
||||||
widget.View.SetWordWrap(true)
|
widget.View.SetWordWrap(true)
|
||||||
widget.View.SetWrap(settings.wrapText)
|
widget.View.SetWrap(settings.wrapText)
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
// Refresh is only called once on start-up. Its job is to display the
|
// Refresh is only called once on start-up. Its job is to display the
|
||||||
// text files that first time. After that, the watcher takes over
|
// text files that first time. After that, the watcher takes over
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.display()
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
@ -70,10 +70,6 @@ func (widget *Widget) HelpText() string {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
|
||||||
widget.Redraw(widget.content)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
title := fmt.Sprintf("[green]%s[white]", widget.CurrentSource())
|
title := fmt.Sprintf("[green]%s[white]", widget.CurrentSource())
|
||||||
|
|
||||||
@ -142,7 +138,7 @@ func (widget *Widget) watchForFileChanges() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-watch.Event:
|
case <-watch.Event:
|
||||||
widget.display()
|
widget.Refresh()
|
||||||
case err := <-watch.Error:
|
case err := <-watch.Error:
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -35,7 +35,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
widget.initializeKeyboardControls()
|
widget.initializeKeyboardControls()
|
||||||
widget.View.SetInputCapture(widget.InputCapture)
|
widget.View.SetInputCapture(widget.InputCapture)
|
||||||
|
|
||||||
widget.SetDisplayFunction(widget.display)
|
widget.SetDisplayFunction(widget.Refresh)
|
||||||
|
|
||||||
widget.client = NewClient(settings)
|
widget.client = NewClient(settings)
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
|
|
||||||
// Refresh is called on the interval and refreshes the data
|
// Refresh is called on the interval and refreshes the data
|
||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
widget.display()
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) HelpText() string {
|
func (widget *Widget) HelpText() string {
|
||||||
@ -61,10 +61,6 @@ func (widget *Widget) HelpText() string {
|
|||||||
|
|
||||||
/* -------------------- Unexported Functions -------------------- */
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
func (widget *Widget) display() {
|
|
||||||
widget.Redraw(widget.content)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
widget.client.screenName = widget.CurrentSource()
|
widget.client.screenName = widget.CurrentSource()
|
||||||
tweets := widget.client.Tweets()
|
tweets := widget.client.Tweets()
|
||||||
|
@ -36,13 +36,9 @@ func (widget *Widget) Refresh() {
|
|||||||
|
|
||||||
teams, err := Fetch(widget.settings.apiID, widget.settings.apiKey)
|
teams, err := Fetch(widget.settings.apiID, widget.settings.apiKey)
|
||||||
|
|
||||||
if err != nil {
|
widget.err = err
|
||||||
widget.err = err
|
widget.teams = teams
|
||||||
widget.teams = nil
|
|
||||||
} else {
|
|
||||||
widget.err = nil
|
|
||||||
widget.teams = teams
|
|
||||||
}
|
|
||||||
widget.Redraw(widget.content)
|
widget.Redraw(widget.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,6 @@ package zendesk
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
|
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
"github.com/wtfutil/wtf/utils"
|
"github.com/wtfutil/wtf/utils"
|
||||||
@ -16,6 +15,7 @@ type Widget struct {
|
|||||||
|
|
||||||
result *TicketArray
|
result *TicketArray
|
||||||
settings *Settings
|
settings *Settings
|
||||||
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewWidget creates a new instance of a widget
|
// NewWidget creates a new instance of a widget
|
||||||
@ -41,12 +41,8 @@ func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *
|
|||||||
func (widget *Widget) Refresh() {
|
func (widget *Widget) Refresh() {
|
||||||
ticketArray, err := widget.newTickets()
|
ticketArray, err := widget.newTickets()
|
||||||
ticketArray.Count = len(ticketArray.Tickets)
|
ticketArray.Count = len(ticketArray.Tickets)
|
||||||
if err != nil {
|
widget.err = err
|
||||||
log.Fatal(err)
|
widget.result = ticketArray
|
||||||
} else {
|
|
||||||
widget.result = ticketArray
|
|
||||||
}
|
|
||||||
|
|
||||||
widget.Render()
|
widget.Render()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +54,10 @@ func (widget *Widget) Render() {
|
|||||||
|
|
||||||
func (widget *Widget) content() (string, string, bool) {
|
func (widget *Widget) content() (string, string, bool) {
|
||||||
title := fmt.Sprintf("%s (%d)", widget.CommonSettings().Title, widget.result.Count)
|
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
|
items := widget.result.Tickets
|
||||||
if len(items) == 0 {
|
if len(items) == 0 {
|
||||||
return title, "No unassigned tickets in queue - woop!!", false
|
return title, "No unassigned tickets in queue - woop!!", false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user