renamed GetTaskById to GetTaskByID

This commit is contained in:
thewhitetulip 2015-11-21 16:33:34 +05:30
parent 65dd3713d1
commit 8eea6f51f5
3 changed files with 20 additions and 25 deletions

View File

@ -60,8 +60,8 @@ func GetTasks(status string) []types.Task {
return task return task
} }
//GetTaskById function gets the tasks from the ID passed to the function //GetTaskByID function gets the tasks from the ID passed to the function
func GetTaskById(id int) types.Task { func GetTaskByID(id int) types.Task {
var task types.Task var task types.Task
var TaskID int var TaskID int
var TaskTitle string var TaskTitle string
@ -223,24 +223,25 @@ func UpdateTask(id int, title string, content string) error {
//SearchTask is used to return the search results depending on the query //SearchTask is used to return the search results depending on the query
func SearchTask(query string) []types.Task { func SearchTask(query string) []types.Task {
stmt := "select id, title, content from task where title like '%" + query + "%' or content like '%" + query + "%'" stmt := "select id, title, content, created_date from task where title like '%" + query + "%' or content like '%" + query + "%'"
var task []types.Task var task []types.Task
var TaskID int var TaskID int
var TaskTitle string var TaskTitle string
var TaskContent string var TaskContent string
var TaskCreated time.Time
rows, err := database.Query(stmt, query, query) rows, err := database.Query(stmt, query, query)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
for rows.Next() { for rows.Next() {
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent) err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated)
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} }
TaskTitle = strings.Replace(TaskTitle, query, "<span class='highlight'>"+query+"</span>", -1) TaskTitle = strings.Replace(TaskTitle, query, "<span class='highlight'>"+query+"</span>", -1)
TaskContent = strings.Replace(TaskContent, query, "<span class='highlight'>"+query+"</span>", -1) TaskContent = strings.Replace(TaskContent, query, "<span class='highlight'>"+query+"</span>", -1)
a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent} a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]}
task = append(task, a) task = append(task, a)
} }
return task return task

View File

@ -1,8 +1,4 @@
{{template "_head.html"}} {{template "_head.html"}}
<!--end mainHeader -->
<button class=" btn-danger btn glyphicon glyphicon-plus floating-action-icon floating-action-icon-add"></button>
<div class="timeline"> <div class="timeline">
{{ if .}} {{range .}} {{ if .}} {{range .}}
<div class="note"> <div class="note">
@ -10,27 +6,25 @@
<hr> <hr>
<p class="noteContent">{{.Content}}</p> <p class="noteContent">{{.Content}}</p>
<span class="notefooter"> <span class="notefooter">
<ul class="menu"> <ul class="menu">
<!-- <li role="presentation"> <li role="presentation">
<a role="menuitem" tabindex="-1" href="/share/{{.Id}}"> <span class="glyphicon glyphicon-time"></span> {{.Created}}</li>
<span class="glyphicon glyphicon-share"></span> Share</a> <!-- <li role="presentation">
<a role="menuitem" tabindex="-1" href="/mask/{{.Id}}">
<span class="glyphicon glyphicon-lock"></span> Mask</a></li> !-->
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/trash/{{.Id}}">
<span class="glyphicon glyphicon-trash"></span> Trash</a>
</li> </li>
<li role="presentation"> <li role="presentation">
<a role="menuitem" tabindex="-1" href="/mask/{{.Id}}"> <a role="menuitem" tabindex="-1" href="/complete/{{.Id}}">
<span class="glyphicon glyphicon-lock"></span> Mask</a> <span class="glyphicon glyphicon-check"></span> Complete</a>
</li> !--> </li>
<li role="presentation"> <li role="presentation">
<a role="menuitem" tabindex="-1" href="/edit/{{.Id}}"> <a role="menuitem" tabindex="-1" href="/edit/{{.Id}}">
<span class="glyphicon glyphicon-pencil"></span> Edit</a> <span class="glyphicon glyphicon-pencil"></span> Edit</a>
</li> </li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/archive/{{.Id}}">
<span class="glyphicon glyphicon-inbox"></span> Complete</a>
</li>
<!--
<li role="presentation"><a role="menuitem" tabindex="-1" href="/delete/{{.Id}}">
<span class="glyphicon glyphicon-trash"></span> Delete</a></li>
-->
</ul> </ul>
</span> </span>
</div> </div>

View File

@ -105,7 +105,7 @@ func EditTaskFunc(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
fmt.Println(err) fmt.Println(err)
} else { } else {
task := db.GetTaskById(id) task := db.GetTaskByID(id)
editTemplate.Execute(w, task) editTemplate.Execute(w, task)
} }
} }