Compare commits
2 Commits
b5dfb135df
...
1caf06934f
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1caf06934f | ||
|
|
c7430bc942 |
@ -37,11 +37,26 @@ type Wishes struct {
|
|||||||
|
|
||||||
type Wishlist struct {
|
type Wishlist struct {
|
||||||
Label string `json:"label" xml:",chardata"`
|
Label string `json:"label" xml:",chardata"`
|
||||||
Wishes hmc.Form[Wishes] `json:"wishes"`
|
Wishes *hmc.Form[Wishes] `json:"wishes"`
|
||||||
NewWish *hmc.Form[hmc.Input] `json:"new_wish"`
|
NewWish *hmc.Form[hmc.Input] `json:"new_wish"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitialWishlist(currentUserId string, wishes []lishwist.Wish) Wishlist {
|
func InitialWishlist(wishes []lishwist.Wish) Wishlist {
|
||||||
|
list := Wishlist{
|
||||||
|
Label: "Your wishlist",
|
||||||
|
NewWish: &hmc.Form[hmc.Input]{
|
||||||
|
Method: "POST",
|
||||||
|
Elements: hmc.Input{
|
||||||
|
Label: "Add gift idea",
|
||||||
|
Name: "gift_name",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(wishes) < 1 {
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
wishInputs := make([]hmc.Option, len(wishes))
|
wishInputs := make([]hmc.Option, len(wishes))
|
||||||
items := make([]Wish, len(wishes))
|
items := make([]Wish, len(wishes))
|
||||||
|
|
||||||
@ -62,41 +77,41 @@ func InitialWishlist(currentUserId string, wishes []lishwist.Wish) Wishlist {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Wishlist{
|
list.Wishes = &hmc.Form[Wishes]{
|
||||||
Label: "Your wishlist",
|
Method: "POST",
|
||||||
Wishes: hmc.Form[Wishes]{
|
Elements: Wishes{
|
||||||
Method: "POST",
|
Items: items,
|
||||||
Elements: Wishes{
|
Select: hmc.Select{
|
||||||
Items: items,
|
Label: "Wishes",
|
||||||
Select: hmc.Select{
|
Multiple: true,
|
||||||
Label: "Wishes",
|
Name: "wish",
|
||||||
Multiple: true,
|
Required: true,
|
||||||
Name: "wish",
|
Options: wishInputs,
|
||||||
Required: true,
|
|
||||||
Options: wishInputs,
|
|
||||||
},
|
|
||||||
Intent: hmc.Select{
|
|
||||||
Label: "Intent",
|
|
||||||
Required: true,
|
|
||||||
Name: "intent",
|
|
||||||
Options: []hmc.Option{{
|
|
||||||
Label: "Delete",
|
|
||||||
Value: "delete",
|
|
||||||
}},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
Intent: hmc.Select{
|
||||||
NewWish: &hmc.Form[hmc.Input]{
|
Label: "Intent",
|
||||||
Method: "POST",
|
Required: true,
|
||||||
Elements: hmc.Input{
|
Name: "intent",
|
||||||
Label: "Add gift idea",
|
Options: []hmc.Option{{
|
||||||
Name: "gift_name",
|
Label: "Delete",
|
||||||
|
Value: "delete",
|
||||||
|
}},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitialTodo(todo []lishwist.Wish) Wishlist {
|
func InitialTodo(todo []lishwist.Wish) Wishlist {
|
||||||
|
list := Wishlist{
|
||||||
|
Label: "Your todo list",
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(todo) < 1 {
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
wishInputs := make([]Wish, len(todo))
|
wishInputs := make([]Wish, len(todo))
|
||||||
options := make([]hmc.Option, len(todo))
|
options := make([]hmc.Option, len(todo))
|
||||||
|
|
||||||
@ -129,37 +144,36 @@ func InitialTodo(todo []lishwist.Wish) Wishlist {
|
|||||||
options[i] = opt
|
options[i] = opt
|
||||||
}
|
}
|
||||||
|
|
||||||
return Wishlist{
|
list.Wishes = &hmc.Form[Wishes]{
|
||||||
Label: "Your todo list",
|
Method: "POST",
|
||||||
Wishes: hmc.Form[Wishes]{
|
Elements: Wishes{
|
||||||
Method: "POST",
|
Items: wishInputs,
|
||||||
Elements: Wishes{
|
Select: hmc.Select{
|
||||||
Items: wishInputs,
|
Label: "Todos",
|
||||||
Select: hmc.Select{
|
Multiple: true,
|
||||||
Label: "Todos",
|
Name: "todo",
|
||||||
Multiple: true,
|
Required: true,
|
||||||
Name: "todo",
|
Options: options,
|
||||||
Required: true,
|
},
|
||||||
Options: options,
|
Intent: hmc.Select{
|
||||||
},
|
Label: "Intent",
|
||||||
Intent: hmc.Select{
|
Required: true,
|
||||||
Label: "Intent",
|
Name: "intent",
|
||||||
Required: true,
|
Options: []hmc.Option{
|
||||||
Name: "intent",
|
{
|
||||||
Options: []hmc.Option{
|
Label: "Unclaim",
|
||||||
{
|
Value: "unclaim_todo",
|
||||||
Label: "Unclaim",
|
},
|
||||||
Value: "unclaim_todo",
|
{
|
||||||
},
|
Label: "Complete",
|
||||||
{
|
Value: "complete_todo",
|
||||||
Label: "Complete",
|
|
||||||
Value: "complete_todo",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w Wishlist) ExtractFormValues(form url.Values) {
|
func (w Wishlist) ExtractFormValues(form url.Values) {
|
||||||
@ -167,6 +181,10 @@ func (w Wishlist) ExtractFormValues(form url.Values) {
|
|||||||
w.NewWish.Elements.ExtractFormValue(form)
|
w.NewWish.Elements.ExtractFormValue(form)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if w.Wishes == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
err := w.Wishes.Elements.Select.ExtractFormValue(form)
|
err := w.Wishes.Elements.Select.ExtractFormValue(form)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Wishes.Elements.Select.Error = err.Error()
|
w.Wishes.Elements.Select.Error = err.Error()
|
||||||
|
|||||||
@ -58,7 +58,7 @@ func Home(app *lishwist.Session, session *session.Session, w rsvp.ResponseWriter
|
|||||||
p := resources.HomeProps{
|
p := resources.HomeProps{
|
||||||
Namespace: hmc.NS(),
|
Namespace: hmc.NS(),
|
||||||
Navbar: navbar,
|
Navbar: navbar,
|
||||||
Wishlist: resources.InitialWishlist(user.Id, gifts),
|
Wishlist: resources.InitialWishlist(gifts),
|
||||||
Todo: resources.InitialTodo(todo),
|
Todo: resources.InitialTodo(todo),
|
||||||
GroupsList: resources.LinksList{
|
GroupsList: resources.LinksList{
|
||||||
Label: "Your groups",
|
Label: "Your groups",
|
||||||
@ -90,7 +90,7 @@ func Home(app *lishwist.Session, session *session.Session, w rsvp.ResponseWriter
|
|||||||
p.Warning = "Extraneous form values"
|
p.Warning = "Extraneous form values"
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Wishlist.Wishes.Elements.Intent.Value() == "delete" {
|
if p.Wishlist.Wishes != nil && p.Wishlist.Wishes.Elements.Intent.Value() == "delete" {
|
||||||
wishesToDelete := slices.Collect(p.Wishlist.Wishes.Elements.Select.Values())
|
wishesToDelete := slices.Collect(p.Wishlist.Wishes.Elements.Select.Values())
|
||||||
err := app.RevokeWishes(wishesToDelete...)
|
err := app.RevokeWishes(wishesToDelete...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -109,16 +109,16 @@ func Home(app *lishwist.Session, session *session.Session, w rsvp.ResponseWriter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
todosToChange := slices.Collect(p.Todo.Wishes.Elements.Select.Values())
|
if p.Todo.Wishes != nil && p.Todo.Wishes.Elements.Intent.Value() == "unclaim_todo" {
|
||||||
|
todosToChange := slices.Collect(p.Todo.Wishes.Elements.Select.Values())
|
||||||
if p.Todo.Wishes.Elements.Intent.Value() == "unclaim_todo" {
|
|
||||||
err := app.ClaimWishes([]string{}, todosToChange)
|
err := app.ClaimWishes([]string{}, todosToChange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to unclaim wish: %s\n", err)
|
log.Printf("Failed to unclaim wish: %s\n", err)
|
||||||
p.Todo.Wishes.Elements.Intent.Error = "Something went wrong"
|
p.Todo.Wishes.Elements.Intent.Error = "Something went wrong"
|
||||||
return rsvp.Data(p).StatusInternalServerError()
|
return rsvp.Data(p).StatusInternalServerError()
|
||||||
}
|
}
|
||||||
} else if p.Todo.Wishes.Elements.Intent.Value() == "complete_todo" {
|
} else if p.Todo.Wishes != nil && p.Todo.Wishes.Elements.Intent.Value() == "complete_todo" {
|
||||||
|
todosToChange := slices.Collect(p.Todo.Wishes.Elements.Select.Values())
|
||||||
err := app.CompleteWishes(todosToChange)
|
err := app.CompleteWishes(todosToChange)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Failed to complete wish: %s\n", err)
|
log.Printf("Failed to complete wish: %s\n", err)
|
||||||
|
|||||||
@ -14,7 +14,8 @@
|
|||||||
<section class="card mb-4">
|
<section class="card mb-4">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<h2>{{.Label}}</h2>
|
<h2>{{.Label}}</h2>
|
||||||
{{with .Wishes.Elements}}
|
{{with .Wishes}}
|
||||||
|
{{with .Elements}}
|
||||||
<form method="post" onchange="acceptNames(this, 'deleteSubmit', 'wish')" autocomplete="off">
|
<form method="post" onchange="acceptNames(this, 'deleteSubmit', 'wish')" autocomplete="off">
|
||||||
<ul class="list-group mb-3">
|
<ul class="list-group mb-3">
|
||||||
{{range .Items}}
|
{{range .Items}}
|
||||||
@ -30,6 +31,7 @@
|
|||||||
<button id="deleteSubmit" class="btn btn-danger mb-3" name="intent" value="delete"
|
<button id="deleteSubmit" class="btn btn-danger mb-3" name="intent" value="delete"
|
||||||
disabled>Delete</button>
|
disabled>Delete</button>
|
||||||
</form>
|
</form>
|
||||||
|
{{end}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<p>Your list is empty. Think of some things to add!</p>
|
<p>Your list is empty. Think of some things to add!</p>
|
||||||
{{end}}
|
{{end}}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user