Commit 0760ba3efb7566b9f56bb066f4b15ba8ea34e1e7
1 parent
566b4962
Exists in
spb-stable
and in
3 other branches
Customization and previewing of broadcast messages
Showing
14 changed files
with
106 additions
and
3 deletions
Show diff stats
CHANGELOG
| @@ -23,6 +23,7 @@ v 6.4.0 | @@ -23,6 +23,7 @@ v 6.4.0 | ||
| 23 | - API Cross-origin resource sharing | 23 | - API Cross-origin resource sharing |
| 24 | - Show READMe link at project home page | 24 | - Show READMe link at project home page |
| 25 | - Show repo size for projects in Admin area | 25 | - Show repo size for projects in Admin area |
| 26 | + - Add color custimization and previewing to broadcast messages | ||
| 26 | 27 | ||
| 27 | v 6.3.0 | 28 | v 6.3.0 |
| 28 | - API for adding gitlab-ci service | 29 | - API for adding gitlab-ci service |
app/assets/javascripts/admin.js.coffee
| @@ -8,6 +8,23 @@ class Admin | @@ -8,6 +8,23 @@ class Admin | ||
| 8 | else | 8 | else |
| 9 | elems.removeAttr 'disabled' | 9 | elems.removeAttr 'disabled' |
| 10 | 10 | ||
| 11 | + $('body').on 'click', '.js-toggle-colors-link', (e) -> | ||
| 12 | + e.preventDefault() | ||
| 13 | + $('.js-toggle-colors-link').hide() | ||
| 14 | + $('.js-toggle-colors-container').show() | ||
| 15 | + | ||
| 16 | + $('input#broadcast_message_color').on 'input', -> | ||
| 17 | + previewColor = $('input#broadcast_message_color').val() | ||
| 18 | + $('div.broadcast-message-preview').css('background-color', previewColor) | ||
| 19 | + | ||
| 20 | + $('input#broadcast_message_font').on 'input', -> | ||
| 21 | + previewColor = $('input#broadcast_message_font').val() | ||
| 22 | + $('div.broadcast-message-preview').css('color', previewColor) | ||
| 23 | + | ||
| 24 | + $('textarea#broadcast_message_message').on 'input', -> | ||
| 25 | + previewMessage = $('textarea#broadcast_message_message').val() | ||
| 26 | + $('div.broadcast-message-preview span').text(previewMessage) | ||
| 27 | + | ||
| 11 | $('.log-tabs a').click (e) -> | 28 | $('.log-tabs a').click (e) -> |
| 12 | e.preventDefault() | 29 | e.preventDefault() |
| 13 | $(this).tab('show') | 30 | $(this).tab('show') |
app/assets/stylesheets/common.scss
| @@ -361,6 +361,11 @@ table { | @@ -361,6 +361,11 @@ table { | ||
| 361 | color: #BBB; | 361 | color: #BBB; |
| 362 | } | 362 | } |
| 363 | 363 | ||
| 364 | +.broadcast-message-preview { | ||
| 365 | + @extend .broadcast-message; | ||
| 366 | + margin-bottom: 20px; | ||
| 367 | +} | ||
| 368 | + | ||
| 364 | .ajax-users-select { | 369 | .ajax-users-select { |
| 365 | width: 400px; | 370 | width: 400px; |
| 366 | 371 |
app/models/broadcast_message.rb
| @@ -9,10 +9,12 @@ | @@ -9,10 +9,12 @@ | ||
| 9 | # alert_type :integer | 9 | # alert_type :integer |
| 10 | # created_at :datetime not null | 10 | # created_at :datetime not null |
| 11 | # updated_at :datetime not null | 11 | # updated_at :datetime not null |
| 12 | +# color :string(255) | ||
| 13 | +# font :string(255) | ||
| 12 | # | 14 | # |
| 13 | 15 | ||
| 14 | class BroadcastMessage < ActiveRecord::Base | 16 | class BroadcastMessage < ActiveRecord::Base |
| 15 | - attr_accessible :alert_type, :ends_at, :message, :starts_at | 17 | + attr_accessible :alert_type, :color, :ends_at, :font, :message, :starts_at |
| 16 | 18 | ||
| 17 | validates :message, presence: true | 19 | validates :message, presence: true |
| 18 | validates :starts_at, presence: true | 20 | validates :starts_at, presence: true |
app/views/admin/broadcast_messages/index.html.haml
| @@ -2,7 +2,9 @@ | @@ -2,7 +2,9 @@ | ||
| 2 | Broadcast Messages | 2 | Broadcast Messages |
| 3 | %p.light | 3 | %p.light |
| 4 | Broadcast messages are displayed for every user and can be used to notify users about scheduled maintenance, recent upgrades and more. | 4 | Broadcast messages are displayed for every user and can be used to notify users about scheduled maintenance, recent upgrades and more. |
| 5 | -%hr | 5 | +.broadcast-message-preview |
| 6 | + %i.icon-bullhorn | ||
| 7 | + %span Your message here | ||
| 6 | 8 | ||
| 7 | = form_for [:admin, @broadcast_message] do |f| | 9 | = form_for [:admin, @broadcast_message] do |f| |
| 8 | -if @broadcast_message.errors.any? | 10 | -if @broadcast_message.errors.any? |
| @@ -13,6 +15,17 @@ | @@ -13,6 +15,17 @@ | ||
| 13 | = f.label :message | 15 | = f.label :message |
| 14 | .controls | 16 | .controls |
| 15 | = f.text_area :message, class: "input-xxlarge", rows: 2, required: true | 17 | = f.text_area :message, class: "input-xxlarge", rows: 2, required: true |
| 18 | + %div | ||
| 19 | + = link_to '#', class: 'js-toggle-colors-link' do | ||
| 20 | + Customize colors | ||
| 21 | + .control-group.js-toggle-colors-container.hide | ||
| 22 | + = f.label :color, "Background Color" | ||
| 23 | + .controls | ||
| 24 | + = f.text_field :color | ||
| 25 | + .control-group.js-toggle-colors-container.hide | ||
| 26 | + = f.label :font, "Font Color" | ||
| 27 | + .controls | ||
| 28 | + = f.text_field :font | ||
| 16 | .control-group | 29 | .control-group |
| 17 | = f.label :starts_at | 30 | = f.label :starts_at |
| 18 | .controls.datetime-controls | 31 | .controls.datetime-controls |
app/views/layouts/_broadcast.html.haml
db/migrate/20131130165425_add_color_and_font_to_broadcast_messages.rb
0 → 100644
db/schema.rb
| @@ -20,6 +20,8 @@ ActiveRecord::Schema.define(version: 20131217102743) do | @@ -20,6 +20,8 @@ ActiveRecord::Schema.define(version: 20131217102743) do | ||
| 20 | t.integer "alert_type" | 20 | t.integer "alert_type" |
| 21 | t.datetime "created_at", null: false | 21 | t.datetime "created_at", null: false |
| 22 | t.datetime "updated_at", null: false | 22 | t.datetime "updated_at", null: false |
| 23 | + t.string "color" | ||
| 24 | + t.string "font" | ||
| 23 | end | 25 | end |
| 24 | 26 | ||
| 25 | create_table "deploy_keys_projects", force: true do |t| | 27 | create_table "deploy_keys_projects", force: true do |t| |
features/admin/broadcast_messages.feature
| @@ -11,3 +11,10 @@ Feature: Admin Broadcast Messages | @@ -11,3 +11,10 @@ Feature: Admin Broadcast Messages | ||
| 11 | When submit form with new broadcast message | 11 | When submit form with new broadcast message |
| 12 | Then I should be redirected to admin messages page | 12 | Then I should be redirected to admin messages page |
| 13 | And I should see newly created broadcast message | 13 | And I should see newly created broadcast message |
| 14 | + | ||
| 15 | + Scenario: Create a customized broadcast message | ||
| 16 | + When submit form with new customized broadcast message | ||
| 17 | + Then I should be redirected to admin messages page | ||
| 18 | + And I should see newly created broadcast message | ||
| 19 | + Then I visit dashboard page | ||
| 20 | + And I should see a customized broadcast message |
features/steps/admin/admin_broadcast_messages.rb
| @@ -24,4 +24,18 @@ class Spinach::Features::AdminBroadcastMessages < Spinach::FeatureSteps | @@ -24,4 +24,18 @@ class Spinach::Features::AdminBroadcastMessages < Spinach::FeatureSteps | ||
| 24 | step 'I should see newly created broadcast message' do | 24 | step 'I should see newly created broadcast message' do |
| 25 | page.should have_content 'Application update from 4:00 CST to 5:00 CST' | 25 | page.should have_content 'Application update from 4:00 CST to 5:00 CST' |
| 26 | end | 26 | end |
| 27 | + | ||
| 28 | + step 'submit form with new customized broadcast message' do | ||
| 29 | + fill_in 'broadcast_message_message', with: 'Application update from 4:00 CST to 5:00 CST' | ||
| 30 | + click_link "Customize colors" | ||
| 31 | + fill_in 'broadcast_message_color', with: '#f2dede' | ||
| 32 | + fill_in 'broadcast_message_font', with: '#b94a48' | ||
| 33 | + select '2018', from: "broadcast_message_ends_at_1i" | ||
| 34 | + click_button "Add broadcast message" | ||
| 35 | + end | ||
| 36 | + | ||
| 37 | + step 'I should see a customized broadcast message' do | ||
| 38 | + page.should have_content 'Application update from 4:00 CST to 5:00 CST' | ||
| 39 | + page.should have_selector %(div[style="background-color:#f2dede;color:#b94a48"]) | ||
| 40 | + end | ||
| 27 | end | 41 | end |
spec/factories/broadcast_messages.rb
| @@ -9,6 +9,8 @@ | @@ -9,6 +9,8 @@ | ||
| 9 | # alert_type :integer | 9 | # alert_type :integer |
| 10 | # created_at :datetime not null | 10 | # created_at :datetime not null |
| 11 | # updated_at :datetime not null | 11 | # updated_at :datetime not null |
| 12 | +# color :string(255) | ||
| 13 | +# font :string(255) | ||
| 12 | # | 14 | # |
| 13 | 15 | ||
| 14 | # Read about factories at https://github.com/thoughtbot/factory_girl | 16 | # Read about factories at https://github.com/thoughtbot/factory_girl |
| @@ -19,5 +21,7 @@ FactoryGirl.define do | @@ -19,5 +21,7 @@ FactoryGirl.define do | ||
| 19 | starts_at "2013-11-12 13:43:25" | 21 | starts_at "2013-11-12 13:43:25" |
| 20 | ends_at "2013-11-12 13:43:25" | 22 | ends_at "2013-11-12 13:43:25" |
| 21 | alert_type 1 | 23 | alert_type 1 |
| 24 | + color "#555" | ||
| 25 | + font "#BBB" | ||
| 22 | end | 26 | end |
| 23 | end | 27 | end |
| @@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
| 1 | +require 'spec_helper' | ||
| 2 | + | ||
| 3 | +describe BroadcastMessagesHelper do | ||
| 4 | + describe 'broadcast_styling' do | ||
| 5 | + let(:broadcast_message) { double(color: "", font: "") } | ||
| 6 | + | ||
| 7 | + context "default style" do | ||
| 8 | + it "should have no style" do | ||
| 9 | + broadcast_styling(broadcast_message).should match('') | ||
| 10 | + end | ||
| 11 | + end | ||
| 12 | + | ||
| 13 | + context "customiezd style" do | ||
| 14 | + before { broadcast_message.stub(color: "#f2dede", font: "#b94a48") } | ||
| 15 | + | ||
| 16 | + it "should have a customized style" do | ||
| 17 | + broadcast_styling(broadcast_message).should match('background-color:#f2dede;color:#b94a48') | ||
| 18 | + end | ||
| 19 | + end | ||
| 20 | + end | ||
| 21 | +end |
spec/models/broadcast_message_spec.rb
| @@ -9,6 +9,8 @@ | @@ -9,6 +9,8 @@ | ||
| 9 | # alert_type :integer | 9 | # alert_type :integer |
| 10 | # created_at :datetime not null | 10 | # created_at :datetime not null |
| 11 | # updated_at :datetime not null | 11 | # updated_at :datetime not null |
| 12 | +# color :string(255) | ||
| 13 | +# font :string(255) | ||
| 12 | # | 14 | # |
| 13 | 15 | ||
| 14 | require 'spec_helper' | 16 | require 'spec_helper' |