From 7490316a5b6f829180cd9593137df9a21813fdbe Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Thu, 15 May 2014 20:30:01 +0300 Subject: [PATCH 1/3] resources :registrations --- app/controllers/admin/registrations_controller.rb | 11 +++++------ app/views/admin/registrations/edit.html.haml | 2 +- .../registrations/{show.html.haml => index.html.haml} | 10 +++++----- app/views/admin/registrations/new.html.haml | 2 +- config/routes.rb | 10 +++------- 5 files changed, 15 insertions(+), 20 deletions(-) rename app/views/admin/registrations/{show.html.haml => index.html.haml} (79%) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 91b2992f..22e4e10a 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -1,7 +1,7 @@ class Admin::RegistrationsController < ApplicationController before_filter :verify_organizer - def show + def index session[:return_to] ||= request.referer @pdf_filename = "#{@conference.title}.pdf" @registrations = @conference.registrations.includes(:person).order("registrations.created_at ASC") @@ -18,8 +18,8 @@ class Admin::RegistrationsController < ApplicationController @registration.update_attribute(:"#{field}",1) end - redirect_to admin_conference_registrations_path(@conference.short_title, @registration) - flash[:notice] = "Updated '#{params[:view_field]}' for #{(Person.where("id = ?", @registration.person_id).first).email}" + redirect_to admin_conference_registrations_path(@conference.short_title) + flash[:notice] = "Updated '#{params[:view_field]}' => #{@registration.attended} for #{(Person.where("id = ?", @registration.person_id).first).email}" end def edit @@ -28,8 +28,7 @@ class Admin::RegistrationsController < ApplicationController end def update - reg_id = params[:format] - @registration = @conference.registrations.where("id = ?", reg_id).first + @registration = @conference.registrations.where("id = ?", params[:id]).first @person = Person.where("id = ?", @registration.person_id).first begin @person.update_attributes!(params[:registration][:person_attributes]) @@ -111,7 +110,7 @@ class Admin::RegistrationsController < ApplicationController end end - def delete + def destroy if has_role?(current_user, "Admin") registration = @conference.registrations.where(:id => params[:id]).first person = Person.where("id = ?", registration.person_id).first diff --git a/app/views/admin/registrations/edit.html.haml b/app/views/admin/registrations/edit.html.haml index 1f1920db..8d1b6518 100644 --- a/app/views/admin/registrations/edit.html.haml +++ b/app/views/admin/registrations/edit.html.haml @@ -5,7 +5,7 @@ %br .row .col-md-12 - = semantic_form_for(@registration, :url => admin_conference_registrations_edit_path(@conference.short_title, @registration.id), :html => { :method => :put }) do |f| + = semantic_form_for(@registration, :url => admin_conference_registration_path(@conference.short_title, @registration)) do |f| = f.inputs "Personal Information" do = f.fields_for :person do |p| = p.input :first_name, :as => :string diff --git a/app/views/admin/registrations/show.html.haml b/app/views/admin/registrations/index.html.haml similarity index 79% rename from app/views/admin/registrations/show.html.haml rename to app/views/admin/registrations/index.html.haml index 05f0fee9..815c83ee 100644 --- a/app/views/admin/registrations/show.html.haml +++ b/app/views/admin/registrations/index.html.haml @@ -7,7 +7,7 @@ = "(#{@registrations.length})" = " - Attended (#{@attended})" .btn-group.pull-right - = link_to "New", admin_conference_registrations_new_path(@conference.short_title), :class => "btn btn-default" + = link_to "New", new_admin_conference_registration_path(@conference.short_title), :class => "btn btn-default" = link_to "Export PDF", admin_conference_registrations_path(@conference.short_title, :format => :pdf), :class => "btn btn-default" = link_to "Export XLS", {:format => :xlsx}, :class => "btn btn-default" %table.table.table-bordered.table-striped.table-hover#registrations @@ -35,10 +35,10 @@ = registration.supporter_level.title -elsif field == 'attended' - = link_to "#{registration.send(field.to_sym)}", admin_conference_registrations_change_field_path(@conference.short_title, :id => registration.id, :view_field => "#{field}"), :method => :put, ":#{field}" => registration.send(field.to_sym), :class => "btn btn-success" + = link_to "#{registration.send(field.to_sym)}", admin_conference_registrations_change_field_path(@conference.short_title, :id => registration.id, :view_field => "#{field}"), :method => :patch, ":#{field}" => registration.send(field.to_sym), :class => "btn btn-success" -elsif (registration.send(field.to_sym).class == TrueClass || registration.send(field.to_sym).class == FalseClass) - = link_to "#{registration.send(field.to_sym)}", admin_conference_registrations_change_field_path(@conference.short_title, :id => registration.id, :view_field => "#{field}"), :method => :put, ":#{field}" => registration.send(field.to_sym) + = link_to "#{registration.send(field.to_sym)}", admin_conference_registrations_change_field_path(@conference.short_title, :id => registration.id, :view_field => "#{field}"), :method => :patch, ":#{field}" => registration.send(field.to_sym) - elsif field == 'arrival' || field == 'departure' = registration.send(field.to_sym).strftime("%d %b %H:%M") if registration.send(field.to_sym) @@ -49,10 +49,10 @@ = link_to "Questions", "javascript: void(0)", :class => "questions btn btn-success", :id => counter, :onclick => "toggle('row#{counter}')" %td - = link_to "Edit", admin_conference_registrations_edit_path(@conference.short_title, :id => registration.id), :method => :get, :class => "btn btn-primary" + = link_to "Edit", edit_admin_conference_registration_path(@conference.short_title, :id => registration), :method => :get, :class => "btn btn-primary" %td - = link_to "Delete", admin_conference_registrations_path(@conference.short_title, :id => registration.id), :method => :delete, :class => "btn btn-danger", :confirm => "Really delete registration for #{registration.public_name} #{registration.email}?" + = link_to "Delete", admin_conference_registration_path(@conference.short_title, registration), :method => :delete, :class => "btn btn-danger", data: {confirm: "Really delete registration for #{registration.public_name} #{registration.email}?"} %tr{:id => "row#{counter}", :style=>"display:none;"} %td{:colspan=>13} = render :partial => "questions", :locals => {:registration => registration} diff --git a/app/views/admin/registrations/new.html.haml b/app/views/admin/registrations/new.html.haml index 78f2b3f4..8d0676d0 100644 --- a/app/views/admin/registrations/new.html.haml +++ b/app/views/admin/registrations/new.html.haml @@ -4,7 +4,7 @@ Create new account and registration .row .col-md-12 - = semantic_form_for(@registration, :url => admin_conference_registrations_new_path(@conference.short_title), :html => { :method => :put }) do |f| + = semantic_form_for(@registration, :url => admin_conference_registrations_path(@conference.short_title)) do |f| = f.inputs "Your details" do = f.fields_for @person do |p| diff --git a/config/routes.rb b/config/routes.rb index 78e9d930..1c10b0b1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,13 +9,6 @@ Osem::Application.routes.draw do get "/schedule" => "schedule#show" patch "/schedule" => "schedule#update" get "/stats" => "stats#index" - get "/registrations" => "registrations#show" - get "/registrations/new" => "registrations#new" - patch "/registrations/new" => "registrations#create" - get "/registrations/edit" => "registrations#edit" - patch "/registrations/edit" => "registrations#update" - delete "/registrations" => "registrations#delete" - patch "/registrations/change_field" => "registrations#change_field" get "/venue" => "venue#show", :as => "venue_info" patch "/venue" => "venue#update", :as => "venue_update" get "/dietary_choices" => "dietchoices#show", :as => "dietary_list" @@ -23,6 +16,9 @@ Osem::Application.routes.draw do get "/volunteers_list" => "volunteers#show" get "/volunteers" => "volunteers#index", :as => "volunteers_info" patch "/volunteers" => "volunteers#update", :as => "volunteers_update" + + patch "/registrations/change_field" => "registrations#change_field" + resources :registrations resources :difficulty_levels, only: [:show, :update, :index] From 544146e7a99736949da7f947b94d074c494886a0 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Thu, 15 May 2014 20:55:27 +0300 Subject: [PATCH 2/3] houndci fixes --- app/controllers/admin/registrations_controller.rb | 12 ++++++++---- config/routes.rb | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index 22e4e10a..ce5f644f 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -19,7 +19,8 @@ class Admin::RegistrationsController < ApplicationController end redirect_to admin_conference_registrations_path(@conference.short_title) - flash[:notice] = "Updated '#{params[:view_field]}' => #{@registration.attended} for #{(Person.where("id = ?", @registration.person_id).first).email}" + flash[:notice] = "Updated '#{params[:view_field]}' => #{@registration.attended} for + #{(Person.where("id = ?", @registration.person_id).first).email}" end def edit @@ -42,7 +43,8 @@ class Admin::RegistrationsController < ApplicationController redirect_to(admin_conference_registrations_path(@conference.short_title)) rescue Exception => e Rails.logger.debug e.backtrace.join("\n") - redirect_to(admin_conference_registrations_path(@conference.short_title), :alert => 'Failed to update registration:' + e.message) + redirect_to(admin_conference_registrations_path(@conference.short_title), + :alert => 'Failed to update registration:' + e.message) return end end @@ -120,11 +122,13 @@ class Admin::RegistrationsController < ApplicationController flash[:notice] = "Deleted registration for #{person.public_name} #{person.email}" rescue Exception => e Rails.logger.debug e.backtrace.join("\n") - redirect_to(admin_conference_registrations_path(@conference.short_title), :alert => 'Failed to delete registration:' + e.message) + redirect_to(admin_conference_registrations_path(@conference.short_title), + :alert => 'Failed to delete registration:' + e.message) return end else - redirect_to(admin_conference_registrations_path(@conference.short_title), :alert => 'You must be an admin to delete a registration.') + redirect_to(admin_conference_registrations_path(@conference.short_title), + :alert => 'You must be an admin to delete a registration.') end end end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 1c10b0b1..1864cb64 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,8 +16,8 @@ Osem::Application.routes.draw do get "/volunteers_list" => "volunteers#show" get "/volunteers" => "volunteers#index", :as => "volunteers_info" patch "/volunteers" => "volunteers#update", :as => "volunteers_update" - - patch "/registrations/change_field" => "registrations#change_field" + + patch '/registrations/change_field' => 'registrations#change_field' resources :registrations resources :difficulty_levels, only: [:show, :update, :index] From e921e4da2209aced82ddb64a015a526c22489911 Mon Sep 17 00:00:00 2001 From: Stella Rouzi Date: Thu, 15 May 2014 21:04:08 +0300 Subject: [PATCH 3/3] new Ruby 1.9 hash syntax --- app/controllers/admin/registrations_controller.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/registrations_controller.rb b/app/controllers/admin/registrations_controller.rb index ce5f644f..3577ef91 100644 --- a/app/controllers/admin/registrations_controller.rb +++ b/app/controllers/admin/registrations_controller.rb @@ -19,7 +19,7 @@ class Admin::RegistrationsController < ApplicationController end redirect_to admin_conference_registrations_path(@conference.short_title) - flash[:notice] = "Updated '#{params[:view_field]}' => #{@registration.attended} for + flash[:notice] = "Updated '#{params[:view_field]}' => #{@registration.attended} for #{(Person.where("id = ?", @registration.person_id).first).email}" end @@ -43,8 +43,8 @@ class Admin::RegistrationsController < ApplicationController redirect_to(admin_conference_registrations_path(@conference.short_title)) rescue Exception => e Rails.logger.debug e.backtrace.join("\n") - redirect_to(admin_conference_registrations_path(@conference.short_title), - :alert => 'Failed to update registration:' + e.message) + redirect_to(admin_conference_registrations_path(@conference.short_title), + alert: 'Failed to update registration:' + e.message) return end end @@ -122,13 +122,13 @@ class Admin::RegistrationsController < ApplicationController flash[:notice] = "Deleted registration for #{person.public_name} #{person.email}" rescue Exception => e Rails.logger.debug e.backtrace.join("\n") - redirect_to(admin_conference_registrations_path(@conference.short_title), - :alert => 'Failed to delete registration:' + e.message) + redirect_to(admin_conference_registrations_path(@conference.short_title), + alert: 'Failed to delete registration:' + e.message) return end else - redirect_to(admin_conference_registrations_path(@conference.short_title), - :alert => 'You must be an admin to delete a registration.') + redirect_to(admin_conference_registrations_path(@conference.short_title), + alert: 'You must be an admin to delete a registration.') end end end \ No newline at end of file