Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use fontawesome for icons #30

Merged
merged 4 commits into from
Mar 21, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions pkg/dashboard/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import (
"github.com/reactiveops/fairwinds/pkg/validator"
)

const TEMPLATE_NAME = "dashboard.gohtml"
const TEMPLATE_FILE = "pkg/dashboard/templates/" + TEMPLATE_NAME

// TemplateData represents data in a format that's template friendly.
type TemplateData struct {
ClusterSummary *validator.ResultSummary
Expand All @@ -23,9 +26,33 @@ func MainHandler(w http.ResponseWriter, r *http.Request, c conf.Configuration, k
http.Error(w, "Error Fetching Deployments", 500)
return
}

tmpl := template.Must(template.ParseFiles("pkg/dashboard/templates/dashboard.gohtml"))
tmpl.Execute(w, templateData)
tmpl, err := template.New(TEMPLATE_NAME).Funcs(template.FuncMap{
"getWarningWidth": func(rs validator.ResultSummary, fullWidth int) uint {
return uint(float64(rs.Successes+rs.Warnings) / float64(rs.Successes+rs.Warnings+rs.Failures) * float64(fullWidth))
},
"getSuccessWidth": func(rs validator.ResultSummary, fullWidth int) uint {
return uint(float64(rs.Successes) / float64(rs.Successes+rs.Warnings+rs.Failures) * float64(fullWidth))
},
"getIcon": func(rm validator.ResultMessage) string {
switch rm.Type {
case "success":
return "fas fa-check"
case "warning":
return "fas fa-exclamation"
default:
return "fas fa-times"
}
},
}).ParseFiles(TEMPLATE_FILE)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
err = template.Must(tmpl.Clone()).Execute(w, templateData)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

// EndpointHandler gets template data and renders json with it.
Expand Down
13 changes: 7 additions & 6 deletions pkg/dashboard/templates/dashboard.gohtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<link href="https://fonts.googleapis.com/css?family=Lobster" rel="stylesheet">
<link rel="stylesheet" href="/static/css/normalize.css">
<link rel="stylesheet" href="/static/css/main.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css" integrity="sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr" crossorigin="anonymous">

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.2/Chart.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/cash/3.0.0-beta.3/cash.min.js"></script>
Expand Down Expand Up @@ -53,17 +54,17 @@
<div class="extra">
<h4>Pod:</h4>
<ul>
{{ range .Messages}}
<li class="{{ .Type }}"><span>&#{{ .HTMLSpecialCharCode }};</span> {{ .Message }}</li>
{{ range $message := .Messages}}
<li class="{{ .Type }}"><i class="{{ getIcon $message }}"></i> {{ .Message }}</li>
{{ end }}
</ul>
</div>
{{ range .ContainerResults}}
<div class="extra">
<h4>Container: {{ .Name }}</h4>
<ul>
{{ range .Messages}}
<li class="{{ .Type }}"><span>&#{{ .HTMLSpecialCharCode }};</span> {{ .Message }}</li>
{{ range $message := .Messages}}
<li class="{{ .Type }}"><i class="{{ getIcon $message }}"></i> {{ .Message }}</li>
{{ end }}
</ul>
</div>
Expand All @@ -73,8 +74,8 @@
<td class="status-bar">
<div class="status">
<div class="failing">
<div class="warning" style="width: {{ .Summary.WarningWidth 200 }}px;">
<div class="passing" style="width: {{ .Summary.SuccessWidth 200 }}px;"></div>
<div class="warning" style="width: {{ getWarningWidth .Summary 200 }}px;">
<div class="passing" style="width: {{ getSuccessWidth .Summary 200 }}px;"></div>
</div>
</div>
</div>
Expand Down
21 changes: 0 additions & 21 deletions pkg/validator/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,3 @@ func (rs *ResultSummary) Score() uint {
return uint(float64(rs.Successes) / float64(rs.Successes+rs.Warnings+rs.Failures) * 100)
}

// WarningWidth is a UI specific helper that helps determine the width of a progress bar.
func (rs *ResultSummary) WarningWidth(fullWidth uint) uint {
return uint(float64(rs.Successes+rs.Warnings) / float64(rs.Successes+rs.Warnings+rs.Failures) * float64(fullWidth))
}

// SuccessWidth is a UI specific helper that helps determine the width of a progress bar.
func (rs *ResultSummary) SuccessWidth(fullWidth uint) uint {
return uint(float64(rs.Successes) / float64(rs.Successes+rs.Warnings+rs.Failures) * float64(fullWidth))
}

// HTMLSpecialCharCode is a UI specific helper that provides an HTML char code.
func (rm *ResultMessage) HTMLSpecialCharCode() string {
switch rm.Type {
case "success":
return "9745"
case "warning":
return "9888"
default:
return "9746"
}
}
15 changes: 10 additions & 5 deletions public/css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -159,26 +159,31 @@ body {
color: #6a6a6a;
}

.namespace-content .extra span {
.namespace-content .extra ul li {
margin-bottom: 5px;
}

.namespace-content .extra i {
display: inline-block;
margin-right: 10px;
text-align: center;
width: 20px;
font-size: 20px;
font-weight: bold;
position: relative;
bottom: -1px;
bottom: -3px;
}

.namespace-content .extra .success span {
.namespace-content .extra .success i {
color: #8BD2DC;
}

.namespace-content .extra .warning span {
.namespace-content .extra .warning i {
color: #f26c21;
font-size: 15px;
}

.namespace-content .extra .failure span {
.namespace-content .extra .failure i {
color: #a11f4c;
}

Expand Down