ui/mobile updates - checkin update

pull/130/head v0.80.36
Hunter Long 2019-01-10 08:47:01 -08:00
parent 0c2d2f39a9
commit 638adbd3ab
9 changed files with 76 additions and 14 deletions

View File

@ -190,10 +190,24 @@ func (c *Checkin) AllFailures() []*types.Failure {
// Create will create a new Checkin
func (c *Checkin) Delete() error {
c.Close()
i := c.index()
service := c.Service()
slice := service.Checkins
service.Checkins = append(slice[:i], slice[i+1:]...)
row := checkinDB().Delete(&c)
return row.Error
}
// index returns a checkin index int for updating the *checkin.Service slice
func (c *Checkin) index() int {
for k, checkin := range c.Service().Checkins {
if c.Id == checkin.Select().Id {
return k
}
}
return 0
}
// Create will create a new Checkin
func (c *Checkin) Create() (int64, error) {
c.ApiKey = utils.RandomString(7)

View File

@ -35,7 +35,7 @@ func Router() *mux.Router {
dir := utils.Directory
CacheStorage = NewStorage()
r := mux.NewRouter()
r.Handle("/", cached("15s", "text/html", http.HandlerFunc(indexHandler)))
r.Handle("/", cached("120s", "text/html", http.HandlerFunc(indexHandler)))
if source.UsingAssets(dir) {
indexHandler := http.FileServer(http.Dir(dir + "/assets/"))
r.PathPrefix("/css/").Handler(http.StripPrefix("/css/", http.FileServer(http.Dir(dir+"/assets/css"))))
@ -82,7 +82,7 @@ func Router() *mux.Router {
// SERVICE Routes
r.Handle("/services", http.HandlerFunc(servicesHandler)).Methods("GET")
r.Handle("/service/{id}", http.HandlerFunc(servicesViewHandler)).Methods("GET")
r.Handle("/service/{id}/edit", http.HandlerFunc(servicesViewHandler))
r.Handle("/service/{id}/edit", http.HandlerFunc(servicesViewHandler)).Methods("GET")
r.Handle("/service/{id}/delete_failures", http.HandlerFunc(servicesDeleteFailuresHandler)).Methods("GET")
// API GROUPS Routes
@ -104,6 +104,8 @@ func Router() *mux.Router {
r.Handle("/api/services/{id}/ping", http.HandlerFunc(apiServicePingDataHandler)).Methods("GET")
r.Handle("/api/services/{id}", http.HandlerFunc(apiServiceUpdateHandler)).Methods("POST")
r.Handle("/api/services/{id}", http.HandlerFunc(apiServiceDeleteHandler)).Methods("DELETE")
r.Handle("/api/services/{id}/failures", http.HandlerFunc(apiServiceFailuresHandler)).Methods("GET")
r.Handle("/api/services/{id}/hits", http.HandlerFunc(apiServiceHitsHandler)).Methods("GET")
// API USER Routes
r.Handle("/api/users", http.HandlerFunc(apiAllUsersHandler)).Methods("GET")

View File

@ -260,3 +260,40 @@ func servicesDeleteFailuresHandler(w http.ResponseWriter, r *http.Request) {
service.DeleteFailures()
ExecuteResponse(w, r, "services.gohtml", core.CoreApp.Services, "/services")
}
func apiServiceFailuresHandler(w http.ResponseWriter, r *http.Request) {
if !IsReadAuthenticated(r) {
sendUnauthorizedJson(w, r)
return
}
vars := mux.Vars(r)
servicer := core.SelectService(utils.ToInt(vars["id"]))
if servicer == nil {
sendErrorJson(errors.New("service not found"), w, r)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(servicer.AllFailures())
}
func apiServiceHitsHandler(w http.ResponseWriter, r *http.Request) {
if !IsReadAuthenticated(r) {
sendUnauthorizedJson(w, r)
return
}
vars := mux.Vars(r)
servicer := core.SelectService(utils.ToInt(vars["id"]))
if servicer == nil {
sendErrorJson(errors.New("service not found"), w, r)
return
}
hits, err := servicer.Hits()
if err != nil {
sendErrorJson(err, w, r)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(hits)
}

View File

@ -414,14 +414,18 @@ HTML, BODY {
background-color: #fcfcfc; }
.sm-container {
margin-top: 40px !important;
margin-top: 0px !important;
padding: 0 !important; }
.list-group-item H5 {
font-size: 0.9rem; }
.container {
padding: 0 !important; }
padding: 0px !important;
padding-top: 15px !important; }
.group_header {
margin-left: 15px; }
.navbar {
margin-left: 0px;

View File

@ -5,7 +5,7 @@
}
.sm-container {
margin-top: 40px !important;
margin-top: 0px !important;
padding: 0 !important;
}
@ -14,7 +14,12 @@
}
.container {
padding: 0 !important;
padding: 0px !important;
padding-top: 15px !important;
}
.group_header {
margin-left: 15px;
}
.navbar {

View File

@ -10,7 +10,7 @@
{{ range Groups true }}
<div class="col-12 full-col-12">
<h4>{{.Name}}</h4>
<h4 class="group_header">{{.Name}}</h4>
<div class="list-group online_list mb-3">
{{ range .Services }}
<a href="#" class="service_li list-group-item list-group-item-action {{if not .Online}}bg-danger text-white{{ end }}" data-id="{{.Id}}">

View File

@ -1,6 +1,6 @@
// Code generated by go generate; DO NOT EDIT.
// This file was generated by robots at
// 2019-01-04 02:40:51.133321 -0800 PST m=+0.790626621
// 2019-01-10 08:45:53.400154 -0800 PST m=+0.716710901
//
// This contains the most recently Markdown source for the Statping Wiki.
package source

View File

@ -21,11 +21,11 @@ import (
// Hit struct is a 'successful' ping or web response entry for a service.
type Hit struct {
Id int64 `gorm:"primary_key;column:id"`
Service int64 `gorm:"column:service"`
Latency float64 `gorm:"column:latency"`
PingTime float64 `gorm:"column:ping_time"`
CreatedAt time.Time `gorm:"column:created_at"`
Id int64 `gorm:"primary_key;column:id" json:"id"`
Service int64 `gorm:"column:service" json:"-"`
Latency float64 `gorm:"column:latency" json:"latency"`
PingTime float64 `gorm:"column:ping_time" json:"ping_time"`
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
}
// DbConfig struct is used for the database connection and creates the 'config.yml' file

View File

@ -1 +1 @@
0.80.35
0.80.36