diff --git a/core/messages.go b/core/messages.go index 6ec3c62f..f1435a71 100644 --- a/core/messages.go +++ b/core/messages.go @@ -52,6 +52,13 @@ func SelectMessage(id int64) (*Message, error) { return &message, db.Error } +func (m *Message) Service() *Service { + if m.ServiceId == 0 { + return nil + } + return SelectService(m.ServiceId) +} + // Create will create a Message and insert it into the database func (m *Message) Create() (int64, error) { m.CreatedAt = time.Now().UTC() diff --git a/core/services.go b/core/services.go index 82c9b94e..ee461db6 100644 --- a/core/services.go +++ b/core/services.go @@ -400,6 +400,18 @@ func (s *Service) Messages() []*Message { return messages } +// ActiveMessages returns all Messages for a Service +func (s *Service) ActiveMessages() []*Message { + var messages []*Message + msgs := SelectServiceMessages(s.Id) + for _, m := range msgs { + if m.StartOn.UTC().After(time.Now().UTC()) { + messages = append(messages, m) + } + } + return messages +} + // ServicesCount returns the amount of services inside the []*core.Services slice func (c *Core) ServicesCount() int { return len(c.Services) diff --git a/source/tmpl/index.html b/source/tmpl/index.html index d4cb9ebd..cd367180 100644 --- a/source/tmpl/index.html +++ b/source/tmpl/index.html @@ -74,6 +74,18 @@ View Service + + {{if .ActiveMessages}} +
+ {{range .ActiveMessages}} + + {{end}} +
+ {{end}} + {{ end }} diff --git a/source/tmpl/messages.html b/source/tmpl/messages.html index 42180bf2..5cd752e6 100644 --- a/source/tmpl/messages.html +++ b/source/tmpl/messages.html @@ -8,6 +8,8 @@ Title + Service + Begins @@ -15,6 +17,8 @@ {{range .}} {{.Title}} + {{if .Service}}{{.Service.Name}}{{end}} + {{Duration 0}}
Edit diff --git a/source/tmpl/service.html b/source/tmpl/service.html index 404f5813..b3cb1212 100644 --- a/source/tmpl/service.html +++ b/source/tmpl/service.html @@ -41,6 +41,17 @@
+ {{if $s.ActiveMessages}} +
+ {{range $s.ActiveMessages}} + + {{end}} +
+ {{end}} +
@@ -59,15 +70,6 @@
{{$s.DowntimeText}}
{{end}} - {{if $s.Messages}} - {{range $s.Messages}} - - {{end}} - {{end}} - {{ if $s.LimitedFailures }}
{{ range $s.LimitedFailures }} diff --git a/types/message.go b/types/message.go index 8b40619d..f4be8599 100644 --- a/types/message.go +++ b/types/message.go @@ -21,15 +21,15 @@ import ( // Message is for creating Announcements, Alerts and other messages for the end users type Message struct { - Id int64 `gorm:"primary_key;column:id"` - Title string `gorm:"column:title"` - Description string `gorm:"column:description"` - StartOn time.Time `gorm:"column:start_on"` - EndOn time.Time `gorm:"column:end_on"` - ServiceId int64 `gorm:"index;column:service"` - NotifyUsers NullBool `gorm:"column:notify_users"` - NotifyMethod string `gorm:"column:notify_method"` - NotifyBefore time.Duration `gorm:"column:notify_before"` - CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` - UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at"` + Id int64 `gorm:"primary_key;column:id" json:"id"` + Title string `gorm:"column:title" json:"title"` + Description string `gorm:"column:description" json:"description"` + StartOn time.Time `gorm:"column:start_on" json:"start_on"` + EndOn time.Time `gorm:"column:end_on" json:"end_on"` + ServiceId int64 `gorm:"index;column:service" json:"service"` + NotifyUsers NullBool `gorm:"column:notify_users" json:"notify_users"` + NotifyMethod string `gorm:"column:notify_method" json:"notify_method"` + NotifyBefore time.Duration `gorm:"column:notify_before" json:"notify_before"` + CreatedAt time.Time `gorm:"column:created_at" json:"created_at" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at" json:"updated_at" json:"updated_at"` } diff --git a/utils/utils.go b/utils/utils.go index 06e86b78..c963544a 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -43,12 +43,6 @@ func init() { } } -func StringPoint(s string) *string { - val := new(string) - *val = s - return val -} - // StringInt converts a string to an int64 func StringInt(s string) int64 { num, _ := strconv.Atoi(s)