mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
WTF-781 Clean up Todoist project ID handling a bit (#783)
Signed-off-by: Chris Cummer <chriscummer@me.com>
This commit is contained in:
parent
ac18990a8c
commit
e1f1d0a410
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/olebedev/config"
|
||||
"github.com/wtfutil/wtf/cfg"
|
||||
"github.com/wtfutil/wtf/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -12,19 +13,21 @@ const (
|
||||
defaultTitle = "Todoist"
|
||||
)
|
||||
|
||||
// Settings defines the configuration properties for this module
|
||||
type Settings struct {
|
||||
common *cfg.Common
|
||||
|
||||
apiKey string
|
||||
projects []interface{}
|
||||
apiKey string `help:"Your Todoist API key"`
|
||||
projects []int
|
||||
}
|
||||
|
||||
// NewSettingsFromYAML creates a new settings instance from a YAML config block
|
||||
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
|
||||
settings := Settings{
|
||||
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
|
||||
|
||||
apiKey: ymlConfig.UString("apiKey", ymlConfig.UString("apikey", os.Getenv("WTF_TODOIST_TOKEN"))),
|
||||
projects: ymlConfig.UList("projects"),
|
||||
projects: utils.ToInts(ymlConfig.UList("projects")),
|
||||
}
|
||||
|
||||
return &settings
|
||||
|
@ -102,28 +102,28 @@ func (widget *Widget) Unselect() {
|
||||
/* -------------------- Keyboard Movement -------------------- */
|
||||
|
||||
// Close closes the currently-selected task in the currently-selected project
|
||||
func (w *Widget) Close() {
|
||||
w.CurrentProject().closeSelectedTask()
|
||||
w.SetItemCount(len(w.CurrentProject().tasks))
|
||||
func (widget *Widget) Close() {
|
||||
widget.CurrentProject().closeSelectedTask()
|
||||
widget.SetItemCount(len(widget.CurrentProject().tasks))
|
||||
|
||||
if w.CurrentProject().isLast() {
|
||||
w.Prev()
|
||||
if widget.CurrentProject().isLast() {
|
||||
widget.Prev()
|
||||
return
|
||||
}
|
||||
w.CurrentProject().index = w.Selected
|
||||
w.RenderFunction()
|
||||
widget.CurrentProject().index = widget.Selected
|
||||
widget.RenderFunction()
|
||||
}
|
||||
|
||||
// Delete deletes the currently-selected task in the currently-selected project
|
||||
func (w *Widget) Delete() {
|
||||
w.CurrentProject().deleteSelectedTask()
|
||||
w.SetItemCount(len(w.CurrentProject().tasks))
|
||||
func (widget *Widget) Delete() {
|
||||
widget.CurrentProject().deleteSelectedTask()
|
||||
widget.SetItemCount(len(widget.CurrentProject().tasks))
|
||||
|
||||
if w.CurrentProject().isLast() {
|
||||
w.Prev()
|
||||
if widget.CurrentProject().isLast() {
|
||||
widget.Prev()
|
||||
}
|
||||
w.CurrentProject().index = w.Selected
|
||||
w.RenderFunction()
|
||||
widget.CurrentProject().index = widget.Selected
|
||||
widget.RenderFunction()
|
||||
}
|
||||
|
||||
/* -------------------- Unexported Functions -------------------- */
|
||||
@ -136,7 +136,7 @@ func (widget *Widget) loadProjects() {
|
||||
projects := []*Project{}
|
||||
|
||||
for _, id := range widget.settings.projects {
|
||||
proj := NewProject(id.(int))
|
||||
proj := NewProject(id)
|
||||
projects = append(projects, proj)
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user