show category in all templates

This commit is contained in:
Suraj 2016-02-29 07:35:38 +05:30
parent 3d83dcd080
commit fa271dfaeb
2 changed files with 39 additions and 22 deletions

View File

@ -81,19 +81,20 @@ func GetTasks(status, category string) (types.Context, error) {
return context, err return context, err
} }
basicSQL := "select id, title, content, created_date, priority from task t" basicSQL := "select t.id, title, content, created_date, priority, c.name from task t, category c where c.id = t.cat_id"
if status == "pending" && category == "" { if status == "pending" && category == "" {
getTasksql = basicSQL + " where finish_date is null and is_deleted='N' order by priority desc, created_date asc" getTasksql = basicSQL + " and finish_date is null and is_deleted='N' order by priority desc, created_date asc"
} else if status == "deleted" { } else if status == "deleted" {
getTasksql = basicSQL + " where is_deleted='Y' order by priority desc, created_date asc" getTasksql = basicSQL + " and is_deleted='Y' order by priority desc, created_date asc"
} else if status == "completed" { } else if status == "completed" {
getTasksql = basicSQL + " where finish_date is not null order by priority desc, created_date asc" getTasksql = basicSQL + " and finish_date is not null order by priority desc, created_date asc"
} }
if category != "" { if category != "" {
status = category status = category
getTasksql = "select t.id, title, content, created_date, priority from task t, category c where c.id = t.cat_id and name = ? and t.is_deleted!='Y' and t.finish_date is null order by priority desc, created_date asc, finish_date asc" getTasksql = basicSQL + " and name = ? and t.is_deleted!='Y' and t.finish_date is null order by priority desc, created_date asc, finish_date asc"
rows, err = database.db.Query(getTasksql, category) rows, err = database.db.Query(getTasksql, category)
if err != nil { if err != nil {
log.Println("something went wrong while getting query") log.Println("something went wrong while getting query")
} }
@ -103,7 +104,9 @@ func GetTasks(status, category string) (types.Context, error) {
defer rows.Close() defer rows.Close()
for rows.Next() { for rows.Next() {
task = types.Task{} task = types.Task{}
err := rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority)
err = rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority, &task.Category)
task.Content = string(md.Markdown([]byte(task.Content))) task.Content = string(md.Markdown([]byte(task.Content)))
// TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1) // TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
if err != nil { if err != nil {
@ -234,28 +237,40 @@ func taskQuery(sql string, args ...interface{}) 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.Context { func SearchTask(query string) types.Context {
stmt := "select id, title, content, created_date from task where title like '%" + query + "%' or content like '%" + query + "%'" var tasks []types.Task
var task []types.Task var task types.Task
var TaskID int
var TaskTitle string
var TaskContent string
var TaskCreated time.Time var TaskCreated time.Time
var context types.Context var context types.Context
comments, err := GetComments()
if err != nil {
log.Println("SearchTask: something went wrong in finding comments")
}
stmt := "select t.id, title, content, created_date, priority, c.name from task t, category c where c.id = t.cat_id and (title like '%" + query + "%' or content like '%" + query + "%') order by created_date desc"
rows := database.query(stmt, query, query) rows := database.query(stmt, query, query)
for rows.Next() { for rows.Next() {
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated) err := rows.Scan(&task.Id, &task.Title, &task.Content, &TaskCreated, &task.Priority, &task.Category)
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }
TaskTitle = strings.Replace(TaskTitle, query, "<span class='highlight'>"+query+"</span>", -1)
TaskContent = strings.Replace(TaskContent, query, "<span class='highlight'>"+query+"</span>", -1) if comments[task.Id] != nil {
TaskContent = string(md.Markdown([]byte(TaskContent))) task.Comments = comments[task.Id]
a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]} }
task = append(task, a)
task.Title = strings.Replace(task.Title, query, "<span class='highlight'>"+query+"</span>", -1)
task.Content = strings.Replace(task.Content, query, "<span class='highlight'>"+query+"</span>", -1)
task.Content = string(md.Markdown([]byte(task.Content)))
TaskCreated = TaskCreated.Local()
task.Created = TaskCreated.Format("Jan 01 2006")
tasks = append(tasks, task)
} }
context = types.Context{Tasks: task, Search: query} context = types.Context{Tasks: tasks, Search: query, Navigation: "search"}
return context return context
} }

View File

@ -65,7 +65,7 @@
<div class="comment"> <div class="comment">
<form method="POST" action="/add-comment/"> <form method="POST" action="/add-comment/">
<textarea rows="1" cols="30" name="commentText" placeholder="Add Comment"></textarea> <textarea rows="1" cols="75" name="commentText" placeholder="Add Comment"></textarea>
<input type="text" class="hidden" name="taskID" value="{{$value.Id}}"> <input type="text" class="hidden" name="taskID" value="{{$value.Id}}">
<input type="submit" value="Comment" class="btn btn-primary" /> <input type="submit" value="Comment" class="btn btn-primary" />
</form> </form>
@ -78,7 +78,7 @@
<li role="presentation">Priority: {{$value.Priority}}</li> <li role="presentation">Priority: {{$value.Priority}}</li>
<li role="presentation"> <li role="presentation">
<span class="glyphicon glyphicon-time"></span> {{$value.Created}}</li> <span class="glyphicon glyphicon-time"></span> {{$value.Created}}</li>
<li role="presentation"> <li role="presentation">
<a role="menuitem" tabindex="-1" href="/mask/{{.Id}}"> <a role="menuitem" tabindex="-1" href="/mask/{{.Id}}">
<span class="glyphicon glyphicon-lock"></span></a> <span class="glyphicon glyphicon-lock"></span></a>
@ -95,7 +95,9 @@
<a role="menuitem" tabindex="-1" href="/edit/{{.Id}}"> <a role="menuitem" tabindex="-1" href="/edit/{{.Id}}">
<span class="glyphicon glyphicon-pencil"></span></a> <span class="glyphicon glyphicon-pencil"></span></a>
</li> </li>
<li role="presentation">
<a href="/category/{{$value.Category}}"> {{$value.Category}}</a>
</li>
</ul> </ul>
</span> </span>
</div> </div>
@ -113,4 +115,4 @@
</body> </body>
</html> </html>