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=?"
log.Println(query)
err := taskQuery(query, newName, oldName)
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 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"
if status == "pending" && category == "" {
@ -111,7 +115,7 @@ func GetTasks(status, category string) (types.Context, error) {
}
TaskCreated = TaskCreated.Local()
task.Created = TaskCreated.Format(time.UnixDate)[0:20]
task.Created = TaskCreated.Format("Jan 01 2006")
tasks = append(tasks, task)
}
@ -258,28 +262,32 @@ func SearchTask(query string) types.Context {
//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
//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)
var id int
var message types.Comment
var taskID int
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)
for rows.Next() {
err := rows.Scan(&id, &message.Content)
err := rows.Scan(&comment.ID, &taskID, &comment.Content, &created)
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
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)
if err != nil {

View File

@ -22,13 +22,17 @@ Layout
padding-left: 25px;
padding-top: 5px;
}
ul{
list-style-type: none;
}
.timestamp{
color: #aaa;
}
input {
border:none;
border-bottom:1px solid gray;
border: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 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}}
<div class="commentslist">
{{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}}
<div class="comment">

View File

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