Implement consistent admin interface

* Consistent route/model/controller/view layout
* Get rid of unused photos, speakers, dietchoices, social_events controllers
* Drop unused :public from Rooms and :description from CallForPapers
This commit is contained in:
Henne Vogelsang 2014-11-25 10:47:18 +01:00
parent f6a87331be
commit 28063129c7
133 changed files with 1461 additions and 1461 deletions

View file

@ -0,0 +1,60 @@
module Admin
class CallForPapersController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference, singleton: true
def show; end
def new
@call_for_paper = @conference.build_call_for_paper
end
def edit; end
def create
@call_for_paper = @conference.build_call_for_paper(call_for_paper_params)
if @call_for_paper.save
redirect_to admin_conference_call_for_paper_path,
notice: 'Call for papers successfully created.'
else
flash[:alert] = "Creating the call for papers failed. #{@call_for_paper.errors.full_messages.join('. ')}."
render :new
end
end
def update
authorize! :update, @conference.call_for_paper
@cfp = @conference.call_for_paper
@cfp.assign_attributes(params[:call_for_paper])
send_mail_on_schedule_public = @cfp.notify_on_schedule_public?
send_mail_on_cfp_dates_updates = @cfp.notify_on_cfp_date_update?
if @cfp.update_attributes(params[:call_for_paper])
Mailbot.delay.send_on_call_for_papers_dates_updates(@conference) if send_mail_on_cfp_dates_updates
Mailbot.delay.send_on_schedule_public(@conference) if send_mail_on_schedule_public
redirect_to(admin_conference_call_for_paper_path(@conference.short_title),
notice: 'Call for papers successfully updated.')
else
flash[:alert] = "Updating call for papers failed. #{@cfp.errors.to_a.join('. ')}."
render :new
end
end
def destroy
if @call_for_paper.destroy
redirect_to admin_conference_call_for_paper_path, notice: 'Call for Papers was successfully deleted.'
else
redirect_to admin_conference_call_for_paper_path, alert: 'A error prohibited this Call for Papers from being destroyed: '\
"#{@call_for_paper.errors.full_messages.join('. ')}."
end
end
private
def call_for_paper_params
params[:call_for_paper]
end
end
end

View file

@ -1,51 +0,0 @@
module Admin
class CallforpapersController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
# load_and_authorize_resource :cfp, class: 'CallForPapers', through: :conference
def show
authorize! :show, CallForPapers.new(conference_id: @conference.id)
@cfp = @conference.call_for_papers
if @cfp.nil?
@cfp = CallForPapers.new
end
end
def update
authorize! :update, @conference.call_for_papers
@cfp = @conference.call_for_papers
@cfp.assign_attributes(params[:call_for_papers])
send_mail_on_schedule_public = @cfp.notify_on_schedule_public?
send_mail_on_cfp_dates_updates = @cfp.notify_on_cfp_date_update?
if @cfp.update_attributes(params[:call_for_papers])
Mailbot.delay.send_on_call_for_papers_dates_updates(@conference) if send_mail_on_cfp_dates_updates
Mailbot.delay.send_on_schedule_public(@conference) if send_mail_on_schedule_public
redirect_to(admin_conference_callforpapers_path(
id: @conference.short_title),
notice: 'Call for Papers was successfully updated.')
else
redirect_to(admin_conference_callforpapers_path(
id: @conference.short_title),
alert: "Updating call for papers failed. #{@cfp.errors.to_a.join('. ')}.")
end
end
def create
authorize! :update, CallForPapers.new(conference_id: @conference.id)
@cfp = CallForPapers.new(params[:call_for_papers])
if @cfp.valid?
@cfp.save
@conference.call_for_papers = @cfp
redirect_to(admin_conference_callforpapers_path(
id: @conference.short_title),
notice: 'Call for Papers was successfully created.')
else
redirect_to(admin_conference_callforpapers_path(
id: @conference.short_title),
alert: "Creating the call for papers failed. #{@cfp.errors.to_a.join('. ')}.")
end
end
end
end

View file

@ -1,19 +0,0 @@
module Admin
class DietchoicesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :dietary_choice, through: :conference
def show
render :diets_list
end
def update
begin
@conference.update_attributes!(params[:conference])
redirect_to(admin_conference_dietary_list_path(conference_id: @conference.short_title), notice: 'Dietary choices were successfully updated.')
rescue => e
redirect_to(admin_conference_dietary_list_path(conference_id: @conference.short_title), alert: "Dietary choices update failed: #{e.message}")
end
end
end
end

