1
0
Fork 0

Bundle dashboard assets with rice

This commit is contained in:
Gregory Eremin 2015-01-28 13:01:30 +07:00
parent 41d2efea8b
commit 088b63a507
5 changed files with 107 additions and 117 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
burlesque
*.rice-box.go

View File

@ -10,13 +10,15 @@ import (
"strings"
"text/template"
"github.com/GeertJohan/go.rice"
"github.com/KosyanMedia/burlesque/hub"
)
type (
Server struct {
port int
hub *hub.Hub
port int
hub *hub.Hub
dashboardTmpl string
}
)
@ -30,6 +32,9 @@ func New(port int, h *hub.Hub) *Server {
hub: h,
}
box := rice.MustFindBox("static")
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(box.HTTPBox())))
http.HandleFunc("/status", s.statusHandler)
http.HandleFunc("/debug", s.debugHandler)
http.HandleFunc("/publish", s.pubHandler)
@ -37,6 +42,8 @@ func New(port int, h *hub.Hub) *Server {
http.HandleFunc("/flush", s.flushHandler)
http.HandleFunc("/dashboard", s.dashboardHandler)
s.dashboardTmpl, _ = box.String("dashboard.tmpl")
return &s
}
@ -136,7 +143,7 @@ func (s *Server) flushHandler(w http.ResponseWriter, r *http.Request) {
func (s *Server) dashboardHandler(w http.ResponseWriter, r *http.Request) {
tmpl := template.New("dashboard")
tmpl, _ = tmpl.Parse(dashboardTmpl)
tmpl, _ = tmpl.Parse(s.dashboardTmpl)
w.Header().Set("Content-Type", "text/html; charset=utf8")
hostname, _ := os.Hostname()

67
server/static/app.css Normal file
View File

@ -0,0 +1,67 @@
* { box-sizing: border-box; }
.title, td, th {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 1.3em;
padding: 0.6em;
font-weight: 300;
}
.title, table {
position: absolute;
left: 50%;
width: 650px;
margin-left: -325px;
}
.title {
top: 10px;
text-align: center;
font-size: 1.8em;
}
table {
top: 100px;
border-spacing: 0;
border-collapse: collapse;
}
th {
font-weight: 400;
}
thead tr {
border-bottom: #666 1px solid;
}
tbody tr:nth-child(even) {
background-color: #f5f5f5;
}
.name {
width: 350px;
max-width: 350px;
text-align: left;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.messages, .subscriptions {
width: 150px;
max-width: 150px;
text-align: right;
}
.zero {
color: #aaa;
}
.fat {
font-weight: 600;
}
.hot {
font-weight: 600;
color: #f20;
}
#loading {
display: none;
position: absolute;
bottom: 10px;
right: 10px;
font-size: 0.5em;
width: auto;
}
#placeholder td {
text-align: center;
}

View File

@ -1,109 +1,3 @@
package server
const dashboardTmpl = `
{{define "dashboard"}}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Queues @ {{.hostname}}</title>
<meta charset="utf8">
<style type="text/css">
* { box-sizing: border-box; }
.title, td, th {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 1.3em;
padding: 0.6em;
font-weight: 300;
}
.title, table {
position: absolute;
left: 50%;
width: 650px;
margin-left: -325px;
}
.title {
top: 10px;
text-align: center;
font-size: 1.8em;
}
table {
top: 100px;
border-spacing: 0;
border-collapse: collapse;
}
th {
font-weight: 400;
}
thead tr {
border-bottom: #666 1px solid;
}
tbody tr:nth-child(even) {
background-color: #f5f5f5;
}
.name {
width: 350px;
max-width: 350px;
text-align: left;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.messages, .subscriptions {
width: 150px;
max-width: 150px;
text-align: right;
}
.zero {
color: #aaa;
}
.fat {
font-weight: 600;
}
.hot {
font-weight: 600;
color: #f20;
}
#loading {
display: none;
position: absolute;
bottom: 10px;
right: 10px;
font-size: 0.5em;
width: auto;
}
#placeholder td {
text-align: center;
}
</style>
</head>
<body>
<h1 class="title">Burlesque v{{.version}} at {{.hostname}}</h1>
<table class="stats">
<thead>
<tr>
<th class="name">Queue</th>
<th class="messages">Messages</th>
<th class="subscriptions">Subscriptions</th>
</tr>
</thead>
<tbody id="queues">
<tr id="placeholder">
<td colspan="3">Loading queues...</td>
</tr>
</tbody>
<div id="loading">Loading...</div>
</table>
<script type="text/javascript">
function loadStatus(callback) {
var xhr = new XMLHttpRequest(),
loading = document.getElementById('loading');
@ -192,11 +86,3 @@ function loop(timeout, func) {
loop(1000, function(){
loadStatus(updateDashboard);
});
</script>
</body>
</html>
{{end}}
`

View File

@ -0,0 +1,29 @@
{{define "dashboard"}}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Queues @ {{.hostname}}</title>
<meta charset="utf8">
<link rel="stylesheet" type="text/css" href="/static/app.css">
</head>
<body>
<h1 class="title">Burlesque v{{.version}} at {{.hostname}}</h1>
<table class="stats">
<thead>
<tr>
<th class="name">Queue</th>
<th class="messages">Messages</th>
<th class="subscriptions">Subscriptions</th>
</tr>
</thead>
<tbody id="queues">
<tr id="placeholder">
<td colspan="3">Loading queues...</td>
</tr>
</tbody>
<div id="loading">Loading...</div>
</table>
<script type="text/javascript" src="/static/app.js"></script>
</body>
</html>
{{end}}