summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-11-12 15:08:20 +0200
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-11-12 15:08:20 +0200
commitc5b667351abcda4b5ac134873007a0ce47976e88 (patch)
treed72c2d04658447ec9d2d2d119e1b7d19635f0488
parent963a31144b0d69af7b08e1912965a920636ce600 (diff)
downloadgitlab-ce-c5b667351abcda4b5ac134873007a0ce47976e88.tar.gz
Show broadcast message to users
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
-rw-r--r--app/assets/stylesheets/common.scss7
-rw-r--r--app/helpers/application_helper.rb4
-rw-r--r--app/models/broadcast_message.rb4
-rw-r--r--app/views/layouts/_broadcast.html.haml4
-rw-r--r--app/views/layouts/application.html.haml1
-rw-r--r--app/views/layouts/projects.html.haml1
-rw-r--r--spec/models/broadcast_message_spec.rb17
7 files changed, 38 insertions, 0 deletions
diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss
index 8cb8e1b3276..56dbd9ac433 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 e2d97901410..02cc696c722 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 69636de90ef..5b0040f6ca3 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 00000000000..4c4de743fdf
--- /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 792fe5e4a28..92edc718235 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 6d8bf9b710b..5ccb69769cd 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 09f79f4d627..daaac73739d 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