diff --git a/app/controllers/admin/books_controller.rb b/app/controllers/admin/books_controller.rb index 848b15c..39c7310 100644 --- a/app/controllers/admin/books_controller.rb +++ b/app/controllers/admin/books_controller.rb @@ -17,6 +17,29 @@ class Admin::BooksController < OrbitMemberController format.xml { render :xml => @books } end end + + def analysis_report + role = params[:role_id] + year_start = params[:year_start].to_i + year_end = params[:year_end].to_i + 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="conference_papers.xlsx"' + } + end + end + def show respond_to do |format| diff --git a/app/helpers/admin/personal_books_helper.rb b/app/helpers/admin/personal_books_helper.rb index 5f7477a..c51cc41 100644 --- a/app/helpers/admin/personal_books_helper.rb +++ b/app/helpers/admin/personal_books_helper.rb @@ -112,4 +112,62 @@ module Admin::PersonalBooksHelper book.member_profile = mp book.save 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 + # d1 = DateTime.new(year_start,1,1,0,0) + # d2 = DateTime.new(year_end,12,31,23,59) + d["data"] = Book.where(:year.gte => year_start, :year.lte => year_end, :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 "book_type" + jls = BookType.all + when "author_type" + jls = BookAuthorType.all + end + + finaldata = [] + role = Role.find(role) rescue nil + mps = [] + if !role.nil? + mps = role.member_profile_ids + end + jls.each do |jl| + data = {} + data["name"] = jl.title + data["data"] = {} + (year_start..year_end).each do |year| + # d1 = DateTime.new(year,1,1,0,0) + # d2 = DateTime.new(year,12,31,23,59) + t = jl.books.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps).count rescue 0 + data["data"][year.to_s] = t + end + finaldata << data + end + data = {"name" => "N/A", "data" => {}} + (year_start..year_end).each do |year| + d1 = DateTime.new(year,1,1,0,0) + d2 = DateTime.new(year,12,31,23,59) + case type + when "book_type" + t = Book.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps, :book_type_id => nil).count rescue 0 + when "author_type" + t = Book.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps, :book_author_type_ids => nil).count rescue 0 + end + + data["data"][year.to_s] = t + end + finaldata << data + finaldata + end end \ No newline at end of file diff --git a/app/views/admin/books/analysis.html.erb b/app/views/admin/books/analysis.html.erb new file mode 100644 index 0000000..47c6194 --- /dev/null +++ b/app/views/admin/books/analysis.html.erb @@ -0,0 +1,115 @@ +<% # encoding: utf-8 %> +<% content_for :page_specific_css do %> + <%= stylesheet_link_tag "lib/main-forms" %> + <%= stylesheet_link_tag "lib/fileupload" %> + <%= stylesheet_link_tag "lib/main-list" %> + <%= stylesheet_link_tag "lib/main-form-col2" %> + +<% end %> +<% content_for :page_specific_javascript do %> + <%= javascript_include_tag "//www.google.com/jsapi", "chartkick"%> + <%= javascript_include_tag "justgage.1.0.1.min" %> + <%= javascript_include_tag "raphael.2.1.0.min" %> + <%= javascript_include_tag "validator" %> +<% end %> +
+
+
+
+
+ +
+ <%= select_year(DateTime.now.year - 5, {:start_year => DateTime.now.year, :end_year => 1950}, {:name => 'start_year', :class => "span1"} ) %> + - + <%= select_year(DateTime.now.year, {:start_year => DateTime.now.year, :end_year => 1950}, {:name => 'end_year', :class => "span1"} ) %> +
+
+
+ +
+ <%= t("personal_book.book_type") %> + <%= t("personal_book.author_type") %> +
+
+
+
+ + Export +
+
+
+
+ <% Role.where(:disabled => false, :title.ne => "", :title.ne => nil).asc(:key).each do |role| %> +
+

<%= role.title %>

