Skip to content

Commit 26a27b1

Browse files
committed
Added subject to confirmation of archive, delete and complete actions
1 parent 10fb494 commit 26a27b1

12 files changed

+59
-9
lines changed

Rakefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Envs = [
1111
{ goos: "windows", arch: "amd64" }
1212
].freeze
1313

14-
Version = "1.7.1".freeze
14+
Version = "1.7.2".freeze
1515

1616
task :build do
1717
`rm -rf dist/#{Version}`

dist/1.7.2/ultodo_win.zip

3.22 MB
Binary file not shown.

dist/1.7.2/ultododarwin_amd64.tar.gz

2.97 MB
Binary file not shown.

dist/1.7.2/ultodolinux_386.tar.gz

2.92 MB
Binary file not shown.

dist/1.7.2/ultodolinux_amd64.tar.gz

3.07 MB
Binary file not shown.

dist/1.7.2/ultodolinux_arm.tar.gz

2.82 MB
Binary file not shown.

dist/1.7.2/ultodolinux_arm64.tar.gz

2.86 MB
Binary file not shown.

main

-16 Bytes
Binary file not shown.

ultodo/app.go

+31-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
const (
1111
// Current version of ultodo.
12-
VERSION string = "1.7.1"
12+
VERSION string = "1.7.2"
1313

1414
DATE_FORMAT string = "2006-01-02"
1515
)
@@ -75,7 +75,7 @@ func (a *App) AddTodo(input string) {
7575

7676
a.TodoList.Add(todoItem)
7777
a.save()
78-
fmt.Printf("Todo %d added.\n", todoItem.ID)
78+
fmt.Printf("Todo %d added:.\n", todoItem.ID)
7979
}
8080

8181
// DeleteTodo deletes a todo.
@@ -85,9 +85,16 @@ func (a *App) DeleteTodo(input string) {
8585
if len(ids) == 0 {
8686
return
8787
}
88+
89+
// Get the todos so we an display info after deletion
90+
deletedTodos := a.TodoList.FindByIDs(ids)
91+
8892
a.TodoList.Delete(ids...)
8993
a.save()
90-
fmt.Printf("%s deleted.\n", pluralize(len(ids), "Todo", "Todos"))
94+
95+
for _, todo := range deletedTodos {
96+
fmt.Printf("Todo deleted. id:%d, Subject:%s\n", todo.ID, todo.Subject)
97+
}
9198
}
9299

93100
// CompleteTodo completes a todo.
@@ -102,7 +109,12 @@ func (a *App) CompleteTodo(input string, archive bool) {
102109
a.TodoList.Archive(ids...)
103110
}
104111
a.save()
105-
fmt.Println("Todo completed.")
112+
113+
completedTodos := a.TodoList.FindByIDs(ids)
114+
115+
for _, todo := range completedTodos {
116+
fmt.Printf("Todo completed. id:%d, Subject:%s\n", todo.ID, todo.Subject)
117+
}
106118
}
107119

108120
// UncompleteTodo uncompletes a todo.
@@ -114,7 +126,11 @@ func (a *App) UncompleteTodo(input string) {
114126
}
115127
a.TodoList.Uncomplete(ids...)
116128
a.save()
117-
fmt.Println("Todo uncompleted.")
129+
130+
unCompletedTodos := a.TodoList.FindByIDs(ids)
131+
for _, todo := range unCompletedTodos {
132+
fmt.Printf("Todo uncompleted. id:%d, Subject:%s\n", todo.ID, todo.Subject)
133+
}
118134
}
119135

120136
// ArchiveTodo archives a todo.
@@ -126,7 +142,11 @@ func (a *App) ArchiveTodo(input string) {
126142
}
127143
a.TodoList.Archive(ids...)
128144
a.save()
129-
fmt.Println("Todo archived.")
145+
146+
archivedTodos := a.TodoList.FindByIDs(ids)
147+
for _, todo := range archivedTodos {
148+
fmt.Printf("Todo archived. id:%d, Subject:%s\n", todo.ID, todo.Subject)
149+
}
130150
}
131151

132152
// UnarchiveTodo unarchives a todo.
@@ -138,7 +158,11 @@ func (a *App) UnarchiveTodo(input string) {
138158
}
139159
a.TodoList.Unarchive(ids...)
140160
a.save()
141-
fmt.Println("Todo unarchived.")
161+
162+
unArchivedTodos := a.TodoList.FindByIDs(ids)
163+
for _, todo := range unArchivedTodos {
164+
fmt.Printf("Todo unarchived. id:%d, Subject:%s\n", todo.ID, todo.Subject)
165+
}
142166
}
143167

144168
// EditTodo edits a todo with the given input.

ultodo/todo_filter.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (f *TodoFilter) ApplyFilter() []*Todo {
4141
}
4242

4343
if f.Filter.HasSearchString {
44-
if !strings.Contains(todo.Subject, f.Filter.SearchString[0]) {
44+
if !strings.Contains(strings.ToLower(todo.Subject), strings.ToLower(f.Filter.SearchString[0])) {
4545
continue
4646
}
4747
}

ultodo/todo_list.go

+17
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,23 @@ func (t *TodoList) FindByID(id int) *Todo {
208208
return nil
209209
}
210210

211+
// FindByID finds a todo by ID.
212+
func (t *TodoList) FindByIDs(ids []int) []*Todo {
213+
var todos []*Todo
214+
215+
for _, todo := range t.Data {
216+
if contains(ids, todo.ID) {
217+
todos = append(todos, todo)
218+
}
219+
}
220+
221+
if len(todos) == 0 {
222+
return nil
223+
} else {
224+
return todos
225+
}
226+
}
227+
211228
// GarbageCollect deletes todos which are archived.
212229
func (t *TodoList) GarbageCollect() {
213230
var toDelete []*Todo

ultodo/util.go

+9
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ func UserHomeDir() string {
4848
return home
4949
}
5050

51+
func contains(s []int, e int) bool {
52+
for _, v := range s {
53+
if v == e {
54+
return true
55+
}
56+
}
57+
return false
58+
}
59+
5160
func newUUID() string {
5261
return (uuid.NewV4()).String()
5362
}

0 commit comments

Comments
 (0)