Set current conference, scope everything under it

This commit is contained in:
Andrew Radev 2015-05-30 17:07:57 +03:00
parent 32402b62e0
commit 296b80494b
6 changed files with 62 additions and 37 deletions

View File

@ -2,5 +2,12 @@ module Management
class HomeController < ManagementController class HomeController < ManagementController
def index def index
end end
def set_conference
conference = Conference.find(params[:id])
set_current_conference(conference)
redirect_to [:management, conference]
end
end end
end end

View File

@ -6,6 +6,20 @@ module Management
private private
def current_conference?
session[:current_conference_id] and current_conference.present?
end
helper_method :current_conference?
def current_conference
@current_conference ||= Conference.find(session[:current_conference_id])
end
helper_method :current_conference
def set_current_conference(conference)
session[:current_conference_id] = conference.id
end
def authorize_user! def authorize_user!
head :forbidden unless current_user.admin? head :forbidden unless current_user.admin?
end end

View File

@ -5,29 +5,20 @@ nav.navbar.navbar-static-top.navbar-inverse role="navigation"
span.icon-bar span.icon-bar
span.icon-bar span.icon-bar
span.icon-bar span.icon-bar
= link_to management_path, class: 'navbar-brand'
= link_to management_root_path, class: 'navbar-brand'
| Clarion | Clarion
.navbar-collapse.collapse.navbar-inverse-collapse .navbar-collapse.collapse.navbar-inverse-collapse
- if user_signed_in? - if current_conference?
ul.nav.navbar-nav ul.nav.navbar-nav
li.dropdown class="#{'active' if current_page?(management_path) || current_page?(management_conferences_path)}"
a.dropdown-toggle href="#" data-toggle="dropdown"
=> icon 'users', class: 'fa-fw'
span = Conference.model_name.human(count: 2).mb_chars.capitalize
span.caret<
ul.dropdown-menu role="menu"
- Conference.all.each do |conference|
li li
= link_to conference.title, management_conference_path(conference) = link_to [:management, current_conference], class: 'navbar-brand'
li class="#{'active' if controller_name == 'sessions'}" => icon 'users', class: 'fa-fw'
= link_to management_users_path do = current_conference.title
=> icon 'user', User.model_name.human(count: 2).mb_chars.capitalize, class: 'fa-fw'
-# TODO Instead of this, provide a generic `yield :navigation`?
- if @conference.present? and @conference.persisted?
li class="#{'active' if controller_name == 'events'}" li class="#{'active' if controller_name == 'events'}"
= link_to management_conference_events_path(@conference) do = link_to management_events_path do
=> icon 'file-text', Event.model_name.human(count: 2).mb_chars.capitalize, class: 'fa-fw' => icon 'file-text', Event.model_name.human(count: 2).mb_chars.capitalize, class: 'fa-fw'
li class="#{'active' if controller_name == 'sponsorship_offers'}" li class="#{'active' if controller_name == 'sponsorship_offers'}"
= link_to '#' do = link_to '#' do

View File

@ -16,11 +16,13 @@
= @conference.events.count = @conference.events.count
div div
= t Event.model_name.human(count: @conference.events.count) = t Event.model_name.human(count: @conference.events.count)
= link_to management_conference_events_path(@conference)
= link_to management_events_path
.panel-footer.text-primary .panel-footer.text-primary
span.pull-left = t 'views.conference.see_details' span.pull-left = t 'views.conference.see_details'
span.pull-right = icon 'arrow-circle-right' span.pull-right = icon 'arrow-circle-right'
span.clearfix span.clearfix
.col-lg-3.col-md-6 .col-lg-3.col-md-6
.panel.panel-danger .panel.panel-danger
.panel-heading .panel-heading
@ -32,11 +34,12 @@
= @conference.events.rejected.count = @conference.events.rejected.count
div div
= t 'event_states.rejected', count: @conference.events.rejected.count = t 'event_states.rejected', count: @conference.events.rejected.count
= link_to management_conference_events_path(@conference, status: :rejected) = link_to management_events_path(status: :rejected)
.panel-footer.text-danger .panel-footer.text-danger
span.pull-left = t 'views.conference.see_details' span.pull-left = t 'views.conference.see_details'
span.pull-right = icon 'arrow-circle-right' span.pull-right = icon 'arrow-circle-right'
span.clearfix span.clearfix
.col-lg-3.col-md-6 .col-lg-3.col-md-6
.panel.panel-info .panel.panel-info
.panel-heading .panel-heading
@ -48,7 +51,7 @@
= @conference.events.approved.count = @conference.events.approved.count
div div
= t 'event_states.approved', count: @conference.events.approved.count = t 'event_states.approved', count: @conference.events.approved.count
= link_to management_conference_events_path(@conference, status: :approved) = link_to management_events_path(status: :approved)
.panel-footer.text-info .panel-footer.text-info
span.pull-left = t 'views.conference.see_details' span.pull-left = t 'views.conference.see_details'
span.pull-right = icon 'arrow-circle-right' span.pull-right = icon 'arrow-circle-right'
@ -64,7 +67,7 @@
= @conference.events.approved.confirmed.count = @conference.events.approved.confirmed.count
div div
= t 'event_states.confirmed', count: @conference.events.approved.confirmed.count = t 'event_states.confirmed', count: @conference.events.approved.confirmed.count
= link_to management_conference_events_path(@conference, status: :approved, confirmed: true) = link_to management_events_path(status: :approved, confirmed: true)
.panel-footer.text-success .panel-footer.text-success
span.pull-left = t 'views.conference.see_details' span.pull-left = t 'views.conference.see_details'
span.pull-right = icon 'arrow-circle-right' span.pull-right = icon 'arrow-circle-right'

View File

@ -0,0 +1,10 @@
.row
.col-lg-12
.dropdown
a.dropdown-toggle href="#" data-toggle="dropdown"
=> icon 'users', class: 'fa-fw'
span = Conference.model_name.human(count: 2).mb_chars.capitalize
span.caret<
ul.dropdown-menu role="menu"
- Conference.all.each do |conference|
li= link_to conference.title, management_set_conference_path(conference), method: :put

View File

@ -2,20 +2,20 @@ Rails.application.routes.draw do
devise_for :users devise_for :users
namespace :management do namespace :management do
get '/', to: 'conferences#index' root to: 'home#index'
resources :conferences do put '/set_conference/:id', to: 'home#set_conference', as: :set_conference
resources :conferences
resources :events resources :events
resources :volunteers resources :volunteers
resources :sponsorship_offers resources :sponsorship_offers
resource :call_for_participation, only: [:create, :destroy] resource :call_for_participation, only: [:create, :destroy]
end
resources :users do resources :users do
member do member do
put :toggle_admin put :toggle_admin
end end
end end
end end
root 'management/conferences#index'
end end