Browse Source

Added organization data excel download

development
Godwin 8 years ago
parent
commit
4e6559d18b
  1. 40
      app/controllers/conferences_controller.rb
  2. 2
      app/helpers/application_helper.rb
  3. 1
      app/views/conferences/admin/_stats.html.haml
  4. 4
      app/views/conferences/stats.xlsx.haml
  5. 7
      config/locales/en.yml

40
app/controllers/conferences_controller.rb

@ -760,6 +760,46 @@ class ConferencesController < ApplicationController
@page_title = 'articles.conference_registration.headings.Administration' @page_title = 'articles.conference_registration.headings.Administration'
case @admin_step.to_sym case @admin_step.to_sym
when :organizations
@organizations = Organization.all
if request.format.xlsx?
logger.info "Generating stats.xls"
@excel_data = {
columns: [:name, :street_address, :city, :subregion, :country, :postal_code, :email, :phone, :status],
keys: {
name: 'forms.labels.generic.name',
street_address: 'forms.labels.generic.street_address',
city: 'forms.labels.generic.city',
subregion: 'forms.labels.generic.subregion',
country: 'forms.labels.generic.country',
postal_code: 'forms.labels.generic.postal_code',
email: 'forms.labels.generic.email',
phone: 'forms.labels.generic.phone',
status: 'forms.labels.generic.status'
},
data: [],
}
@organizations.each do | org |
if org.present?
address = org.locations.first
@excel_data[:data] << {
name: org.name,
street_address: address.present? ? address.street : nil,
city: address.present? ? address.city : nil,
subregion: address.present? ? I18n.t("geography.subregions.#{address.country}.#{address.territory}") : nil,
country: address.present? ? I18n.t("geography.countries.#{address.country}") : nil,
postal_code: address.present? ? address.postal_code : nil,
email: org.email_address,
phone: org.phone,
status: org.status
}
end
end
return respond_to do | format |
format.xlsx { render xlsx: :stats, filename: "organizations" }
end
end
when :stats when :stats
@registrations = ConferenceRegistration.where(:conference_id => @this_conference.id) @registrations = ConferenceRegistration.where(:conference_id => @this_conference.id)

2
app/helpers/application_helper.rb

@ -951,7 +951,7 @@ module ApplicationHelper
end end
def valid_admin_steps def valid_admin_steps
admin_steps + [:broadcast_sent] admin_steps + [:broadcast_sent, :organizations]
end end
def admin_menu def admin_menu

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

@ -15,3 +15,4 @@
= "$#{@donations || 0.00}" = "$#{@donations || 0.00}"
.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]

4
app/views/conferences/stats.xlsx.haml

@ -8,7 +8,9 @@
- @excel_data[:data].each do |row| - @excel_data[:data].each do |row|
%tr %tr
- @excel_data[:columns].each do |column| - @excel_data[:columns].each do |column|
%td{class: @excel_data[:column_types][column].present? ? @excel_data[:column_types][column].to_s : nil}=_!row[column] %td{class: (@excel_data[:column_types].present? && @excel_data[:column_types][column].present?) ? @excel_data[:column_types][column].to_s : nil}
- if row[column].present?
=_!row[column]
- format_xls 'table' do - format_xls 'table' do
- workbook use_autowidth: true - workbook use_autowidth: true

7
config/locales/en.yml

@ -5704,6 +5704,12 @@ en:
length: Length length: Length
workshop_block: Block workshop_block: Block
send_to: Send To send_to: Send To
street_address: Street Address
city: City
subregion: State / Province
country: Country
postal_code: Postal Code
status: Status
actions: actions:
generic: generic:
login: Sign In login: Sign In
@ -5805,6 +5811,7 @@ en:
Help_contribute: Help contribute Help_contribute: Help contribute
download: download:
Excel: Download Data in Excel Format Excel: Download Data in Excel Format
Organizations_Excel: Download Organization Data
page_descriptions: page_descriptions:
home: Bike!Bike! A conference for bike collectives, co-ops, non-profit DIY bike home: Bike!Bike! A conference for bike collectives, co-ops, non-profit DIY bike
shops shops

Loading…
Cancel
Save