diff --git a/app/controllers/admin/courses_controller.rb b/app/controllers/admin/courses_controller.rb index 12bc3c7..adf255c 100644 --- a/app/controllers/admin/courses_controller.rb +++ b/app/controllers/admin/courses_controller.rb @@ -25,6 +25,28 @@ class Admin::CoursesController < OrbitMemberController def show 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="courses.xlsx"' + } + end + end + def edit end diff --git a/app/helpers/admin/courses_helper.rb b/app/helpers/admin/courses_helper.rb index c78309b..644cd05 100644 --- a/app/helpers/admin/courses_helper.rb +++ b/app/helpers/admin/courses_helper.rb @@ -6,4 +6,63 @@ module Admin::CoursesHelper page = pages.first if page.nil? request.protocol+(request.host_with_port+page.url+'/'+course_object.to_param).gsub('//','/') rescue "/" 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"] = Course.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 "semester" + jls = CourseSemester.all + when "category" + jls = CourseCategory.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.courses.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 "semester" + t = Course.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps, :course_semester_id => nil).count rescue 0 + when "category" + t = Course.where(:year.gte => year, :year.lte => year, :member_profile_id.in => mps, :course_category_id => 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/courses/analysis.html.erb b/app/views/admin/courses/analysis.html.erb new file mode 100644 index 0000000..3e6a09d --- /dev/null +++ b/app/views/admin/courses/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_course.course_semester") %> + <%= t("personal_course.course_category") %> +
+
+
+
+ + 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/courses/analysis_report.html.erb b/app/views/admin/courses/analysis_report.html.erb new file mode 100644 index 0000000..b4e8aa4 --- /dev/null +++ b/app/views/admin/courses/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/courses/download_excel.xlsx.axlsx b/app/views/admin/courses/download_excel.xlsx.axlsx new file mode 100644 index 0000000..8a724d6 --- /dev/null +++ b/app/views/admin/courses/download_excel.xlsx.axlsx @@ -0,0 +1,39 @@ +# 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_course.title") + " - " + t(locale.to_s) + end + @site_in_use_locales.each do |locale| + row << t("personal_course.objective") + " - " + t(locale.to_s) + end + + + row << t("personal_course.year") + row << t("personal_course.course_semester") + row << t("personal_course.course_category") + + sheet.add_row row, :style => heading + + data.each do |course| + row = [course.member_profile.name] + @site_in_use_locales.each do |locale| + row << course.title_translations[locale.to_s] + end + @site_in_use_locales.each do |locale| + row << course.objective_translations[locale.to_s] + end + row << course.year + row << course.course_semester.title rescue "" + row << course.course_category.title rescue "" + sheet.add_row row + end + end +end \ No newline at end of file diff --git a/app/views/admin/courses/index.html.erb b/app/views/admin/courses/index.html.erb index 18b56ea..253462b 100644 --- a/app/views/admin/courses/index.html.erb +++ b/app/views/admin/courses/index.html.erb @@ -37,6 +37,6 @@ <% if params[:error] == "1" %> <% end %> \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 32b5b3d..53395d0 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -15,4 +15,5 @@ en: course_multimedia_file: Multimedia Files course_material_file: Material Files course_supplement_file: Supplement File - course_evaluation_file: Evaluation File \ No newline at end of file + course_evaluation_file: Evaluation File + graph_by : "Graph By" \ No newline at end of file diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 4c84111..aa3a1df 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -15,4 +15,5 @@ zh_tw: course_multimedia_file: 教學媒體應用 course_material_file: 自編教材 course_supplement_file: 補充教材 - course_evaluation_file: 評量紀錄 \ No newline at end of file + course_evaluation_file: 評量紀錄 + graph_by : "Graph By" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2961650..f6f06c9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,6 +6,9 @@ Rails.application.routes.draw do resources :courses do collection do get 'toggle_hide' => 'courses#toggle_hide' + get 'analysis' + get 'analysis_report' + get "download_excel" end end diff --git a/lib/personal_course/engine.rb b/lib/personal_course/engine.rb index 0b7525a..46f12ae 100644 --- a/lib/personal_course/engine.rb +++ b/lib/personal_course/engine.rb @@ -4,7 +4,7 @@ module PersonalCourse OrbitApp.registration "PersonalCourse",:type=> 'ModuleApp' do module_label 'module_name.courses' base_url File.expand_path File.dirname(__FILE__) - personal_plugin :enable => true, :sort_number => '35', :app_name=>"Course", :intro_app_name=>"CourseIntro",:path=>"/plugin/personal_course/profile",:front_path=>"/profile",:admin_path=>"/admin/courses/",:i18n=>'module_name.courses', :module_app_name=>'Course' + personal_plugin :enable => true, :sort_number => '35', :app_name=>"Course", :intro_app_name=>"CourseIntro",:path=>"/plugin/personal_course/profile",:front_path=>"/profile",:admin_path=>"/admin/courses/",:i18n=>'module_name.courses', :module_app_name=>'Course', :analysis => true, :analysis_path => "/admin/courses/analysis" version "0.1" desktop_enabled true