forked from OrgGo/Tasks
mark task incomplete from complete
This commit is contained in:
parent
31b9e8b111
commit
dbc61a0082
20
db/db.go
20
db/db.go
|
@ -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 = ?")
|
||||
|
|
1
main.go
1
main.go
|
@ -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)
|
||||
|
|
|
@ -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>
|
||||
<li role="presentation">
|
||||
<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>
|
||||
|
|
|
@ -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" {
|
||||
|
|
Loading…
Reference in New Issue