mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
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.
76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package bamboohr
|
|
|
|
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(" 👽 BambooHR ", "bamboohr", false),
|
|
}
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
if widget.Disabled() {
|
|
return
|
|
}
|
|
|
|
url, _ := Config.String("wtf.mods.bamboohr.url")
|
|
|
|
client := NewClient(url)
|
|
todayItems := client.Away(
|
|
"timeOff",
|
|
wtf.Now().Format(wtf.DateFormat),
|
|
wtf.Now().Format(wtf.DateFormat),
|
|
)
|
|
|
|
widget.View.SetTitle(fmt.Sprintf(" 👽 Away (%d) ", len(todayItems)))
|
|
|
|
widget.View.Clear()
|
|
fmt.Fprintf(widget.View, "%s", widget.contentFrom(todayItems))
|
|
|
|
widget.RefreshedAt = time.Now()
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) contentFrom(items []Item) string {
|
|
if len(items) == 0 {
|
|
return fmt.Sprintf("\n\n\n\n\n\n\n\n%s", wtf.CenterText("[grey]no one[white]", 50))
|
|
}
|
|
|
|
str := ""
|
|
for _, item := range items {
|
|
str = str + widget.format(item)
|
|
}
|
|
|
|
return str
|
|
}
|
|
|
|
func (widget *Widget) format(item Item) string {
|
|
var str string
|
|
|
|
if item.IsOneDay() {
|
|
str = fmt.Sprintf(" [green]%s[white]\n %s\n\n", item.Name(), item.PrettyEnd())
|
|
} else {
|
|
str = fmt.Sprintf(" [green]%s[white]\n %s - %s\n\n", item.Name(), item.PrettyStart(), item.PrettyEnd())
|
|
}
|
|
|
|
return str
|
|
}
|