pull/10/head
Hunter Long 2018-06-09 21:09:20 -07:00
parent 6441b325ff
commit 8f9e96c365
5 changed files with 25 additions and 14 deletions

View File

@ -11,7 +11,7 @@ type Hit struct {
func SelectAllHits(id int64) []Hit { func SelectAllHits(id int64) []Hit {
var tks []Hit var tks []Hit
rows, err := db.Query("SELECT * FROM hits WHERE service=$1 ORDER BY id ASC", id) rows, err := db.Query("SELECT * FROM hits WHERE service=$1 ORDER BY id DESC LIMIT 256", id)
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -25,4 +25,8 @@ HTML,BODY {
.stats_area { .stats_area {
text-align: center; text-align: center;
}
.offline_bg {
background-color: #c5c5c578 !important;
} }

View File

@ -12,6 +12,7 @@
</head> </head>
<body> <body>
<h1 class="text-center">{{.Project}}</h1>
<div class="container"> <div class="container">
@ -19,13 +20,11 @@
{{ range .Services }} {{ range .Services }}
<div class="col-12 mb-4"> <div class="col-12 mb-4">
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body{{if .Online}}{{else}} offline_bg{{end}}">
<h3>{{ .Name }} <span class="badge badge-secondary float-right">{{if .Online}} ONLINE {{ else }} OFFLINE {{end}}</span></h3> <h3>{{ .Name }} <span class="badge badge-secondary float-right">{{if .Online}} ONLINE {{ else }} OFFLINE {{end}}</span></h3>
<div class="row stats_area mt-3 mb-3"> <div class="row stats_area mt-3 mb-3">
{{.Online}}
<div class="col-4"> <div class="col-4">
<span class="lg_number">{{.Online24Hours}}%</span> <span class="lg_number">{{.Online24Hours}}%</span>
Online last 24 Hours Online last 24 Hours
@ -90,11 +89,17 @@ var chartdata = new Chart(ctx, {
yAxes: [{ yAxes: [{
ticks: { ticks: {
beginAtZero: true beginAtZero: true
},
gridLines: {
display:false
} }
}], }],
xAxes: [{ xAxes: [{
type: 'time', type: 'time',
distribution: 'series' distribution: 'series',
gridLines: {
display:false
}
}] }]
}, },
elements: { elements: {

View File

@ -9,7 +9,7 @@ import (
) )
var ( var (
services []Service services []*Service
) )
type Service struct { type Service struct {
@ -45,8 +45,8 @@ func SelectService(id string) Service {
return tk return tk
} }
func SelectAllServices() []Service { func SelectAllServices() []*Service {
var tks []Service var tks []*Service
rows, err := db.Query("SELECT * FROM services ORDER BY id ASC") rows, err := db.Query("SELECT * FROM services ORDER BY id ASC")
if err != nil { if err != nil {
panic(err) panic(err)
@ -58,7 +58,7 @@ func SelectAllServices() []Service {
panic(err) panic(err)
} }
tk.FormatData() tk.FormatData()
tks = append(tks, tk) tks = append(tks, &tk)
} }
return tks return tks
} }
@ -130,6 +130,7 @@ func (u *Service) Create() int {
if err != nil { if err != nil {
panic(err) panic(err)
} }
services = SelectAllServices()
return lastInsertId return lastInsertId
} }

11
web.go
View File

@ -8,7 +8,7 @@ import (
) )
type dashboard struct { type dashboard struct {
Services []Service Services []*Service
Users []User Users []User
Core *Core Core *Core
} }
@ -125,7 +125,8 @@ func SetupHandler(w http.ResponseWriter, r *http.Request) {
} }
type index struct { type index struct {
Services []Service Project string
Services []*Service
} }
func IndexHandler(w http.ResponseWriter, r *http.Request) { func IndexHandler(w http.ResponseWriter, r *http.Request) {
@ -144,7 +145,7 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) {
return template.JS(html) return template.JS(html)
}, },
}).Parse(indexFile) }).Parse(indexFile)
out := index{services} out := index{core.Name, services}
indexTmpl.Execute(w, out) indexTmpl.Execute(w, out)
} }
@ -169,7 +170,7 @@ func DashboardHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
out := dashboard{SelectAllServices(), SelectAllUsers(), core} out := dashboard{services, SelectAllUsers(), core}
dashboardTmpl.Execute(w, out) dashboardTmpl.Execute(w, out)
} }
@ -189,7 +190,7 @@ func ServicesHandler(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
panic(err) panic(err)
} }
tokensTmpl.Execute(w, SelectAllServices()) tokensTmpl.Execute(w, services)
} }
func UsersHandler(w http.ResponseWriter, r *http.Request) { func UsersHandler(w http.ResponseWriter, r *http.Request) {