mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* WTF-1031 Rename WtfApp.app to WtfApp.tviewApp Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-1031 Add scaffolding for main to support multiple WtfApp instances Signed-off-by: Chris Cummer <chriscummer@me.com> * WTF-1031 WIP Signed-off-by: Chris Cummer <chriscummer@me.com> * Remove common functionality from KeyboardWidget and into Base Signed-off-by: Chris Cummer <chriscummer@me.com> * Augment with some descriptive comments Signed-off-by: Chris Cummer <chriscummer@me.com> * Add full support for multiple app instances via the AppManager. Still to do: * Config support for multiple apps/multiple config files * The ability to switch between apps Signed-off-by: Chris Cummer <chriscummer@me.com> * Move SetTerminal out of main and into its own file Signed-off-by: Chris Cummer <chriscummer@me.com>
76 lines
1.5 KiB
Go
76 lines
1.5 KiB
Go
package bamboohr
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/rivo/tview"
|
|
"github.com/wtfutil/wtf/utils"
|
|
"github.com/wtfutil/wtf/view"
|
|
"github.com/wtfutil/wtf/wtf"
|
|
)
|
|
|
|
const apiURI = "https://api.bamboohr.com/api/gateway.php"
|
|
|
|
type Widget struct {
|
|
view.TextWidget
|
|
|
|
settings *Settings
|
|
items []Item
|
|
}
|
|
|
|
func NewWidget(tviewApp *tview.Application, settings *Settings) *Widget {
|
|
widget := Widget{
|
|
TextWidget: view.NewTextWidget(tviewApp, nil, settings.Common),
|
|
|
|
settings: settings,
|
|
}
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
client := NewClient(
|
|
apiURI,
|
|
widget.settings.apiKey,
|
|
widget.settings.subdomain,
|
|
)
|
|
|
|
widget.items = client.Away(
|
|
"timeOff",
|
|
time.Now().Local().Format(wtf.DateFormat),
|
|
time.Now().Local().Format(wtf.DateFormat),
|
|
)
|
|
|
|
widget.Redraw(widget.content)
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) content() (string, string, bool) {
|
|
str := ""
|
|
if len(widget.items) == 0 {
|
|
str = fmt.Sprintf("\n\n\n\n\n\n\n\n%s", utils.CenterText("[grey]no one[white]", 50))
|
|
} else {
|
|
for _, item := range widget.items {
|
|
str += widget.format(item)
|
|
}
|
|
}
|
|
|
|
return widget.CommonSettings().Title, str, false
|
|
}
|
|
|
|
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
|
|
}
|