View file

@ -1,32 +1,55 @@
module Admin
class DifficultyLevelsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
authorize_resource through: :conference
load_and_authorize_resource :difficulty_level, through: :conference
def index
authorize! :index, DifficultyLevel.new(conference_id: @conference.id)
end
def update
if @conference.update_attributes(params[:conference])
if !(@conference.difficulty_levels.count > 0) && @conference.use_difficulty_levels == true
begin
@conference.use_difficulty_levels = false
@conference.save!
flash[:error] = 'You cannot enable the usage of difficulty levels without having set any levels.'
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
rescue ActiveRecord::RecordInvalid
flash[:error] = 'Something went wrong. Difficulty Levels update failed.'
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
end
else
flash[:notice] = 'Difficulty Levels were successfully updated.'
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
end
def edit; end
def new
@difficulty_level = @conference.difficulty_levels.new
end
def create
@difficulty_level = @conference.difficulty_levels.new(difficulty_level_params)
if @difficulty_level.save
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title),
notice: 'Difficulty level successfully created.')
else
flash[:error] = 'Difficulty Levels update failed.'
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title))
flash[:error] = "Creating difficulty level failed: #{@difficulty_level.errors.full_messages.join('. ')}."
render :new
end
end
def update
if @difficulty_level.update_attributes(difficulty_level_params)
redirect_to(admin_conference_difficulty_levels_path(
conference_id: @conference.short_title),
notice: 'Difficulty level successfully updated.')
else
flash[:error] = "Update difficulty level failed: #{@difficulty_level.errors.full_messages.join('. ')}."
render :edit
end
end
def destroy
if @difficulty_level.destroy
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title),
notice: 'Difficulty level successfully deleted.')
else
redirect_to(admin_conference_difficulty_levels_path(conference_id: @conference.short_title),
error: 'Deleting difficulty level type failed! ' \
"#{@difficulty_level.errors.full_messages.join('. ')}.")
end
end
private
def difficulty_level_params
params[:difficulty_level]
end
end
end

View file

@ -1,25 +1,55 @@
module Admin
class EventTypesController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
authorize_resource :event_type, through: :conference
load_and_authorize_resource :event_type, through: :conference
def index
authorize! :index, EventType.new(conference_id: @conference.id)
end
def show
render :eventtypes
def edit; end
def new
@event_type = @conference.event_types.new
end
def create
@event_type = @conference.event_types.new(event_type_params)
if @event_type.save
redirect_to(admin_conference_event_types_path(conference_id: @conference.short_title),
notice: 'Event type successfully created.')
else
flash[:error] = "Creating event type failed: #{@event_type.errors.full_messages.join('. ')}."
render :new
end
end
def update
@conference.update_attributes!(params[:conference])
redirect_to(admin_conference_event_types_path(
conference_id: @conference.short_title),
notice: 'Event types were successfully updated.')
rescue => e
redirect_to(admin_conference_event_types_path(
conference_id: @conference.short_title),
alert: "Event types update failed: #{e.message}")
if @event_type.update_attributes(event_type_params)
redirect_to(admin_conference_event_types_path(
conference_id: @conference.short_title),
notice: 'Event type successfully updated.')
else
flash[:error] = "Update event type failed: #{@event_type.errors.full_messages.join('. ')}."
render :edit
end
end
def destroy
if @event_type.destroy
redirect_to(admin_conference_event_types_path(conference_id: @conference.short_title),
notice: 'Event type successfully deleted.')
else
redirect_to(admin_conference_event_types_path(conference_id: @conference.short_title),
error: 'Destroying event type failed! ' \
"#{@event_type.errors.full_messages.join('. ')}.")
end
end
private
def event_type_params
params[:event_type]
end
end
end

View file

