timestamps on comments

This commit is contained in:
Suraj 2016-02-16 22:23:03 +05:30
parent d598f289f3
commit f800a32436
6 changed files with 40 additions and 17 deletions

View File

@ -103,7 +103,12 @@ func UpdateCategoryByName(oldName, newName string) error {
query := "update category set name = ? where name=?" query := "update category set name = ? where name=?"
log.Println(query) log.Println(query)
err := taskQuery(query, newName, oldName) err := taskQuery(query, newName, oldName)
return err return err
}
//DeleteCommentByID will actually delete the comment from db
func DeleteCommentByID(id int) error {
query := "delete from comments where id=?"
err := taskQuery(query, id)
return err
} }

View File

@ -75,7 +75,11 @@ func GetTasks(status, category string) (types.Context, error) {
var getTasksql string var getTasksql string
var rows *sql.Rows var rows *sql.Rows
comments := GetComments() comments, err := GetComments()
if err != nil {
return context, err
}
basicSQL := "select id, title, content, created_date, priority from task t" basicSQL := "select id, title, content, created_date, priority from task t"
if status == "pending" && category == "" { if status == "pending" && category == "" {
@ -111,7 +115,7 @@ func GetTasks(status, category string) (types.Context, error) {
} }
TaskCreated = TaskCreated.Local() TaskCreated = TaskCreated.Local()
task.Created = TaskCreated.Format(time.UnixDate)[0:20] task.Created = TaskCreated.Format("Jan 01 2006")
tasks = append(tasks, task) tasks = append(tasks, task)
} }
@ -258,28 +262,32 @@ func SearchTask(query string) types.Context {
//GetComments is used to get comments, all of them. //GetComments is used to get comments, all of them.
//We do not want 100 different pages to show tasks, we want to use as few pages as possible //We do not want 100 different pages to show tasks, we want to use as few pages as possible
//so we are going to populate everything on the damn home pages //so we are going to populate everything on the damn home pages
func GetComments() map[int][]types.Comment { func GetComments() (map[int][]types.Comment, error) {
commentMap := make(map[int][]types.Comment) commentMap := make(map[int][]types.Comment)
var id int var taskID int
var message types.Comment var comment types.Comment
var created time.Time
stmt := "select taskID, content from comments;" stmt := "select id, taskID, content, created from comments;"
rows := database.query(stmt) rows := database.query(stmt)
for rows.Next() { for rows.Next() {
err := rows.Scan(&id, &message.Content) err := rows.Scan(&comment.ID, &taskID, &comment.Content, &created)
if err != nil { if err != nil {
return commentMap, err
} }
commentMap[id] = append(commentMap[id], message) // comment.Content = string(md.Markdown([]byte(comment.Content))) ## have to fix the <p> issue markdown support
created = created.Local()
comment.Created = created.Format("02 Jan 2006 15:04:05")
commentMap[taskID] = append(commentMap[taskID], comment)
} }
return commentMap return commentMap, nil
} }
//AddComments will be used to add comments in the database //AddComments will be used to add comments in the database
func AddComments(id int, comment string) error { func AddComments(id int, comment string) error {
stmt := "insert into comments(taskID, content) values (?,?)" stmt := "insert into comments(taskID, content, created) values (?,?,datetime())"
err := taskQuery(stmt, id, comment) err := taskQuery(stmt, id, comment)
if err != nil { if err != nil {

View File

@ -22,13 +22,17 @@ Layout
padding-left: 25px; padding-left: 25px;
padding-top: 5px; padding-top: 5px;
} }
ul{ ul{
list-style-type: none; list-style-type: none;
} }
.timestamp{
color: #aaa;
}
input { input {
border:none; border:none;
border-bottom:1px solid gray;
box-shadow:none; box-shadow:none;
} }

View File

@ -12,4 +12,4 @@ CREATE TABLE files(name varchar(1000) not null, autoName varchar(255) not null);
CREATE TABLE category( id integer primary key autoincrement ,name varchar(1000) not null); CREATE TABLE category( id integer primary key autoincrement ,name varchar(1000) not null);
CREATE TABLE comments(id integer primary key autoincrement, content ntext, taskID references task(id)); CREATE TABLE comments(id integer primary key autoincrement, content ntext, taskID references task(id), created datetime);

View File

@ -56,7 +56,11 @@
{{$value.Content}} {{$value.Content}}
<div class="commentslist"> <div class="commentslist">
{{range $value.Comments}} {{range $value.Comments}}
<div class="comment">{{.Content}}</div> <div class="comment">
<span>{{.Content}}</span>
<span class="timestamp">{{.Created}}</span>
<a href="/del-comment/{{.ID}}"><span class="glyphicon glyphicon-trash timestamp"></span></a>
</div>
{{end}} {{end}}
<div class="comment"> <div class="comment">

View File

@ -18,7 +18,9 @@ type Task struct {
//Comment is the struct used to populate comments per tasks //Comment is the struct used to populate comments per tasks
type Comment struct { type Comment struct {
ID int
Content string Content string
Created string
} }
//Context is the struct passed to templates //Context is the struct passed to templates