This commit is contained in:
James Mason 2018-09-19 21:50:43 +00:00 committed by GitHub
commit bd0c95bc35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 66 additions and 65 deletions

View file

@ -8,13 +8,17 @@ module Admin
def index def index
authorize! :show, Registration.new(conference_id: @conference.id) authorize! :show, Registration.new(conference_id: @conference.id)
@pdf_filename = "#{@conference.title}.pdf" @registrations = @conference.registrations.eager_load(
@registrations = @conference.registrations.includes(:user).order('registrations.created_at ASC') :qanswers, user: :roles
@attended = @conference.registrations.where('attended = ?', true).count ).order('registrations.created_at ASC').to_a
@attended = @registrations.count(&:attended)
@questions = @conference.questions.to_a
@registration_distribution = @conference.registration_distribution @registration_distribution = @conference.registration_distribution
@affiliation_distribution = @conference.affiliation_distribution @affiliation_distribution = @conference.affiliation_distribution
@code_of_conduct = @conference.code_of_conduct.present? @code_of_conduct = @conference.code_of_conduct.present?
@pdf_filename = "#{@conference.title}.pdf"
end end
def edit; end def edit; end

View file

@ -1,9 +1,5 @@
- @conference.questions.each do |q| - cache [:admin, @conference, registration.qanswers] do
%dl
%b Q: - registration.qanswers.each do |qa|
= q.title %dt= qa.question.title
%dd= qa.answer.title
%b A:
- registration.qanswers.where(question_id: q.id).each do |qa|
= qa.answer.title
%br

View file

@ -32,18 +32,19 @@
%abbr{ title: 'Code of Conduct' } CoC %abbr{ title: 'Code of Conduct' } CoC
%th Arrival %th Arrival
%th Departure %th Departure
- if @conference.questions.any? - if @questions.any?
%th Questions %th Questions
%th Actions %th Actions
%tbody %tbody
- @registrations.each_with_index do |registration, index| - @registrations.each_with_index do |registration, index|
- cache [:admin, registration, registration.user] do
%tr %tr
%td %td
= registration.id = registration.id
%td %td
= registration.name.present? ? registration.name : registration.username = registration.name.present? ? registration.name : registration.username
%br %b
- registration.user.roles.where(resource: @conference).each do |role| - registration.user.roles.select{|r| r.resource == @conference}.each do |role|
%span.label.label-info %span.label.label-info
= role.name.titleize = role.name.titleize
%td %td
@ -65,13 +66,18 @@
= registration.departure.strftime('%d %b %H:%M') = registration.departure.strftime('%d %b %H:%M')
- else - else
n/a n/a
-if @conference.questions.any? -if @questions.any?
%td %td
= link_to 'Questions','#', class: 'btn btn-success question-btn', 'data-id' => index, 'data-name' => registration.name = link_to 'Questions','#', class: 'btn btn-success question-btn', 'data-id' => index, 'data-name' => registration.name
%td{ 'data-order' => registration.attended.to_s } %td{ 'data-order' => registration.attended.to_s }
= check_box_tag "#{@conference.short_title}_#{registration.id}", registration.id, registration.attended, = check_box_tag "#{@conference.short_title}_#{registration.id}", registration.id, registration.attended,
class: 'switch-checkbox', class: 'switch-checkbox', method: :patch,
url: toggle_attendance_admin_conference_registration_path(@conference.short_title, id: registration.id)+"?attended=" url: toggle_attendance_admin_conference_registration_path(@conference.short_title, id: registration.id)+"?attended=",
data: { size: 'small',
on_color: 'success',
off_color: 'warning',
on_text: 'Present',
off_text: 'Absent' }
.btn-group .btn-group
= link_to 'Edit', edit_admin_conference_registration_path(@conference.short_title, id: registration), = link_to 'Edit', edit_admin_conference_registration_path(@conference.short_title, id: registration),
method: :get, class: 'btn btn-primary' method: :get, class: 'btn btn-primary'

View file

@ -23,10 +23,8 @@ prawn_document(force_download: true, filename: @pdf_filename, page_layout: :land
row << registration.departure.to_s || '' row << registration.departure.to_s || ''
@conference.questions.each do |question| @conference.questions.each do |question|
qa = registration.qanswers.find_by(question: question) qa = registration.qanswers.find{|qa| qa.question_id == question.id }
answer = ( qa ? qa.answer.title : '' ) row << ( qa ? qa.answer.title : '' )
row << answer
end end
table_array << row table_array << row

View file

@ -5,7 +5,7 @@ wb.add_worksheet(name: 'registrations') do |sheet|
bold_style = wb.styles.add_style(b: true) bold_style = wb.styles.add_style(b: true)
row = ['Attended', 'Name', 'Nickname', 'Affilιation', 'Email', 'Arrival', 'Departure'] row = ['Attended', 'Name', 'Nickname', 'Affilιation', 'Email', 'Arrival', 'Departure']
@conference.questions.each do |question| @conference.questions.sort_by(&:id).each do |question|
row << question.title row << question.title
end end
@ -21,13 +21,10 @@ wb.add_worksheet(name: 'registrations') do |sheet|
row << registration.arrival.to_s row << registration.arrival.to_s
row << registration.departure.to_s row << registration.departure.to_s
@conference.questions.each do |question| @conference.questions.each do |question|
qa = registration.qanswers.find_by(question: question) current_qa = registration.qanswers.find{ |qa| qa.question_id == question.id }
answer = ( qa ? qa.answer.title : '' ) row << ( current_qa ? current_qa.answer.title : '' )
row << answer
end end
sheet.add_row row sheet.add_row row
end end
end end