diff --git a/db/files.go b/db/files.go index d1c7b18..572ca80 100644 --- a/db/files.go +++ b/db/files.go @@ -5,6 +5,8 @@ stores the functions related to file IO */ import ( "log" + + "github.com/thewhitetulip/Tasks/types" ) // AddFile is used to add the md5 of a file name which is uploaded to our application @@ -43,14 +45,14 @@ func GetFileName(token string) (string, error) { //GetCategories will return the list of categories to be //rendered in the template -func GetCategories() []string { - stmt := "select name from category" +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)" rows := database.query(stmt) - var categories []string - var category string + var categories []types.CategoryCount + var category types.CategoryCount for rows.Next() { - err := rows.Scan(&category) + err := rows.Scan(&category.Name, &category.Count) if err != nil { log.Println(err) } diff --git a/public/static/css/styles.css b/public/static/css/styles.css index 39cb469..c1fc1f6 100644 --- a/public/static/css/styles.css +++ b/public/static/css/styles.css @@ -17,6 +17,12 @@ ul{ list-style-type: none; } +.badge{ + background-color: #7D8EF0; + margin-right:10px; + float:right; +} + .center{ text-align:center; } diff --git a/templates/_head.html b/templates/_head.html index 7f72ecd..438e3dd 100644 --- a/templates/_head.html +++ b/templates/_head.html @@ -116,7 +116,7 @@ {{ range $index, $cat := .Categories }} {{end}} diff --git a/templates/edit.html b/templates/edit.html index 10fc37d..3633676 100644 --- a/templates/edit.html +++ b/templates/edit.html @@ -24,8 +24,8 @@ Category: diff --git a/types/types.go b/types/types.go index 65ea8a7..12a495c 100644 --- a/types/types.go +++ b/types/types.go @@ -21,5 +21,14 @@ type Context struct { Search string Message string CSRFToken string - Categories []string + Categories []CategoryCount +} + +//CategoryCount is the struct used to populate the sidebar +//which contains the category name and the count of the tasks +//in each category + +type CategoryCount struct { + Name string + Count int }