Browse Source

Added all registration data in a table on the stats page

development
Godwin 8 years ago
parent
commit
99898c0823
  1. 4
      app/assets/javascripts/main.js
  2. 23
      app/assets/javascripts/registrations.js
  3. 14
      app/assets/stylesheets/_application.scss
  4. 165
      app/controllers/conferences_controller.rb
  5. 9
      app/helpers/application_helper.rb
  6. 8
      app/views/conferences/admin/_stats.html.haml
  7. 2
      config/initializers/assets.rb

4
app/assets/javascripts/main.js

@ -152,9 +152,9 @@
} }
window.initNodeFunctions = [ function(node) { window.initNodeFunctions = [ function(node) {
forEachElement('.number-field,.email-field,.text-field,.password-field', function(field) { forEachElement('.number-field,.email-field,.text-field,.password-field,.search-field', function(field) {
var input = field.querySelector('input'); var input = field.querySelector('input');
var positionLabel = function(input) { var positionLabel = function(input) {
field.classList[input.value ? 'remove' : 'add']('empty'); field.classList[input.value ? 'remove' : 'add']('empty');
} }
positionLabel(input); positionLabel(input);

23
app/assets/javascripts/registrations.js

@ -0,0 +1,23 @@
(function() {
var searchControl = document.getElementById('search');
function filterTable() {
forEach(document.getElementById('search-rows').getElementsByTagName('tr'), function(tr) {
tr.classList.remove('hidden');
var value = searchControl.value;
if (value) {
var words = value.split(/\s+/);
for (var i = 0; i < words.length; i++) {
var word = new RegExp(words[i].replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), "i");
if (tr.innerHTML.search(word) == -1) {
tr.classList.add('hidden');
}
}
}
});
}
searchControl.addEventListener('keyup', filterTable);
searchControl.addEventListener('search', filterTable);
})();

14
app/assets/stylesheets/_application.scss

@ -166,6 +166,10 @@ table, .table {
} }
} }
} }
&.bold {
@include font-family(secondary);
}
} }
tbody th { tbody th {
@ -175,6 +179,14 @@ table, .table {
&.admin-edit { &.admin-edit {
width: 100%; width: 100%;
} }
tr.hidden {
display: none;
}
}
.table-scroller {
overflow: auto;
} }
.table { .table {
@ -376,6 +388,7 @@ input {
.number-field, .number-field,
.email-field, .email-field,
.search-field,
.telephone-field, .telephone-field,
.password-field, .password-field,
.text-field { .text-field {
@ -449,6 +462,7 @@ input {
.email-field, .email-field,
.password-field, .password-field,
.telephone-field, .telephone-field,
.search-field,
.text-field, .text-field,
.text-area-field { .text-area-field {
text-align: left; text-align: left;

165
app/controllers/conferences_controller.rb

@ -134,7 +134,7 @@ class ConferencesController < ApplicationController
else else
@registration.is_attending = 'y' @registration.is_attending = 'y'
end end
@registration.housing_data = { @registration.housing_data = {
address: params[:address], address: params[:address],
phone: params[:phone], phone: params[:phone],
@ -336,95 +336,96 @@ class ConferencesController < ApplicationController
end end
end end
when :stats when :stats
if request.format.xlsx? @registrations = ConferenceRegistration.where(:conference_id => @this_conference.id).sort { |a,b| (a.user.present? ? (a.user.firstname || '') : '').downcase <=> (b.user.present? ? (b.user.firstname || '') : '').downcase }
@registrations = ConferenceRegistration.where(:conference_id => @this_conference.id).sort { |a,b| (a.user.present? ? (a.user.firstname || '') : '').downcase <=> (b.user.present? ? (b.user.firstname || '') : '').downcase } @excel_data = {
logger.info "Generating stats.xls" columns: [
@excel_data = { :name,
columns: [ :email,
:name, :status,
:email, :registration_fees_paid,
:status, :date,
:registration_fees_paid, :city,
:date, :preferred_language,
:city, :languages,
:preferred_language, :arrival,
:languages, :departure,
:arrival, :housing,
:departure, :bike,
:housing, :food,
:bike, :companion,
:food, :allergies
:companion, ],
:allergies column_types: {
], name: :bold,
column_types: { date: :datetime,
name: :bold, arrival: [:date, :day],
date: :datetime, departure: [:date, :day],
arrival: [:date, :day], registration_fees_paid: :money
departure: [:date, :day], },
registration_fees_paid: :money keys: {
}, name: 'forms.labels.generic.name',
keys: { email: 'forms.labels.generic.email',
name: 'forms.labels.generic.name', status: 'forms.labels.generic.registration_status',
email: 'forms.labels.generic.email', city: 'forms.labels.generic.location',
status: 'forms.labels.generic.registration_status', date: 'articles.conference_registration.terms.Date',
city: 'forms.labels.generic.location', languages: 'articles.conference_registration.terms.Languages',
date: 'articles.conference_registration.terms.Date', preferred_language: 'articles.conference_registration.terms.Preferred_Languages',
languages: 'articles.conference_registration.terms.Languages', arrival: 'forms.labels.generic.arrival',
preferred_language: 'articles.conference_registration.terms.Preferred_Languages', departure: 'forms.labels.generic.departure',
arrival: 'forms.labels.generic.arrival', housing: 'forms.labels.generic.housing',
departure: 'forms.labels.generic.departure', bike: 'forms.labels.generic.bike',
housing: 'forms.labels.generic.housing', food: 'forms.labels.generic.food',
bike: 'forms.labels.generic.bike', companion: 'articles.conference_registration.terms.companion',
food: 'forms.labels.generic.food', allergies: 'forms.labels.generic.allergies',
companion: 'articles.conference_registration.terms.companion', registration_fees_paid: 'articles.conference_registration.headings.fees_paid'
allergies: 'forms.labels.generic.allergies', },
registration_fees_paid: 'articles.conference_registration.headings.fees_paid' data: []
}, }
data: [] @registrations.each do | r |
} user = r.user_id ? User.where(id: r.user_id).first : nil
@registrations.each do | r | if user.present?
user = r.user_id ? User.where(id: r.user_id).first : nil companion = ''
if user.present? if r.housing_data.present? && r.housing_data['companions'].present?
companion = '' companion_user = User.find_by_email(r.housing_data['companions'].first)
if r.housing_data.present? && r.housing_data['companions'].present? companion = view_context._'articles.conference_registration.terms.registration_status.unregistered'
companion_user = User.find_by_email(r.housing_data['companions'].first)
companion = view_context._'articles.conference_registration.terms.registration_status.unregistered' if companion_user.present?
cr = ConferenceRegistration.where(user_id: companion_user.id).order(created_at: :desc).limit(1).first
if companion_user.present?
cr = ConferenceRegistration.where(user_id: companion_user.id).order(created_at: :desc).limit(1).first if cr.present? && ((cr.steps_completed || []).include? 'questions')
companion = companion_user.named_email
if cr.present? && ((cr.steps_completed || []).include? 'questions')
companion = companion_user.named_email
end
end end
end end
steps = r.steps_completed || []
@excel_data[:data] << {
name: user.firstname || '',
email: user.email || '',
status: (view_context._"articles.conference_registration.terms.registration_status.#{(steps.include? 'questions') ? 'registered' : ((steps.include? 'contact_info') ? 'preregistered' : 'unregistered')}"),
date: r.created_at ? r.created_at.strftime("%F %T") : '',
city: r.city || '',
preferred_language: user.locale.present? ? (view_context.language_name user.locale) : '',
languages: ((r.languages || []).map { |x| view_context.language_name x }).join(', ').to_s,
arrival: r.arrival ? r.arrival.strftime("%F %T") : '',
departure: r.departure ? r.departure.strftime("%F %T") : '',
housing: r.housing || '',
bike: r.bike.present? ? (view_context._"articles.conference_registration.questions.bike.#{r.bike}") : '',
food: r.food.present? ? (view_context._"articles.conference_registration.questions.food.#{r.food}") : '',
companion: companion,
allergies: r.allergies,
registration_fees_paid: r.registration_fees_paid
}
end end
steps = r.steps_completed || []
@excel_data[:data] << {
name: user.firstname || '',
email: user.email || '',
status: (view_context._"articles.conference_registration.terms.registration_status.#{(steps.include? 'questions') ? 'registered' : ((steps.include? 'contact_info') ? 'preregistered' : 'unregistered')}"),
date: r.created_at ? r.created_at.strftime("%F %T") : '',
city: r.city || '',
preferred_language: user.locale.present? ? (view_context.language_name user.locale) : '',
languages: ((r.languages || []).map { |x| view_context.language_name x }).join(', ').to_s,
arrival: r.arrival ? r.arrival.strftime("%F %T") : '',
departure: r.departure ? r.departure.strftime("%F %T") : '',
housing: r.housing || '',
bike: r.bike.present? ? (view_context._"articles.conference_registration.questions.bike.#{r.bike}") : '',
food: r.food.present? ? (view_context._"articles.conference_registration.questions.food.#{r.food}") : '',
companion: companion,
allergies: r.allergies,
registration_fees_paid: r.registration_fees_paid
}
end end
end
if request.format.xlsx?
logger.info "Generating stats.xls"
return respond_to do | format | return respond_to do | format |
format.xlsx { render xlsx: :stats, filename: "stats-#{DateTime.now.strftime('%Y-%m-%d')}" } format.xlsx { render xlsx: :stats, filename: "stats-#{DateTime.now.strftime('%Y-%m-%d')}" }
end end
else else
@registrations = ConferenceRegistration.where(:conference_id => @this_conference.id) # @registrations = ConferenceRegistration.where(:conference_id => @this_conference.id)
@registration_count = @registrations.size @registration_count = @registrations.size
@completed_registrations = 0 @completed_registrations = 0
@bikes = 0 @bikes = 0

9
app/helpers/application_helper.rb

@ -1288,6 +1288,10 @@ module ApplicationHelper
textfield(name, value, options.merge({type: :number})) textfield(name, value, options.merge({type: :number}))
end end
def searchfield(name, value, options = {})
textfield(name, value, options.merge({type: :search}))
end
def emailfield(name, value, options = {}) def emailfield(name, value, options = {})
textfield(name, value, options.merge({type: :email})) textfield(name, value, options.merge({type: :email}))
end end
@ -1345,7 +1349,7 @@ module ApplicationHelper
when :phone when :phone
input_options[:autocomplete] = 'tel' input_options[:autocomplete] = 'tel'
when :paypal_email_address, :paypal_username, :paypal_password, :paypal_signature when :paypal_email_address, :paypal_username, :paypal_password, :paypal_signature
input_options[:autocomplete] = 'false' input_options[:autocomplete] = 'off'
end end
case options[:type] case options[:type]
@ -1358,6 +1362,7 @@ module ApplicationHelper
end end
html += select_tag(name, option_list, input_options) html += select_tag(name, option_list, input_options)
else else
input_options[:autocomplete] = 'off' if options[:type] == :search
html += send("#{(options[:type] || :text).to_s}_field_tag", name, value, input_options) html += send("#{(options[:type] || :text).to_s}_field_tag", name, value, input_options)
end end
@ -1544,8 +1549,6 @@ module ApplicationHelper
format 'td.bold', font_name: 'Calibri', fg_color: '333333', b: true format 'td.bold', font_name: 'Calibri', fg_color: '333333', b: true
end end
key = excel_data[:key] || 'excel.columns'
content_tag(:table) do content_tag(:table) do
(content_tag(:thead) do (content_tag(:thead) do
content_tag(:tr, excel_header_columns(excel_data)) content_tag(:tr, excel_header_columns(excel_data))

8
app/views/conferences/admin/_stats.html.haml

@ -1,3 +1,4 @@
- add_inline_script :registrations
.details .details
= data_set(:h4, 'articles.admin.stats.headings.completed_registrations') do = data_set(:h4, 'articles.admin.stats.headings.completed_registrations') do
= (@completed_registrations || 0).to_s = (@completed_registrations || 0).to_s
@ -18,3 +19,10 @@
.actions .actions
= link_to (_'links.download.Excel'), administration_step_path(@this_conference.slug, :stats, :format => :xlsx), class: [:button, :download] = link_to (_'links.download.Excel'), administration_step_path(@this_conference.slug, :stats, :format => :xlsx), class: [:button, :download]
= link_to (_'links.download.Organizations_Excel'), administration_step_path(@this_conference.slug, :organizations, :format => :xlsx), class: [:button, :download, :subdued] = link_to (_'links.download.Organizations_Excel'), administration_step_path(@this_conference.slug, :organizations, :format => :xlsx), class: [:button, :download, :subdued]
%h4 Registrations
= searchfield :search, nil, big: true
.table-scroller
%table.registrations.admin-edit
%thead
%tr=excel_header_columns(@excel_data)
%tbody#search-rows=excel_rows(@excel_data)

2
config/initializers/assets.rb

@ -8,4 +8,4 @@ Rails.application.config.assets.version = '1.0'
# Precompile additional assets. # Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
Rails.application.config.assets.precompile += %w( user-mailer.css map.js pen.js time.js editor.js markdown.js html2canvas.js main.js housing.js schedule.js favicon.ico ) Rails.application.config.assets.precompile += %w( user-mailer.css map.js pen.js time.js editor.js markdown.js html2canvas.js main.js registrations.js housing.js schedule.js favicon.ico )

Loading…
Cancel
Save