@ -6,8 +6,6 @@ module Admin
def index
end
def show; end
def new
@lodging = @conference.lodgings.new
end
@ -27,7 +25,7 @@ module Admin
def update
if @lodging.update_attributes(lodging_params)
redirect_to(admin_conference_lodging_path(conference_id: @conference.short_title, id: @lodging.id),
redirect_to(admin_conference_lodgings_path(conference_id: @conference.short_title),
notice: 'Lodging successfully updated.')
else
flash[:error] = "Update Lodging failed: #{@lodging.errors.full_messages.join('. ')}."

View file

@ -1,53 +0,0 @@
module Admin
class PhotosController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource through: :conference
# GET /admin/photos
def index
@photos = @conference.photos.all
end
# GET /admin/photos/new
def new
@photo = @conference.photos.build
end
# GET /admin/photos/1/edit
def edit; end
# POST /admin/photos
def create
@photo = @conference.photos.build(photo_params)
if @photo.save
redirect_to admin_conference_photos_path, notice: 'Photo was successfully created.'
else
flash[:alert] = "A error prohibited this Photo from being saved: #{@photo.errors.full_messages.join('. ')}."
render :new
end
end
# PATCH/PUT /admin/photos/1
def update
if @photo.update(photo_params)
redirect_to admin_conference_photos_path, notice: 'Photo was successfully updated.'
else
flash[:alert] = "A error prohibited this Photo from being saved: #{@photo.errors.full_messages.join('. ')}."
render :edit
end
end
# DELETE /admin/photos/1
def destroy
@photo.destroy
redirect_to admin_conference_photos_path, notice: 'Photo was successfully destroyed.'
end
private
# Only allow a trusted parameter "white list" through.
def photo_params
params[:photo]
end
end
end

View file

@ -11,18 +11,6 @@ module Admin
@attended = @conference.registrations.where('attended = ?', true).count
end
def toogle_attended
@registration.attended = !@registration.attended
if @registration.save
flash[:notice] = "Successfully updated Attended for #{@user.email}"
redirect_to admin_conference_registrations_path(@conference.short_title)
else
flash[:notice] = "Update Attended for #{@user.email} failed!" \
"#{@registration.errors.full_messages.join('. ')}"
redirect_to admin_conference_registrations_path(@conference.short_title)
end
end
def edit; end
def update
@ -48,6 +36,30 @@ module Admin
end
end
def present
@registration.attended = true
if @registration.save
flash[:notice] = "#{@user.email} has attended"
redirect_to admin_conference_registrations_path(@conference.short_title)
else
flash[:notice] = "Update Attended for #{@user.email} failed!" \
"#{@registration.errors.full_messages.join('. ')}"
redirect_to admin_conference_registrations_path(@conference.short_title)
end
end
def absent
@registration.attended = false
if @registration.save
flash[:notice] = "#{@user.email} has not attended"
redirect_to admin_conference_registrations_path(@conference.short_title)
else
flash[:notice] = "Update Attended for #{@user.email} failed!" \
"#{@registration.errors.full_messages.join('. ')}"
redirect_to admin_conference_registrations_path(@conference.short_title)
end
end
protected
def set_user

View file

@ -1,18 +0,0 @@
module Admin
class SocialEventsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
authorize_resource :social_event, through: :conference
def show
render :social_events_list
end
def update
if @conference.update_attributes(params[:conference])
redirect_to(admin_conference_social_events_path(conference_id: @conference.short_title), notice: 'Social events were successfully updated.')
else
redirect_to(admin_conference_social_events_path(conference_id: @conference.short_title), notice: 'Social events update failed.')
end
end
end
end

View file

@ -1,21 +0,0 @@
module Admin
class SpeakersController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :event
respond_to :js, :html
def edit
authorize! :update, @conference.events.new
@speaker = @event.event_users.where(event_role: 'speaker').first
end
def update
authorize! :update, @conference.events.new
@speaker = @event.event_users.where(event_role: 'speaker').first
@speaker.user_id = params[:speaker][:user_id]
@speaker.save
respond_with @speaker, location: admin_conference_events_path(@conference.short_title)
end
end
end

View file

@ -1,22 +1,55 @@
module Admin
class SponsorsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
authorize_resource :sponsor, through: :conference
load_and_authorize_resource :sponsor, through: :conference
def index
authorize! :index, Sponsor.new(conference_id: @conference.id)
end
def update
if @conference.update_attributes(params[:conference])
redirect_to(admin_conference_sponsors_path(
conference_id: @conference.short_title),
notice: 'Sponsorships were successfully updated.')
def edit; end
def new
@sponsor = @conference.sponsors.new
end
def create
@sponsor = @conference.sponsors.new(sponsor_params)
if @sponsor.save
redirect_to(admin_conference_sponsors_path(conference_id: @conference.short_title),
notice: 'Sponsor successfully created.')
else
flash[:error] = "Creating sponsor failed: #{@sponsor.errors.full_messages.join('. ')}."
render :new
end
end
def update
if @sponsor.update_attributes(sponsor_params)
redirect_to(admin_conference_sponsors_path(
conference_id: @conference.short_title),
alert: 'Sponsorships update failed.')
notice: 'Sponsor successfully updated.')
else
flash[:error] = "Update sponsor failed: #{@sponsor.errors.full_messages.join('. ')}."
render :edit
end
end
def destroy
if @sponsor.destroy
redirect_to(admin_conference_sponsors_path(conference_id: @conference.short_title),
notice: 'Sponsor successfully deleted.')
else
redirect_to(admin_conference_sponsors_path(conference_id: @conference.short_title),
error: 'Deleting sponsor failed! ' \
"#{@sponsor.errors.full_messages.join('. ')}.")
end
end
private
def sponsor_params
params[:sponsor]
end
end
end

