to show edit task thing
This commit is contained in:
parent
3113502041
commit
1752d74589
|
@ -118,12 +118,12 @@ func GetTaskByID(id int) (types.Context, error) {
|
|||
var tasks []types.Task
|
||||
var task types.Task
|
||||
|
||||
getTasksql := "select id, title, content, priority from task where id=?"
|
||||
getTasksql := "select t.id, t.title, t.content, t.priority, c.name from task t left outer join category c where c.id = t.cat_id and t.id=?"
|
||||
|
||||
rows := database.query(getTasksql, id)
|
||||
defer rows.Close()
|
||||
if rows.Next() {
|
||||
err := rows.Scan(&task.Id, &task.Title, &task.Content, &task.Priority)
|
||||
err := rows.Scan(&task.Id, &task.Title, &task.Content, &task.Priority, &task.Category)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
//send email to respective people
|
||||
|
|
|
@ -4,23 +4,30 @@
|
|||
<div class="modal-header">
|
||||
<h4 class="modal-title" id="newNoteLabel"><span class="glyphicon glyphicon-pencil"></span> Edit Task</h4>
|
||||
</div>
|
||||
{{range .Tasks}}
|
||||
{{ $categories := .Categories }}
|
||||
{{range $index, $task := .Tasks}}
|
||||
<div class="modal-body">
|
||||
<form action="/update/" method="POST">
|
||||
<div class="form-group">
|
||||
<input type="text" name="title" value="{{.Title}}" class="form-control" id="add-note-title" placeholder="Title" style="border:none;border-bottom:1px solid gray; box-shadow:none;">
|
||||
<input type="text" name="title" value="{{ $task.Title}}" class="form-control" id="add-note-title" placeholder="Title" style="border:none;border-bottom:1px solid gray; box-shadow:none;">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<textarea class="form-control" name="content" id="add-note-content" placeholder="Content"
|
||||
rows="10" style="border:none;border-bottom:1px solid gray; box-shadow:none;">{{.Content}}</textarea>
|
||||
rows="10" style="border:none;border-bottom:1px solid gray; box-shadow:none;">{{ $task.Content}}</textarea>
|
||||
|
||||
<input type="text" name="id" value="{{.Id}}" class="hidden" />
|
||||
Priority:
|
||||
<input type="radio" name="priority" value="3" {{if eq .Priority "3"}} checked="checked" {{end}} /> High
|
||||
<input type="radio" name="priority" value="2" {{if eq .Priority "2"}} checked="checked" {{end}} /> Medium
|
||||
<input type="radio" name="priority" value="1" {{if eq .Priority "1"}} checked="checked" {{end}} /> Low
|
||||
</select>
|
||||
</div>
|
||||
Category:
|
||||
<select name="category">
|
||||
<option>---</option>
|
||||
{{range $cat := $categories}}
|
||||
<option value="{{$cat}}" {{if eq $cat $task.Category}} selected="true" {{end}}> {{$cat}} </option>
|
||||
{{end}}
|
||||
</select>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||
|
|
|
@ -11,6 +11,7 @@ type Task struct {
|
|||
Content string
|
||||
Created string
|
||||
Priority string
|
||||
Category string
|
||||
}
|
||||
|
||||
//Context is the struct passed to templates
|
||||
|
|
|
@ -133,3 +133,26 @@ func AddCategoryFunc(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//EditTaskFunc is used to edit tasks, handles "/edit/" URL
|
||||
func EditTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||
if r.Method == "GET" {
|
||||
id, err := strconv.Atoi(r.URL.Path[len("/edit/"):])
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
http.Redirect(w, r, "/", http.StatusBadRequest)
|
||||
} else {
|
||||
task, err := db.GetTaskByID(id)
|
||||
categories := db.GetCategories()
|
||||
task.Categories = categories
|
||||
|
||||
if err != nil {
|
||||
task.Message = "Error fetching Tasks"
|
||||
}
|
||||
editTemplate.Execute(w, task)
|
||||
}
|
||||
} else {
|
||||
message = "Method not allowed"
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue