mark task incomplete from complete

This commit is contained in:
Suraj patil 2016-01-09 10:33:35 +05:30
parent 31b9e8b111
commit dbc61a0082
4 changed files with 51 additions and 9 deletions

View File

@ -168,6 +168,26 @@ func RestoreTask(id int) error {
return err
}
//RestoreTaskFromComplete is used to restore tasks from the Trash
func RestoreTaskFromComplete(id int) error {
restoreSQL, err := database.Prepare("update task set is_deleted='N',finish_date=null,last_modified_at=datetime() where id=?")
if err != nil {
fmt.Println(err)
}
tx, err := database.Begin()
if err != nil {
fmt.Println(err)
}
_, err = tx.Stmt(restoreSQL).Exec(id)
if err != nil {
fmt.Println("doing rollback")
tx.Rollback()
} else {
tx.Commit()
}
return err
}
//DeleteTask is used to delete the task from the database
func DeleteTask(id int) error {
deleteSQL, err := database.Prepare("delete from task where id = ?")

View File

@ -21,6 +21,7 @@ func main() {
http.HandleFunc("/edit/", views.EditTaskFunc)
http.HandleFunc("/completed/", views.ShowCompleteTasksFunc)
http.HandleFunc("/restore/", views.RestoreTaskFunc)
http.HandleFunc("/incomplete/", views.RestoreFromCompleteFunc)
http.HandleFunc("/add/", views.AddTaskFunc)
http.HandleFunc("/update/", views.UpdateTaskFunc)
http.HandleFunc("/search/", views.SearchTaskFunc)

View File

@ -8,11 +8,15 @@
<p class="noteContent">{{.Content}}</p>
<span class="notefooter">
<ul class="menu">
<!-- <li role="presentation">
<a role="menuitem" tabindex="-1" href="/share/{{.Id}}">
<span class="glyphicon glyphicon-share"></span> Share</a>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/incomplete/{{.Id}}">
<span class="glyphicon glyphicon-share"></span> Mark incomplete</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/trash/{{.Id}}">
<span class="glyphicon glyphicon-trash"></span> Trash</a>
</li>
<!--<li role="presentation">
<a role="menuitem" tabindex="-1" href="/mask/{{.Id}}">
<span class="glyphicon glyphicon-lock"></span> Mask</a>
</li>
@ -20,10 +24,6 @@
<a role="menuitem" tabindex="-1" href="/archive/{{.Id}}">
<span class="glyphicon glyphicon-inbox"></span> Edit</a>
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/trash/{{.Id}}">
<span class="glyphicon glyphicon-trash"></span> Trash</a>
</li>
<!-- <li role="presentation"><a role="menuitem" tabindex="-1" href="/restore/{{.Id}}">
<span class="glyphicon glyphicon-inbox"></span> Restore</a></li> -->
</ul>

View File

@ -236,6 +236,27 @@ func RestoreTaskFunc(w http.ResponseWriter, r *http.Request) {
}
}
//RestoreFromCompleteFunc restores the task from complete to pending
func RestoreFromCompleteFunc(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" {
id, err := strconv.Atoi(r.URL.Path[len("/incomplete/"):])
if err != nil {
fmt.Println(err)
} else {
err = db.RestoreTaskFromComplete(id)
if err != nil {
message = "Restore failed"
} else {
message = "Task restored"
}
http.Redirect(w, r, "/pending/", http.StatusFound)
}
} else {
message = "Method not allowed"
http.Redirect(w, r, "/", http.StatusFound)
}
}
//UpdateTaskFunc is used to update a task, handes "/update/" URL
func UpdateTaskFunc(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {