Several schedules in the backend && routes changed
- Introduce plural resources for Schedule in routes.rb - Introduce #index and #create actions for ScheduleController - Make it possible to set a schedule as selected_schedule
This commit is contained in:
parent
3897ec79ca
commit
42848f929b
8 changed files with 90 additions and 36 deletions
|
|
@ -71,7 +71,7 @@ var Schedule = {
|
||||||
var e = $("#" + element);
|
var e = $("#" + element);
|
||||||
var unscheduled = $(".unscheduled-events");
|
var unscheduled = $(".unscheduled-events");
|
||||||
|
|
||||||
var url = '/admin/conference/' + conference + '/schedule';
|
var url = '/admin/conference/' + conference + '/schedule/' + schedule_id;
|
||||||
var params = {
|
var params = {
|
||||||
event: e.attr("guid"),
|
event: e.attr("guid"),
|
||||||
room: "none",
|
room: "none",
|
||||||
|
|
@ -93,7 +93,7 @@ var Schedule = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
save: function (event_id, room_id, date, time) {
|
save: function (event_id, room_id, date, time) {
|
||||||
var url = '/admin/conference/' + conference + '/schedule';
|
var url = '/admin/conference/' + conference + '/schedule/' + schedule_id;
|
||||||
var params = {
|
var params = {
|
||||||
event: event_id,
|
event: event_id,
|
||||||
room: room_id,
|
room: room_id,
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,47 @@
|
||||||
module Admin
|
module Admin
|
||||||
class SchedulesController < Admin::BaseController
|
class ScheduleController < Admin::BaseController
|
||||||
# By authorizing 'conference' resource, we can ensure there will be no unauthorized access to
|
# By authorizing 'conference' resource, we can ensure there will be no unauthorized access to
|
||||||
# the schedule of a conference, which should not be accessed in the first place
|
# the schedule of a conference, which should not be accessed in the first place
|
||||||
load_and_authorize_resource :conference, find_by: :short_title
|
load_and_authorize_resource :conference, find_by: :short_title
|
||||||
load_and_authorize_resource :program, through: :conference, singleton: true
|
load_and_authorize_resource :program, through: :conference, singleton: true
|
||||||
load_resource :venue, through: :conference, singleton: true
|
load_resource :venue, through: :conference, singleton: true
|
||||||
|
|
||||||
skip_before_filter :verify_authenticity_token, only: [:update]
|
skip_before_action :verify_authenticity_token, only: [:update]
|
||||||
|
|
||||||
|
def index
|
||||||
|
@schedules = @conference.program.schedules
|
||||||
|
@selected_schedule = @conference.program.selected_schedule
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
new_schedule = @program.schedules.create
|
||||||
|
redirect_to action: 'show', id: new_schedule.id
|
||||||
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
event = @program.events.new
|
authorize! :update, @program.events.new
|
||||||
authorize! :update, event
|
@schedule_id = params[:id].to_i
|
||||||
event.destroy
|
@selected_schedule_id = @conference.program.selected_schedule.try(:id)
|
||||||
if @conference.nil?
|
|
||||||
redirect_to admin_conference_index_path
|
|
||||||
return
|
|
||||||
end
|
|
||||||
@dates = @conference.start_date..@conference.end_date
|
@dates = @conference.start_date..@conference.end_date
|
||||||
if @venue && @venue.rooms.any?
|
@rooms = (@venue && @venue.rooms.any?) ? @venue.rooms : [Room.new(name: 'No Rooms!', size: 0)]
|
||||||
@rooms = @venue.rooms
|
|
||||||
else
|
|
||||||
@rooms = [ Room.new(name: 'No Rooms!', size: 0) ]
|
|
||||||
end
|
|
||||||
# if there is not selected schedule we create it
|
|
||||||
unless @program.selected_schedule.present?
|
|
||||||
schedule = @program.schedules.create
|
|
||||||
@program.selected_schedule = schedule
|
|
||||||
@program.save!
|
|
||||||
end
|
|
||||||
@schedule_id = @program.selected_schedule.id
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
authorize! :update, @program.events.new
|
event = @program.events.new
|
||||||
|
authorize! :update, event
|
||||||
|
event.destroy
|
||||||
|
|
||||||
|
if params[:selected_schedule].present?
|
||||||
|
if params[:selected_schedule] == 'true'
|
||||||
|
@program.selected_schedule_id = params[:id].to_i
|
||||||
|
elsif params[:selected_schedule] == 'false' && (@program.selected_schedule_id == params[:id].to_i)
|
||||||
|
@program.selected_schedule_id = nil
|
||||||
|
end
|
||||||
|
@program.save!
|
||||||
|
render json: { 'status' => 'ok' }
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
event = Event.where(guid: params[:event]).first
|
event = Event.where(guid: params[:event]).first
|
||||||
error_message = nil
|
error_message = nil
|
||||||
if event.nil?
|
if event.nil?
|
||||||
|
|
@ -74,11 +83,17 @@ module Admin
|
||||||
render json: { 'status' => 'ok' }
|
render json: { 'status' => 'ok' }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
def destroy
|
||||||
|
if @schedule.destroy
|
||||||
def event_params
|
redirect_to admin_conference_schedule_index_path(conference_id: @conference.short_title),
|
||||||
params.require(:event).permit(:guid)
|
notice: 'Schedule successfully deleted.'
|
||||||
|
else
|
||||||
|
redirect_to admin_conference_schedule_index_path(conference_id: @conference.short_title),
|
||||||
|
error: "Schedule couldn't be deleted. #{@schedule.errors.full_messages.join('. ')}."
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
def room_params
|
def room_params
|
||||||
params.require(:room)
|
params.require(:room)
|
||||||
32
app/views/admin/schedule/index.html.haml
Normal file
32
app/views/admin/schedule/index.html.haml
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
|
.page-header
|
||||||
|
%h1 Schedules
|
||||||
|
%p.text-muted
|
||||||
|
The schedules for your conference
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
|
%table.table.table-hover#event_types
|
||||||
|
%thead
|
||||||
|
%th Schedule
|
||||||
|
%th Selected
|
||||||
|
%th Actions
|
||||||
|
%tbody
|
||||||
|
- @schedules.each do |schedule|
|
||||||
|
%tr
|
||||||
|
%td
|
||||||
|
Schedule
|
||||||
|
= schedule.id
|
||||||
|
%td
|
||||||
|
= (schedule == @selected_schedule) ? 'Yes' : 'No'
|
||||||
|
%td
|
||||||
|
.btn-group{role: "group"}
|
||||||
|
= link_to 'Show', admin_conference_schedule_path(@conference.short_title, schedule.id),
|
||||||
|
method: :get, class: 'btn btn-primary'
|
||||||
|
= link_to 'Delete', admin_conference_schedule_path(@conference.short_title, schedule.id),
|
||||||
|
method: :delete, class: 'btn btn-danger', data: { confirm: "Do you really want to delete Schedule #{schedule.id}?" }
|
||||||
|
|
||||||
|
.row
|
||||||
|
.col-md-12.text-right
|
||||||
|
= link_to 'Add Schedule', admin_conference_schedule_index_path(@conference.short_title),
|
||||||
|
method: :post, class: 'btn btn-primary'
|
||||||
|
|
@ -7,6 +7,13 @@
|
||||||
|
|
||||||
.row
|
.row
|
||||||
.col-md-2
|
.col-md-2
|
||||||
|
Selected schedule
|
||||||
|
= check_box_tag @conference.short_title, @schedule_id, (@schedule_id == @selected_schedule_id),
|
||||||
|
method: :put, url: "/admin/conference/#{@conference.short_title}/schedule/#{@schedule_id}?selected_schedule=",
|
||||||
|
class: 'switch-checkbox', data: { size: 'small',
|
||||||
|
off_color: 'warning',
|
||||||
|
on_text: 'Yes',
|
||||||
|
off_text: 'No' }
|
||||||
.h4
|
.h4
|
||||||
Unscheduled events
|
Unscheduled events
|
||||||
.unscheduled-events
|
.unscheduled-events
|
||||||
|
|
@ -82,8 +82,8 @@
|
||||||
%li{:class=> active_nav_li(admin_conference_program_difficulty_levels_path(@conference.short_title))}
|
%li{:class=> active_nav_li(admin_conference_program_difficulty_levels_path(@conference.short_title))}
|
||||||
= link_to 'Difficulty Levels', admin_conference_program_difficulty_levels_path(@conference.short_title)
|
= link_to 'Difficulty Levels', admin_conference_program_difficulty_levels_path(@conference.short_title)
|
||||||
- if can? :update, @conference.program.events.build
|
- if can? :update, @conference.program.events.build
|
||||||
%li{class: active_nav_li(admin_conference_schedule_path(@conference.short_title))}
|
%li{class: active_nav_li(admin_conference_schedule_index_path(@conference.short_title))}
|
||||||
= link_to 'Schedule', admin_conference_schedule_path(@conference.short_title)
|
= link_to 'Schedules', admin_conference_schedule_index_path(@conference.short_title)
|
||||||
|
|
||||||
- if can? :update, Registration.new(conference_id: @conference.id)
|
- if can? :update, Registration.new(conference_id: @conference.id)
|
||||||
%li{:class=> active_nav_li(admin_conference_registrations_path(@conference.short_title))}
|
%li{:class=> active_nav_li(admin_conference_registrations_path(@conference.short_title))}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ Osem::Application.routes.draw do
|
||||||
resources :comments, only: [:index]
|
resources :comments, only: [:index]
|
||||||
resources :conference do
|
resources :conference do
|
||||||
resource :contact, except: [:index, :new, :create, :show, :destroy]
|
resource :contact, except: [:index, :new, :create, :show, :destroy]
|
||||||
resource :schedule, only: [:show, :update]
|
resources :schedule, only: [:index, :create, :show, :update, :destroy]
|
||||||
get 'commercials/render_commercial' => 'commercials#render_commercial'
|
get 'commercials/render_commercial' => 'commercials#render_commercial'
|
||||||
resources :commercials, only: [:index, :create, :update, :destroy]
|
resources :commercials, only: [:index, :create, :update, :destroy]
|
||||||
get '/volunteers_list' => 'volunteers#show'
|
get '/volunteers_list' => 'volunteers#show'
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,8 @@ feature 'Has correct abilities' do
|
||||||
visit admin_conference_program_events_path(conference1.short_title)
|
visit admin_conference_program_events_path(conference1.short_title)
|
||||||
expect(current_path).to eq(admin_conference_program_events_path(conference1.short_title))
|
expect(current_path).to eq(admin_conference_program_events_path(conference1.short_title))
|
||||||
|
|
||||||
visit admin_conference_schedule_path(conference1.short_title)
|
visit admin_conference_schedule_index_path(conference1.short_title)
|
||||||
expect(current_path).to eq(admin_conference_schedule_path(conference1.short_title))
|
expect(current_path).to eq(admin_conference_schedule_index_path(conference1.short_title))
|
||||||
|
|
||||||
visit admin_conference_campaigns_path(conference1.short_title)
|
visit admin_conference_campaigns_path(conference1.short_title)
|
||||||
expect(current_path).to eq(admin_conference_campaigns_path(conference1.short_title))
|
expect(current_path).to eq(admin_conference_campaigns_path(conference1.short_title))
|
||||||
|
|
@ -147,8 +147,8 @@ feature 'Has correct abilities' do
|
||||||
visit admin_conference_program_events_path(conference2.short_title)
|
visit admin_conference_program_events_path(conference2.short_title)
|
||||||
expect(current_path).to eq(admin_conference_program_events_path(conference2.short_title))
|
expect(current_path).to eq(admin_conference_program_events_path(conference2.short_title))
|
||||||
|
|
||||||
visit admin_conference_schedule_path(conference2.short_title)
|
visit admin_conference_schedule_index_path(conference2.short_title)
|
||||||
expect(current_path).to eq(admin_conference_schedule_path(conference2.short_title))
|
expect(current_path).to eq(root_path)
|
||||||
|
|
||||||
visit admin_conference_campaigns_path(conference2.short_title)
|
visit admin_conference_campaigns_path(conference2.short_title)
|
||||||
expect(current_path).to eq(root_path)
|
expect(current_path).to eq(root_path)
|
||||||
|
|
@ -221,7 +221,7 @@ feature 'Has correct abilities' do
|
||||||
visit admin_conference_program_events_path(conference3.short_title)
|
visit admin_conference_program_events_path(conference3.short_title)
|
||||||
expect(current_path).to eq(root_path)
|
expect(current_path).to eq(root_path)
|
||||||
|
|
||||||
visit admin_conference_schedule_path(conference3.short_title)
|
visit admin_conference_schedule_index_path(conference3.short_title)
|
||||||
expect(current_path).to eq(root_path)
|
expect(current_path).to eq(root_path)
|
||||||
|
|
||||||
visit admin_conference_campaigns_path(conference3.short_title)
|
visit admin_conference_campaigns_path(conference3.short_title)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue