Commit dd501aa7a79644919ba0c47d1ed764b6db768c8d
1 parent
f1ecf53c
Exists in
master
and in
4 other branches
Broadcast messages scaffold in admin area
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
5 changed files
with
73 additions
and
0 deletions
Show diff stats
app/assets/stylesheets/gitlab_bootstrap/forms.scss
| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | +class Admin::BroadcastMessagesController < Admin::ApplicationController | |
| 2 | + before_filter :broadcast_messages | |
| 3 | + | |
| 4 | + def index | |
| 5 | + @broadcast_message = BroadcastMessage.new | |
| 6 | + end | |
| 7 | + | |
| 8 | + def create | |
| 9 | + @broadcast_message = BroadcastMessage.new(params[:broadcast_message]) | |
| 10 | + | |
| 11 | + if @broadcast_message.save | |
| 12 | + redirect_to admin_broadcast_messages_path, notice: 'Broadcast Message was successfully created.' | |
| 13 | + else | |
| 14 | + render :index | |
| 15 | + end | |
| 16 | + end | |
| 17 | + | |
| 18 | + protected | |
| 19 | + | |
| 20 | + def broadcast_messages | |
| 21 | + @broadcast_messages ||= BroadcastMessage.order("starts_at DESC").page(params[:page]) | |
| 22 | + end | |
| 23 | +end | ... | ... |
app/models/broadcast_message.rb
| ... | ... | @@ -0,0 +1,41 @@ |
| 1 | +%h3.page-title | |
| 2 | + Broadcast Messages | |
| 3 | +%p.light | |
| 4 | + Broadcast messages displayed for every user and can be used to notify application about scheduled maintenance. | |
| 5 | +%hr | |
| 6 | + | |
| 7 | += form_for [:admin, @broadcast_message] do |f| | |
| 8 | + -if @broadcast_message.errors.any? | |
| 9 | + .alert.alert-error | |
| 10 | + - @broadcast_message.errors.full_messages.each do |msg| | |
| 11 | + %p= msg | |
| 12 | + .control-group | |
| 13 | + = f.label :message | |
| 14 | + .controls | |
| 15 | + = f.text_area :message, class: "input-xxlarge", rows: 2, required: true | |
| 16 | + .control-group | |
| 17 | + = f.label :starts_at | |
| 18 | + .controls.datetime-controls | |
| 19 | + = f.datetime_select :starts_at | |
| 20 | + .control-group | |
| 21 | + = f.label :ends_at | |
| 22 | + .controls.datetime-controls | |
| 23 | + = f.datetime_select :ends_at | |
| 24 | + .form-actions | |
| 25 | + = f.submit "Add broadcast message", class: "btn btn-create" | |
| 26 | + | |
| 27 | +-if @broadcast_messages.any? | |
| 28 | + %ul.bordered-list | |
| 29 | + - @broadcast_messages.each do |broadcast_message| | |
| 30 | + %li | |
| 31 | + .pull-right | |
| 32 | + - if broadcast_message.starts_at | |
| 33 | + %strong | |
| 34 | + #{broadcast_message.starts_at.to_s(:short)} | |
| 35 | + \... | |
| 36 | + - if broadcast_message.ends_at | |
| 37 | + %strong | |
| 38 | + #{broadcast_message.ends_at.to_s(:short)} | |
| 39 | + .message= broadcast_message.message | |
| 40 | + | |
| 41 | + = paginate @broadcast_messages | ... | ... |
config/routes.rb
| ... | ... | @@ -86,6 +86,7 @@ Gitlab::Application.routes.draw do |
| 86 | 86 | get :test |
| 87 | 87 | end |
| 88 | 88 | |
| 89 | + resources :broadcast_messages, only: [:index, :create] | |
| 89 | 90 | resource :logs, only: [:show] |
| 90 | 91 | resource :background_jobs, controller: 'background_jobs', only: [:show] |
| 91 | 92 | resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:index, :show] | ... | ... |