Support listing notes by tag
This commit is contained in:
parent
105275f3e0
commit
95865257a3
2 changed files with 17 additions and 4 deletions
|
|
@ -398,3 +398,12 @@ func (n *Note) ToggleBox(nthBox int) {
|
|||
n.Body = buf.Bytes()
|
||||
n.Save()
|
||||
}
|
||||
|
||||
func (n *Note) HasTag(tag string) bool {
|
||||
for _, tag_ := range n.Tags {
|
||||
if tag_ == tag {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,6 +199,8 @@ type titleAndURL struct {
|
|||
func list(w http.ResponseWriter, r *http.Request) {
|
||||
user := r.Context().Value(middleware.ContextKey("user")).(string)
|
||||
|
||||
tag := r.FormValue("tag")
|
||||
|
||||
titlesAndUrls := make([]titleAndURL, 0)
|
||||
|
||||
ns := notes.Notes.Get(user)
|
||||
|
|
@ -206,10 +208,12 @@ func list(w http.ResponseWriter, r *http.Request) {
|
|||
log.Printf("Notes for %s: %+v", user, ns)
|
||||
|
||||
for note := range ns {
|
||||
titlesAndUrls = append(
|
||||
titlesAndUrls,
|
||||
titleAndURL{Title: note.Title, URL: myurls.Reverse("view", urls.Repl{"note": note.Uid})},
|
||||
)
|
||||
if tag == "" || note.HasTag(tag) {
|
||||
titlesAndUrls = append(
|
||||
titlesAndUrls,
|
||||
titleAndURL{Title: note.Title, URL: myurls.Reverse("view", urls.Repl{"note": note.Uid})},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
urlNew := myurls.Reverse("new", urls.Repl{})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue