forked from OrgGo/Tasks
added priority to tasks
This commit is contained in:
parent
43278053cb
commit
43bd75fe78
28
db/db.go
28
db/db.go
|
@ -33,14 +33,16 @@ func GetTasks(status string) types.Context {
|
||||||
var TaskTitle string
|
var TaskTitle string
|
||||||
var TaskContent string
|
var TaskContent string
|
||||||
var TaskCreated time.Time
|
var TaskCreated time.Time
|
||||||
|
var TaskPriority string
|
||||||
var getTasksql string
|
var getTasksql string
|
||||||
|
|
||||||
|
basicSQL := "select id, title, content, created_date, priority from task "
|
||||||
if status == "pending" {
|
if status == "pending" {
|
||||||
getTasksql = "select id, title, content, created_date from task where finish_date is null and is_deleted='N' order by created_date asc"
|
getTasksql = basicSQL + " where finish_date is null and is_deleted='N' order by priority desc, created_date asc"
|
||||||
} else if status == "deleted" {
|
} else if status == "deleted" {
|
||||||
getTasksql = "select id, title, content, created_date from task where is_deleted='Y' order by created_date asc"
|
getTasksql = basicSQL + " where is_deleted='Y' order by priority desc, created_date asc"
|
||||||
} else if status == "completed" {
|
} else if status == "completed" {
|
||||||
getTasksql = "select id, title, content, created_date from task where finish_date is not null order by created_date asc"
|
getTasksql = basicSQL + " where finish_date is not null order by priority desc, created_date asc"
|
||||||
}
|
}
|
||||||
|
|
||||||
rows, err := database.Query(getTasksql)
|
rows, err := database.Query(getTasksql)
|
||||||
|
@ -49,13 +51,13 @@ func GetTasks(status string) types.Context {
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated)
|
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent, &TaskCreated, &TaskPriority)
|
||||||
TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
|
TaskContent = strings.Replace(TaskContent, "\n", "<br>", -1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
TaskCreated = TaskCreated.Local()
|
TaskCreated = TaskCreated.Local()
|
||||||
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], Priority: TaskPriority}
|
||||||
task = append(task, a)
|
task = append(task, a)
|
||||||
}
|
}
|
||||||
context = types.Context{Tasks: task, Navigation: status}
|
context = types.Context{Tasks: task, Navigation: status}
|
||||||
|
@ -66,10 +68,8 @@ func GetTasks(status string) types.Context {
|
||||||
func GetTaskByID(id int) types.Context {
|
func GetTaskByID(id int) types.Context {
|
||||||
var tasks []types.Task
|
var tasks []types.Task
|
||||||
var task types.Task
|
var task types.Task
|
||||||
var TaskID int
|
|
||||||
var TaskTitle string
|
getTasksql := "select id, title, content, priority from task where id=?"
|
||||||
var TaskContent string
|
|
||||||
getTasksql := "select id, title, content from task where id=?"
|
|
||||||
|
|
||||||
rows, err := database.Query(getTasksql, id)
|
rows, err := database.Query(getTasksql, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -77,11 +77,11 @@ func GetTaskByID(id int) types.Context {
|
||||||
}
|
}
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
if rows.Next() {
|
if rows.Next() {
|
||||||
err := rows.Scan(&TaskID, &TaskTitle, &TaskContent)
|
err := rows.Scan(&task.Id, &task.Title, &task.Content, &task.Priority)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
|
//send email to respective people
|
||||||
}
|
}
|
||||||
task = types.Task{Id: TaskID, Title: TaskTitle, Content: TaskContent}
|
|
||||||
}
|
}
|
||||||
tasks = append(tasks, task)
|
tasks = append(tasks, task)
|
||||||
context := types.Context{Tasks: tasks, Navigation: "edit"}
|
context := types.Context{Tasks: tasks, Navigation: "edit"}
|
||||||
|
@ -209,13 +209,13 @@ func DeleteTask(id int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
//AddTask is used to add the task in the database
|
//AddTask is used to add the task in the database
|
||||||
func AddTask(title, content string) error {
|
func AddTask(title, content string, taskPriority int) error {
|
||||||
restoreSQL, err := database.Prepare("insert into task(title, content, created_date, last_modified_at) values(?,?,datetime(), datetime())")
|
restoreSQL, err := database.Prepare("insert into task(title, content, priority, created_date, last_modified_at) values(?,?,datetime(), datetime())")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
tx, err := database.Begin()
|
tx, err := database.Begin()
|
||||||
_, err = tx.Stmt(restoreSQL).Exec(title, content)
|
_, err = tx.Stmt(restoreSQL).Exec(title, content, taskPriority)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<p class="noteContent">{{.Content}}</p>
|
<p class="noteContent">{{.Content}}</p>
|
||||||
<span class="notefooter">
|
<span class="notefooter">
|
||||||
<ul class="menu">
|
<ul class="menu">
|
||||||
|
<li role="presentation">Priority: {{.Priority}}</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a role="menuitem" tabindex="-1" href="/incomplete/{{.Id}}">
|
<a role="menuitem" tabindex="-1" href="/incomplete/{{.Id}}">
|
||||||
<span class="glyphicon glyphicon-eye-close"></span></a>
|
<span class="glyphicon glyphicon-eye-close"></span></a>
|
||||||
|
@ -35,7 +36,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{template "_footer.gtpl"}}
|
{{template "_footer.html"}}
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
<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">Priority: {{.Priority}}</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<a role="menuitem" tabindex="-1" href="/delete/{{.Id}}">
|
<a role="menuitem" tabindex="-1" href="/delete/{{.Id}}">
|
||||||
<span class="glyphicon glyphicon-trash"></span></a>
|
<span class="glyphicon glyphicon-trash"></span></a>
|
||||||
|
@ -43,7 +44,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{template "footer.gtpl"}}
|
{{template "footer.html"}}
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,12 @@
|
||||||
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;">{{.Content}}</textarea>
|
||||||
|
|
||||||
<input type="text" name="id" value="{{.Id}}" class="hidden" />
|
<input type="text" name="id" value="{{.Id}}" class="hidden" />
|
||||||
|
Priority: <select name="priority">
|
||||||
|
<option>---</option>
|
||||||
|
<option {{if eq .Priority "3"}} selected="true" {{end}} value="high">High</option>
|
||||||
|
<option {{if eq .Priority "2"}} selected="true" {{end}} value="medium">Medium</option>
|
||||||
|
<option {{if eq .Priority "1"}} selected="true" {{end}} value="low">Low</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
|
@ -25,7 +31,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{template "_footer.gtpl"}}
|
{{template "_footer.html"}}
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
|
@ -14,14 +14,20 @@
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<form enctype="multipart/form-data" action="/add/" method="POST">
|
<form enctype="multipart/form-data" action="/add/" method="POST">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<!-- <label for="note-title" class="control-label">Title:</label> -->
|
|
||||||
<input type="text" name="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" class="form-control" id="add-note-title" placeholder="Title" style="border:none;border-bottom:1px solid gray; box-shadow:none;">
|
||||||
<input type="hidden" name="CSRFToken" value={{.CSRFToken}}>
|
<input type="hidden" name="CSRFToken" value={{.CSRFToken}}>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<input type="file" name="uploadfile" />
|
|
||||||
<!-- <label for="note-content" class="control-label">Content:</label> -->
|
|
||||||
<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;"></textarea>
|
<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;"></textarea>
|
||||||
|
File: <input type="file" name="uploadfile" /> <br>
|
||||||
|
Priority: <select name="priority">
|
||||||
|
<option>---</option>
|
||||||
|
<option value="3">High</option>
|
||||||
|
<option value="2">Medium</option>
|
||||||
|
<option value="1">Low</option>
|
||||||
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -42,6 +48,7 @@
|
||||||
<p class="noteContent">{{.Content}}</p>
|
<p class="noteContent">{{.Content}}</p>
|
||||||
<span class="notefooter">
|
<span class="notefooter">
|
||||||
<ul class="menu">
|
<ul class="menu">
|
||||||
|
<li role="presentation">Priority: {{.Priority}}</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<span class="glyphicon glyphicon-time"></span> {{.Created}}</li>
|
<span class="glyphicon glyphicon-time"></span> {{.Created}}</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
<p class="noteContent">{{.Content}}</p>
|
<p class="noteContent">{{.Content}}</p>
|
||||||
<span class="notefooter">
|
<span class="notefooter">
|
||||||
<ul class="menu">
|
<ul class="menu">
|
||||||
|
<li role="presentation">Priority: {{.Priority}}</li>
|
||||||
<li role="presentation">
|
<li role="presentation">
|
||||||
<span class="glyphicon glyphicon-time"></span> {{.Created}}</li>
|
<span class="glyphicon glyphicon-time"></span> {{.Created}}</li>
|
||||||
<!-- <li role="presentation">
|
<!-- <li role="presentation">
|
||||||
|
@ -34,7 +35,7 @@
|
||||||
</div>
|
</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
</div>
|
</div>
|
||||||
{{template "_footer.gtpl"}}
|
{{template "_footer.html"}}
|
||||||
|
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -6,5 +6,5 @@ CREATE TABLE task (
|
||||||
created_date timestamp,
|
created_date timestamp,
|
||||||
last_modified_at timestamp,
|
last_modified_at timestamp,
|
||||||
finish_date timestamp
|
finish_date timestamp
|
||||||
);
|
, priority int);
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ type Task struct {
|
||||||
Title string
|
Title string
|
||||||
Content string
|
Content string
|
||||||
Created string
|
Created string
|
||||||
|
Priority string
|
||||||
}
|
}
|
||||||
|
|
||||||
//Context is the struct passed to templates
|
//Context is the struct passed to templates
|
||||||
|
|
|
@ -3,6 +3,7 @@ package views
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"github.com/thewhitetulip/Tasks/db"
|
"github.com/thewhitetulip/Tasks/db"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -11,7 +12,6 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
"io"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var homeTemplate *template.Template
|
var homeTemplate *template.Template
|
||||||
|
@ -113,7 +113,17 @@ func AddTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
file, handler, err := r.FormFile("uploadfile")
|
file, handler, err := r.FormFile("uploadfile")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return
|
}
|
||||||
|
|
||||||
|
taskPriority, priorityErr := strconv.Atoi(r.FormValue("priority"))
|
||||||
|
if priorityErr != nil {
|
||||||
|
log.Print("Someone trying to hack")
|
||||||
|
}
|
||||||
|
priorityList := []int{1, 2, 3}
|
||||||
|
for _, priority := range priorityList {
|
||||||
|
if taskPriority != priority {
|
||||||
|
log.Println("someone trying to hack")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
title := template.HTMLEscapeString(r.Form.Get("title"))
|
title := template.HTMLEscapeString(r.Form.Get("title"))
|
||||||
content := template.HTMLEscapeString(r.Form.Get("content"))
|
content := template.HTMLEscapeString(r.Form.Get("content"))
|
||||||
|
@ -131,11 +141,11 @@ func AddTaskFunc(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
io.Copy(f, file)
|
io.Copy(f, file)
|
||||||
filelink := "<br> <a href=./files/"+handler.Filename+">"+ handler.Filename+"</a>"
|
filelink := "<br> <a href=/files/" + handler.Filename + ">" + handler.Filename + "</a>"
|
||||||
content = content + filelink
|
content = content + filelink
|
||||||
}
|
}
|
||||||
|
|
||||||
truth := db.AddTask(title, content)
|
truth := db.AddTask(title, content, taskPriority)
|
||||||
if truth != nil {
|
if truth != nil {
|
||||||
message = "Error adding task"
|
message = "Error adding task"
|
||||||
log.Println("error adding task to db")
|
log.Println("error adding task to db")
|
||||||
|
|
Loading…
Reference in New Issue