diff --git a/app/controllers/admin/journal_papers_controller.rb b/app/controllers/admin/journal_papers_controller.rb index 5a45371..f528a9a 100644 --- a/app/controllers/admin/journal_papers_controller.rb +++ b/app/controllers/admin/journal_papers_controller.rb @@ -23,6 +23,20 @@ class Admin::JournalPapersController < OrbitMemberController end end + def analysis + 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 create if !journal_paper_params['member_profile_id'].blank? @@ -140,6 +154,7 @@ class Admin::JournalPapersController < OrbitMemberController def setting end + def frontend_setting @member = MemberProfile.find_by(:uid=>params['uid']) rescue nil @intro = JournalPaperIntro.find_by(:member_profile_id=>@member.id) rescue nil diff --git a/app/helpers/admin/journal_papers_helper.rb b/app/helpers/admin/journal_papers_helper.rb index bbb2135..0858313 100644 --- a/app/helpers/admin/journal_papers_helper.rb +++ b/app/helpers/admin/journal_papers_helper.rb @@ -115,6 +115,54 @@ module Admin::JournalPapersHelper jp.member_profile = mp jp.save end + + def get_chart_data(year_start,year_end,role,type) + case type + when "paper_type" + jls = JournalPaperType.all + when "level_type" + jls = JournalLevel.all + when "author_type" + jls = JournalPaperAuthorType.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.journal_papers.where(:created_at.gte => d1, :created_at.lte => d2, :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 "paper_type" + t = JournalPaper.where(:created_at.gte => d1, :created_at.lte => d2, :member_profile_id.in => mps, :journal_paper_type_id => nil).count rescue 0 + when "level_type" + t = JournalPaper.where(:created_at.gte => d1, :created_at.lte => d2, :member_profile_id.in => mps, :journal_level_ids => nil).count rescue 0 + when "author_type" + t = JournalPaper.where(:created_at.gte => d1, :created_at.lte => d2, :member_profile_id.in => mps, :journal_paper_author_type_ids => nil).count rescue 0 + end + + data["data"][year.to_s] = t + end + finaldata << data + finaldata + end + end diff --git a/app/views/admin/journal_papers/analysis.html.erb b/app/views/admin/journal_papers/analysis.html.erb new file mode 100644 index 0000000..5c30677 --- /dev/null +++ b/app/views/admin/journal_papers/analysis.html.erb @@ -0,0 +1,110 @@ +<% # 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_journal.paper_type") %> + <%= t("personal_journal.level_type") %> + <%= t("personal_journal.author_type") %> +
+
+
+
+ + +
+
+
+
+ <% Role.where(:disabled => false, :title.ne => "", :title.ne => nil).each do |role| %> +
+

<%= role.title %>

+
+ loading +
+
+ <% end %> +
+
+ + + + + diff --git a/app/views/admin/journal_papers/analysis_report.html.erb b/app/views/admin/journal_papers/analysis_report.html.erb new file mode 100644 index 0000000..b4e8aa4 --- /dev/null +++ b/app/views/admin/journal_papers/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/config/locales/en.yml b/config/locales/en.yml index 206ea14..47e1627 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -31,6 +31,7 @@ en: author_type : "Author Type" from : "From" to : "To" + graph_by : "Graph by" file : "File" file_name : "File name" description : "File Description" diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index d3ed1de..990b9d0 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -30,6 +30,7 @@ zh_tw: paper_type: "論文類型" from : "起" to : "迄" + graph_by : "Graph by" file : "檔案" file_name : "檔案名稱" description : "描述" diff --git a/config/routes.rb b/config/routes.rb index e6262e3..06bb00c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -9,6 +9,8 @@ Rails.application.routes.draw do resources :journal_papers do collection do get 'toggle_hide' => 'journal_papers#toggle_hide' + get 'analysis' => 'journal_papers#analysis' + get 'analysis_report' => 'journal_papers#analysis_report' end end diff --git a/lib/personal_journal/engine.rb b/lib/personal_journal/engine.rb index c864d94..5d81ffa 100644 --- a/lib/personal_journal/engine.rb +++ b/lib/personal_journal/engine.rb @@ -4,7 +4,7 @@ module PersonalJournal OrbitApp.registration "PersonalJournal",:type=> 'ModuleApp' do module_label 'module_name.journal_paper' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '5', :app_name=>"JournalPaper", :intro_app_name=>"JournalPaperlIntro",:path=>"/plugin/personal_journal/profile",:front_path=>"/profile",:admin_path=>"/admin/journal_papers/",:i18n=>'module_name.journal_paper', :module_app_name=>'PersonalJournal', :one_line_title => true, :field_modifiable => true + personal_plugin :enable => true, :sort_number => '5', :app_name=>"JournalPaper", :intro_app_name=>"JournalPaperlIntro",:path=>"/plugin/personal_journal/profile",:front_path=>"/profile",:admin_path=>"/admin/journal_papers/",:i18n=>'module_name.journal_paper', :module_app_name=>'PersonalJournal', :one_line_title => true, :field_modifiable => true, :analysis => true, :analysis_path => "/admin/journal_papers/analysis" version "0.1" desktop_enabled true