diff --git a/db/tasks.go b/db/tasks.go index 801140f..b2d8396 100644 --- a/db/tasks.go +++ b/db/tasks.go @@ -10,6 +10,7 @@ DeleteAll() import ( "database/sql" "log" + "strconv" "strings" "time" @@ -121,6 +122,19 @@ func GetTasks(username, status, category string) (types.Context, error) { err = rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority, &task.Category) + taskCompleted := 0 + totalTasks := 0 + + if strings.HasPrefix(task.Content, "- [") { + for _, value := range strings.Split(task.Content, "\n") { + if strings.HasPrefix(value, "- [x]") { + taskCompleted += 1 + } + totalTasks += 1 + } + task.CompletedMsg = strconv.Itoa(taskCompleted) + " complete out of " + strconv.Itoa(totalTasks) + } + task.Content = string(md.Markdown([]byte(task.Content))) // TaskContent = strings.Replace(TaskContent, "\n", "
", -1) if err != nil { diff --git a/templates/home.html b/templates/home.html index 697fdff..4ad2fca 100644 --- a/templates/home.html +++ b/templates/home.html @@ -60,6 +60,7 @@ {{$value.Content}} + {{$value.CompletedMsg}}
{{range $value.Comments}}
diff --git a/types/types.go b/types/types.go index f5becbf..f9c6a7b 100644 --- a/types/types.go +++ b/types/types.go @@ -6,16 +6,17 @@ is passed while templates are executed. */ //Task is the struct used to identify tasks type Task struct { - Id int `json:"id"` - Title string `json:"title"` - Content string `json:"content"` - Created string `json:"created"` - Priority string `json:"priority"` - Category string `json:"category"` - Referer string `json:"referer,omitempty"` - Comments []Comment `json:"comments,omitempty"` - IsOverdue bool `json:"isoverdue, omitempty"` - IsHidden int `json:"ishidden, omitempty` + Id int `json:"id"` + Title string `json:"title"` + Content string `json:"content"` + Created string `json:"created"` + Priority string `json:"priority"` + Category string `json:"category"` + Referer string `json:"referer,omitempty"` + Comments []Comment `json:"comments,omitempty"` + IsOverdue bool `json:"isoverdue, omitempty"` + IsHidden int `json:"ishidden, omitempty` + CompletedMsg string `json:"ishidden, omitempty"` } type Tasks []Task