From fc33ad4ba910f62e56fe9bfad544c9ddb9d49f7a Mon Sep 17 00:00:00 2001 From: Brian Scott Date: Sun, 15 Jan 2017 15:12:00 -0800 Subject: [PATCH 1/3] init of editing hosts --- actions/app.go | 1 + actions/hosts.go | 5 +++++ templates/hosts/_edit.html | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 templates/hosts/_edit.html diff --git a/actions/app.go b/actions/app.go index 80ea826..5902837 100644 --- a/actions/app.go +++ b/actions/app.go @@ -31,6 +31,7 @@ func App() *buffalo.App { app.GET("/hosts/create", HostsCreate) app.GET("/hosts/show", HostsShow) app.POST("/hosts/new", HostsNew) + app.PUT("/hosts/update", HostsUpdate) app.ServeFiles("/assets", assetsPath()) } diff --git a/actions/hosts.go b/actions/hosts.go index a85f834..69dd700 100644 --- a/actions/hosts.go +++ b/actions/hosts.go @@ -34,4 +34,9 @@ import ( return c.Render(200, r.String("Host Created")) } + + // HostsUpdate implements the update of an Host entry + func HostsUpdate(c buffalo.Context) error { + + } \ No newline at end of file diff --git a/templates/hosts/_edit.html b/templates/hosts/_edit.html new file mode 100644 index 0000000..fac3cc5 --- /dev/null +++ b/templates/hosts/_edit.html @@ -0,0 +1,19 @@ +
+

Wrangler - Edit host to inventory


 +

 +

 + Name for Host (e.g. My Rancher Server):
+ Description of Host (e.g. Rancher Server in AWS US West 2):
+ Rancher Server URL (e.g. https://rancher.domain.com:8080/): 
 +

 + Rancher Server API Version (e.g. v1 or v2-beta):
 + v1
 + v2-beta +

 + Rancher API Access Key: 
 +

 + Rancher API Secret Key: 
 +
+ 


 + 
 +
\ No newline at end of file From 049d8f97bf04a08338f0eb3c52e6f5fa58d623fb Mon Sep 17 00:00:00 2001 From: Brian Scott Date: Sat, 21 Jan 2017 16:10:58 -0800 Subject: [PATCH 2/3] Updated edit form but getting an crash - some value is nil --- actions/app.go | 2 +- actions/hosts.go | 17 +++++++++++++++-- templates/hosts/_edit.html | 15 +++++++-------- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/actions/app.go b/actions/app.go index 5902837..d664600 100644 --- a/actions/app.go +++ b/actions/app.go @@ -31,7 +31,7 @@ func App() *buffalo.App { app.GET("/hosts/create", HostsCreate) app.GET("/hosts/show", HostsShow) app.POST("/hosts/new", HostsNew) - app.PUT("/hosts/update", HostsUpdate) + app.GET("/hosts/{id}/edit", HostsEdit) app.ServeFiles("/assets", assetsPath()) } diff --git a/actions/hosts.go b/actions/hosts.go index 69dd700..f259f49 100644 --- a/actions/hosts.go +++ b/actions/hosts.go @@ -3,6 +3,7 @@ package actions import ( "github.com/gobuffalo/buffalo" "github.com/bscott/rancher-wrangler/models" + ) // HostsShow default implementation. @@ -35,8 +36,20 @@ import ( } - // HostsUpdate implements the update of an Host entry - func HostsUpdate(c buffalo.Context) error { + // HostEdit implements the update of an Host entry + func HostsEdit(c buffalo.Context) error { + var hh models.Host + //models.DB.All(&hh) + var id = c.Param("id") + + err := models.DB.Find(&hh, id) + + if err != nil { + return c.Error(500, err) + } + + c.Set("host", hh) + return c.Render(200, r.HTML("hosts/_edit.html")) } \ No newline at end of file diff --git a/templates/hosts/_edit.html b/templates/hosts/_edit.html index fac3cc5..e15fefb 100644 --- a/templates/hosts/_edit.html +++ b/templates/hosts/_edit.html @@ -1,18 +1,17 @@

Wrangler - Edit host to inventory



 -

 - Name for Host (e.g. My Rancher Server):
- Description of Host (e.g. Rancher Server in AWS US West 2):
- Rancher Server URL (e.g. https://rancher.domain.com:8080/): 
 +
 + Name for Host (e.g. My Rancher Server):
+ Description of Host (e.g. Rancher Server in AWS US West 2):
+ Rancher Server URL (e.g. https://rancher.domain.com:8080/):

 Rancher Server API Version (e.g. v1 or v2-beta):
 - v1
 - v2-beta +

 - Rancher API Access Key: 
 + Rancher API Access Key:

 - Rancher API Secret Key: 
 + Rancher API Secret Key:


 From 54cfe03da75df638a5819f2f8d8d8d2c1374f56d Mon Sep 17 00:00:00 2001 From: Brian Scott Date: Mon, 23 Jan 2017 20:02:28 -0800 Subject: [PATCH 3/3] Removed api_version radio button from edit --- actions/hosts.go | 20 +++++++++++++++++++- templates/hosts/_edit.html | 3 --- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/actions/hosts.go b/actions/hosts.go index f259f49..cea3425 100644 --- a/actions/hosts.go +++ b/actions/hosts.go @@ -36,7 +36,7 @@ import ( } - // HostEdit implements the update of an Host entry + // HostEdit implements the edit of an Host entry func HostsEdit(c buffalo.Context) error { var hh models.Host //models.DB.All(&hh) @@ -52,4 +52,22 @@ import ( c.Set("host", hh) return c.Render(200, r.HTML("hosts/_edit.html")) } + + // HostUpdate implements the update of an Host entry + func HostsUpdate(c buffalo.Context) error { + var hh models.Host + //models.DB.All(&hh) + var id = c.Param("id") + + err := models.DB.Find(&hh, id) + + if err != nil { + return c.Error(500, err) + } + + + c.Set("host", hh) + return c.Render(200, r.HTML("hosts/_edit.html")) + } + \ No newline at end of file diff --git a/templates/hosts/_edit.html b/templates/hosts/_edit.html index e15fefb..03bea4f 100644 --- a/templates/hosts/_edit.html +++ b/templates/hosts/_edit.html @@ -6,9 +6,6 @@

Wrangler - Edit host to inventory


 Description of Host (e.g. Rancher Server in AWS US West 2):
Rancher Server URL (e.g. https://rancher.domain.com:8080/):

 - Rancher Server API Version (e.g. v1 or v2-beta):
 - -

 Rancher API Access Key:

 Rancher API Secret Key: