Commit c5b667351abcda4b5ac134873007a0ce47976e88

Authored by Dmitriy Zaporozhets
1 parent 963a3114

Show broadcast message to users

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/assets/stylesheets/common.scss
... ... @@ -351,3 +351,10 @@ table {
351 351 @extend .btn-new;
352 352 padding: 5px 15px;
353 353 }
  354 +
  355 +.broadcast-message {
  356 + padding: 10px;
  357 + text-align: center;
  358 + background: #555;
  359 + color: #BBB;
  360 +}
... ...
app/helpers/application_helper.rb
... ... @@ -208,4 +208,8 @@ module ApplicationHelper
208 208 line += "..." if lines.size > 1
209 209 line
210 210 end
  211 +
  212 + def broadcast_message
  213 + BroadcastMessage.current
  214 + end
211 215 end
... ...
app/models/broadcast_message.rb
... ... @@ -4,4 +4,8 @@ class BroadcastMessage &lt; ActiveRecord::Base
4 4 validates :message, presence: true
5 5 validates :starts_at, presence: true
6 6 validates :ends_at, presence: true
  7 +
  8 + def self.current
  9 + where("ends_at > :now AND starts_at < :now", now: Time.zone.now).last
  10 + end
7 11 end
... ...
app/views/layouts/_broadcast.html.haml 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +- if broadcast_message.present?
  2 + .broadcast-message
  3 + %i.icon-bullhorn
  4 + = broadcast_message.message
... ...
app/views/layouts/application.html.haml
... ... @@ -2,6 +2,7 @@
2 2 %html{ lang: "en"}
3 3 = render "layouts/head", title: "Dashboard"
4 4 %body{class: "#{app_theme} application", :'data-page' => body_data_page }
  5 + = render "layouts/broadcast"
5 6 = render "layouts/head_panel", title: "Dashboard"
6 7 = render "layouts/flash"
7 8 %nav.main-nav
... ...
app/views/layouts/projects.html.haml
... ... @@ -2,6 +2,7 @@
2 2 %html{ lang: "en"}
3 3 = render "layouts/head", title: @project.name_with_namespace
4 4 %body{class: "#{app_theme} project", :'data-page' => body_data_page, :'data-project-id' => @project.id }
  5 + = render "layouts/broadcast"
5 6 = render "layouts/head_panel", title: project_title(@project)
6 7 = render "layouts/init_auto_complete"
7 8 = render "layouts/flash"
... ...
spec/models/broadcast_message_spec.rb
... ... @@ -4,4 +4,21 @@ describe BroadcastMessage do
4 4 subject { create(:broadcast_message) }
5 5  
6 6 it { should be_valid }
  7 +
  8 + describe :current do
  9 + it "should return last message if time match" do
  10 + broadcast_message = create(:broadcast_message, starts_at: Time.now.yesterday, ends_at: Time.now.tomorrow)
  11 + BroadcastMessage.current.should == broadcast_message
  12 + end
  13 +
  14 + it "should return nil if time not come" do
  15 + broadcast_message = create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days)
  16 + BroadcastMessage.current.should be_nil
  17 + end
  18 +
  19 + it "should return nil if time has passed" do
  20 + broadcast_message = create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday)
  21 + BroadcastMessage.current.should be_nil
  22 + end
  23 + end
7 24 end
... ...