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}} +