From bb5e280a69d3d4e762826ab9ccefaa4224b5824d Mon Sep 17 00:00:00 2001 From: thewhitetulip Date: Sat, 21 Nov 2015 18:50:51 +0530 Subject: [PATCH] made templates contextual --- db/db.go | 12 +++++++----- public/templates/_head.html | 15 ++++++++------- public/templates/completed.html | 4 ++-- public/templates/deleted.html | 4 ++-- public/templates/home.html | 4 ++-- public/templates/search.html | 2 +- types/types.go | 7 +++++++ views/views.go | 14 ++++++++++---- 8 files changed, 39 insertions(+), 23 deletions(-) diff --git a/db/db.go b/db/db.go index b232118..170facd 100644 --- a/db/db.go +++ b/db/db.go @@ -26,18 +26,20 @@ func Close() { //GetTasks retrieves all the tasks depending on the //status pending or trashed or completed -func GetTasks(status string) []types.Task { +func GetTasks(status string) types.Context { var task []types.Task + var context types.Context var TaskID int var TaskTitle string var TaskContent string var TaskCreated time.Time var getTasksql string + if status == "pending" { getTasksql = "select id, title, content, created_date from task where finish_date is null and is_deleted='N' order by created_date asc" - } else if status == "trashed" { + } else if status == "deleted" { getTasksql = "select id, title, content, created_date from task where is_deleted='Y' order by created_date asc" - } else if status == "complete" { + } else if status == "completed" { getTasksql = "select id, title, content, created_date from task where finish_date is not null order by created_date asc" } @@ -56,8 +58,8 @@ func GetTasks(status string) []types.Task { a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]} task = append(task, a) } - - return task + context = types.Context{Tasks: task, Navigation: status} + return context } //GetTaskByID function gets the tasks from the ID passed to the function diff --git a/public/templates/_head.html b/public/templates/_head.html index 82f50bd..4fcbe52 100755 --- a/public/templates/_head.html +++ b/public/templates/_head.html @@ -4,7 +4,8 @@ - Tasks + {{if eq .Navigation "pending"}} Tasks {{ else if eq .Navigation "completed"}}Completed + {{ else if eq .Navigation "deleted"}}Deleted{{end}} @@ -40,8 +41,8 @@