OSDN Git Service

Broadcast messages scaffold in admin area
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Tue, 12 Nov 2013 12:28:12 +0000 (14:28 +0200)
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Tue, 12 Nov 2013 12:28:12 +0000 (14:28 +0200)
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
app/assets/stylesheets/gitlab_bootstrap/forms.scss
app/controllers/admin/broadcast_messages_controller.rb [new file with mode: 0644]
app/models/broadcast_message.rb
app/views/admin/broadcast_messages/index.html.haml [new file with mode: 0644]
config/routes.rb

index a261216..3df5eba 100644 (file)
@@ -49,3 +49,9 @@ fieldset legend {
   font-size: 16px;
   margin-bottom: 10px;
 }
+
+.datetime-controls {
+  select {
+    width: 100px;
+  }
+}
diff --git a/app/controllers/admin/broadcast_messages_controller.rb b/app/controllers/admin/broadcast_messages_controller.rb
new file mode 100644 (file)
index 0000000..3ba8d09
--- /dev/null
@@ -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
index 0318c9b..69636de 100644 (file)
@@ -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
diff --git a/app/views/admin/broadcast_messages/index.html.haml b/app/views/admin/broadcast_messages/index.html.haml
new file mode 100644 (file)
index 0000000..22f7b71
--- /dev/null
@@ -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
index 58bbd2b..d41a078 100644 (file)
@@ -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]