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 //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 + "%'" 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 var TaskCreated time.Time
var context types.Context
rows, err := database.Query(stmt, query, query) rows, err := database.Query(stmt, query, query)
if err != nil { 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]} 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 context = types.Context{Tasks: task, Search: query}
return context
} }

View File

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

View File

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

View File

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

View File

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