Commit 99334d4b authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'feature/broadcast_messages' of /home/git/repositories/gitlab/gitlabhq

parents 0a08c775 3397361f
...@@ -351,3 +351,10 @@ table { ...@@ -351,3 +351,10 @@ table {
@extend .btn-new; @extend .btn-new;
padding: 5px 15px; padding: 5px 15px;
} }
.broadcast-message {
padding: 10px;
text-align: center;
background: #555;
color: #BBB;
}
...@@ -49,3 +49,9 @@ fieldset legend { ...@@ -49,3 +49,9 @@ fieldset legend {
font-size: 16px; font-size: 16px;
margin-bottom: 10px; margin-bottom: 10px;
} }
.datetime-controls {
select {
width: 100px;
}
}
...@@ -21,3 +21,9 @@ ...@@ -21,3 +21,9 @@
.controls { margin-left: 130px; } .controls { margin-left: 130px; }
.form-actions { padding-left: 130px; background: #fff } .form-actions { padding-left: 130px; background: #fff }
} }
.broadcast-messages {
.message {
line-height: 2;
}
}
class Admin::BroadcastMessagesController < Admin::ApplicationController
before_filter :broadcast_messages
def index
@broadcast_message = BroadcastMessage.new
end
def create
@broadcast_message = BroadcastMessage.new(params[:broadcast_message])
if @broadcast_message.save
redirect_to admin_broadcast_messages_path, notice: 'Broadcast Message was successfully created.'
else
render :index
end
end
def destroy
BroadcastMessage.find(params[:id]).destroy
respond_to do |format|
format.html { redirect_to :back }
format.js { render nothing: true }
end
end
protected
def broadcast_messages
@broadcast_messages ||= BroadcastMessage.order("starts_at DESC").page(params[:page])
end
end
...@@ -208,4 +208,8 @@ module ApplicationHelper ...@@ -208,4 +208,8 @@ module ApplicationHelper
line += "..." if lines.size > 1 line += "..." if lines.size > 1
line line
end end
def broadcast_message
BroadcastMessage.current
end
end end
class BroadcastMessage < ActiveRecord::Base
attr_accessible :alert_type, :ends_at, :message, :starts_at
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
%h3.page-title
Broadcast Messages
%p.light
Broadcast messages displayed for every user and can be used to notify application about scheduled maintenance.
%hr
= form_for [:admin, @broadcast_message] do |f|
-if @broadcast_message.errors.any?
.alert.alert-error
- @broadcast_message.errors.full_messages.each do |msg|
%p= msg
.control-group
= f.label :message
.controls
= f.text_area :message, class: "input-xxlarge", rows: 2, required: true
.control-group
= f.label :starts_at
.controls.datetime-controls
= f.datetime_select :starts_at
.control-group
= f.label :ends_at
.controls.datetime-controls
= f.datetime_select :ends_at
.form-actions
= f.submit "Add broadcast message", class: "btn btn-create"
-if @broadcast_messages.any?
%ul.bordered-list.broadcast-messages
- @broadcast_messages.each do |broadcast_message|
%li
.pull-right
- if broadcast_message.starts_at
%strong
#{broadcast_message.starts_at.to_s(:short)}
\...
- if broadcast_message.ends_at
%strong
#{broadcast_message.ends_at.to_s(:short)}
&nbsp;
= link_to [:admin, broadcast_message], method: :delete, remote: true, class: 'remove-row btn btn-tiny' do
%i.icon-remove.cred
.message= broadcast_message.message
= paginate @broadcast_messages
- if broadcast_message.present?
.broadcast-message
%i.icon-bullhorn
= broadcast_message.message
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
%html{ lang: "en"} %html{ lang: "en"}
= render "layouts/head", title: "Dashboard" = render "layouts/head", title: "Dashboard"
%body{class: "#{app_theme} application", :'data-page' => body_data_page } %body{class: "#{app_theme} application", :'data-page' => body_data_page }
= render "layouts/broadcast"
= render "layouts/head_panel", title: "Dashboard" = render "layouts/head_panel", title: "Dashboard"
= render "layouts/flash" = render "layouts/flash"
%nav.main-nav %nav.main-nav
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
= link_to "Users", admin_users_path = link_to "Users", admin_users_path
= nav_link(controller: :logs) do = nav_link(controller: :logs) do
= link_to "Logs", admin_logs_path = link_to "Logs", admin_logs_path
= nav_link(controller: :broadcast_messages) do
= link_to "Messages", admin_broadcast_messages_path
= nav_link(controller: :hooks) do = nav_link(controller: :hooks) do
= link_to "Hooks", admin_hooks_path = link_to "Hooks", admin_hooks_path
= nav_link(controller: :background_jobs) do = nav_link(controller: :background_jobs) do
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
%html{ lang: "en"} %html{ lang: "en"}
= render "layouts/head", title: @project.name_with_namespace = render "layouts/head", title: @project.name_with_namespace
%body{class: "#{app_theme} project", :'data-page' => body_data_page, :'data-project-id' => @project.id } %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/head_panel", title: project_title(@project)
= render "layouts/init_auto_complete" = render "layouts/init_auto_complete"
= render "layouts/flash" = render "layouts/flash"
......
...@@ -86,6 +86,7 @@ Gitlab::Application.routes.draw do ...@@ -86,6 +86,7 @@ Gitlab::Application.routes.draw do
get :test get :test
end end
resources :broadcast_messages, only: [:index, :create, :destroy]
resource :logs, only: [:show] resource :logs, only: [:show]
resource :background_jobs, controller: 'background_jobs', only: [:show] resource :background_jobs, controller: 'background_jobs', only: [:show]
resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:index, :show] resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:index, :show]
......
class CreateBroadcastMessages < ActiveRecord::Migration
def change
create_table :broadcast_messages do |t|
t.text :message, null: false
t.datetime :starts_at
t.datetime :ends_at
t.integer :alert_type
t.timestamps
end
end
end
...@@ -11,7 +11,16 @@ ...@@ -11,7 +11,16 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20131106151520) do ActiveRecord::Schema.define(:version => 20131112114325) do
create_table "broadcast_messages", :force => true do |t|
t.text "message", :null => false
t.datetime "starts_at"
t.datetime "ends_at"
t.integer "alert_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "deploy_keys_projects", :force => true do |t| create_table "deploy_keys_projects", :force => true do |t|
t.integer "deploy_key_id", :null => false t.integer "deploy_key_id", :null => false
......
...@@ -27,6 +27,11 @@ Feature: Admin active tab ...@@ -27,6 +27,11 @@ Feature: Admin active tab
Then the active main tab should be Logs Then the active main tab should be Logs
And no other main tabs should be active And no other main tabs should be active
Scenario: On Admin Messages
Given I visit admin messages page
Then the active main tab should be Messages
And no other main tabs should be active
Scenario: On Admin Hooks Scenario: On Admin Hooks
Given I visit admin hooks page Given I visit admin hooks page
Then the active main tab should be Hooks Then the active main tab should be Hooks
......
Feature: Admin Broadcast Messages
Background:
Given I sign in as an admin
And application already has admin messages
And I visit admin messages page
Scenario: See broadcast messages list
Then I should be all broadcast messages
Scenario: Create a broadcast message
When submit form with new broadcast message
Then I should be redirected to admin messages page
And I should see newly created broadcast message
...@@ -30,4 +30,8 @@ class AdminActiveTab < Spinach::FeatureSteps ...@@ -30,4 +30,8 @@ class AdminActiveTab < Spinach::FeatureSteps
Then 'the active main tab should be Resque' do Then 'the active main tab should be Resque' do
ensure_active_main_tab('Background Jobs') ensure_active_main_tab('Background Jobs')
end end
Then 'the active main tab should be Messages' do
ensure_active_main_tab('Messages')
end
end end
class Spinach::Features::AdminBroadcastMessages < Spinach::FeatureSteps
include SharedAuthentication
include SharedPaths
include SharedAdmin
step 'application already has admin messages' do
FactoryGirl.create(:broadcast_message, message: "Migration to new server")
end
step 'I should be all broadcast messages' do
page.should have_content "Migration to new server"
end
step 'submit form with new broadcast message' do
fill_in 'broadcast_message_message', with: 'Application update from 4:00 CST to 5:00 CST'
select '2018', from: "broadcast_message_ends_at_1i"
click_button "Add broadcast message"
end
step 'I should be redirected to admin messages page' do
current_path.should == admin_broadcast_messages_path
end
step 'I should see newly created broadcast message' do
page.should have_content 'Application update from 4:00 CST to 5:00 CST'
end
end
...@@ -105,6 +105,10 @@ module SharedPaths ...@@ -105,6 +105,10 @@ module SharedPaths
visit admin_logs_path visit admin_logs_path
end end
step 'I visit admin messages page' do
visit admin_broadcast_messages_path
end
step 'I visit admin hooks page' do step 'I visit admin hooks page' do
visit admin_hooks_path visit admin_hooks_path
end end
......
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :broadcast_message do
message "MyText"
starts_at "2013-11-12 13:43:25"
ends_at "2013-11-12 13:43:25"
alert_type 1
end
end
require 'spec_helper'
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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment