refined search template
This commit is contained in:
parent
38ff87609f
commit
d7ae8febf3
|
@ -1,6 +1,6 @@
|
||||||
{{template "_head.html" .}}
|
{{template "_head.html" .}}
|
||||||
<div class="timeline">
|
<div class="timeline">
|
||||||
{{ if .}} {{range .}}
|
{{ if .Tasks}} {{range .Tasks}}
|
||||||
<div class="note">
|
<div class="note">
|
||||||
<p class="noteHeading">{{.Title}}</p>
|
<p class="noteHeading">{{.Title}}</p>
|
||||||
<hr>
|
<hr>
|
||||||
|
|
|
@ -12,4 +12,5 @@ type Task struct {
|
||||||
type Context struct {
|
type Context struct {
|
||||||
Tasks []Task
|
Tasks []Task
|
||||||
Navigation string
|
Navigation string
|
||||||
|
Search string
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,6 +42,7 @@ func PopulateTemplates() {
|
||||||
templates, err = template.ParseFiles(allFiles...)
|
templates, err = template.ParseFiles(allFiles...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
homeTemplate = templates.Lookup("home.html")
|
homeTemplate = templates.Lookup("home.html")
|
||||||
deletedTemplate = templates.Lookup("deleted.html")
|
deletedTemplate = templates.Lookup("deleted.html")
|
||||||
|
@ -84,15 +85,15 @@ func SearchTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
//AddTaskFunc is used to handle the addition of new task, "/add" URL
|
//AddTaskFunc is used to handle the addition of new task, "/add" URL
|
||||||
func AddTaskFunc(w http.ResponseWriter, r *http.Request) {
|
func AddTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == "POST" {
|
if r.Method == "POST" { // Will work only for GET requests, will redirect to home
|
||||||
r.ParseForm()
|
r.ParseForm()
|
||||||
title := r.Form.Get("title")
|
title := r.Form.Get("title")
|
||||||
content := r.Form.Get("content")
|
content := r.Form.Get("content")
|
||||||
truth := db.AddTask(title, content)
|
truth := db.AddTask(title, content)
|
||||||
if truth != nil {
|
if truth != nil {
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
|
||||||
} else {
|
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
|
} else {
|
||||||
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
|
@ -135,7 +136,6 @@ func CompleteTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
fmt.Println("redirecting to home")
|
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -155,7 +155,10 @@ func DeleteTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
db.DeleteTask(id)
|
err = db.DeleteTask(id)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
http.Redirect(w, r, "/deleted/", http.StatusFound)
|
http.Redirect(w, r, "/deleted/", http.StatusFound)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +174,10 @@ func TrashTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
} else {
|
} else {
|
||||||
db.TrashTask(id)
|
err = db.TrashTask(id)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -204,7 +210,10 @@ func UpdateTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
title := r.Form.Get("title")
|
title := r.Form.Get("title")
|
||||||
content := r.Form.Get("content")
|
content := r.Form.Get("content")
|
||||||
db.UpdateTask(id, title, content)
|
err = db.UpdateTask(id, title, content)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
} else {
|
} else {
|
||||||
http.Redirect(w, r, "/", http.StatusFound)
|
http.Redirect(w, r, "/", http.StatusFound)
|
||||||
|
|
Loading…
Reference in New Issue