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
}
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 == "" {
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" {
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" {
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 != "" {
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)
if err != nil {
log.Println("something went wrong while getting query")
}
@ -103,7 +104,9 @@ func GetTasks(status, category string) (types.Context, error) {
defer rows.Close()
for rows.Next() {
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)))
// TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
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
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 tasks []types.Task
var task types.Task
var TaskCreated time.Time
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)
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 {
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)
TaskContent = string(md.Markdown([]byte(TaskContent)))
a := types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent, Created: TaskCreated.Format(time.UnixDate)[0:20]}
task = append(task, a)
if comments[task.Id] != nil {
task.Comments = comments[task.Id]
}
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
}

View File

@ -65,7 +65,7 @@
<div class="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="submit" value="Comment" class="btn btn-primary" />
</form>
@ -78,7 +78,7 @@
<li role="presentation">Priority: {{$value.Priority}}</li>
<li role="presentation">
<span class="glyphicon glyphicon-time"></span> {{$value.Created}}</li>
<li role="presentation">
<li role="presentation">
<a role="menuitem" tabindex="-1" href="/mask/{{.Id}}">
<span class="glyphicon glyphicon-lock"></span></a>
@ -95,7 +95,9 @@
<a role="menuitem" tabindex="-1" href="/edit/{{.Id}}">
<span class="glyphicon glyphicon-pencil"></span></a>
</li>
<li role="presentation">
<a href="/category/{{$value.Category}}"> {{$value.Category}}</a>
</li>
</ul>
</span>
</div>