Compare commits

...

2 Commits

Author SHA1 Message Date
e96bbdb0dd Add option to show/hide completed items 2024-09-05 18:21:52 -06:00
d14d1ec468 Editing and better sorting 2024-08-19 23:26:47 -06:00
8 changed files with 347 additions and 131 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
test.db test.db
todo-web

View File

@ -102,7 +102,7 @@ func GetAllTodos() ([]types.Todo, error) {
func GetOverdueTodos() ([]types.Todo, error) { func GetOverdueTodos() ([]types.Todo, error) {
var todos []types.Todo var todos []types.Todo
rows, err := db.Query("SELECT * FROM items WHERE due < ? AND due IS NOT NULL ORDER BY due", time.Now().Unix()) rows, err := db.Query("SELECT * FROM items WHERE due < ? AND due IS NOT NULL ORDER BY completed, due", time.Now().Unix())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -136,7 +136,7 @@ func GetTodayTodos() ([]types.Todo, error) {
now := time.Now() now := time.Now()
year, month, day := now.Date() year, month, day := now.Date()
today := time.Date(year, month, day, 0, 0, 0, 0, time.Local) today := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
rows, err := db.Query("SELECT * FROM items WHERE (start <= ? OR start IS NULL) AND (due >= ? OR due IS NULL) ORDER BY due NULLS LAST", today.Unix(), now.Unix()) rows, err := db.Query("SELECT * FROM items WHERE (start <= ? OR start IS NULL) AND (due >= ? OR due IS NULL) ORDER BY completed, due NULLS LAST", today.Unix(), now.Unix())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -169,7 +169,7 @@ func GetUpcomingTodos() ([]types.Todo, error) {
year, month, day := time.Now().Date() year, month, day := time.Now().Date()
today := time.Date(year, month, day, 0, 0, 0, 0, time.Local) today := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
rows, err := db.Query("SELECT * FROM items WHERE start > ? ORDER BY start", today.Unix()) rows, err := db.Query("SELECT * FROM items WHERE start > ? ORDER BY completed, start", today.Unix())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -197,6 +197,11 @@ func GetUpcomingTodos() ([]types.Todo, error) {
return todos, nil return todos, nil
} }
func UpdateTodo(newValues types.Todo) error {
_, err := db.Exec("UPDATE items SET start=?, due=?, text=? WHERE id=?", toNullInt64(newValues.Start), toNullInt64(newValues.Due), newValues.Text, newValues.Id)
return err;
}
func SetCompleted(id int, completed bool) error { func SetCompleted(id int, completed bool) error {
_, err := db.Exec("UPDATE items SET completed=? WHERE id=?", completed, id) _, err := db.Exec("UPDATE items SET completed=? WHERE id=?", completed, id)
return err return err

View File

@ -15,6 +15,7 @@ func main() {
db_path := flag.String("db", "./test.db", "Path to the sqlite3 database") db_path := flag.String("db", "./test.db", "Path to the sqlite3 database")
bind_port := flag.Int("p", 8080, "Port to bind to") bind_port := flag.Int("p", 8080, "Port to bind to")
bind_addr := flag.String("a", "0.0.0.0", "Address to bind to") bind_addr := flag.String("a", "0.0.0.0", "Address to bind to")
static_dir := flag.String("static", "./static", "Path to static files")
noFront := flag.Bool("no-frontend", false, "Disable the frontend endpoints") noFront := flag.Bool("no-frontend", false, "Disable the frontend endpoints")
a := false; noBack := &a // flag.Bool("no-backend", false, "Disable the backend endpoints") a := false; noBack := &a // flag.Bool("no-backend", false, "Disable the backend endpoints")
@ -28,7 +29,7 @@ func main() {
} }
if !*noFront { if !*noFront {
addFrontendEndpoints(mux) addFrontendEndpoints(mux, *static_dir)
} }
if !*noBack { if !*noBack {
@ -50,7 +51,7 @@ func main() {
} }
} }
func addFrontendEndpoints(mux *http.ServeMux) { func addFrontendEndpoints(mux *http.ServeMux, static_path string) {
fmt.Println("Frontend enabled") fmt.Println("Frontend enabled")
mux.HandleFunc("/", Error404) mux.HandleFunc("/", Error404)
@ -61,9 +62,10 @@ func addFrontendEndpoints(mux *http.ServeMux) {
mux.HandleFunc("/upcoming", pages.UpcomingFragment) mux.HandleFunc("/upcoming", pages.UpcomingFragment)
mux.HandleFunc("DELETE /delete/{id}", pages.DeleteItem) mux.HandleFunc("DELETE /delete/{id}", pages.DeleteItem)
mux.HandleFunc("PATCH /set/{id}", pages.SetItemCompleted) mux.HandleFunc("PATCH /set/{id}", pages.SetItemCompleted)
mux.HandleFunc("PUT /update", pages.UpdateItem)
mux.HandleFunc("POST /new", pages.CreateItem) mux.HandleFunc("POST /new", pages.CreateItem)
fileServer := http.FileServer(http.Dir("./static")) fileServer := http.FileServer(http.Dir(static_path))
mux.Handle("/css/", fileServer) mux.Handle("/css/", fileServer)
mux.Handle("/js/", fileServer) mux.Handle("/js/", fileServer)
} }

View File

@ -8,7 +8,7 @@ import (
templ RootPage() { templ RootPage() {
<!Doctype HTML> <!Doctype HTML>
<html lang="en-US"> <html lang="en-US" data-show-completed="false">
<head> <head>
<title>Todo</title> <title>Todo</title>
@ -30,7 +30,10 @@ templ RootPage() {
<a id="new-button" href="#create-item">New</a> <a id="new-button" href="#create-item">New</a>
</div> </div>
<div id="nav-center"></div> <div id="nav-center"></div>
<div id="nav-right"></div> <div id="nav-right">
<label for="show-completed">Show completed</label>
<input id="show-completed" type="checkbox" name="show-completed"/>
</div>
</div> </div>
</nav> </nav>
@ -54,28 +57,50 @@ templ RootPage() {
</div> </div>
<form id="create-item" hx-post="/new" hx-swap="none"> <form id="create-item" hx-post="/new" hx-swap="none">
<div id="create-item-title">Create new Todo</div> <div class="form-title">Create new Todo</div>
<div id="create-item-form-container"> <div class="form-container">
<div class="create-item-form-column"> <div class="form-column">
<div class="create-item-form-column">
<label for="name">Name</label> <label for="name">Name</label>
<br/> <br/>
<input type="text" name="name"/> <input id="create-item-name" type="text" name="name"/>
<br/> <br/>
<label for="start">Start</label> <label for="start">Start</label>
<br/> <br/>
<input id="create-item-form-start" name="start" type="datetime-local"/> <input id="create-item-start" name="start" type="datetime-local"/>
<br/> <br/>
<label for="due">Due</label> <label for="due">Due</label>
<br/> <br/>
<input id="create-item-form-due" name="due" type="datetime-local"/> <input id="create-item-due" name="due" type="datetime-local"/>
</div> </div>
<div class="form-column"></div>
</div> </div>
<div class="create-item-form-column"></div> <div class="form-button-container">
<button id="create-save" class="form-save-button button" type="submit">Save</button>
<a class="form-close-button button" href="#">Close</a>
</div> </div>
<div id="create-item-button-container"> </form>
<button id="create-item-save-button" class="button" type="submit">Save</button>
<a id="create-item-close-button" class="button" href="#">Close</a> <form id="edit-item" data-id="" hx-put="/update" hx-swap="outerHTML">
<div class="form-title">Edit Todo</div>
<div class="form-container">
<div class="form-column">
<label for="name">Name</label>
<br/>
<input id="edit-item-name" type="text" name="name"/>
<br/>
<label for="start">Start</label>
<br/>
<input id="edit-item-start" name="start" type="datetime-local"/>
<br/>
<label for="due">Due</label>
<br/>
<input id="edit-item-due" name="due" type="datetime-local"/>
</div>
<div class="form-column"></div>
</div>
<div class="form-button-container">
<button id="edit-save" class="form-save-button button" type="submit">Save</button>
<a class="form-close-button button" href="#">Close</a>
</div> </div>
</form> </form>
</div> </div>
@ -83,12 +108,16 @@ templ RootPage() {
</html> </html>
} }
script edit(item_id string) {
edit(item_id)
}
templ TodoItem(item types.Todo) { templ TodoItem(item types.Todo) {
<div class="todo-item" data-start={ fmt.Sprintf("%d", item.Start) } data-due={ fmt.Sprintf("%d", item.Due) }> <div id={ fmt.Sprintf("item-%d", item.Id) } class="todo-item" data-idnum={ fmt.Sprintf("%d", item.Id) } data-start={ fmt.Sprintf("%d", item.Start) } data-due={ fmt.Sprintf("%d", item.Due) }>
<input type="checkbox" name="completed" checked?={ item.Completed } hx-patch={ string(templ.URL(fmt.Sprintf("/set/%d", item.Id))) }/> <input type="checkbox" name="completed" checked?={ item.Completed } hx-patch={ string(templ.URL(fmt.Sprintf("/set/%d", item.Id))) }/>
<div class="todo-text">{ item.Text }</div> <div class="todo-text">{ item.Text }</div>
<div class="todo-item-actions"> <div class="todo-item-actions">
<i class="action-edit fa-solid fa-pencil"></i> <i class="action-edit fa-solid fa-pencil" onclick="edit(this.parentElement.parentElement.id)"></i>
<i class="action-delete fa-solid fa-trash" hx-delete={ fmt.Sprintf("/delete/%d", item.Id) } hx-target="closest .todo-item" hx-swap="outerHTML"></i> <i class="action-delete fa-solid fa-trash" hx-delete={ fmt.Sprintf("/delete/%d", item.Id) } hx-target="closest .todo-item" hx-swap="outerHTML"></i>
</div> </div>
</div> </div>

View File

@ -1,14 +1,12 @@
// Code generated by templ - DO NOT EDIT. // Code generated by templ - DO NOT EDIT.
// templ: version: v0.2.663 // templ: version: v0.2.747
package templates package templates
//lint:file-ignore SA4006 This context is only used if a nested component is present. //lint:file-ignore SA4006 This context is only used if a nested component is present.
import "github.com/a-h/templ" import "github.com/a-h/templ"
import "context" import templruntime "github.com/a-h/templ/runtime"
import "io"
import "bytes"
import ( import (
"fmt" "fmt"
@ -17,11 +15,16 @@ import (
) )
func RootPage() templ.Component { func RootPage() templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var1 := templ.GetChildren(ctx) templ_7745c5c3_Var1 := templ.GetChildren(ctx)
@ -29,23 +32,35 @@ func RootPage() templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent templ_7745c5c3_Var1 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype HTML><html lang=\"en-US\"><head><title>Todo</title><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><link rel=\"stylesheet\" href=\"/css/styles.css\"><script src=\"/js/script.js\"></script><script src=\"/js/lib/htmx.min.js\"></script><!-- Font Awesome --><script src=\"https://kit.fontawesome.com/469cdddb31.js\" crossorigin=\"anonymous\"></script></head><body><nav><div id=\"nav-container\"><div id=\"nav-left\"><a id=\"new-button\" href=\"#create-item\">New</a></div><div id=\"nav-center\"></div><div id=\"nav-right\"></div></div></nav><div id=\"main-content\"><div id=\"lists\"><div id=\"overdue-list\" class=\"todo-list\"><div class=\"todo-list-title\">Overdue</div><div class=\"todo-list-items\" hx-get=\"/overdue\" hx-trigger=\"load\" hx-swap=\"outerHTML\"></div><div class=\"new-item\"></div></div><div id=\"today-list\" class=\"todo-list\"><div class=\"todo-list-title\">Today</div><div class=\"todo-list-items\" hx-get=\"/today\" hx-trigger=\"load\" hx-swap=\"outerHTML\"></div><div class=\"new-item\"></div></div><div id=\"upcoming-list\" class=\"todo-list\"><div class=\"todo-list-title\">Upcoming</div><div class=\"todo-list-items\" hx-get=\"/upcoming\" hx-trigger=\"load\" hx-swap=\"outerHTML\"></div><div class=\"new-item\"></div></div></div><form id=\"create-item\" hx-post=\"/new\" hx-swap=\"none\"><div id=\"create-item-title\">Create new Todo</div><div id=\"create-item-form-container\"><div class=\"create-item-form-column\"><div class=\"create-item-form-column\"><label for=\"name\">Name</label><br><input type=\"text\" name=\"name\"><br><label for=\"start\">Start</label><br><input id=\"create-item-form-start\" name=\"start\" type=\"datetime-local\"><br><label for=\"due\">Due</label><br><input id=\"create-item-form-due\" name=\"due\" type=\"datetime-local\"></div></div><div class=\"create-item-form-column\"></div></div><div id=\"create-item-button-container\"><button id=\"create-item-save-button\" class=\"button\" type=\"submit\">Save</button> <a id=\"create-item-close-button\" class=\"button\" href=\"#\">Close</a></div></form></div></body></html>") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<!doctype HTML><html lang=\"en-US\" data-show-completed=\"false\"><head><title>Todo</title><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><link rel=\"stylesheet\" href=\"/css/styles.css\"><script src=\"/js/script.js\"></script><script src=\"/js/lib/htmx.min.js\"></script><!-- Font Awesome --><script src=\"https://kit.fontawesome.com/469cdddb31.js\" crossorigin=\"anonymous\"></script></head><body><nav><div id=\"nav-container\"><div id=\"nav-left\"><a id=\"new-button\" href=\"#create-item\">New</a></div><div id=\"nav-center\"></div><div id=\"nav-right\"><label for=\"show-completed\">Show completed</label> <input id=\"show-completed\" type=\"checkbox\" name=\"show-completed\"></div></div></nav><div id=\"main-content\"><div id=\"lists\"><div id=\"overdue-list\" class=\"todo-list\"><div class=\"todo-list-title\">Overdue</div><div class=\"todo-list-items\" hx-get=\"/overdue\" hx-trigger=\"load\" hx-swap=\"outerHTML\"></div><div class=\"new-item\"></div></div><div id=\"today-list\" class=\"todo-list\"><div class=\"todo-list-title\">Today</div><div class=\"todo-list-items\" hx-get=\"/today\" hx-trigger=\"load\" hx-swap=\"outerHTML\"></div><div class=\"new-item\"></div></div><div id=\"upcoming-list\" class=\"todo-list\"><div class=\"todo-list-title\">Upcoming</div><div class=\"todo-list-items\" hx-get=\"/upcoming\" hx-trigger=\"load\" hx-swap=\"outerHTML\"></div><div class=\"new-item\"></div></div></div><form id=\"create-item\" hx-post=\"/new\" hx-swap=\"none\"><div class=\"form-title\">Create new Todo</div><div class=\"form-container\"><div class=\"form-column\"><label for=\"name\">Name</label><br><input id=\"create-item-name\" type=\"text\" name=\"name\"><br><label for=\"start\">Start</label><br><input id=\"create-item-start\" name=\"start\" type=\"datetime-local\"><br><label for=\"due\">Due</label><br><input id=\"create-item-due\" name=\"due\" type=\"datetime-local\"></div><div class=\"form-column\"></div></div><div class=\"form-button-container\"><button id=\"create-save\" class=\"form-save-button button\" type=\"submit\">Save</button> <a class=\"form-close-button button\" href=\"#\">Close</a></div></form><form id=\"edit-item\" data-id=\"\" hx-put=\"/update\" hx-swap=\"outerHTML\"><div class=\"form-title\">Edit Todo</div><div class=\"form-container\"><div class=\"form-column\"><label for=\"name\">Name</label><br><input id=\"edit-item-name\" type=\"text\" name=\"name\"><br><label for=\"start\">Start</label><br><input id=\"edit-item-start\" name=\"start\" type=\"datetime-local\"><br><label for=\"due\">Due</label><br><input id=\"edit-item-due\" name=\"due\" type=\"datetime-local\"></div><div class=\"form-column\"></div></div><div class=\"form-button-container\"><button id=\"edit-save\" class=\"form-save-button button\" type=\"submit\">Save</button> <a class=\"form-close-button button\" href=\"#\">Close</a></div></form></div></body></html>")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err return templ_7745c5c3_Err
}) })
} }
func edit(item_id string) templ.ComponentScript {
return templ.ComponentScript{
Name: `__templ_edit_2f09`,
Function: `function __templ_edit_2f09(item_id){edit(item_id)
}`,
Call: templ.SafeScript(`__templ_edit_2f09`, item_id),
CallInline: templ.SafeScriptInline(`__templ_edit_2f09`, item_id),
}
}
func TodoItem(item types.Todo) templ.Component { func TodoItem(item types.Todo) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var2 := templ.GetChildren(ctx) templ_7745c5c3_Var2 := templ.GetChildren(ctx)
@ -53,29 +68,55 @@ func TodoItem(item types.Todo) templ.Component {
templ_7745c5c3_Var2 = templ.NopComponent templ_7745c5c3_Var2 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"todo-item\" data-start=\"") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div id=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var3 string var templ_7745c5c3_Var3 string
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", item.Start)) templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("item-%d", item.Id))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 87, Col: 69} return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 116, Col: 45}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" class=\"todo-item\" data-idnum=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var4 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", item.Id))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 116, Col: 105}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-start=\"")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
var templ_7745c5c3_Var5 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", item.Start))
if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 116, Col: 150}
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5))
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-due=\"") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("\" data-due=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var4 string var templ_7745c5c3_Var6 string
templ_7745c5c3_Var4, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", item.Due)) templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", item.Due))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 87, Col: 110} return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 116, Col: 191}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var4)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -93,12 +134,12 @@ func TodoItem(item types.Todo) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var5 string var templ_7745c5c3_Var7 string
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(string(templ.URL(fmt.Sprintf("/set/%d", item.Id)))) templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(string(templ.URL(fmt.Sprintf("/set/%d", item.Id))))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 88, Col: 137} return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 117, Col: 137}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var5)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -106,25 +147,25 @@ func TodoItem(item types.Todo) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var6 string var templ_7745c5c3_Var8 string
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(item.Text) templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(item.Text)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 89, Col: 42} return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 118, Col: 42}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var6)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div><div class=\"todo-item-actions\"><i class=\"action-edit fa-solid fa-pencil\"></i> <i class=\"action-delete fa-solid fa-trash\" hx-delete=\"") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("</div><div class=\"todo-item-actions\"><i class=\"action-edit fa-solid fa-pencil\" onclick=\"edit(this.parentElement.parentElement.id)\"></i> <i class=\"action-delete fa-solid fa-trash\" hx-delete=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var7 string var templ_7745c5c3_Var9 string
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("/delete/%d", item.Id)) templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("/delete/%d", item.Id))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 92, Col: 101} return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 121, Col: 101}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -132,36 +173,38 @@ func TodoItem(item types.Todo) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err return templ_7745c5c3_Err
}) })
} }
func OobTodoItem(targetSelector string, item types.Todo) templ.Component { func OobTodoItem(targetSelector string, item types.Todo) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var8 := templ.GetChildren(ctx) templ_7745c5c3_Var10 := templ.GetChildren(ctx)
if templ_7745c5c3_Var8 == nil { if templ_7745c5c3_Var10 == nil {
templ_7745c5c3_Var8 = templ.NopComponent templ_7745c5c3_Var10 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div hx-swap-oob=\"") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div hx-swap-oob=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var9 string var templ_7745c5c3_Var11 string
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%s:%s", "afterend", targetSelector)) templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%s:%s", "afterend", targetSelector))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 98, Col: 71} return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 127, Col: 71}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var9)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -177,36 +220,38 @@ func OobTodoItem(targetSelector string, item types.Todo) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err return templ_7745c5c3_Err
}) })
} }
func TodoList(fillerText string, items []types.Todo) templ.Component { func TodoList(fillerText string, items []types.Todo) templ.Component {
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) { return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer) templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
if !templ_7745c5c3_IsBuffer { if !templ_7745c5c3_IsBuffer {
templ_7745c5c3_Buffer = templ.GetBuffer() defer func() {
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer) templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
if templ_7745c5c3_Err == nil {
templ_7745c5c3_Err = templ_7745c5c3_BufErr
}
}()
} }
ctx = templ.InitializeContext(ctx) ctx = templ.InitializeContext(ctx)
templ_7745c5c3_Var10 := templ.GetChildren(ctx) templ_7745c5c3_Var12 := templ.GetChildren(ctx)
if templ_7745c5c3_Var10 == nil { if templ_7745c5c3_Var12 == nil {
templ_7745c5c3_Var10 = templ.NopComponent templ_7745c5c3_Var12 = templ.NopComponent
} }
ctx = templ.ClearChildren(ctx) ctx = templ.ClearChildren(ctx)
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"todo-list-items\" data-item-count=\"") _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"todo-list-items\" data-item-count=\"")
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var11 string var templ_7745c5c3_Var13 string
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(items))) templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(items)))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 104, Col: 80} return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 133, Col: 80}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var11)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -214,12 +259,12 @@ func TodoList(fillerText string, items []types.Todo) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
var templ_7745c5c3_Var12 string var templ_7745c5c3_Var14 string
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fillerText) templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(fillerText)
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 105, Col: 45} return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/templates/root.templ`, Line: 134, Col: 45}
} }
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var14))
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
@ -237,9 +282,6 @@ func TodoList(fillerText string, items []types.Todo) templ.Component {
if templ_7745c5c3_Err != nil { if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err return templ_7745c5c3_Err
} }
if !templ_7745c5c3_IsBuffer {
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
}
return templ_7745c5c3_Err return templ_7745c5c3_Err
}) })
} }

View File

@ -99,3 +99,61 @@ func SetItemCompleted(w http.ResponseWriter, r *http.Request) {
w.Write([]byte{}) w.Write([]byte{})
} }
func UpdateItem(w http.ResponseWriter, r *http.Request) {
var todo types.Todo
var err error
idStr := r.FormValue("id")
todo.Text = r.FormValue("name")
start := r.FormValue("start")
due := r.FormValue("due")
todo.Id, err = strconv.ParseInt(idStr, 10, 64)
if idStr == "" || err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
if start != "" {
todo.Start, err = strconv.ParseInt(start, 10, 64)
if err != nil {
fmt.Printf("Bad start time: %s\n", start)
w.WriteHeader(http.StatusBadRequest)
return
}
} else {
todo.Start = 0
}
if due != "" {
todo.Due, err = strconv.ParseInt(due, 10, 64)
if err != nil {
fmt.Printf("Bad due time: %s\n", due)
w.WriteHeader(http.StatusBadRequest)
return
}
} else {
todo.Due = 0
}
fmt.Printf("New values:\n(%d) %s: %d - %d\n\n", todo.Id, todo.Text, todo.Start, todo.Due)
err = db.UpdateTodo(todo)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
now := time.Now().Unix()
var targetSelector = "#today-list > .new-item"
if todo.Due != 0 && todo.Due < now {
targetSelector = "#overdue-list > .new-item"
}
if todo.Start > now {
targetSelector = "#upcoming-list > .new-item"
}
templates.OobTodoItem(targetSelector, todo).Render(r.Context(), w)
}

View File

@ -13,6 +13,7 @@ nav {
margin: 0 auto; margin: 0 auto;
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
align-items: center;
} }
#new-button { #new-button {
@ -107,6 +108,11 @@ nav {
gap: 10px; gap: 10px;
} }
[data-show-completed="false"]
.todo-item:has(input[type="checkbox"]:checked) {
display: none;
}
.todo-text { .todo-text {
flex: 1; flex: 1;
text-wrap: nowrap; text-wrap: nowrap;
@ -133,7 +139,7 @@ nav {
cursor: pointer; cursor: pointer;
} }
#create-item { form {
position: absolute; position: absolute;
left: 50%; left: 50%;
top: 50%; top: 50%;
@ -152,35 +158,35 @@ nav {
padding: 30px; padding: 30px;
} }
#create-item:target { form:target {
top: 48%; top: 48%;
visibility: visible; visibility: visible;
opacity: 1; opacity: 1;
transition: visibility 0s, top .5s, opacity .5s linear; transition: visibility 0s, top .5s, opacity .5s linear;
} }
#create-item-title { .form-title {
font-size: 2em; font-size: 2em;
font-weight: bold; font-weight: bold;
margin-top: -10px; margin-top: -10px;
} }
#create-item-form-container { .form-container {
display: flex; display: flex;
flex: 1; flex: 1;
flex-direction: row; flex-direction: row;
} }
.create-item-form-column { .form-column {
flex: 1; flex: 1;
padding: 20px; padding: 20px;
} }
.create-item-form-column input { .form-column input {
margin-bottom: 20px; margin-bottom: 20px;
} }
#create-item-button-container { .form-button-container {
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
@ -189,7 +195,7 @@ nav {
gap: 20px; gap: 20px;
} }
.button { form .button {
padding: 10px 20px; padding: 10px 20px;
text-decoration: none; text-decoration: none;
border: 2px solid; border: 2px solid;
@ -200,15 +206,15 @@ nav {
cursor: pointer; cursor: pointer;
} }
.button:hover { form .button:hover {
background-color: #ddd; background-color: #ddd;
} }
#create-item-close-button { .form-close-button {
color: initial; color: initial;
} }
#create-item-save-button { .form-save-button {
color: blue; color: blue;
border-color: blue; border-color: blue;
} }

View File

@ -1,34 +1,61 @@
document.addEventListener("keyup", (event) => {
if (event.key === "Escape") {
window.location.hash = '';
}
});
function on_load() { function on_load() {
let start_input = document.getElementById("create-item-form-start"); let create_start_input = document.getElementById("create-item-start");
let due_input = document.getElementById("create-item-form-due"); let create_due_input = document.getElementById("create-item-due");
let create_form = document.getElementById("create-item"); let create_form = document.getElementById("create-item");
create_form.addEventListener("htmx:configRequest", function(evt) { create_form.addEventListener("htmx:configRequest", function(evt) {
evt.detail.parameters["start"] = start_input.value ? start_input.valueAsNumber / 1000 : 0; evt.detail.parameters["start"] = create_start_input.value ? create_start_input.valueAsNumber / 1000 : 0;
evt.detail.parameters["due"] = due_input.value ? due_input.valueAsNumber / 1000 : 0; evt.detail.parameters["due"] = create_due_input.value ? create_due_input.valueAsNumber / 1000 : 0;
}); });
create_form.addEventListener("htmx:afterRequest", function(evt) { create_form.addEventListener("htmx:afterRequest", function(evt) {
if (evt.detail.successful) { if (evt.detail.successful) {
window.location.hash = ''; window.location.hash = '';
evt.detail.elt.reset(); create_form.reset();
}
});
let edit_start_input = document.getElementById("edit-item-start");
let edit_due_input = document.getElementById("edit-item-due");
let edit_form = document.getElementById("edit-item");
edit_form.addEventListener("htmx:configRequest", function(evt) {
let target = document.getElementById(edit_form.getAttribute("data-id"));
evt.detail.parameters["id"] = parseInt(target.getAttribute("data-idnum"));
evt.detail.parameters["start"] = edit_start_input.value ? edit_start_input.valueAsNumber / 1000 : 0;
evt.detail.parameters["due"] = edit_due_input.value ? edit_due_input.valueAsNumber / 1000 : 0;
});
edit_form.addEventListener("htmx:afterRequest", function(evt) {
if (evt.detail.successful) {
window.location.hash = '';
edit_form.reset();
}
});
edit_form.addEventListener("htmx:beforeSwap", function(evt) {
let target = document.getElementById(edit_form.getAttribute("data-id"));
if (target === null || target === undefined) {
evt.detail.shouldSwap = false;
} else {
evt.detail.target = target;
} }
}); });
document.querySelector("#overdue-list > .new-item").addEventListener("htmx:oobBeforeSwap", function(evt) { document.querySelector("#overdue-list > .new-item").addEventListener("htmx:oobBeforeSwap", function(evt) {
let overdue_items = document.querySelector("#overdue-list > .todo-list-items"); let overdue_items = document.querySelector("#overdue-list > .todo-list-items");
let due = parseInt(evt.detail.fragment.firstElementChild.getAttribute("data-due")); let due = parseInt(evt.detail.fragment.firstElementChild.getAttribute("data-due"));
let id = parseInt(evt.detail.fragment.firstElementChild.getAttribute("data-idnum"));
let target = overdue_items.children[overdue_items.children.length - 1]; let target = overdue_items.children[overdue_items.children.length - 1];
for (let i = 1; i < overdue_items.children.length; i++) { for (let i = 1; i < overdue_items.children.length; i++) {
if (parseInt(overdue_items.children[i].getAttribute("data-due")) > due) { let other_due = parseInt(today_items.children[i].getAttribute("data-due"));
let other_id = parseInt(today_items.children[i].getAttribute("data-idnum"));
if (other_due > due || (other_due === due && other_id > id)) {
target = overdue_items.children[i - 1]; target = overdue_items.children[i - 1];
break; break;
} }
@ -39,19 +66,26 @@ function on_load() {
overdue_items.setAttribute("data-item-count", parseInt(overdue_items.getAttribute("data-item-count")) + 1); overdue_items.setAttribute("data-item-count", parseInt(overdue_items.getAttribute("data-item-count")) + 1);
}); });
let checkbox = document.getElementById("show-completed");
checkbox.addEventListener("change", function(evt) {
document.documentElement.setAttribute("data-show-completed", checkbox.checked);
});
document.querySelector("#today-list > .new-item").addEventListener("htmx:oobBeforeSwap", function(evt) { document.querySelector("#today-list > .new-item").addEventListener("htmx:oobBeforeSwap", function(evt) {
let today_items = document.querySelector("#today-list > .todo-list-items"); let today_items = document.querySelector("#today-list > .todo-list-items");
let due = parseInt(evt.detail.fragment.firstElementChild.getAttribute("data-due")); let due = parseInt(evt.detail.fragment.firstElementChild.getAttribute("data-due"));
let id = parseInt(evt.detail.fragment.firstElementChild.getAttribute("data-idnum"));
let target = today_items.children[today_items.children.length - 1]; let target = today_items.children[today_items.children.length - 1];
if (due !== 0) {
for (let i = 1; i < today_items.children.length; i++) { for (let i = 1; i < today_items.children.length; i++) {
if (parseInt(today_items.children[i].getAttribute("data-due")) > due) { let other_due = parseInt(today_items.children[i].getAttribute("data-due"));
let other_id = parseInt(today_items.children[i].getAttribute("data-idnum"));
if ((other_due > due && due !== 0) || (other_due === due && other_id > id)) {
target = today_items.children[i - 1]; target = today_items.children[i - 1];
break; break;
} }
} }
}
evt.detail.target = target; evt.detail.target = target;
@ -61,10 +95,14 @@ function on_load() {
document.querySelector("#upcoming-list > .new-item").addEventListener("htmx:oobBeforeSwap", function(evt) { document.querySelector("#upcoming-list > .new-item").addEventListener("htmx:oobBeforeSwap", function(evt) {
let upcoming_items = document.querySelector("#upcoming-list > .todo-list-items"); let upcoming_items = document.querySelector("#upcoming-list > .todo-list-items");
let start = parseInt(evt.detail.fragment.firstElementChild.getAttribute("data-start")); let start = parseInt(evt.detail.fragment.firstElementChild.getAttribute("data-start"));
let id = parseInt(evt.detail.fragment.firstElementChild.getAttribute("data-idnum"));
let target = upcoming_items.children[0]; let target = upcoming_items.children[0];
for (let i = 1; i < upcoming_items.children.length; i++) { for (let i = 1; i < upcoming_items.children.length; i++) {
if (parseInt(upcoming_items.children[i].getAttribute("data-start")) > start) { let other_start = parseInt(today_items.children[i].getAttribute("data-start"));
let other_id = parseInt(today_items.children[i].getAttribute("data-idnum"));
if (other_start > start || (other_start === start && other_id > id)) {
target = upcoming_items.children[i - 1]; target = upcoming_items.children[i - 1];
break; break;
} }
@ -77,9 +115,44 @@ function on_load() {
} }
if (document.readyState === "completed") { if (document.readyState === "completed") {
on_load(); on_load();
} else { } else {
document.addEventListener("DOMContentLoaded", on_load); document.addEventListener("DOMContentLoaded", on_load);
} }
document.addEventListener("keyup", (event) => {
if (event.key === "Escape") {
window.location.hash = '';
}
});
function edit(item_id) {
let item = document.getElementById(item_id);
let start = parseInt(item.getAttribute("data-start"));
let due = parseInt(item.getAttribute("data-due"));
let text = item.querySelector(".todo-text").textContent;
let edit_form = document.getElementById("edit-item");
document.getElementById("edit-item-name").value = text;
if (start != 0) {
document.getElementById("edit-item-start").valueAsNumber = start * 1000;
} else {
document.getElementById("edit-item-start").value = null;
}
if (due != 0) {
document.getElementById("edit-item-due").valueAsNumber = due * 1000;
} else {
document.getElementById("edit-item-due").value = null;
}
//document.getElementByid("edit-item-start").value = new Date(start * 100).toISOString().slice(0, 16);
//document.getElementByid("edit-item-due").value = new Date(due * 100).toISOString().slice(0, 16);
edit_form.setAttribute("data-id", item_id);
window.location.hash = "edit-item";
}