+
+ loading +
+
+ <% end %> +
+
+ + + + + diff --git a/app/views/admin/books/analysis_report.html.erb b/app/views/admin/books/analysis_report.html.erb new file mode 100644 index 0000000..b4e8aa4 --- /dev/null +++ b/app/views/admin/books/analysis_report.html.erb @@ -0,0 +1 @@ +<%= column_chart @data, :id => params[:role_id], :height => "350px", :xtitle => "Year", :ytitle => "Total number" %> \ No newline at end of file diff --git a/app/views/admin/books/download_excel.xlsx.axlsx b/app/views/admin/books/download_excel.xlsx.axlsx new file mode 100644 index 0000000..02119a6 --- /dev/null +++ b/app/views/admin/books/download_excel.xlsx.axlsx @@ -0,0 +1,88 @@ +# 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_book.book_title") + " - " + t(locale.to_s) + end + @site_in_use_locales.each do |locale| + row << t("personal_book.extracted_chapters") + " - " + t(locale.to_s) + end + @site_in_use_locales.each do |locale| + row << t("personal_book.publisher") + " - " + t(locale.to_s) + end + @site_in_use_locales.each do |locale| + row << t("personal_book.editor") + " - " + t(locale.to_s) + end + + @site_in_use_locales.each do |locale| + row << t("personal_book.authors") + " - " + t(locale.to_s) + end + + row << t("personal_book.year") + + row << t("personal_book.language") + + row << t("personal_book.book_paper_type") + + row << t("personal_book.pages") + + row << t("personal_book.author_type") + + row << t("personal_book.number_of_authors") + + row << t("personal_book.publish_date") + + row << t("personal_book.isbn") + + row << t("personal_book.url") + + row << t("personal_book.keywords") + + row << t("personal_book.note") + + sheet.add_row row, :style => heading + + data.each do |book| + row = [book.member_profile.name] + @site_in_use_locales.each do |locale| + row << book.book_title_translations[locale.to_s] + end + @site_in_use_locales.each do |locale| + row << book.extracted_chapters_translations[locale.to_s] + end + @site_in_use_locales.each do |locale| + row << book.publisher_translations[locale.to_s] + end + @site_in_use_locales.each do |locale| + row << book.editor_translations[locale.to_s] + end + @site_in_use_locales.each do |locale| + row << book.authors_translations[locale.to_s] + end + + row << book.year + row << book.language + row << book.book_types.map{|bpt| bpt.title}.join(", ") rescue "" + row << book.pages + row << book.book_author_types.map{|bpt| bpt.title}.join(", ") rescue "" + row << book.number_of_authors + row << book.publish_date.strftime("%Y-%m-%d") rescue "" + row << book.isbn + row << book.url + row << book.keywords + row << book.note + sheet.add_row row + end + end +end + + + diff --git a/config/locales/en.yml b/config/locales/en.yml index b42c7b2..f3674e0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -37,6 +37,7 @@ en: description : "File Description" pages : "Pages" book_paper_type : "Book Type" + graph_by : "Graph By" frontend: writing_books: "Book Front-end" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 2a7be01..d61cc4d 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -37,6 +37,7 @@ zh_tw: book_paper_type : "專書類別" publish_date : "出版日期" editor : "主編" + graph_by : "Graph By" frontend: writing_books: "專書前台" diff --git a/config/routes.rb b/config/routes.rb index a1c4668..fdd0070 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,9 @@ Rails.application.routes.draw do resources :books do collection do get 'toggle_hide' => 'books#toggle_hide' + get 'analysis' + get 'analysis_report' + get "download_excel" end end diff --git a/lib/personal_book/engine.rb b/lib/personal_book/engine.rb index 1148de1..3df5986 100644 --- a/lib/personal_book/engine.rb +++ b/lib/personal_book/engine.rb @@ -4,7 +4,7 @@ module PersonalBook OrbitApp.registration "PersonalBook",:type=> 'ModuleApp' do module_label 'module_name.book' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '25', :app_name=>"Book", :intro_app_name=>"BookIntro",:path=>"/plugin/personal_book/profile",:front_path=>"/profile",:admin_path=>"/admin/books",:i18n=>'module_name.book',:module_app_name=>'PersonalBook', :one_line_title => true, :field_modifiable => true + personal_plugin :enable => true, :sort_number => '25', :app_name=>"Book", :intro_app_name=>"BookIntro",:path=>"/plugin/personal_book/profile",:front_path=>"/profile",:admin_path=>"/admin/books",:i18n=>'module_name.book',:module_app_name=>'PersonalBook', :one_line_title => true, :field_modifiable => true, :analysis => true, :analysis_path => "/admin/books/analysis" version "0.1" desktop_enabled true