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)
|
settings := textfile.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = textfile.NewWidget(app, pages, settings)
|
widget = textfile.NewWidget(app, pages, settings)
|
||||||
case "todo":
|
case "todo":
|
||||||
cfg := todo.NewSettingsFromYAML(wtf.Config)
|
settings := todo.NewSettingsFromYAML(wtf.Config)
|
||||||
widget = todo.NewWidget(app, pages, cfg)
|
widget = todo.NewWidget(app, pages, settings)
|
||||||
case "todoist":
|
case "todoist":
|
||||||
widget = todoist.NewWidget(app, pages)
|
settings := todoist.NewSettingsFromYAML(wtf.Config)
|
||||||
|
widget = todoist.NewWidget(app, pages, settings)
|
||||||
case "travisci":
|
case "travisci":
|
||||||
widget = travisci.NewWidget(app, pages)
|
widget = travisci.NewWidget(app, pages)
|
||||||
case "trello":
|
case "trello":
|
||||||
|
@ -46,6 +46,5 @@ func (widget *Widget) display() {
|
|||||||
str = str + row + wtf.PadRow((checkWidth+len(item.Content)), (checkWidth+maxLen+1)) + "\n"
|
str = str + row + wtf.PadRow((checkWidth+len(item.Content)), (checkWidth+maxLen+1)) + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
//widget.View.Clear()
|
|
||||||
widget.View.SetText(str)
|
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
|
package todoist
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
|
|
||||||
"github.com/darkSasori/todoist"
|
"github.com/darkSasori/todoist"
|
||||||
"github.com/gdamore/tcell"
|
"github.com/gdamore/tcell"
|
||||||
"github.com/rivo/tview"
|
"github.com/rivo/tview"
|
||||||
@ -31,18 +29,21 @@ type Widget struct {
|
|||||||
wtf.HelpfulWidget
|
wtf.HelpfulWidget
|
||||||
wtf.TextWidget
|
wtf.TextWidget
|
||||||
|
|
||||||
projects []*Project
|
|
||||||
idx int
|
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{
|
widget := Widget{
|
||||||
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
HelpfulWidget: wtf.NewHelpfulWidget(app, pages, HelpText),
|
||||||
TextWidget: wtf.NewTextWidget(app, "Todoist", "todoist", true),
|
TextWidget: wtf.NewTextWidget(app, "Todoist", "todoist", true),
|
||||||
|
|
||||||
|
settings: settings,
|
||||||
}
|
}
|
||||||
|
|
||||||
widget.loadAPICredentials()
|
widget.loadAPICredentials()
|
||||||
widget.projects = loadProjects()
|
widget.loadProjects()
|
||||||
|
|
||||||
widget.HelpfulWidget.SetView(widget.View)
|
widget.HelpfulWidget.SetView(widget.View)
|
||||||
widget.View.SetInputCapture(widget.keyboardIntercept)
|
widget.View.SetInputCapture(widget.keyboardIntercept)
|
||||||
@ -169,21 +170,18 @@ func (w *Widget) keyboardIntercept(event *tcell.EventKey) *tcell.EventKey {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (widget *Widget) loadAPICredentials() {
|
func (widget *Widget) loadAPICredentials() {
|
||||||
todoist.Token = wtf.Config.UString(
|
todoist.Token = widget.settings.apiKey
|
||||||
"wtf.mods.todoist.apiKey",
|
|
||||||
os.Getenv("WTF_TODOIST_TOKEN"),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadProjects() []*Project {
|
func (widget *Widget) loadProjects() {
|
||||||
projects := []*Project{}
|
projects := []*Project{}
|
||||||
|
|
||||||
for _, id := range wtf.Config.UList("wtf.mods.todoist.projects") {
|
for _, id := range widget.settings.projects {
|
||||||
proj := NewProject(id.(int))
|
proj := NewProject(id.(int))
|
||||||
projects = append(projects, proj)
|
projects = append(projects, proj)
|
||||||
}
|
}
|
||||||
|
|
||||||
return projects
|
widget.projects = projects
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Widget) vimBindings(event *tcell.EventKey) tcell.Key {
|
func (w *Widget) vimBindings(event *tcell.EventKey) tcell.Key {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user