pending tasks shown in count of categories & in the list

This commit is contained in:
Suraj 2016-02-06 12:39:38 +05:30
parent 8aef7693a8
commit 2ea4b1b364
3 changed files with 6 additions and 2 deletions

View File

@ -46,7 +46,7 @@ func GetFileName(token string) (string, error) {
//GetCategories will return the list of categories to be //GetCategories will return the list of categories to be
//rendered in the template //rendered in the template
func GetCategories() []types.CategoryCount { 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) rows := database.query(stmt)
var categories []types.CategoryCount var categories []types.CategoryCount
var category types.CategoryCount var category types.CategoryCount

View File

@ -89,7 +89,7 @@ func GetTasks(status, category string) (types.Context, error) {
if category != "" { if category != "" {
status = 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) rows, err = database.db.Query(getTasksql, category)
if err != nil { if err != nil {
log.Println("something went wrong while getting query") log.Println("something went wrong while getting query")

View File

@ -48,6 +48,8 @@ func ShowAllTasksFunc(w http.ResponseWriter, r *http.Request) {
func ShowTrashTaskFunc(w http.ResponseWriter, r *http.Request) { func ShowTrashTaskFunc(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" { if r.Method == "GET" {
context, err := db.GetTasks("deleted", "") context, err := db.GetTasks("deleted", "")
categories := db.GetCategories()
context.Categories = categories
if err != nil { if err != nil {
http.Redirect(w, r, "/trash", http.StatusInternalServerError) 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) { func ShowCompleteTasksFunc(w http.ResponseWriter, r *http.Request) {
if r.Method == "GET" { if r.Method == "GET" {
context, err := db.GetTasks("completed", "") context, err := db.GetTasks("completed", "")
categories := db.GetCategories()
context.Categories = categories
if err != nil { if err != nil {
http.Redirect(w, r, "/completed", http.StatusInternalServerError) http.Redirect(w, r, "/completed", http.StatusInternalServerError)
} }