Broadcast messages scaffold in admin area
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
f1ecf53c1e
commit
dd501aa7a7
5 changed files with 73 additions and 0 deletions
|
@ -49,3 +49,9 @@ fieldset legend {
|
|||
font-size: 16px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.datetime-controls {
|
||||
select {
|
||||
width: 100px;
|
||||
}
|
||||
}
|
||||
|
|
23
app/controllers/admin/broadcast_messages_controller.rb
Normal file
23
app/controllers/admin/broadcast_messages_controller.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
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
|
||||
|
||||
protected
|
||||
|
||||
def broadcast_messages
|
||||
@broadcast_messages ||= BroadcastMessage.order("starts_at DESC").page(params[:page])
|
||||
end
|
||||
end
|
|
@ -2,4 +2,6 @@ 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
|
||||
end
|
||||
|
|
41
app/views/admin/broadcast_messages/index.html.haml
Normal file
41
app/views/admin/broadcast_messages/index.html.haml
Normal file
|
@ -0,0 +1,41 @@
|
|||
%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.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)}
|
||||
.message= broadcast_message.message
|
||||
|
||||
= paginate @broadcast_messages
|
|
@ -86,6 +86,7 @@ Gitlab::Application.routes.draw do
|
|||
get :test
|
||||
end
|
||||
|
||||
resources :broadcast_messages, only: [:index, :create]
|
||||
resource :logs, only: [:show]
|
||||
resource :background_jobs, controller: 'background_jobs', only: [:show]
|
||||
resources :projects, constraints: { id: /[a-zA-Z.\/0-9_\-]+/ }, only: [:index, :show]
|
||||
|
|
Loading…
Reference in a new issue