1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

WTF-400 Todoist extracted to new config format

This commit is contained in:
Chris Cummer 2019-04-16 10:01:55 -07:00
parent c489f2a4f4
commit 8b2fc71f92
4 changed files with 42 additions and 16 deletions

View File

@ -292,10 +292,11 @@ func makeWidget(app *tview.Application, pages *tview.Pages, widgetName string) w
settings := textfile.NewSettingsFromYAML(wtf.Config)
widget = textfile.NewWidget(app, pages, settings)
case "todo":
cfg := todo.NewSettingsFromYAML(wtf.Config)
widget = todo.NewWidget(app, pages, cfg)
settings := todo.NewSettingsFromYAML(wtf.Config)
widget = todo.NewWidget(app, pages, settings)
case "todoist":
widget = todoist.NewWidget(app, pages)
settings := todoist.NewSettingsFromYAML(wtf.Config)
widget = todoist.NewWidget(app, pages, settings)
case "travisci":
widget = travisci.NewWidget(app, pages)
case "trello":

View File

@ -46,6 +46,5 @@ func (widget *Widget) display() {
str = str + row + wtf.PadRow((checkWidth+len(item.Content)), (checkWidth+maxLen+1)) + "\n"
}
//widget.View.Clear()
widget.View.SetText(str)
}

View File

@ -0,0 +1,28 @@
package todoist
import (
"os"
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
)
type Settings struct {
common *cfg.Common
apiKey string
projects []interface{}
}
func NewSettingsFromYAML(ymlConfig *config.Config) *Settings {
localConfig, _ := ymlConfig.Get("wtf.mods.todoist")
settings := Settings{
common: cfg.NewCommonSettingsFromYAML(ymlConfig),
apiKey: localConfig.UString("apiKey", os.Getenv("WTF_TODOIST_TOKEN")),
projects: localConfig.UList("projects"),
}
return &settings
}

View File

@ -1,8 +1,6 @@
package todoist
import (
"os"
"github.com/darkSasori/todoist"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
@ -31,18 +29,21 @@ type Widget struct {
wtf.HelpfulWidget
wtf.TextWidget
projects []*Project
idx int
projects []*Project
settings *Settings
}
func NewWidget(app *tview.Application, pages *tview.Pages) *Widget {
func NewWidget(app *tview.Application, pages *tview.Pages, settings *Settings) *Widget {
widget := Widget{
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
TextWidget: wtf.NewTextWidget(app, "Todoist", "todoist", true),
settings: settings,
}
widget.loadAPICredentials()
widget.projects = loadProjects()
widget.loadProjects()
widget.HelpfulWidget.SetView(widget.View)
widget.View.SetInputCapture(widget.keyboardIntercept)
@ -169,21 +170,18 @@ func (w *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
}
func (widget *Widget) loadAPICredentials() {
todoist.Token = wtf.Config.UString(
"wtf.mods.todoist.apiKey",
os.Getenv("WTF_TODOIST_TOKEN"),
)
todoist.Token = widget.settings.apiKey
}
func loadProjects() []*Project {
func (widget *Widget) loadProjects() {
projects := []*Project{}
for _, id := range wtf.Config.UList("wtf.mods.todoist.projects") {
for _, id := range widget.settings.projects {
proj := NewProject(id.(int))
projects = append(projects, proj)
}
return projects
widget.projects = projects
}
func (w *Widget) vimBindings(event *tcell.EventKey) tcell.Key {