Commit 0760ba3e authored by Andrew Tomaka's avatar Andrew Tomaka

Customization and previewing of broadcast messages

parent 566b4962
...@@ -23,6 +23,7 @@ v 6.4.0 ...@@ -23,6 +23,7 @@ v 6.4.0
- API Cross-origin resource sharing - API Cross-origin resource sharing
- Show READMe link at project home page - Show READMe link at project home page
- Show repo size for projects in Admin area - Show repo size for projects in Admin area
- Add color custimization and previewing to broadcast messages
v 6.3.0 v 6.3.0
- API for adding gitlab-ci service - API for adding gitlab-ci service
......
...@@ -8,6 +8,23 @@ class Admin ...@@ -8,6 +8,23 @@ class Admin
else else
elems.removeAttr 'disabled' elems.removeAttr 'disabled'
$('body').on 'click', '.js-toggle-colors-link', (e) ->
e.preventDefault()
$('.js-toggle-colors-link').hide()
$('.js-toggle-colors-container').show()
$('input#broadcast_message_color').on 'input', ->
previewColor = $('input#broadcast_message_color').val()
$('div.broadcast-message-preview').css('background-color', previewColor)
$('input#broadcast_message_font').on 'input', ->
previewColor = $('input#broadcast_message_font').val()
$('div.broadcast-message-preview').css('color', previewColor)
$('textarea#broadcast_message_message').on 'input', ->
previewMessage = $('textarea#broadcast_message_message').val()
$('div.broadcast-message-preview span').text(previewMessage)
$('.log-tabs a').click (e) -> $('.log-tabs a').click (e) ->
e.preventDefault() e.preventDefault()
$(this).tab('show') $(this).tab('show')
......
...@@ -361,6 +361,11 @@ table { ...@@ -361,6 +361,11 @@ table {
color: #BBB; color: #BBB;
} }
.broadcast-message-preview {
@extend .broadcast-message;
margin-bottom: 20px;
}
.ajax-users-select { .ajax-users-select {
width: 400px; width: 400px;
......
module BroadcastMessagesHelper
def broadcast_styling(broadcast_message)
if(broadcast_message.color || broadcast_message.font)
"background-color:#{broadcast_message.color};color:#{broadcast_message.font}"
else
""
end
end
end
...@@ -9,10 +9,12 @@ ...@@ -9,10 +9,12 @@
# alert_type :integer # alert_type :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# color :string(255)
# font :string(255)
# #
class BroadcastMessage < ActiveRecord::Base class BroadcastMessage < ActiveRecord::Base
attr_accessible :alert_type, :ends_at, :message, :starts_at attr_accessible :alert_type, :color, :ends_at, :font, :message, :starts_at
validates :message, presence: true validates :message, presence: true
validates :starts_at, presence: true validates :starts_at, presence: true
......
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
Broadcast Messages Broadcast Messages
%p.light %p.light
Broadcast messages are displayed for every user and can be used to notify users about scheduled maintenance, recent upgrades and more. Broadcast messages are displayed for every user and can be used to notify users about scheduled maintenance, recent upgrades and more.
%hr .broadcast-message-preview
%i.icon-bullhorn
%span Your message here
= form_for [:admin, @broadcast_message] do |f| = form_for [:admin, @broadcast_message] do |f|
-if @broadcast_message.errors.any? -if @broadcast_message.errors.any?
...@@ -13,6 +15,17 @@ ...@@ -13,6 +15,17 @@
= f.label :message = f.label :message
.controls .controls
= f.text_area :message, class: "input-xxlarge", rows: 2, required: true = f.text_area :message, class: "input-xxlarge", rows: 2, required: true
%div
= link_to '#', class: 'js-toggle-colors-link' do
Customize colors
.control-group.js-toggle-colors-container.hide
= f.label :color, "Background Color"
.controls
= f.text_field :color
.control-group.js-toggle-colors-container.hide
= f.label :font, "Font Color"
.controls
= f.text_field :font
.control-group .control-group
= f.label :starts_at = f.label :starts_at
.controls.datetime-controls .controls.datetime-controls
......
- if broadcast_message.present? - if broadcast_message.present?
.broadcast-message .broadcast-message{ style: broadcast_styling(broadcast_message) }
%i.icon-bullhorn %i.icon-bullhorn
= broadcast_message.message = broadcast_message.message
class AddColorAndFontToBroadcastMessages < ActiveRecord::Migration
def change
add_column :broadcast_messages, :color, :string
add_column :broadcast_messages, :font, :string
end
end
...@@ -20,6 +20,8 @@ ActiveRecord::Schema.define(version: 20131217102743) do ...@@ -20,6 +20,8 @@ ActiveRecord::Schema.define(version: 20131217102743) do
t.integer "alert_type" t.integer "alert_type"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.string "color"
t.string "font"
end end
create_table "deploy_keys_projects", force: true do |t| create_table "deploy_keys_projects", force: true do |t|
......
...@@ -11,3 +11,10 @@ Feature: Admin Broadcast Messages ...@@ -11,3 +11,10 @@ Feature: Admin Broadcast Messages
When submit form with new broadcast message When submit form with new broadcast message
Then I should be redirected to admin messages page Then I should be redirected to admin messages page
And I should see newly created broadcast message And I should see newly created broadcast message
Scenario: Create a customized broadcast message
When submit form with new customized broadcast message
Then I should be redirected to admin messages page
And I should see newly created broadcast message
Then I visit dashboard page
And I should see a customized broadcast message
...@@ -24,4 +24,18 @@ class Spinach::Features::AdminBroadcastMessages < Spinach::FeatureSteps ...@@ -24,4 +24,18 @@ class Spinach::Features::AdminBroadcastMessages < Spinach::FeatureSteps
step 'I should see newly created broadcast message' do step 'I should see newly created broadcast message' do
page.should have_content 'Application update from 4:00 CST to 5:00 CST' page.should have_content 'Application update from 4:00 CST to 5:00 CST'
end end
step 'submit form with new customized broadcast message' do
fill_in 'broadcast_message_message', with: 'Application update from 4:00 CST to 5:00 CST'
click_link "Customize colors"
fill_in 'broadcast_message_color', with: '#f2dede'
fill_in 'broadcast_message_font', with: '#b94a48'
select '2018', from: "broadcast_message_ends_at_1i"
click_button "Add broadcast message"
end
step 'I should see a customized broadcast message' do
page.should have_content 'Application update from 4:00 CST to 5:00 CST'
page.should have_selector %(div[style="background-color:#f2dede;color:#b94a48"])
end
end end
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
# alert_type :integer # alert_type :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# color :string(255)
# font :string(255)
# #
# Read about factories at https://github.com/thoughtbot/factory_girl # Read about factories at https://github.com/thoughtbot/factory_girl
...@@ -19,5 +21,7 @@ FactoryGirl.define do ...@@ -19,5 +21,7 @@ FactoryGirl.define do
starts_at "2013-11-12 13:43:25" starts_at "2013-11-12 13:43:25"
ends_at "2013-11-12 13:43:25" ends_at "2013-11-12 13:43:25"
alert_type 1 alert_type 1
color "#555"
font "#BBB"
end end
end end
require 'spec_helper'
describe BroadcastMessagesHelper do
describe 'broadcast_styling' do
let(:broadcast_message) { double(color: "", font: "") }
context "default style" do
it "should have no style" do
broadcast_styling(broadcast_message).should match('')
end
end
context "customiezd style" do
before { broadcast_message.stub(color: "#f2dede", font: "#b94a48") }
it "should have a customized style" do
broadcast_styling(broadcast_message).should match('background-color:#f2dede;color:#b94a48')
end
end
end
end
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
# alert_type :integer # alert_type :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# color :string(255)
# font :string(255)
# #
require 'spec_helper' require 'spec_helper'
......
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