Event state management
This commit is contained in:
parent
9f8ab2b3aa
commit
0efe4b95cb
|
@ -23,12 +23,12 @@
|
|||
@extend .pull-right;
|
||||
@extend .btn-group;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
a {
|
||||
.actions > div > a {
|
||||
@extend .btn;
|
||||
@extend .btn-default;
|
||||
}
|
||||
}
|
||||
|
||||
.toggle {
|
||||
a {
|
||||
|
|
|
@ -1,16 +1,40 @@
|
|||
module Management
|
||||
class EventsController < ManagementController
|
||||
before_action :assign_suggestion, only: [:show]
|
||||
before_action :assign_suggestion, only: [:show, :state]
|
||||
|
||||
def index
|
||||
@suggestion_groups = SuggestionGroup.for_conference Conference.current
|
||||
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
|
||||
end
|
||||
|
||||
def state
|
||||
@suggestion.state = state_params
|
||||
@suggestion.save
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def state_params
|
||||
params.require :state
|
||||
end
|
||||
|
||||
def assign_suggestion
|
||||
@suggestion = Event.find params[:id]
|
||||
end
|
||||
|
|
|
@ -13,6 +13,12 @@ class Event < ActiveRecord::Base
|
|||
|
||||
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
|
||||
|
||||
def send_new_event_notification
|
||||
|
|
|
@ -8,7 +8,7 @@ class SuggestionGroup
|
|||
end
|
||||
end
|
||||
|
||||
def self.for_conference(conference)
|
||||
where tracks: {conference_id: conference.id}
|
||||
def self.for_conference(conference, conditions = {})
|
||||
where conditions.merge({tracks: {conference_id: conference.id}})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,8 +22,20 @@ html
|
|||
ul.nav.navbar-nav
|
||||
li class="#{'active' if controller_name == 'users'}"
|
||||
= link_to User.model_name.human(count: 2), management_users_path
|
||||
li class="#{'active' if controller_name == 'events'}"
|
||||
= link_to Event.model_name.human(count: 2), management_events_path
|
||||
li class="dropdown #{'active' if controller_name == 'events'}"
|
||||
= 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
|
||||
== yield
|
||||
= javascript_include_tag "management/application"
|
||||
|
|
|
@ -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
|
|
@ -26,3 +26,4 @@
|
|||
div
|
||||
= link_to management_event_path(suggestion), title: t(:view), remote: true
|
||||
= glyph(:share)
|
||||
= render partial: 'state', locals: {suggestion: suggestion}
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
$('#suggestion-<%= @suggestion.id %>-state').replaceWith('<%= j render partial: 'state', locals: {suggestion: @suggestion} %>');
|
|
@ -13,7 +13,17 @@ Rails.application.routes.draw do
|
|||
end
|
||||
end
|
||||
|
||||
resources :events
|
||||
resources :events do
|
||||
member do
|
||||
patch 'state'
|
||||
end
|
||||
|
||||
collection do
|
||||
get 'approved'
|
||||
get 'rejected'
|
||||
get 'undecided'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
root 'home#index'
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue