added excel export
This commit is contained in:
parent
ebfaf2df79
commit
0e6994b3ac
|
@ -33,10 +33,21 @@ class Admin::JournalPapersController < OrbitMemberController
|
|||
graph_by = params[:graph_by]
|
||||
|
||||
@data = get_chart_data(year_start,year_end,role,params[:graph_by])
|
||||
|
||||
|
||||
render :layout => false
|
||||
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="journal_papers.xlsx"'
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
if !journal_paper_params['member_profile_id'].blank?
|
||||
|
|
|
@ -116,6 +116,21 @@ module Admin::JournalPapersHelper
|
|||
jp.save
|
||||
end
|
||||
|
||||
def get_data_for_excel(year_start,year_end)
|
||||
data = []
|
||||
roles = Role.where(:disabled => false, :title.ne => "", :title.ne => nil)
|
||||
roles.each do |role|
|
||||
d = {}
|
||||
d["name"] = role.title
|
||||
mps = role.member_profile_ids
|
||||
d1 = DateTime.new(year_start,1,1,0,0)
|
||||
d2 = DateTime.new(year_end,12,31,23,59)
|
||||
d["data"] = JournalPaper.where(:publication_date.gte => d1, :publication_date.lte => d2, :member_profile_id.in => mps) rescue []
|
||||
data << d
|
||||
end
|
||||
return data
|
||||
end
|
||||
|
||||
def get_chart_data(year_start,year_end,role,type)
|
||||
case type
|
||||
when "paper_type"
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
</div>
|
||||
<div class="form-actions">
|
||||
<button id="generate_graph" class="btn btn-info">Graphs</button>
|
||||
<button class="btn btn-primary">Export</button>
|
||||
<button id="generate_excel" class="btn btn-primary">Export</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
@ -76,6 +76,11 @@
|
|||
roleArea = $("#analysis-area .analysis-show-area"),
|
||||
totalRoles = roleArea.find(".role").length;
|
||||
form.form.on("submit",function(){return false;})
|
||||
|
||||
$("#generate_excel").on("click",function(){
|
||||
window.location.href = "/admin/journal_papers/download_excel.xlsx?" + "year_start=" + form.form.find("select[name=start_year]").val() + "&year_end=" + form.form.find("select[name=end_year]").val();
|
||||
})
|
||||
|
||||
$("#generate_graph").on("click",function(){
|
||||
if(form.isFormValidated()){
|
||||
generateCharts(0);
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
# 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_journal.paper_title") + " - " + t(locale.to_s)
|
||||
end
|
||||
|
||||
@site_in_use_locales.each do |locale|
|
||||
row << t("personal_journal.journal_title") + " - " + t(locale.to_s)
|
||||
end
|
||||
|
||||
@site_in_use_locales.each do |locale|
|
||||
row << t("personal_journal.authors") + " - " + t(locale)
|
||||
end
|
||||
|
||||
row << t("personal_journal.year")
|
||||
|
||||
row << t("personal_journal.language")
|
||||
|
||||
row << t("personal_journal.vol_no")
|
||||
|
||||
row << t("personal_journal.issue_no")
|
||||
|
||||
row << t("personal_journal.total_pages")
|
||||
|
||||
row << t("personal_journal.level_type")
|
||||
|
||||
row << t("personal_journal.paper_type")
|
||||
|
||||
row << t("personal_journal.author_type")
|
||||
|
||||
row << t("personal_journal.number_of_authors")
|
||||
|
||||
row << t("personal_journal.isbn")
|
||||
|
||||
row << t("personal_journal.publication_date")
|
||||
|
||||
row << t("personal_journal.url")
|
||||
|
||||
row << t("personal_journal.keywords")
|
||||
|
||||
row << t("personal_journal.abstract")
|
||||
|
||||
row << t("personal_journal.note")
|
||||
|
||||
row << t("personal_journal.associated_project")
|
||||
|
||||
sheet.add_row row, :style => heading
|
||||
|
||||
data.each do |jp|
|
||||
row = [jp.member_profile.name]
|
||||
@site_in_use_locales.each do |locale|
|
||||
row << jp.paper_title_translations[locale.to_s]
|
||||
end
|
||||
@site_in_use_locales.each do |locale|
|
||||
row << jp.journal_title_translations[locale.to_s]
|
||||
end
|
||||
@site_in_use_locales.each do |locale|
|
||||
row << jp.authors_translations[locale.to_s]
|
||||
end
|
||||
row << jp.year
|
||||
row << jp.language
|
||||
row << jp.vol_no
|
||||
row << jp.issue_no
|
||||
row << jp.total_pages
|
||||
row << (jp.journal_levels.map{|jl| jl.title}.join(", ") rescue "")
|
||||
row << (jp.journal_paper_type.title rescue "")
|
||||
row << (jp.journal_paper_author_types.map{|jl| jl.title}.join(", ") rescue "")
|
||||
row << jp.number_of_authors
|
||||
row << jp.isbn
|
||||
row << jp.publication_date.strftime("%Y-%m-%d") rescue ""
|
||||
row << jp.url
|
||||
row << jp.keywords
|
||||
row << jp.abstract
|
||||
row << jp.note
|
||||
row << jp.associated_project
|
||||
sheet.add_row row
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -11,6 +11,7 @@ Rails.application.routes.draw do
|
|||
get 'toggle_hide' => 'journal_papers#toggle_hide'
|
||||
get 'analysis' => 'journal_papers#analysis'
|
||||
get 'analysis_report' => 'journal_papers#analysis_report'
|
||||
get "download_excel"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue