diff --git a/project.go b/project.go index 3b5b9ea..de69a2a 100644 --- a/project.go +++ b/project.go @@ -246,6 +246,25 @@ func projectItems(project toggl.Project, arg string) (items []alfred.Item, err e } } + if isWorkspacePremium(project.Wid) && alfred.FuzzyMatches("billable:", arg) { + var item alfred.Item + + updateEntry := project + updateEntry.Billable = !project.Billable + + item.Title = "Billable" + item.Subtitle = "Update default project's billable flag" + item.Autocomplete = "Billable: " + alfred.Stringify(project.Billable) + item.Arg = &alfred.ItemArg{ + Keyword: "projects", + Mode: alfred.ModeDo, + Data: alfred.Stringify(projectCfg{ToUpdate: &updateEntry}), + } + item.AddCheckBox(project.Billable) + + items = append(items, item) + } + if alfred.FuzzyMatches("timers", arg) { items = append(items, alfred.Item{ Title: "Time entries...", diff --git a/support.go b/support.go index 21340af..9fc9ad3 100644 --- a/support.go +++ b/support.go @@ -115,6 +115,15 @@ func getClientByID(id int) (client toggl.Client, index int, found bool) { return } +func getWorkspaceByID(id int) (workspace toggl.Workspace, index int, found bool) { + for i, workspace := range cache.Account.Data.Workspaces { + if workspace.ID == id { + return workspace, i, true + } + } + return +} + func findTimersByProjectID(pid int) (entries []toggl.TimeEntry) { for _, entry := range cache.Account.Data.TimeEntries[:] { if entry.Pid == pid { @@ -189,6 +198,11 @@ func getLatestTimeEntriesForProject(pid int) (matchedArr []toggl.TimeEntry) { return } +func isWorkspacePremium(id int) bool { + workspace, _, _ := getWorkspaceByID(id) + return workspace.Premium +} + func projectHasTimeEntries(pid int) bool { entries := cache.Account.Data.TimeEntries for i := range entries { diff --git a/time_entry.go b/time_entry.go index ae022dc..62b4d5b 100644 --- a/time_entry.go +++ b/time_entry.go @@ -358,6 +358,7 @@ type timerCfg struct { Timer *int `json:"timer,omitempty"` Property *string `json:"property,omitempty"` Project *int `json:"project,omitempty"` + Billable *int `json:"billable,omitempty"` Tag *int `json:"tag,omitempty"` ToStart *startDesc `json:"tostart,omitempty"` ToUpdate *toggl.TimeEntry `json:"toupdate,omitempty"` @@ -404,7 +405,8 @@ func startTimeEntry(desc startDesc) (entry toggl.TimeEntry, err error) { session := toggl.OpenSession(config.APIKey) if desc.Pid != 0 { - entry, err = session.StartTimeEntryForProject(desc.Description, desc.Pid) + project, _, _ := getProjectByID(desc.Pid) + entry, err = session.StartTimeEntryForProject(desc.Description, desc.Pid, project.Billable) } else { entry, err = session.StartTimeEntry(desc.Description) } @@ -661,6 +663,25 @@ func timeEntryItems(entry *toggl.TimeEntry, query string) (items []alfred.Item, } } + if isWorkspacePremium(entry.Wid) && alfred.FuzzyMatches("billable:", parts[0]) { + var item alfred.Item + + updateEntry := entry.Copy() + updateEntry.Billable = !entry.Billable + + item.Title = "Billable" + item.Subtitle = "Update this entry's billable condition" + item.Autocomplete = "Billable: " + alfred.Stringify(entry.Billable) + item.Arg = &alfred.ItemArg{ + Keyword: "timers", + Mode: alfred.ModeDo, + Data: alfred.Stringify(timerCfg{ToUpdate: &updateEntry}), + } + item.AddCheckBox(entry.Billable) + + items = append(items, item) + } + if alfred.FuzzyMatches("start:", parts[0]) { command := "Start"