mirror of https://github.com/statping/statping
groups - public visibility
parent
6d9dee6a33
commit
47493c8f19
|
@ -36,7 +36,7 @@ var (
|
|||
)
|
||||
|
||||
func init() {
|
||||
DbModels = []interface{}{&types.Service{}, &types.User{}, &types.Hit{}, &types.Failure{}, &types.Message{}, &types.Checkin{}, &types.CheckinHit{}, ¬ifier.Notification{}}
|
||||
DbModels = []interface{}{&types.Service{}, &types.User{}, &types.Hit{}, &types.Failure{}, &types.Message{}, &types.Group{}, &types.Checkin{}, &types.CheckinHit{}, ¬ifier.Notification{}}
|
||||
}
|
||||
|
||||
// DbConfig stores the config.yml file for the statup configuration
|
||||
|
@ -82,6 +82,11 @@ func messagesDb() *gorm.DB {
|
|||
return DbSession.Model(&types.Message{})
|
||||
}
|
||||
|
||||
// messagesDb returns the Checkin records for a service
|
||||
func groupsDb() *gorm.DB {
|
||||
return DbSession.Model(&types.Group{})
|
||||
}
|
||||
|
||||
// HitsBetween returns the gorm database query for a collection of service hits between a time range
|
||||
func (s *Service) HitsBetween(t1, t2 time.Time, group string, column string) *gorm.DB {
|
||||
selector := Dbtimestamp(group, column)
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package core
|
||||
|
||||
import "github.com/hunterlong/statping/types"
|
||||
|
||||
// SelectGroups returns all messages
|
||||
func SelectGroups() ([]*types.Group, error) {
|
||||
var groups []*types.Group
|
||||
db := groupsDb().Find(&groups).Order("id desc")
|
||||
return groups, db.Error
|
||||
}
|
|
@ -51,7 +51,11 @@ func servicesHandler(w http.ResponseWriter, r *http.Request) {
|
|||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||
return
|
||||
}
|
||||
ExecuteResponse(w, r, "services.gohtml", core.CoreApp.Services, nil)
|
||||
data := map[string]interface{}{
|
||||
"Services": core.CoreApp.Services,
|
||||
"Groups": core.CoreApp.Services,
|
||||
}
|
||||
ExecuteResponse(w, r, "services.gohtml", data, nil)
|
||||
}
|
||||
|
||||
type serviceOrder struct {
|
||||
|
|
|
@ -101,6 +101,26 @@
|
|||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="service_type" class="col-sm-4 col-form-label">Group</label>
|
||||
<div class="col-sm-8">
|
||||
<select name="group_id" class="form-control" id="group_id" value="{{.GroupId}}" {{if ne .GroupId ""}}readonly{{end}}>
|
||||
<option value="http" {{if eq .GroupId "http"}}selected{{end}}>HTTP Service</option>
|
||||
<option value="tcp" {{if eq .GroupId "tcp"}}selected{{end}}>TCP Service</option>
|
||||
<option value="udp" {{if eq .GroupId "udp"}}selected{{end}}>UDP Service</option>
|
||||
</select>
|
||||
<small class="form-text text-muted">Use HTTP if you are checking a website or use TCP if you are checking a server</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<label for="order" class="col-sm-4 col-form-label">Visible</label>
|
||||
<div class="col-8 mt-1">
|
||||
<span class="switch float-left">
|
||||
<input type="checkbox" name="public" class="switch" id="switch-service" {{if eq .Id 0}}checked{{end}}{{if .AllowNotifications.Bool}}checked{{end}}>
|
||||
<label for="switch-service">Show Failures and service endpoint information to the public</label>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="{{if ne .Id 0}}col-6{{else}}col-12{{end}}">
|
||||
<button type="submit" class="btn btn-success btn-block">{{if ne .Id 0}}Update Service{{else}}Create Service{{end}}</button>
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Title</th>
|
||||
<th scope="col">Service</th>
|
||||
<th scope="col">Begins</th>
|
||||
<th scope="col" class="d-none d-md-table-cell">Service</th>
|
||||
<th scope="col" class="d-none d-md-table-cell">Begins</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -18,8 +18,8 @@
|
|||
{{range .}}
|
||||
<tr id="message_{{.Id}}">
|
||||
<td>{{.Title}}</td>
|
||||
<td>{{if .Service}}<a href="/service/{{.Service.Id}}">{{.Service.Name}}</a>{{end}}</td>
|
||||
<td>{{.StartOn}}</td>
|
||||
<td class="d-none d-md-table-cell">{{if .Service}}<a href="/service/{{.Service.Id}}">{{.Service.Name}}</a>{{end}}</td>
|
||||
<td class="d-none d-md-table-cell">{{.StartOn}}</td>
|
||||
<td class="text-right">
|
||||
{{if Auth}}<div class="btn-group">
|
||||
<a href="/message/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-exclamation-triangle"></i> Edit</a>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{{template "nav"}}
|
||||
|
||||
<div class="col-12">
|
||||
{{if ne (len .) 0}}
|
||||
{{if ne (len .Services) 0}}
|
||||
<h3>Services</h3>
|
||||
<table class="table">
|
||||
<thead>
|
||||
|
@ -15,7 +15,7 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody class="sortable" id="services_table">
|
||||
{{range .}}
|
||||
{{range .Services}}
|
||||
<tr id="service_{{.Id}}" data-id="{{.Id}}">
|
||||
<td><span class="drag_icon d-none d-md-inline"><i class="fas fa-bars"></i></span> {{.Name}}</td>
|
||||
<td class="d-none d-md-table-cell">{{if .Online}}<span class="badge badge-success">ONLINE</span>{{else}}<span class="badge badge-danger">OFFLINE</span>{{end}} </td>
|
||||
|
@ -35,6 +35,40 @@
|
|||
{{template "form_service" NewService}}
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
<div class="col-12">
|
||||
{{if ne (len .Groups) 0}}
|
||||
<h3>Groups</h3>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Name</th>
|
||||
<th scope="col" class="d-none d-md-table-cell">Status</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="sortable" id="services_table">
|
||||
{{range .Groups}}
|
||||
<tr id="service_{{.Id}}" data-id="{{.Id}}">
|
||||
<td><span class="drag_icon d-none d-md-inline"><i class="fas fa-bars"></i></span> {{.Name}}</td>
|
||||
<td class="d-none d-md-table-cell">{{if .Online}}<span class="badge badge-success">ONLINE</span>{{else}}<span class="badge badge-danger">OFFLINE</span>{{end}} </td>
|
||||
<td class="text-right">
|
||||
<div class="btn-group">
|
||||
<a href="/service/{{.Id}}" class="btn btn-outline-secondary"><i class="fas fa-chart-area"></i> View</a>
|
||||
{{if Auth}}<a href="/api/services/{{.Id}}" class="ajax_delete btn btn-danger" data-method="DELETE" data-obj="service_{{.Id}}" data-id="{{.Id}}"><i class="fas fa-times"></i></a>{{end}}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{{end}}
|
||||
</tbody>
|
||||
</table>
|
||||
{{end}}
|
||||
{{if Auth}}
|
||||
<h3>Create Service</h3>
|
||||
{{template "form_service" NewService}}
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{{end}}
|
||||
{{define "extra_scripts"}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// Code generated by go generate; DO NOT EDIT.
|
||||
// This file was generated by robots at
|
||||
// 2018-12-19 21:35:31.636341 -0800 PST m=+0.699027992
|
||||
// 2018-12-31 03:39:26.710899 -0800 PST m=+0.479547222
|
||||
//
|
||||
// This contains the most recently Markdown source for the Statping Wiki.
|
||||
package source
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package types
|
||||
|
||||
import "time"
|
||||
|
||||
// Group is the main struct for Groups
|
||||
type Group struct {
|
||||
Id int64 `gorm:"primary_key;column:id" json:"id"`
|
||||
Name string `gorm:"column:name" json:"name"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
}
|
|
@ -34,6 +34,8 @@ type Service struct {
|
|||
Timeout int `gorm:"default:30;column:timeout" json:"timeout"`
|
||||
Order int `gorm:"default:0;column:order_id" json:"order_id"`
|
||||
AllowNotifications NullBool `gorm:"default:false;column:allow_notifications" json:"allow_notifications"`
|
||||
Public NullBool `gorm:"default:false;column:public" json:"public"`
|
||||
GroupId int `gorm:"default:0;column:group_id" json:"group_id"`
|
||||
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"`
|
||||
Online bool `gorm:"-" json:"online"`
|
||||
|
|
Loading…
Reference in New Issue