Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Restructure the environments tree to have individual entries
Browse files Browse the repository at this point in the history
  • Loading branch information
arbulu89 committed Apr 28, 2021
1 parent a45bab5 commit baf0133
Show file tree
Hide file tree
Showing 14 changed files with 241 additions and 82 deletions.
8 changes: 5 additions & 3 deletions web/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ func NewAppWithDeps(host string, port int, deps Dependencies) (*App, error) {
engine.GET("/clusters", NewClustersListHandler(deps.consul))
engine.GET("/clusters/:name", NewClusterHandler(deps.consul))
engine.GET("/environments", NewEnvironmentsListHandler(deps.consul))
engine.GET("/environments/:env", NewLandscapesListHandler(deps.consul))
engine.GET("/environments/:env/landscapes/:land", NewSAPSystemsListHandler(deps.consul))
engine.GET("/environments/:env/landscapes/:land/sapsystems/:sys", NewSAPSystemHostsListHandler(deps.consul))
engine.GET("/environments/:env", NewEnvironmentListHandler(deps.consul))
engine.GET("/landscapes", NewLandscapesListHandler(deps.consul))
engine.GET("/landscapes/:land", NewLandscapeListHandler(deps.consul))
engine.GET("/sapsystems", NewSAPSystemsListHandler(deps.consul))
engine.GET("/sapsystems/:sys", NewSAPSystemHostsListHandler(deps.consul))

apiGroup := engine.Group("/api")
{
Expand Down
79 changes: 74 additions & 5 deletions web/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,30 @@ func NewEnvironmentsListHandler(client consul.Client) gin.HandlerFunc {
}
}

func NewEnvironmentListHandler(client consul.Client) gin.HandlerFunc {
return func(c *gin.Context) {
environments, err := loadEnvironments(client)
if err != nil {
_ = c.Error(err)
return
}

c.HTML(http.StatusOK, "environment.html.tmpl", gin.H{
"Environments": environments,
"EnvName": c.Param("env"),
})
}
}

func NewLandscapesListHandler(client consul.Client) gin.HandlerFunc {
return func(c *gin.Context) {
var env string = ""

query := c.Request.URL.Query()
if len(query["environment"]) > 0 {
env = query["environment"][0]
}

environments, err := loadEnvironments(client)
if err != nil {
_ = c.Error(err)
Expand All @@ -119,13 +141,48 @@ func NewLandscapesListHandler(client consul.Client) gin.HandlerFunc {

c.HTML(http.StatusOK, "landscapes.html.tmpl", gin.H{
"Environments": environments,
"EnvName": c.Param("env"),
"EnvName": env,
})
}
}

func NewLandscapeListHandler(client consul.Client) gin.HandlerFunc {
return func(c *gin.Context) {
var env string = ""

query := c.Request.URL.Query()
if len(query["environment"]) > 0 {
env = query["environment"][0]
}

environments, err := loadEnvironments(client)
if err != nil {
_ = c.Error(err)
return
}

c.HTML(http.StatusOK, "landscape.html.tmpl", gin.H{
"Environments": environments,
"EnvName": env,
"LandName": c.Param("land"),
})
}
}

func NewSAPSystemsListHandler(client consul.Client) gin.HandlerFunc {
return func(c *gin.Context) {
var env string = ""
var land string = ""

query := c.Request.URL.Query()
if len(query["environment"]) > 0 {
env = query["environment"][0]
}

if len(query["landscape"]) > 0 {
land = query["landscape"][0]
}

environments, err := loadEnvironments(client)
if err != nil {
_ = c.Error(err)
Expand All @@ -134,14 +191,26 @@ func NewSAPSystemsListHandler(client consul.Client) gin.HandlerFunc {

c.HTML(http.StatusOK, "sapsystems.html.tmpl", gin.H{
"Environments": environments,
"EnvName": c.Param("env"),
"LandName": c.Param("land"),
"EnvName": env,
"LandName": land,
})
}
}

func NewSAPSystemHostsListHandler(client consul.Client) gin.HandlerFunc {
return func(c *gin.Context) {
var env string = ""
var land string = ""

query := c.Request.URL.Query()
if len(query["environment"]) > 0 {
env = query["environment"][0]
}

if len(query["landscape"]) > 0 {
land = query["landscape"][0]
}

environments, err := loadEnvironments(client)
if err != nil {
_ = c.Error(err)
Expand All @@ -150,8 +219,8 @@ func NewSAPSystemHostsListHandler(client consul.Client) gin.HandlerFunc {

c.HTML(http.StatusOK, "sapsystem.html.tmpl", gin.H{
"Environments": environments,
"EnvName": c.Param("env"),
"LandName": c.Param("land"),
"EnvName": env,
"LandName": land,
"SAPSysName": c.Param("sys"),
})
}
Expand Down
15 changes: 9 additions & 6 deletions web/environments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestEnvironmentsListHandler(t *testing.T) {
assert.Equal(t, 200, resp.Code)
assert.Contains(t, minified, "Environments")
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/environments/env1'\".*<td>env1</td><td>2</td><td>2</td><td>.*passing.*</td>"), minified)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/environments/env2'\".*<td>env2</td><td>1</td><td>1</td><td>.*critical.*</td>"), minified)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/environments/env1'\".*<td>env2</td><td>1</td><td>1</td><td>.*critical.*</td>"), minified)
}

func TestLandscapesListHandler(t *testing.T) {
Expand All @@ -177,7 +177,7 @@ func TestLandscapesListHandler(t *testing.T) {
}

resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/environments/env1", nil)
req, err := http.NewRequest("GET", "/landscapes", nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -199,8 +199,9 @@ func TestLandscapesListHandler(t *testing.T) {
}

assert.Equal(t, 200, resp.Code)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/environments/env1/landscapes/land1'\".*<td>land1</td><td>1</td><td>2</td><td>.*passing.*</td>"), minified)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/environments/env1/landscapes/land2'\".*<td>land2</td><td>1</td><td>2</td><td>.*passing.*</td>"), minified)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/landscapes/land1\\?environment=env1'\"><td>land1</td><td>.*env1.*</td><td>1</td><td>2</td><td>.*passing.*</td>"), minified)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/landscapes/land2\\?environment=env1'\".*<td>land2</td><td>.*env1.*<td>1</td><td>2</td><td>.*passing.*</td>"), minified)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/landscapes/land3\\?environment=env2'\".*<td>land3</td><td>.*env2.*<td>1</td><td>2</td><td>.*critical.*</td>"), minified)
}

func TestSAPSystemsListHandler(t *testing.T) {
Expand All @@ -216,7 +217,7 @@ func TestSAPSystemsListHandler(t *testing.T) {
}

resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/environments/env1/landscapes/land1", nil)
req, err := http.NewRequest("GET", "/sapsystems", nil)
if err != nil {
t.Fatal(err)
}
Expand All @@ -238,5 +239,7 @@ func TestSAPSystemsListHandler(t *testing.T) {
}

assert.Equal(t, 200, resp.Code)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/environments/env1/landscapes/land1/sapsystems/sys1'\".*<td>sys1</td><td>.*passing.*</td>"), minified)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/sapsystems/sys1\\?environment=env1&landscape=land1'\".*<td>sys1</td><td>.*passing.*</td>"), minified)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/sapsystems/sys2\\?environment=env1&landscape=land2'\".*<td>sys2</td><td>.*passing.*</td>"), minified)
assert.Regexp(t, regexp.MustCompile("<tr.*onclick=\"window.location='/sapsystems/sys3\\?environment=env2&landscape=land3'\".*<td>sys3</td><td>.*critical.*</td>"), minified)
}
22 changes: 22 additions & 0 deletions web/templates/blocks/landscapes_row.html.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{{ define "landscapes_row" }}
{{- $EnvName := .Name }}
{{- range .Landscapes }}
<tr class='clickable' onclick="window.location='/landscapes/{{ .Name }}?environment={{ $EnvName }}'">
<td>{{ .Name }}</td>
<td><a href="/environment/{{ $EnvName }}">{{ $EnvName }}</a></td>
{{- $SAPSystemNumber := 0 }}
{{- $HostsNumber := 0 }}
{{- $SAPSystemNumber = sum $SAPSystemNumber (len .SAPSystems) }}
{{- range .SAPSystems }}
{{- $HostsNumber = sum $HostsNumber (len .Hosts) }}
{{- end }}
<td>{{ $SAPSystemNumber }}</td>
<td>{{ $HostsNumber }}</td>
<td>
{{- $Health := .Health }}
{{- /* It would be nice to show the summary of the the health as tooltip. How many passing, critical and warning in a nice an visual way */ -}}
<span class='badge badge-pill badge-{{ if eq $Health.Health "passing" }}primary{{ else if eq $Health.Health "warning" }}warning{{ else }}danger{{ end }}'>{{ $Health.Health }}</span>
</td>
</tr>
{{- end }}
{{ end }}
24 changes: 24 additions & 0 deletions web/templates/blocks/landscapes_table.html.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{{ define "landscapes_table" }}
<table class='table eos-table'>
<thead>
<tr>
<th scope='col'>Landscape</th>
<th scope='col'>Environment</th>
<th scope='col'>SAP systems number</th>
<th scope='col'>Hosts number</th>
<th scope='col'>Status</th>
</tr>
</thead>
<tbody>
{{- if .EnvName }}
{{ $EnvName := .EnvName }}
{{ $Env := index .Environments .EnvName }}
{{ template "landscapes_row" $Env }}
{{- else }}
{{- range .Environments }}
{{ template "landscapes_row" . }}
{{- end }}
{{- end }}
</tbody>
</table>
{{ end }}
56 changes: 56 additions & 0 deletions web/templates/blocks/sapsystems_table.html.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{ define "sapsystems_table" }}
<div class='table-responsive'>
<table class='table eos-table'>
<thead>
<tr>
<th scope='col'>SAP System</th>
<th scope='col'>Environment</th>
<th scope='col'>Landscape</th>
<th scope='col'>Hosts number</th>
<th scope='col'>Status</th>
</tr>
</thead>
<tbody>
{{- if .EnvName }}
{{ $EnvName := .EnvName }}
{{ $LandName := .LandName }}
{{ $Env := index .Environments .EnvName }}
{{ $Land := index $Env.Landscapes .LandName }}
{{- range $Land.SAPSystems }}
<tr class='clickable' onclick="window.location='/sapsystems/{{ .Name }}?environment={{ $EnvName }}&landscape={{ $LandName }}'">
<td>{{ .Name }}</td>
<td><a href="/landscapes?/environment={{ $EnvName }}">{{ $EnvName }}</a></td>
<td><a href="/sapsystems?landscape={{ $LandName }}">{{ $EnvName }}</a></td>
<td>{{ len .Hosts }}</td>
<td>
{{- $Health := .Health }}
{{- /* It would be nice to show the summary of the the health as tooltip. How many passing, critical and warning in a nice an visual way */ -}}
<span class='badge badge-pill badge-{{ if eq $Health.Health "passing" }}primary{{ else if eq $Health.Health "warning" }}warning{{ else }}danger{{ end }}'>{{ $Health.Health }}</span>
</td>
</tr>
{{- end }}
{{- else }}
{{- range .Environments }}
{{- $EnvName := .Name }}
{{- range .Landscapes }}
{{- $LandName := .Name }}
{{- range .SAPSystems }}
<tr class='clickable' onclick="window.location='/sapsystems/{{ .Name }}?environment={{ $EnvName }}&landscape={{ $LandName }}'">
<td>{{ .Name }}</td>
<td><a href="/landscapes?/environment={{ $EnvName }}">{{ $EnvName }}</a></td>
<td><a href="/sapsystems?landscape={{ $LandName }}">{{ $LandName }}</a></td>
<td>{{ len .Hosts }}</td>
<td>
{{- $Health := .Health }}
{{- /* It would be nice to show the summary of the the health as tooltip. How many passing, critical and warning in a nice an visual way */ -}}
<span class='badge badge-pill badge-{{ if eq $Health.Health "passing" }}primary{{ else if eq $Health.Health "warning" }}warning{{ else }}danger{{ end }}'>{{ $Health.Health }}</span>
</td>
</tr>
{{- end }}
{{- end }}
{{- end }}
{{- end }}
</tbody>
</table>
</div>
{{ end }}
8 changes: 8 additions & 0 deletions web/templates/blocks/sidebar.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
<i class='eos-icons'>collocation</i>
<span class="menu-title-content">Environments</span>
</a>
<a class="menu-title js-select-current-parent js-feature-flag" href="/landscapes">
<i class='eos-icons'>collocation</i>
<span class="menu-title-content">Landscapes</span>
</a>
<a class="menu-title js-select-current-parent js-feature-flag" href="/sapsystems">
<i class='eos-icons'>collocation</i>
<span class="menu-title-content">SAP Systems</span>
</a>
</li>
</ul>
</div>
Expand Down
15 changes: 15 additions & 0 deletions web/templates/environment.html.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{ define "content" }}
<div class="col">
<h6><a href="/environments">Environments</a><h6>
<h1>Environment details</h1>
<dl class="inline">
<dt class="inline">Name</dt>
<dd class="inline">{{ .EnvName }}</dd>
</dl>
<hr/>
<p class='clearfix'/>
<h1>Landscapes</h1>
{{ template "landscapes_table" . }}
</div>
</div>
{{ end }}
2 changes: 1 addition & 1 deletion web/templates/environments.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<table class='table eos-table'>
<thead>
<tr>
<th scope='col'>Environmemt</th>
<th scope='col'>Environment</th>
<th scope='col'>Landscapes number</th>
<th scope='col'>SAP systems number</th>
<th scope='col'>Hosts number</th>
Expand Down
4 changes: 2 additions & 2 deletions web/templates/host.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<dt class="inline">Environment</dt>
<dd class="inline"><a href="/environments/{{ $Env }}">{{ $Env }}</a></dd>
<dt class="inline">Landscape</dt>
<dd class="inline"><a href="/environments/{{ $Env }}/landscapes/{{ $Land }}">{{ $Land }}</a></dd>
<dd class="inline"><a href="/landscapes/{{ $Land }}?environment={{ $Env }}">{{ $Land }}</a></dd>
<dt class="inline">SAP System</dt>
<dd class="inline"><a href="/environments/{{ $Env }}/landscapes/{{ $Land }}/sapsystems/{{ $SAPSys }}">{{ $SAPSys }}</a></dd>
<dd class="inline"><a href="/sapsystems/{{ $SAPSys }}?environment={{ $Env }}&landscape={{ $Land }}">{{ $SAPSys }}</a></dd>
<dt class="inline">Cluster</dt>
<dd class="inline"><a href="/clusters/{{ index .Host.TrentoMeta "trento-ha-cluster" }}">{{ index .Host.TrentoMeta "trento-ha-cluster" }}</a></dd>
</dl>
Expand Down
13 changes: 13 additions & 0 deletions web/templates/landscape.html.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{ define "content" }}
<div class="col">
<h6><a href="/environments">Environments</a> > <a href="/environments/{{ .EnvName }}">{{ .EnvName }}</a><h6>
<h1>Landscape details</h1>
<dl class="inline">
<dt class="inline">Name</dt>
<dd class="inline">{{ .LandName }}</dd>
</dl>
<hr/>
<h1>SAP Systems</h1>
{{ template "sapsystems_table" . }}
</div>
{{ end }}
36 changes: 1 addition & 35 deletions web/templates/landscapes.html.tmpl
Original file line number Diff line number Diff line change
@@ -1,40 +1,6 @@
{{ define "content" }}
<div class="col">
<h6><a href="/environments">Environments</a> > {{ .EnvName }}</h6>
<h1>Landscapes</h1>
<div class='table-responsive'>
<table class='table eos-table'>
<thead>
<tr>
<th scope='col'>Landscape</th>
<th scope='col'>SAP systems number</th>
<th scope='col'>Hosts number</th>
<th scope='col'>Status</th>
</tr>
</thead>
<tbody>
{{ $EnvName := .EnvName }}
{{ $Env := index .Environments .EnvName }}
{{- range $Env.Landscapes }}
<tr class='clickable' onclick="window.location='/environments/{{ $EnvName }}/landscapes/{{ .Name }}'">
<td>{{ .Name }}</td>
{{- $SAPSystemNumber := 0 }}
{{- $HostsNumber := 0 }}
{{- $SAPSystemNumber = sum $SAPSystemNumber (len .SAPSystems) }}
{{- range .SAPSystems }}
{{- $HostsNumber = sum $HostsNumber (len .Hosts) }}
{{- end }}
<td>{{ $SAPSystemNumber }}</td>
<td>{{ $HostsNumber }}</td>
<td>
{{- $Health := .Health }}
{{- /* It would be nice to show the summary of the the health as tooltip. How many passing, critical and warning in a nice an visual way */ -}}
<span class='badge badge-pill badge-{{ if eq $Health.Health "passing" }}primary{{ else if eq $Health.Health "warning" }}warning{{ else }}danger{{ end }}'>{{ $Health.Health }}</span>
</td>
</tr>
{{- end }}
</tbody>
</table>
</div>
{{ template "landscapes_table" . }}
</div>
{{ end }}
Loading

0 comments on commit baf0133

Please sign in to comment.