add admin :download_excel
This commit is contained in:
parent
7fca57c5fb
commit
c3cc50d293
|
@ -72,6 +72,17 @@ class Admin::ActivitiesController < OrbitMemberController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def download_excel
|
||||||
|
year_start = params[:year_start].to_i
|
||||||
|
year_end = params[:year_end].to_i
|
||||||
|
@data = get_data_for_excel(year_start,year_end)
|
||||||
|
respond_to do |format|
|
||||||
|
format.xlsx {
|
||||||
|
response.headers['Content-Disposition'] = 'attachment; filename="activities.xlsx"'
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def set_activity
|
def set_activity
|
||||||
|
|
|
@ -18,4 +18,17 @@ module Admin::PersonalActivitiesHelper
|
||||||
finaldata << data
|
finaldata << data
|
||||||
finaldata
|
finaldata
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_data_for_excel(year_start,year_end)
|
||||||
|
data = []
|
||||||
|
roles = Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key)
|
||||||
|
roles.each do |role|
|
||||||
|
d = {}
|
||||||
|
d["name"] = role.title
|
||||||
|
mps = role.member_profile_ids
|
||||||
|
d["data"] = Activity.where(:year.gte => year_start, :year.lte => year_end, :member_profile_id.in => mps) rescue []
|
||||||
|
data << d
|
||||||
|
end
|
||||||
|
return data
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,54 @@
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
wb = xlsx_package.workbook
|
||||||
|
@data.each_with_index do |role,idx|
|
||||||
|
data = role["data"]
|
||||||
|
wb.add_worksheet(name: role["name"] + "-" + idx.to_s) do |sheet|
|
||||||
|
|
||||||
|
heading = sheet.styles.add_style(:b => true, :locked => true)
|
||||||
|
|
||||||
|
row = ["Name"]
|
||||||
|
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << t("personal_activity.activity_name") + " - " + t(locale.to_s)
|
||||||
|
end
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << t("personal_activity.activity_organizer") + " - " + t(locale.to_s)
|
||||||
|
end
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << t("personal_activity.activity_area") + " - " + t(locale.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
row << t("personal_activity.year")
|
||||||
|
|
||||||
|
row << t("personal_activity.activity_start_date")
|
||||||
|
|
||||||
|
row << t("personal_activity.activity_end_date")
|
||||||
|
|
||||||
|
row << t("personal_activity.note")
|
||||||
|
|
||||||
|
sheet.add_row row, :style => heading
|
||||||
|
|
||||||
|
data.each do |activity|
|
||||||
|
row = [activity.member_profile.name]
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << activity.activity_name_translations[locale.to_s]
|
||||||
|
end
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << activity.activity_organizer_translations[locale.to_s]
|
||||||
|
end
|
||||||
|
@site_in_use_locales.each do |locale|
|
||||||
|
row << activity.activity_area_translations[locale.to_s]
|
||||||
|
end
|
||||||
|
|
||||||
|
row << activity.year
|
||||||
|
row << activity.activity_start_date
|
||||||
|
row << activity.activity_end_date
|
||||||
|
row << activity.note
|
||||||
|
sheet.add_row row
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ Rails.application.routes.draw do
|
||||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||||
namespace :admin do
|
namespace :admin do
|
||||||
get 'activities/download_excel_format' => 'activities#download_excel_format'
|
get 'activities/download_excel_format' => 'activities#download_excel_format'
|
||||||
#post 'books/import_from_excel' => 'books#import_from_excel'
|
#post 'activities/import_from_excel' => 'activities#import_from_excel'
|
||||||
|
|
||||||
resources :activities do
|
resources :activities do
|
||||||
collection do
|
collection do
|
||||||
|
@ -12,7 +12,7 @@ Rails.application.routes.draw do
|
||||||
# get 'toggle_hide' => 'books#toggle_hide'
|
# get 'toggle_hide' => 'books#toggle_hide'
|
||||||
get 'analysis'
|
get 'analysis'
|
||||||
get 'analysis_report'
|
get 'analysis_report'
|
||||||
# get "download_excel"
|
get 'download_excel'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue