Event state management

This commit is contained in:
Petko Bordjukov 2014-10-10 19:10:34 +03:00
parent 9f8ab2b3aa
commit 0efe4b95cb
10 changed files with 83 additions and 10 deletions

View File

@ -23,11 +23,11 @@
@extend .pull-right; @extend .pull-right;
@extend .btn-group; @extend .btn-group;
white-space: nowrap; white-space: nowrap;
}
a { .actions > div > a {
@extend .btn; @extend .btn;
@extend .btn-default; @extend .btn-default;
}
} }
.toggle { .toggle {

View File

@ -1,16 +1,40 @@
module Management module Management
class EventsController < ManagementController class EventsController < ManagementController
before_action :assign_suggestion, only: [:show] before_action :assign_suggestion, only: [:show, :state]
def index def index
@suggestion_groups = SuggestionGroup.for_conference Conference.current @suggestion_groups = SuggestionGroup.for_conference Conference.current
end end
def approved
@suggestion_groups = SuggestionGroup.for_conference Conference.current, state: Event.states[:approved]
render :index
end
def undecided
@suggestion_groups = SuggestionGroup.for_conference Conference.current, state: Event.states[:undecided]
render :index
end
def rejected
@suggestion_groups = SuggestionGroup.for_conference Conference.current, state: Event.states[:rejected]
render :index
end
def show def show
end end
def state
@suggestion.state = state_params
@suggestion.save
end
private private
def state_params
params.require :state
end
def assign_suggestion def assign_suggestion
@suggestion = Event.find params[:id] @suggestion = Event.find params[:id]
end end

View File

@ -13,6 +13,12 @@ class Event < ActiveRecord::Base
after_create :send_new_event_notification after_create :send_new_event_notification
enum state: [:undecided, :approved, :rejected]
# XXX: this belongs in a decorator
STATE_TO_GLYPH = {undecided: 'question-sign', rejected: 'thumbs-down', approved: 'thumbs-up'}
STATE_TO_CLASS = {undecided: 'warning', rejected: 'danger', approved: 'success'}
private private
def send_new_event_notification def send_new_event_notification

View File

@ -8,7 +8,7 @@ class SuggestionGroup
end end
end end
def self.for_conference(conference) def self.for_conference(conference, conditions = {})
where tracks: {conference_id: conference.id} where conditions.merge({tracks: {conference_id: conference.id}})
end end
end end

View File

@ -22,8 +22,20 @@ html
ul.nav.navbar-nav ul.nav.navbar-nav
li class="#{'active' if controller_name == 'users'}" li class="#{'active' if controller_name == 'users'}"
= link_to User.model_name.human(count: 2), management_users_path = link_to User.model_name.human(count: 2), management_users_path
li class="#{'active' if controller_name == 'events'}" li class="dropdown #{'active' if controller_name == 'events'}"
= link_to Event.model_name.human(count: 2), management_events_path = link_to '#', class: 'dropdown-toggle', data: {toggle: "dropdown"}
= Event.model_name.human(count: 2)
span.caret
ul.dropdown-menu role="menu"
li class="#{'active' if action_name == 'index'}"
= link_to "Всички", management_events_path
li class="#{'active' if action_name == 'undecided'}"
= link_to "Висящи", undecided_management_events_path
li class="#{'active' if action_name == 'approved'}"
= link_to "Одобрени", approved_management_events_path
li class="#{'active' if action_name == 'rejected'}"
= link_to "Отхвърлени", rejected_management_events_path
div.container div.container
== yield == yield
= javascript_include_tag "management/application" = javascript_include_tag "management/application"

View File

@ -0,0 +1,9 @@
.btn-group id="suggestion-#{suggestion.id}-state"
button class="btn dropdown-toggle btn-#{Event::STATE_TO_CLASS[suggestion.state.to_sym]}" type="button" data-toggle="dropdown"
=> glyph Event::STATE_TO_GLYPH[suggestion.state.to_sym]
span.caret
ul.dropdown-menu role="menu"
- Event.states.each do |state, number|
- next if state == suggestion.state
li
= link_to glyph(Event::STATE_TO_GLYPH[state.to_sym]), state_management_event_path(suggestion, state: state), class: "btn text-#{Event::STATE_TO_CLASS[state.to_sym]}", remote: true, method: :patch

View File

@ -26,3 +26,4 @@
div div
= link_to management_event_path(suggestion), title: t(:view), remote: true = link_to management_event_path(suggestion), title: t(:view), remote: true
= glyph(:share) = glyph(:share)
= render partial: 'state', locals: {suggestion: suggestion}

View File

@ -0,0 +1 @@
$('#suggestion-<%= @suggestion.id %>-state').replaceWith('<%= j render partial: 'state', locals: {suggestion: @suggestion} %>');

View File

@ -13,7 +13,17 @@ Rails.application.routes.draw do
end end
end end
resources :events resources :events do
member do
patch 'state'
end
collection do
get 'approved'
get 'rejected'
get 'undecided'
end
end
end end
root 'home#index' root 'home#index'

View File

@ -0,0 +1,10 @@
class ChangeEventStateDefaults < ActiveRecord::Migration
def up
execute 'UPDATE events SET state = 0'
change_column :events, :state, :integer, null: false, default: 0
end
def down
change_column :events, :state, :integer, null: true
end
end