From 2ea4b1b36452a2600e56983f78711d03546bb7b1 Mon Sep 17 00:00:00 2001 From: Suraj Date: Sat, 6 Feb 2016 12:39:38 +0530 Subject: [PATCH] pending tasks shown in count of categories & in the list --- db/files.go | 2 +- db/tasks.go | 2 +- views/views.go | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/db/files.go b/db/files.go index 58e97df..0ae0c02 100644 --- a/db/files.go +++ b/db/files.go @@ -46,7 +46,7 @@ func GetFileName(token string) (string, error) { //GetCategories will return the list of categories to be //rendered in the template func GetCategories() []types.CategoryCount { - stmt := "select c.name, count(*) from category c left outer join task t where c.id = t.cat_id group by name union select name, 0 from category where name not in (select distinct name from task t join category c on t.cat_id = c.id)" + stmt := "select c.name, count(*) from category c left outer join task t where c.id = t.cat_id and t.is_deleted='N' and t.finish_date is null group by name union select name, 0 from category where name not in (select distinct name from task t join category c on t.cat_id = c.id)" rows := database.query(stmt) var categories []types.CategoryCount var category types.CategoryCount diff --git a/db/tasks.go b/db/tasks.go index 2065a77..e130a2a 100644 --- a/db/tasks.go +++ b/db/tasks.go @@ -89,7 +89,7 @@ func GetTasks(status, category string) (types.Context, error) { if category != "" { status = category - getTasksql = "select t.id, title, content, created_date, priority from task t, category c where c.id = t.cat_id and name = ? and is_deleted!='Y' order by priority desc, created_date asc, finish_date asc" + getTasksql = "select t.id, title, content, created_date, priority from task t, category c where c.id = t.cat_id and name = ? and t.is_deleted!='Y' and t.finish_date is null order by priority desc, created_date asc, finish_date asc" rows, err = database.db.Query(getTasksql, category) if err != nil { log.Println("something went wrong while getting query") diff --git a/views/views.go b/views/views.go index 647063b..236465f 100644 --- a/views/views.go +++ b/views/views.go @@ -48,6 +48,8 @@ func ShowAllTasksFunc(w http.ResponseWriter, r *http.Request) { func ShowTrashTaskFunc(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { context, err := db.GetTasks("deleted", "") + categories := db.GetCategories() + context.Categories = categories if err != nil { http.Redirect(w, r, "/trash", http.StatusInternalServerError) } @@ -66,6 +68,8 @@ func ShowTrashTaskFunc(w http.ResponseWriter, r *http.Request) { func ShowCompleteTasksFunc(w http.ResponseWriter, r *http.Request) { if r.Method == "GET" { context, err := db.GetTasks("completed", "") + categories := db.GetCategories() + context.Categories = categories if err != nil { http.Redirect(w, r, "/completed", http.StatusInternalServerError) }