diff --git a/app/assets/stylesheets/management/_record_table.css.scss b/app/assets/stylesheets/management/_record_table.css.scss index 4efd78e..16d5049 100644 --- a/app/assets/stylesheets/management/_record_table.css.scss +++ b/app/assets/stylesheets/management/_record_table.css.scss @@ -23,11 +23,11 @@ @extend .pull-right; @extend .btn-group; white-space: nowrap; + } - a { - @extend .btn; - @extend .btn-default; - } + .actions > div > a { + @extend .btn; + @extend .btn-default; } .toggle { diff --git a/app/controllers/management/events_controller.rb b/app/controllers/management/events_controller.rb index 36fb081..9bb0ac9 100644 --- a/app/controllers/management/events_controller.rb +++ b/app/controllers/management/events_controller.rb @@ -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 diff --git a/app/models/event.rb b/app/models/event.rb index 7693a0f..fd25349 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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 diff --git a/app/models/suggestion_group.rb b/app/models/suggestion_group.rb index 8d09f16..34666bc 100644 --- a/app/models/suggestion_group.rb +++ b/app/models/suggestion_group.rb @@ -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 diff --git a/app/views/layouts/management.html.slim b/app/views/layouts/management.html.slim index da5f01f..0b969ee 100644 --- a/app/views/layouts/management.html.slim +++ b/app/views/layouts/management.html.slim @@ -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" diff --git a/app/views/management/events/_state.html.slim b/app/views/management/events/_state.html.slim new file mode 100644 index 0000000..3412220 --- /dev/null +++ b/app/views/management/events/_state.html.slim @@ -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 diff --git a/app/views/management/events/_suggestion_group.html.slim b/app/views/management/events/_suggestion_group.html.slim index 3401027..8a9166b 100644 --- a/app/views/management/events/_suggestion_group.html.slim +++ b/app/views/management/events/_suggestion_group.html.slim @@ -26,3 +26,4 @@ div = link_to management_event_path(suggestion), title: t(:view), remote: true = glyph(:share) + = render partial: 'state', locals: {suggestion: suggestion} diff --git a/app/views/management/events/state.js.erb b/app/views/management/events/state.js.erb new file mode 100644 index 0000000..756cc18 --- /dev/null +++ b/app/views/management/events/state.js.erb @@ -0,0 +1 @@ +$('#suggestion-<%= @suggestion.id %>-state').replaceWith('<%= j render partial: 'state', locals: {suggestion: @suggestion} %>'); diff --git a/config/routes.rb b/config/routes.rb index 3057924..5f10322 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/db/migrate/20141010142514_change_event_state_defaults.rb b/db/migrate/20141010142514_change_event_state_defaults.rb new file mode 100644 index 0000000..6efaca5 --- /dev/null +++ b/db/migrate/20141010142514_change_event_state_defaults.rb @@ -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