View file

@ -1,25 +1,54 @@
module Admin
class TargetsController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
authorize_resource through: :conference
load_and_authorize_resource :target, through: :conference
def index
authorize! :index, Target.new(conference_id: @conference.id)
authorize! :update, Target.new(conference_id: @conference.id)
end
def update
authorize! :update, @conference => Target
def new
@target = @conference.targets.new
end
if @conference.update_attributes(params[:conference])
redirect_to(admin_conference_targets_path(
conference_id: @conference.short_title),
notice: 'Targets were successfully updated.')
def create
@target = @conference.targets.new(target_params)
if @target.save(target_params)
redirect_to(admin_conference_targets_path(conference_id: @conference.short_title),
notice: 'Target successfully created.')
else
redirect_to(admin_conference_targets_path(
conference_id: @conference.short_title),
alert: 'Targets update failed: ' \
"#{@conference.errors.full_messages.join('. ')}")
flash[:alert] = "Creating target failed: #{@target.errors.full_messages.join('. ')}."
render :new
end
end
def edit; end
def update
if @target.update_attributes(target_params)
redirect_to(admin_conference_targets_path(conference_id: @conference.short_title),
notice: 'Target successfully updated.')
else
flash[:alert] = "Target update failed: #{@target.errors.full_messages.join('. ')}."
render :edit
end
end
def destroy
if @target.destroy
redirect_to(admin_conference_targets_path(conference_id: @conference.short_title),
notice: 'Target successfully destroyed.')
else
redirect_to(admin_conference_targets_path(conference_id: @conference.short_title),
alert: 'Target was successfully destroyed.' \
"#{@target.errors.full_messages.join('. ')}.")
end
end
private
def target_params
params[:target]
end
end
end

View file

@ -1,29 +1,59 @@
module Admin
class TracksController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
authorize_resource through: :conference
load_and_authorize_resource :track, through: :conference
def index
authorize! :index, Track.new(conference_id: @conference.id)
end
def index; end
def show
respond_to do |format|
format.html { render :tracks_list }
format.html { render }
format.json { render json: @conference.tracks.to_json }
end
end
def update
if @conference.update_attributes(params[:conference])
redirect_to(admin_conference_tracks_path(
conference_id: @conference.short_title),
notice: 'Tracks were successfully updated.')
def new
@track = @conference.tracks.new
end
def create
@track = @conference.tracks.new(track_params)
if @track.save
redirect_to(admin_conference_tracks_path(conference_id: @conference.short_title),
notice: 'Track successfully created.')
else
redirect_to(admin_conference_tracks_path(
conference_id: @conference.short_title),
notice: 'Tracks update failed.')
flash[:alert] = "Creating Track failed: #{@track.errors.full_messages.join('. ')}."
render :new
end
end
def edit; end
def update
if @track.update_attributes(track_params)
redirect_to(admin_conference_tracks_path(conference_id: @conference.short_title),
notice: 'Track successfully updated.')
else
flash[:alert] = "Track update failed: #{@track.errors.full_messages.join('. ')}."
render :edit
end
end
def destroy
if @track.destroy
redirect_to(admin_conference_tracks_path(conference_id: @conference.short_title),
notice: 'Track successfully deleted.')
else
redirect_to(admin_conference_tracks_path(conference_id: @conference.short_title),
alert: 'Track couldn\'t be deleted.' \
"#{@track.errors.full_messages.join('. ')}.")
end
end
private
def track_params
params[:track]
end
end
end