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

Set table filters properly when the page is reloaded in a new tab #717

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions web/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func NewClusterListHandler(clustersService services.ClustersService) gin.Handler
return
}

filterClusterNames, err := clustersService.GetAllClusterNames()
if err != nil {
_ = c.Error(err)
return
}

filterClusterTypes, err := clustersService.GetAllClusterTypes()
if err != nil {
_ = c.Error(err)
Expand Down Expand Up @@ -88,6 +94,7 @@ func NewClusterListHandler(clustersService services.ClustersService) gin.Handler
c.HTML(http.StatusOK, "clusters.html.tmpl", gin.H{
"ClustersTable": clusterList,
"AppliedFilters": query,
"filterClusterNames": filterClusterNames,
"FilterClusterTypes": filterClusterTypes,
"FilterSIDs": filterSIDs,
"FilterTags": filterTags,
Expand Down
4 changes: 4 additions & 0 deletions web/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ func TestClustersListHandler(t *testing.T) {
mockClusterService := new(services.MockClustersService)
mockClusterService.On("GetAll", mock.Anything, mock.Anything).Return(clustersList, nil)
mockClusterService.On("GetCount").Return(4, nil)
mockClusterService.On("GetAllClusterNames", mock.Anything).Return(
[]string{"hana_cluster", "other_cluster", "netweaver_cluster"},
nil,
)
mockClusterService.On("GetAllClusterTypes", mock.Anything).Return(
[]string{models.ClusterTypeHANAScaleUp, models.ClusterTypeUnknown},
nil,
Expand Down
16 changes: 16 additions & 0 deletions web/services/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type ClustersService interface {
GetAll(*ClustersFilter, *Page) (models.ClusterList, error)
GetByID(string) (*models.Cluster, error)
GetCount() (int, error)
GetAllClusterNames() ([]string, error)
GetAllClusterTypes() ([]string, error)
GetAllSIDs() ([]string, error)
GetAllTags() ([]string, error)
Expand Down Expand Up @@ -134,6 +135,21 @@ func (s *clustersService) GetCount() (int, error) {
return int(count), err
}

func (s *clustersService) GetAllClusterNames() ([]string, error) {
var clusterNames []string

err := s.db.Model(&entities.Cluster{}).
Distinct().
Pluck("name", &clusterNames).
Error

if err != nil {
return nil, err
}

return clusterNames, nil
}

func (s *clustersService) GetAllClusterTypes() ([]string, error) {
var clusterTypes []string

Expand Down
23 changes: 23 additions & 0 deletions web/services/clusters_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions web/services/clusters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ func (suite *ClustersServiceTestSuite) TestClustersService_GetClustersCount() {
suite.Equal(3, count)
}

func (suite *ClustersServiceTestSuite) TestClustersService_GetAllClusterNames() {
clusterNames, _ := suite.clustersService.GetAllClusterNames()
suite.ElementsMatch([]string{"cluster1", "cluster2", "cluster3"}, clusterNames)
}

func (suite *ClustersServiceTestSuite) TestClustersService_GetAllClusterTypes() {
clusterTypes, _ := suite.clustersService.GetAllClusterTypes()
suite.ElementsMatch(
Expand Down
4 changes: 2 additions & 2 deletions web/templates/blocks/health_filter.html.tmpl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{ define "health_filter" }}
<select name="health" id="health" class="selectpicker" multiple data-selected-text-format="count > 3"
<select name="health" class="selectpicker" multiple data-selected-text-format="count > 3"
data-act/healions-box="true" title="Health status...">
<option data-content="<span class='badge badge-success'>Passing</span>" value="passing">Passing</option>
<option data-content="<span class='badge badge-warning'>Warning</span>" value="warning">Warning</option>
<option data-content="<span class='badge badge-danger'>Critical</span>" value="critical">Critical</option>
</select>
{{- end }}
{{- end }}
21 changes: 8 additions & 13 deletions web/templates/clusters.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,26 @@
<div class="horizontal-container">
<script>
$(document).ready(function () {
{{- range $Key, $Value := .AppliedFilters }}
$("#{{ $Key }}").selectpicker("val", {{ $Value }});
{{- end }}
$('#clean').click(function () {
$('.selectpicker').selectpicker("deselectAll")
});
{{- range $Key, $Value := .AppliedFilters }}
$("[name='{{ $Key }}']").selectpicker("val", {{ $Value }});
{{- end }}
});
</script>
{{ template "health_filter" }}
<select name="name" id="name_filter" class="selectpicker" multiple
<select name="name" class="selectpicker" multiple
data-selected-text-format="count > 3" data-actions-box="true" data-live-search="true"
title="Cluster name">
{{- range .ClustersTable }}
{{- if .Name }}
<option value="{{ .Name }}">{{ .Name }}</option>
{{- end }}
{{- range .filterClusterNames }}
<option value="{{ . }}">{{ . }}</option>
{{- end}}
</select>
<select name="sids" id="sid_filter" class="selectpicker" multiple
<select name="sids" class="selectpicker" multiple
data-selected-text-format="count > 3" data-actions-box="true" data-live-search="true" title="SID">
{{- range .FilterSIDs }}
<option value="{{ . }}">{{ . }}</option>
{{- end }}
</select>
<select name="cluster_type" id="cluster_type_filter" class="selectpicker" multiple
<select name="cluster_type" class="selectpicker" multiple
data-selected-text-format="count > 3" data-actions-box="true" data-live-search="true"
title="Cluster type">
{{- range .FilterClusterTypes }}
Expand Down
13 changes: 5 additions & 8 deletions web/templates/hosts.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,14 @@
<div class="horizontal-container">
<script>
$(document).ready(function () {
{{- range $Key, $Value := .AppliedFilters }}
$("#{{ $Key }}").selectpicker("val", {{ $Value }});
{{- end }}
$('#clean').click(function () {
$('.selectpicker').selectpicker("deselectAll")
});
{{- range $Key, $Value := .AppliedFilters }}
$("[name='{{ $Key }}']").selectpicker("val", {{ $Value }});
{{- end }}
});
</script>
{{ template "health_filter" }}
<select name="sids" id="trento-sap-systems" class="selectpicker" multiple
data-selected-text-format="count > 3" data-actions-box="true" data-live-search="true"
<select name="sids" class="selectpicker" multiple
data-selected-text-format="count > 3" data-actions-box="true" data-live-search="true"
title="SAP system...">
{{- range .FilterSIDs }}
<option value="{{ . }}">{{ . }}</option>
Expand Down
11 changes: 4 additions & 7 deletions web/templates/sap_systems.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@
<div class="horizontal-container">
<script>
$(document).ready(function () {
{{- range $Key, $Value := .AppliedFilters }}
$("#{{ $Key }}").selectpicker("val", {{ $Value }});
{{- end }}
$('#clean').click(function () {
$('.selectpicker').selectpicker("deselectAll")
});
{{- range $Key, $Value := .AppliedFilters }}
$("[name='{{ $Key }}']").selectpicker("val", {{ $Value }});
{{- end }}
});
</script>
{{/* {{ template "health_filter" }} */}}
<select name="sids" id="sids" class="selectpicker" multiple
<select name="sids" class="selectpicker" multiple
data-selected-text-format="count > 3" data-actions-box="true" data-live-search="true" title="SID">
{{- range .FilterSIDs }}
<option value="{{ . }}">{{ . }}</option>
Expand Down