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 (
"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", "<br>", -1)
if err != nil {

View File

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

View File

@ -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