diff --git a/db/tasks.go b/db/tasks.go
index e130a2a..ca294c5 100644
--- a/db/tasks.go
+++ b/db/tasks.go
@@ -68,16 +68,15 @@ func Close() {
//GetTasks retrieves all the tasks depending on the
//status pending or trashed or completed
func GetTasks(status, category string) (types.Context, error) {
- var task []types.Task
- var context types.Context
- var TaskID int
- var TaskTitle string
- var TaskContent string
+ var tasks []types.Task
+ var task types.Task
var TaskCreated time.Time
- var TaskPriority string
+ var context types.Context
var getTasksql string
var rows *sql.Rows
+ comments := GetComments()
+
basicSQL := "select id, title, content, created_date, priority from task t"
if status == "pending" && category == "" {
getTasksql = basicSQL + " where finish_date is null and is_deleted='N' order by priority desc, created_date asc"
@@ -99,17 +98,24 @@ func GetTasks(status, category string) (types.Context, error) {
}
defer rows.Close()
for rows.Next() {
- err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated, &TaskPriority)
- TaskContent = string(md.Markdown([]byte(TaskContent)))
+ task = types.Task{}
+ err := rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority)
+ task.Content = string(md.Markdown([]byte(task.Content)))
// TaskContent = strings.Replace(TaskContent, "\n", "
", -1)
if err != nil {
log.Println(err)
}
+
+ if comments[task.Id] != nil {
+ task.Comments = comments[task.Id]
+ }
+
TaskCreated = TaskCreated.Local()
- a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20], Priority: TaskPriority}
- task = append(task, a)
+ task.Created = TaskCreated.Format(time.UnixDate)[0:20]
+
+ tasks = append(tasks, task)
}
- context = types.Context{Tasks: task, Navigation: status}
+ context = types.Context{Tasks: tasks, Navigation: status}
return context, nil
}
@@ -248,3 +254,39 @@ func SearchTask(query string) types.Context {
context = types.Context{Tasks: task, Search: query}
return 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 {
+ commentMap := make(map[int][]types.Comment)
+
+ var id int
+ var message types.Comment
+
+ stmt := "select taskID, content from comments;"
+ rows := database.query(stmt)
+
+ for rows.Next() {
+ err := rows.Scan(&id, &message.Content)
+ if err != nil {
+
+ }
+ commentMap[id] = append(commentMap[id], message)
+ }
+ return commentMap
+}
+
+//AddComments will be used to add comments in the database
+func AddComments(id int, comment string) error {
+ stmt := "insert into comments(taskID, content) values (?,?)"
+ err := taskQuery(stmt, id, comment)
+
+ if err != nil {
+ return err
+ }
+
+ log.Println("added comment to task ID ", id)
+
+ return nil
+}
diff --git a/main.go b/main.go
index 6d0b479..a95bd5c 100644
--- a/main.go
+++ b/main.go
@@ -17,6 +17,7 @@ func main() {
views.PopulateTemplates()
http.HandleFunc("/", views.ShowAllTasksFunc)
http.HandleFunc("/add-category/", views.AddCategoryFunc)
+ http.HandleFunc("/add-comment/", views.AddCommentFunc)
http.HandleFunc("/del-category/", views.DeleteCategoryFunc)
http.HandleFunc("/upd-category/", views.UpdateCategoryFunc)
http.HandleFunc("/category/", views.ShowCategoryFunc)
diff --git a/public/static/css/styles.css b/public/static/css/styles.css
index e1ebafa..c8c2489 100644
--- a/public/static/css/styles.css
+++ b/public/static/css/styles.css
@@ -17,8 +17,14 @@ ul{
list-style-type: none;
}
+input {
+ border:none;
+ border-bottom:1px solid gray;
+ box-shadow:none;
+}
+
.badge{
- background-color: #7D8EF0;
+ background-color: #1a78c9;
margin-right:10px;
float:right;
}
diff --git a/public/static/js/script.js b/public/static/js/script.js
index a1eefb8..2ba79f4 100644
--- a/public/static/js/script.js
+++ b/public/static/js/script.js
@@ -35,7 +35,12 @@ $(document).ready(function(){
$('#toggleAddFileGrp').addClass('hidden') ;
});
- if ($('#actlMsg').html()==' '){
+ $("#noti").click(
+ function(){
+ this.fadeOut();
+ }
+ );
+ if ($('#actlMsg').html()==''){
$('.notification').addClass('hidden');
} else {
$('.notification').fadeOut(9000);
@@ -53,6 +58,22 @@ $(document).ready(function(){
}
}
);*/
+
+ $("#addNoteBtn").on("click", function() {
+ this.preventDefaults();
+ var task_id = $("#task-id").val();
+ $.ajax({
+ url: "/tasks/" + task_id,
+ type: "POST",
+ data: {'title':'randome note', 'content':'this and that'}
+ }).done(function(res, status) {
+ console.log(status, res);
+ var response = res
+ $("#timeline").append(response)
+ });
+ });
+
+
$('.toggle').click(function(){
$(this).next().toggle();
});
diff --git a/templates/_head.html b/templates/_head.html
index a7fe208..f1229d3 100644
--- a/templates/_head.html
+++ b/templates/_head.html
@@ -40,7 +40,7 @@