contextualized templates

This commit is contained in:
thewhitetulip 2015-11-21 19:42:20 +05:30
parent bb5e280a69
commit 38ff87609f
5 changed files with 22 additions and 11 deletions

View File

@ -224,13 +224,14 @@ func UpdateTask(id int, title string, content string) error {
}
//SearchTask is used to return the search results depending on the query
func SearchTask(query string) []types.Task {
func SearchTask(query string) types.Context {
stmt := "select id, title, content, created_date from task where title like '%" + query + "%' or content like '%" + query + "%'"
var task []types.Task
var TaskID int
var TaskTitle string
var TaskContent string
var TaskCreated time.Time
var context types.Context
rows, err := database.Query(stmt, query, query)
if err != nil {
@ -246,5 +247,6 @@ func SearchTask(query 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, Search: query}
return context
}

View File

@ -4,8 +4,11 @@
<head>
<title>{{if eq .Navigation "pending"}} Tasks {{ else if eq .Navigation "completed"}}Completed
{{ else if eq .Navigation "deleted"}}Deleted{{end}}</title>
<title>{{if eq .Navigation "pending"}} Tasks
{{ else if eq .Navigation "completed"}}Completed
{{ else if eq .Navigation "deleted"}}Deleted
{{end}}
</title>
<!-- Mobile viewport optimized -->
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
@ -41,8 +44,15 @@
<nav class="navbar navbar-default navbar-fixed-top mainHeader">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href='{{ if eq .Navigation "pending"}} / {{else}} /{{.Navigation}} {{end}}'> {{if eq .Navigation "pending"}} Tasks {{ else if eq .Navigation "completed"}}Completed
{{ else if eq .Navigation "deleted"}}Deleted{{end}}</a>
{{if .Search}} <a class="navbar-brand"> Results for: {{.Search}}</a>
{{else}}
<a class="navbar-brand"
href='{{ if eq .Navigation "pending"}} / {{else}} /{{.Navigation}} {{end}}'>
{{if eq .Navigation "pending"}} Tasks
{{ else if eq .Navigation "completed"}}Completed
{{ else if eq .Navigation "deleted"}}Deleted
{{end}}</a>
{{end}}
<span id="icons">
<form action="/search/" method="POST">
<input type="text" name="query" placeholder="Search" style="border:none;border-bottom:1px solid gray; box-shadow:none;">
@ -76,7 +86,6 @@
</li>
</ul>
</li>
</ul>
</div>
</div>

View File

@ -1,7 +1,7 @@
{{template "_head.html" .}}
<div class="timeline">
{{ if .}} {{range .Tasks}}
{{ if .Tasks}} {{range .Tasks}}
<div class="note">
<p class="noteHeading">{{.Title}}</p>
<hr>
@ -19,7 +19,7 @@
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/archive/{{.Id}}">
<span class="glyphicon glyphicon-inbox"></span> Edit</a>
</li>!-->
</li>
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/trash/{{.Id}}">
<span class="glyphicon glyphicon-trash"></span> Trash</a>

View File

@ -7,7 +7,7 @@
{{end}}
<div class="timeline">
{{ if .}} {{range .Tasks}}
{{ if .Tasks}} {{range .Tasks}}
<div class="note">
<p class="noteHeading">{{.Title}}</p>
<hr>

View File

@ -32,7 +32,7 @@
</div>
<div class="timeline">
{{ if .}} {{range .Tasks}}
{{ if .Tasks}} {{range .Tasks}}
<div class="note">
<p class="noteHeading">{{.Title}}</p>
<hr>