From 93ca9d278e4c593be13e3a3fe297fbc5b081a320 Mon Sep 17 00:00:00 2001 From: Bronku Date: Wed, 29 Jan 2025 19:04:08 +0100 Subject: [PATCH] complete dropdown --- .gitignore | 3 +++ controller/cake.go | 14 ++++++++++++ controller/controller.go | 4 ++-- controller/new_order.go | 9 -------- public/index.html | 40 +++++++++++++++++++++++++++++----- templates/cake/options.html | 41 +++++++++++++++++++++++++++++++++++ templates/order/get_new.html | 3 ++- templates/order/post_new.html | 13 ++++++----- 8 files changed, 103 insertions(+), 24 deletions(-) create mode 100644 controller/cake.go create mode 100644 templates/cake/options.html diff --git a/.gitignore b/.gitignore index 6915aaf..0873d77 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ go.work.sum # env file .env .idea + +tmp +tmp/main diff --git a/controller/cake.go b/controller/cake.go new file mode 100644 index 0000000..96832f9 --- /dev/null +++ b/controller/cake.go @@ -0,0 +1,14 @@ +package controller + +import ( + "net/http" +) + +func (c *Controller) cakeOptions(w http.ResponseWriter, _ *http.Request) { + type cake struct { + Name string + ID int + } + //w.Header().Set("Content-Type", "text/html") + c.tmpl["cake/options"].Execute(w, struct{ Cakes []cake }{Cakes: []cake{{"Hello", 1}, {"World", 2}}}) +} diff --git a/controller/controller.go b/controller/controller.go index 9eedb2c..1b7d240 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -15,7 +15,7 @@ type Controller struct { func (c *Controller) LoadTemplates(fs fs.FS) { c.tmpl = make(map[string]*template.Template) c.tmpl["order/post_new"], _ = template.ParseFS(fs, "templates/order/post_new.html") - c.tmpl["order/get_new"], _ = template.ParseFS(fs, "templates/order/get_new.html") + c.tmpl["cake/options"], _ = template.ParseFS(fs, "templates/cake/options.html") } func (c *Controller) LoadRouter(pub fs.FS) { @@ -23,7 +23,7 @@ func (c *Controller) LoadRouter(pub fs.FS) { serveMux.Handle("GET /", http.FileServerFS(unwrap(fs.Sub(pub, "public")))) serveMux.HandleFunc("POST /order/new", c.postNewOrder) - serveMux.HandleFunc("GET /order/new", c.getNewOrder) + serveMux.HandleFunc("GET /cake/options", c.cakeOptions) c.Handler = serveMux } diff --git a/controller/new_order.go b/controller/new_order.go index 08d7849..7f60502 100644 --- a/controller/new_order.go +++ b/controller/new_order.go @@ -15,12 +15,3 @@ func (c *Controller) postNewOrder(w http.ResponseWriter, r *http.Request) { fmt.Println(r.Form) _ = c.tmpl["order/post_new"].Execute(w, struct{ Status any }{Status: r.Form}) } - -func (c *Controller) getNewOrder(w http.ResponseWriter, r *http.Request) { - fmt.Println("received Get request: ", r) - type cake struct { - Name string - ID int - } - _ = c.tmpl["order/get_new"].Execute(w, struct{ Cakes []cake }{Cakes: []cake{cake{"Hello", 1}, cake{"World", 2}}}) -} diff --git a/public/index.html b/public/index.html index e405e6c..0d8fa4d 100644 --- a/public/index.html +++ b/public/index.html @@ -6,8 +6,7 @@ IROON - - + @@ -15,10 +14,39 @@

I ran out of names

-
- -
-
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + +
+
+
diff --git a/templates/cake/options.html b/templates/cake/options.html new file mode 100644 index 0000000..2ee668a --- /dev/null +++ b/templates/cake/options.html @@ -0,0 +1,41 @@ + + \ No newline at end of file diff --git a/templates/order/get_new.html b/templates/order/get_new.html index 4c24d56..ee91e06 100644 --- a/templates/order/get_new.html +++ b/templates/order/get_new.html @@ -1,4 +1,4 @@ -
+
@@ -46,4 +46,5 @@ parent.appendChild(selected) }) +
\ No newline at end of file diff --git a/templates/order/post_new.html b/templates/order/post_new.html index 3752b79..6e09132 100644 --- a/templates/order/post_new.html +++ b/templates/order/post_new.html @@ -1,6 +1,7 @@ -
- - - {{.Status}} -
\ No newline at end of file + +{{.Status}} + \ No newline at end of file