diff options
| author | Quey-Liang Kao <s101062801@m101.nthu.edu.tw> | 2017-08-14 14:41:40 +0800 |
|---|---|---|
| committer | Quey-Liang Kao <s101062801@m101.nthu.edu.tw> | 2017-08-14 14:58:32 +0800 |
| commit | 5d28dac9b2e1d153f33551b968ab4c92cfce23ce (patch) | |
| tree | b323964d5a61014105b0884e81c9d88be1a74118 /todolist | |
| parent | 49ab75141a7799aa746765547bd74cb07b45bfee (diff) | |
Implement the "an" feature: Adding notes to todos
This patch introduce a new attribute of a todo item, which is
"Notes", of type []string. The following enhancing patches will
contain the listing, removing and editing features.
Diffstat (limited to 'todolist')
| -rw-r--r-- | todolist/app.go | 15 | ||||
| -rw-r--r-- | todolist/parser.go | 12 | ||||
| -rw-r--r-- | todolist/parser_test.go | 12 | ||||
| -rw-r--r-- | todolist/todo_item.go | 1 | ||||
| -rw-r--r-- | todolist/todos.json | 2 |
5 files changed, 41 insertions, 1 deletions
diff --git a/todolist/app.go b/todolist/app.go index 42b1361..c2bd66a 100644 --- a/todolist/app.go +++ b/todolist/app.go @@ -132,6 +132,21 @@ func (a *App) ExpandTodo(input string) { fmt.Println("Todo expanded.") } +func (a *App) ManipulateNotes(input string) { + a.Load() + id, todo := a.getId(input) + parser := &Parser{} + if id == -1 { + return + } + + retStr := parser.ParseNotes(todo, input) + if retStr != "" { + a.Save() + fmt.Println("Notes " + retStr + "ed.") + } +} + func (a *App) ArchiveCompleted() { a.Load() for _, todo := range a.TodoList.Todos() { diff --git a/todolist/parser.go b/todolist/parser.go index cdfb179..207791d 100644 --- a/todolist/parser.go +++ b/todolist/parser.go @@ -83,6 +83,18 @@ func (p *Parser) Contexts(input string) []string { return p.matchWords(input, r) } +func (p *Parser) ParseNotes(todo *Todo, input string) string { + r, _ := regexp.Compile(`(\w+) \d+\s+(.*)?`) + matches := r.FindStringSubmatch(input) + if matches[1] == "an" { + todo.Notes = append(todo.Notes, matches[2]) + return "add" + } + + fmt.Println("Could not match command or id") + return "" +} + func (p *Parser) hasDue(input string) bool { r1, _ := regexp.Compile(`due \w+$`) r2, _ := regexp.Compile(`due \w+ \d+$`) diff --git a/todolist/parser_test.go b/todolist/parser_test.go index 476edaa..9412bdf 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -74,6 +74,18 @@ func TestParseContexts(t *testing.T) { } } +func TestParseNotes(t *testing.T) { + parser := &Parser{} + todo := parser.ParseNewTodo("add search engine survey") + + if parser.ParseNotes(todo, "an 1 www.google.com") != "add" { + t.Error("Expected Notes to be added") + } + if todo.Notes[0] != "www.google.com" { + t.Error("Expected note 1 to be 'www.google.com' but got", todo.Notes[0]) + } +} + func TestDueToday(t *testing.T) { assert := assert.New(t) parser := &Parser{} diff --git a/todolist/todo_item.go b/todolist/todo_item.go index 0c30707..5b9bcbc 100644 --- a/todolist/todo_item.go +++ b/todolist/todo_item.go @@ -15,6 +15,7 @@ type Todo struct { CompletedDate string `json:"completedDate"` Archived bool `json:"archived"` IsPriority bool `json:"isPriority"` + Notes []string `json:"notes"` } func NewTodo() *Todo { diff --git a/todolist/todos.json b/todolist/todos.json index 7f511ed..39593be 100644 --- a/todolist/todos.json +++ b/todolist/todos.json @@ -1 +1 @@ -[{"id":1,"subject":"this is the first subject","projects":["test1"],"contexts":["root"],"due":"2016-04-04","completed":false,"completedDate":"","archived":true,"isPriority":false},{"id":2,"subject":" audit userify for 2FA","projects":["test1"],"contexts":["root","more"],"due":"","completed":true,"completedDate":"","archived":false,"isPriority":false}]
\ No newline at end of file +[{"id":1,"subject":"this is the first subject","projects":["test1"],"contexts":["root"],"due":"2016-04-04","completed":false,"completedDate":"","archived":true,"isPriority":false,"notes":null},{"id":2,"subject":" audit userify for 2FA","projects":["test1"],"contexts":["root","more"],"due":"","completed":true,"completedDate":"","archived":false,"isPriority":false,"notes":null}]
\ No newline at end of file |
