We now show the task list status, x out of x completed

This commit is contained in:
Suraj Patil 2016-08-25 23:39:49 +05:30
parent 65a05d54ba
commit e0ec55ac2c
3 changed files with 26 additions and 10 deletions

View File

@ -10,6 +10,7 @@ DeleteAll()
import ( import (
"database/sql" "database/sql"
"log" "log"
"strconv"
"strings" "strings"
"time" "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) 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))) task.Content = string(md.Markdown([]byte(task.Content)))
// TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1) // TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
if err != nil { if err != nil {

View File

@ -60,6 +60,7 @@
<span class="noteContent"> <span class="noteContent">
{{$value.Content}} {{$value.Content}}
{{$value.CompletedMsg}}
<div class="commentslist"> <div class="commentslist">
{{range $value.Comments}} {{range $value.Comments}}
<div class="comment"> <div class="comment">

View File

@ -6,16 +6,17 @@ is passed while templates are executed.
*/ */
//Task is the struct used to identify tasks //Task is the struct used to identify tasks
type Task struct { type Task struct {
Id int `json:"id"` Id int `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`
Created string `json:"created"` Created string `json:"created"`
Priority string `json:"priority"` Priority string `json:"priority"`
Category string `json:"category"` Category string `json:"category"`
Referer string `json:"referer,omitempty"` Referer string `json:"referer,omitempty"`
Comments []Comment `json:"comments,omitempty"` Comments []Comment `json:"comments,omitempty"`
IsOverdue bool `json:"isoverdue, omitempty"` IsOverdue bool `json:"isoverdue, omitempty"`
IsHidden int `json:"ishidden, omitempty` IsHidden int `json:"ishidden, omitempty`
CompletedMsg string `json:"ishidden, omitempty"`
} }
type Tasks []Task type Tasks []Task