From c5b667351abcda4b5ac134873007a0ce47976e88 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 12 Nov 2013 15:08:20 +0200 Subject: [PATCH] Show broadcast message to users Signed-off-by: Dmitriy Zaporozhets --- app/assets/stylesheets/common.scss | 7 +++++++ app/helpers/application_helper.rb | 4 ++++ app/models/broadcast_message.rb | 4 ++++ app/views/layouts/_broadcast.html.haml | 4 ++++ app/views/layouts/application.html.haml | 1 + app/views/layouts/projects.html.haml | 1 + spec/models/broadcast_message_spec.rb | 17 +++++++++++++++++ 7 files changed, 38 insertions(+) create mode 100644 app/views/layouts/_broadcast.html.haml diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 8cb8e1b32..56dbd9ac4 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -351,3 +351,10 @@ table { @extend .btn-new; padding: 5px 15px; } + +.broadcast-message { + padding: 10px; + text-align: center; + background: #555; + color: #BBB; +} diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index e2d979014..02cc696c7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -208,4 +208,8 @@ module ApplicationHelper line += "..." if lines.size > 1 line end + + def broadcast_message + BroadcastMessage.current + end end diff --git a/app/models/broadcast_message.rb b/app/models/broadcast_message.rb index 69636de90..5b0040f6c 100644 --- a/app/models/broadcast_message.rb +++ b/app/models/broadcast_message.rb @@ -4,4 +4,8 @@ class BroadcastMessage < ActiveRecord::Base validates :message, presence: true validates :starts_at, presence: true validates :ends_at, presence: true + + def self.current + where("ends_at > :now AND starts_at < :now", now: Time.zone.now).last + end end diff --git a/app/views/layouts/_broadcast.html.haml b/app/views/layouts/_broadcast.html.haml new file mode 100644 index 000000000..4c4de743f --- /dev/null +++ b/app/views/layouts/_broadcast.html.haml @@ -0,0 +1,4 @@ +- if broadcast_message.present? + .broadcast-message + %i.icon-bullhorn + = broadcast_message.message diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 792fe5e4a..92edc7182 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -2,6 +2,7 @@ %html{ lang: "en"} = render "layouts/head", title: "Dashboard" %body{class: "#{app_theme} application", :'data-page' => body_data_page } + = render "layouts/broadcast" = render "layouts/head_panel", title: "Dashboard" = render "layouts/flash" %nav.main-nav diff --git a/app/views/layouts/projects.html.haml b/app/views/layouts/projects.html.haml index 6d8bf9b71..5ccb69769 100644 --- a/app/views/layouts/projects.html.haml +++ b/app/views/layouts/projects.html.haml @@ -2,6 +2,7 @@ %html{ lang: "en"} = render "layouts/head", title: @project.name_with_namespace %body{class: "#{app_theme} project", :'data-page' => body_data_page, :'data-project-id' => @project.id } + = render "layouts/broadcast" = render "layouts/head_panel", title: project_title(@project) = render "layouts/init_auto_complete" = render "layouts/flash" diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 09f79f4d6..daaac7373 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -4,4 +4,21 @@ describe BroadcastMessage do subject { create(:broadcast_message) } it { should be_valid } + + describe :current do + it "should return last message if time match" do + broadcast_message = create(:broadcast_message, starts_at: Time.now.yesterday, ends_at: Time.now.tomorrow) + BroadcastMessage.current.should == broadcast_message + end + + it "should return nil if time not come" do + broadcast_message = create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days) + BroadcastMessage.current.should be_nil + end + + it "should return nil if time has passed" do + broadcast_message = create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday) + BroadcastMessage.current.should be_nil + end + end end -- 2.11.0