Editing and better sorting
This commit is contained in:
parent
e90d5c8a63
commit
d14d1ec468
5
db/db.go
5
db/db.go
@ -197,6 +197,11 @@ func GetUpcomingTodos() ([]types.Todo, error) {
|
||||
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 {
|
||||
_, err := db.Exec("UPDATE items SET completed=? WHERE id=?", completed, id)
|
||||
return err
|
||||
|
1
main.go
1
main.go
@ -61,6 +61,7 @@ func addFrontendEndpoints(mux *http.ServeMux) {
|
||||
mux.HandleFunc("/upcoming", pages.UpcomingFragment)
|
||||
mux.HandleFunc("DELETE /delete/{id}", pages.DeleteItem)
|
||||
mux.HandleFunc("PATCH /set/{id}", pages.SetItemCompleted)
|
||||
mux.HandleFunc("PUT /update", pages.UpdateItem)
|
||||
mux.HandleFunc("POST /new", pages.CreateItem)
|
||||
|
||||
fileServer := http.FileServer(http.Dir("./static"))
|
||||
|
@ -54,28 +54,50 @@ templ RootPage() {
|
||||
</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 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="create-item-form-column"></div>
|
||||
<div class="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 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>
|
||||
@ -83,12 +105,16 @@ templ RootPage() {
|
||||
</html>
|
||||
}
|
||||
|
||||
script edit(item_id string) {
|
||||
edit(item_id)
|
||||
}
|
||||
|
||||
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))) }/>
|
||||
<div class="todo-text">{ item.Text }</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,14 +1,12 @@
|
||||
// Code generated by templ - DO NOT EDIT.
|
||||
|
||||
// templ: version: v0.2.663
|
||||
// templ: version: v0.2.747
|
||||
package templates
|
||||
|
||||
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
||||
|
||||
import "github.com/a-h/templ"
|
||||
import "context"
|
||||
import "io"
|
||||
import "bytes"
|
||||
import templruntime "github.com/a-h/templ/runtime"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -17,11 +15,16 @@ import (
|
||||
)
|
||||
|
||||
func RootPage() templ.Component {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
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 {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
||||
@ -29,23 +32,35 @@ func RootPage() templ.Component {
|
||||
templ_7745c5c3_Var1 = templ.NopComponent
|
||||
}
|
||||
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\"><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 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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
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 {
|
||||
return templ.ComponentFunc(func(ctx context.Context, templ_7745c5c3_W io.Writer) (templ_7745c5c3_Err error) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
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 {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var2 := templ.GetChildren(ctx)
|
||||
@ -53,29 +68,55 @@ func TodoItem(item types.Todo) templ.Component {
|
||||
templ_7745c5c3_Var2 = templ.NopComponent
|
||||
}
|
||||
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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
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 {
|
||||
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: 113, Col: 45}
|
||||
}
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
||||
if templ_7745c5c3_Err != nil {
|
||||
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: 113, 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: 113, 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=\"")
|
||||
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.Due))
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", item.Due))
|
||||
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: 113, 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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@ -93,12 +134,12 @@ func TodoItem(item types.Todo) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var5 string
|
||||
templ_7745c5c3_Var5, templ_7745c5c3_Err = templ.JoinStringErrs(string(templ.URL(fmt.Sprintf("/set/%d", item.Id))))
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(string(templ.URL(fmt.Sprintf("/set/%d", item.Id))))
|
||||
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: 114, 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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@ -106,25 +147,25 @@ func TodoItem(item types.Todo) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var6 string
|
||||
templ_7745c5c3_Var6, templ_7745c5c3_Err = templ.JoinStringErrs(item.Text)
|
||||
var templ_7745c5c3_Var8 string
|
||||
templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(item.Text)
|
||||
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: 115, 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 {
|
||||
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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var7 string
|
||||
templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("/delete/%d", item.Id))
|
||||
var templ_7745c5c3_Var9 string
|
||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("/delete/%d", item.Id))
|
||||
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: 118, 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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@ -132,36 +173,38 @@ func TodoItem(item types.Todo) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
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) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
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 {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var8 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var8 == nil {
|
||||
templ_7745c5c3_Var8 = templ.NopComponent
|
||||
templ_7745c5c3_Var10 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var10 == nil {
|
||||
templ_7745c5c3_Var10 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div hx-swap-oob=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var9 string
|
||||
templ_7745c5c3_Var9, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%s:%s", "afterend", targetSelector))
|
||||
var templ_7745c5c3_Var11 string
|
||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%s:%s", "afterend", targetSelector))
|
||||
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: 124, 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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@ -177,36 +220,38 @@ func OobTodoItem(targetSelector string, item types.Todo) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
||||
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) {
|
||||
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templ_7745c5c3_W.(*bytes.Buffer)
|
||||
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
||||
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 {
|
||||
templ_7745c5c3_Buffer = templ.GetBuffer()
|
||||
defer templ.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
defer func() {
|
||||
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
||||
if templ_7745c5c3_Err == nil {
|
||||
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
||||
}
|
||||
}()
|
||||
}
|
||||
ctx = templ.InitializeContext(ctx)
|
||||
templ_7745c5c3_Var10 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var10 == nil {
|
||||
templ_7745c5c3_Var10 = templ.NopComponent
|
||||
templ_7745c5c3_Var12 := templ.GetChildren(ctx)
|
||||
if templ_7745c5c3_Var12 == nil {
|
||||
templ_7745c5c3_Var12 = templ.NopComponent
|
||||
}
|
||||
ctx = templ.ClearChildren(ctx)
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString("<div class=\"todo-list-items\" data-item-count=\"")
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var11 string
|
||||
templ_7745c5c3_Var11, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(items)))
|
||||
var templ_7745c5c3_Var13 string
|
||||
templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("%d", len(items)))
|
||||
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: 130, 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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@ -214,12 +259,12 @@ func TodoList(fillerText string, items []types.Todo) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
var templ_7745c5c3_Var12 string
|
||||
templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(fillerText)
|
||||
var templ_7745c5c3_Var14 string
|
||||
templ_7745c5c3_Var14, templ_7745c5c3_Err = templ.JoinStringErrs(fillerText)
|
||||
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: 131, 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 {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
@ -237,9 +282,6 @@ func TodoList(fillerText string, items []types.Todo) templ.Component {
|
||||
if templ_7745c5c3_Err != nil {
|
||||
return templ_7745c5c3_Err
|
||||
}
|
||||
if !templ_7745c5c3_IsBuffer {
|
||||
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteTo(templ_7745c5c3_W)
|
||||
}
|
||||
return templ_7745c5c3_Err
|
||||
})
|
||||
}
|
||||
|
@ -99,3 +99,61 @@ func SetItemCompleted(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
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)
|
||||
}
|
||||
|
@ -133,7 +133,7 @@ nav {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#create-item {
|
||||
form {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
top: 50%;
|
||||
@ -152,35 +152,35 @@ nav {
|
||||
padding: 30px;
|
||||
}
|
||||
|
||||
#create-item:target {
|
||||
form:target {
|
||||
top: 48%;
|
||||
visibility: visible;
|
||||
opacity: 1;
|
||||
transition: visibility 0s, top .5s, opacity .5s linear;
|
||||
}
|
||||
|
||||
#create-item-title {
|
||||
.form-title {
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
margin-top: -10px;
|
||||
}
|
||||
|
||||
#create-item-form-container {
|
||||
.form-container {
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: row;
|
||||
}
|
||||
|
||||
.create-item-form-column {
|
||||
.form-column {
|
||||
flex: 1;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.create-item-form-column input {
|
||||
.form-column input {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
#create-item-button-container {
|
||||
.form-button-container {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
@ -189,7 +189,7 @@ nav {
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.button {
|
||||
form .button {
|
||||
padding: 10px 20px;
|
||||
text-decoration: none;
|
||||
border: 2px solid;
|
||||
@ -200,15 +200,15 @@ nav {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
form .button:hover {
|
||||
background-color: #ddd;
|
||||
}
|
||||
|
||||
#create-item-close-button {
|
||||
.form-close-button {
|
||||
color: initial;
|
||||
}
|
||||
|
||||
#create-item-save-button {
|
||||
.form-save-button {
|
||||
color: blue;
|
||||
border-color: blue;
|
||||
}
|
||||
|
@ -1,34 +1,61 @@
|
||||
document.addEventListener("keyup", (event) => {
|
||||
if (event.key === "Escape") {
|
||||
window.location.hash = '';
|
||||
}
|
||||
});
|
||||
|
||||
function on_load() {
|
||||
let start_input = document.getElementById("create-item-form-start");
|
||||
let due_input = document.getElementById("create-item-form-due");
|
||||
let create_start_input = document.getElementById("create-item-start");
|
||||
let create_due_input = document.getElementById("create-item-due");
|
||||
|
||||
let create_form = document.getElementById("create-item");
|
||||
|
||||
create_form.addEventListener("htmx:configRequest", function(evt) {
|
||||
evt.detail.parameters["start"] = start_input.value ? start_input.valueAsNumber / 1000 : 0;
|
||||
evt.detail.parameters["due"] = due_input.value ? due_input.valueAsNumber / 1000 : 0;
|
||||
evt.detail.parameters["start"] = create_start_input.value ? create_start_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) {
|
||||
if (evt.detail.successful) {
|
||||
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) {
|
||||
let overdue_items = document.querySelector("#overdue-list > .todo-list-items");
|
||||
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];
|
||||
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];
|
||||
break;
|
||||
}
|
||||
@ -42,14 +69,16 @@ function on_load() {
|
||||
document.querySelector("#today-list > .new-item").addEventListener("htmx:oobBeforeSwap", function(evt) {
|
||||
let today_items = document.querySelector("#today-list > .todo-list-items");
|
||||
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];
|
||||
if (due !== 0) {
|
||||
for (let i = 1; i < today_items.children.length; i++) {
|
||||
if (parseInt(today_items.children[i].getAttribute("data-due")) > due) {
|
||||
target = today_items.children[i - 1];
|
||||
break;
|
||||
}
|
||||
for (let i = 1; i < today_items.children.length; i++) {
|
||||
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];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,10 +90,14 @@ function on_load() {
|
||||
document.querySelector("#upcoming-list > .new-item").addEventListener("htmx:oobBeforeSwap", function(evt) {
|
||||
let upcoming_items = document.querySelector("#upcoming-list > .todo-list-items");
|
||||
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];
|
||||
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];
|
||||
break;
|
||||
}
|
||||
@ -77,9 +110,44 @@ function on_load() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (document.readyState === "completed") {
|
||||
on_load();
|
||||
} else {
|
||||
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";
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user