diff --git a/core/checkin.go b/core/checkin.go index 221c8d84..97d823ca 100644 --- a/core/checkin.go +++ b/core/checkin.go @@ -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) diff --git a/handlers/routes.go b/handlers/routes.go index 1f1386cc..c2cd6075 100644 --- a/handlers/routes.go +++ b/handlers/routes.go @@ -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") diff --git a/handlers/services.go b/handlers/services.go index 5265fc03..a8f3cf9a 100644 --- a/handlers/services.go +++ b/handlers/services.go @@ -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) +} diff --git a/source/css/base.css b/source/css/base.css index 58e687bc..da1b43c3 100644 --- a/source/css/base.css +++ b/source/css/base.css @@ -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; diff --git a/source/scss/mobile.scss b/source/scss/mobile.scss index 46565ae5..0ae37874 100644 --- a/source/scss/mobile.scss +++ b/source/scss/mobile.scss @@ -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 { diff --git a/source/tmpl/index.gohtml b/source/tmpl/index.gohtml index e5fa5993..7785740d 100644 --- a/source/tmpl/index.gohtml +++ b/source/tmpl/index.gohtml @@ -10,7 +10,7 @@ {{ range Groups true }}
-

{{.Name}}

+

{{.Name}}

{{ range .Services }} diff --git a/source/wiki.go b/source/wiki.go index 8862cc85..fc0995b5 100644 --- a/source/wiki.go +++ b/source/wiki.go @@ -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 diff --git a/types/types.go b/types/types.go index 8e2e143e..d85bdb1c 100644 --- a/types/types.go +++ b/types/types.go @@ -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 diff --git a/version.txt b/version.txt index b80e8405..63106728 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.80.35 \ No newline at end of file +0.80.36