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:
parent
c489f2a4f4
commit
8b2fc71f92
7
main.go
7
main.go
@ -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":
|
||||
|
@ -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)
|
||||
}
|
||||
|
28
modules/todoist/settings.go
Normal file
28
modules/todoist/settings.go
Normal 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
|
||||
}
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user