Skip to content

Commit

Permalink
ui/mobile updates - checkin update
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Jan 10, 2019
1 parent 0c2d2f3 commit 638adbd
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 14 deletions.
14 changes: 14 additions & 0 deletions core/checkin.go
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions handlers/routes.go
Expand Up @@ -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"))))
Expand Down Expand Up @@ -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
Expand All @@ -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")
Expand Down
37 changes: 37 additions & 0 deletions handlers/services.go
Expand Up @@ -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)
}
8 changes: 6 additions & 2 deletions source/css/base.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions source/scss/mobile.scss
Expand Up @@ -5,7 +5,7 @@
}

.sm-container {
margin-top: 40px !important;
margin-top: 0px !important;
padding: 0 !important;
}

Expand All @@ -14,7 +14,12 @@
}

.container {
padding: 0 !important;
padding: 0px !important;
padding-top: 15px !important;
}

.group_header {
margin-left: 15px;
}

.navbar {
Expand Down
2 changes: 1 addition & 1 deletion source/tmpl/index.gohtml
Expand Up @@ -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}}">
Expand Down
2 changes: 1 addition & 1 deletion source/wiki.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions types/types.go
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion version.txt
@@ -1 +1 @@
0.80.35
0.80.36

0 comments on commit 638adbd

Please sign in to comment.