From 6cc56bee26d7362f90510ef2e43578a5a02334c2 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 29 Jun 2017 16:06:30 +0800 Subject: [PATCH] added export and filter for users --- .../admin/member_counselors_controller.rb | 45 +++++++++- .../export_records.xlsx.axlsx | 51 +++++++++++ .../admin/member_counselors/index.html.erb | 52 ++++++++++- .../admin/member_counselors/records.html.erb | 37 ++++++++ .../admin/member_counselors/results.html.erb | 39 +++++++++ .../member_counselors/showrecord.html.erb | 87 +++++++++++++++++++ config/locales/en.yml | 5 ++ config/locales/zh_tw.yml | 5 ++ config/routes.rb | 6 ++ lib/member_counselor/engine.rb | 14 ++- 10 files changed, 338 insertions(+), 3 deletions(-) create mode 100644 app/views/admin/member_counselors/export_records.xlsx.axlsx create mode 100644 app/views/admin/member_counselors/records.html.erb create mode 100644 app/views/admin/member_counselors/results.html.erb create mode 100644 app/views/admin/member_counselors/showrecord.html.erb diff --git a/app/controllers/admin/member_counselors_controller.rb b/app/controllers/admin/member_counselors_controller.rb index 4b99f39..9940333 100644 --- a/app/controllers/admin/member_counselors_controller.rb +++ b/app/controllers/admin/member_counselors_controller.rb @@ -5,8 +5,26 @@ class Admin::MemberCounselorsController < OrbitAdminController @table_fields = ["member_counselor.file_date","member_counselor.file_title", "member_counselor.downloaded_times", "member_counselor.account", "member_counselor.user_type", "actions"] end + def results + @files = HpsResult.all.desc(:created_at).page(params[:page]).per(10) + @table_fields = ["member_counselor.file_date","member_counselor.file_title", "member_counselor.downloaded_times", "member_counselor.account", "member_counselor.user_type", "actions"] + end + + def records + @records = HpsCounselingRecord.all.desc(:created_at).page(params[:page]).per(10) + @table_fields = ["member_counselor.file_date","member_counselor.title", "member_counselor.event_title", "member_counselor.account", "actions"] + end + def index - @counselors = HpsMember.all.desc(:created_at).page(params[:page]).per(10) + if !params[:user_type].present? + @counselors = HpsMember.all.desc(:created_at) + else + types = params[:user_type].collect{|ut| ut.to_i if ut.is_i?} + types.delete(nil) + @counselors = HpsMember.where(:user_type.in => params[:user_type]) + end + @counselors = search_data(@counselors,[:name, :account]).page(params[:page]).per(10) + @table_fields = ["member_counselor.account","member_counselor.name", "member_counselor.user_type"] end @@ -59,6 +77,31 @@ class Admin::MemberCounselorsController < OrbitAdminController redirect_to uploads_admin_member_counselors_path end + def destroy_result + hpresult = HpsResult.find(params[:id]) + hpresult.destroy + redirect_to results_admin_member_counselors_path + end + + def destroy_record + record = HpsCounselingRecord.find(params[:id]) + record.destroy + redirect_to records_admin_member_counselors_path + end + + def showrecord + @record = HpsCounselingRecord.find(params[:id]) + end + + def export_records + @records = HpsCounselingRecord.all.desc(:created_at) + respond_to do |format| + format.xlsx { + response.headers['Content-Disposition'] = 'attachment; filename="counselor_records.xlsx"' + } + end + end + private def counselor_params diff --git a/app/views/admin/member_counselors/export_records.xlsx.axlsx b/app/views/admin/member_counselors/export_records.xlsx.axlsx new file mode 100644 index 0000000..20fa9fa --- /dev/null +++ b/app/views/admin/member_counselors/export_records.xlsx.axlsx @@ -0,0 +1,51 @@ +# encoding: utf-8 + +wb = xlsx_package.workbook + +wb.add_worksheet(name: "Counselor Records") do |sheet| + + heading = sheet.styles.add_style(:b => true, :locked => true) + row = [] + row << "新增日期" + row << "縣市" + row << "對象" + row << "輔導日期" + row << "方式" + row << "會議/活動名稱" + row << "縣市輔導項目(可複選)" + row << "學校輔導項目(可複選)" + row << "內容記要(如:所輔導內容、所解決困難、所達成共識、待解決問題…):" + row << "委員建議(如:對該縣市健康促進計畫推動、輔導學校之建議…):" + + sheet.add_row row, :style => heading + + @records.each do |record| + row = [] + row << record.created_at.strftime("%Y-%m-%d %H:%M:%S") + row << (record.get_city.name rescue "") + "/" + (record.get_county.name rescue "") + row << record.get_school.name + row << record.counseling_date.strftime("%Y-%m-%d %H:%M:%S") + s = "" + record.counseling_method.each do |methd| + s = s + methd + end + s = s + (record.counseling_method_description rescue "") if record.counseling_method.include?("個別議題輔導") + row << s + row << record.event_title + s = "" + record.purpose_for_county.each do |methd| + s = s + methd + end + s = s + (record.purpose_for_county_extra rescue "") if record.purpose_for_county.include?("(8)其他(請填寫):") + row << s + s = "" + record.purpose_for_school.each do |methd| + s = s + methd + end + s = s + (record.purpose_for_school_extra rescue "") if record.purpose_for_school.include?("(7)其他(請填寫):") + row << record.minutes_of_event + row << record.evaluation_of_event + + sheet.add_row row + end +end \ No newline at end of file diff --git a/app/views/admin/member_counselors/index.html.erb b/app/views/admin/member_counselors/index.html.erb index 2aaf69f..fbffdc0 100644 --- a/app/views/admin/member_counselors/index.html.erb +++ b/app/views/admin/member_counselors/index.html.erb @@ -1,3 +1,37 @@ +<% content_for :right_nav do %> +
+
+ + <% if params[:keywords].present? %> + <%= t(:clear) %> + <% end %> +
+
+
+ +
+
" id="collapse-type"> +
+
+ + + +
+
+ <% if params[:user_type].present? %> + + <% end %> +
+
+<% end %> @@ -38,4 +72,20 @@ content_tag :div, class: "bottomnav clearfix" do content_tag :div, paginate(@counselors), class: "pagination pagination-centered" end -%> \ No newline at end of file +%> + \ No newline at end of file diff --git a/app/views/admin/member_counselors/records.html.erb b/app/views/admin/member_counselors/records.html.erb new file mode 100644 index 0000000..7c5cf23 --- /dev/null +++ b/app/views/admin/member_counselors/records.html.erb @@ -0,0 +1,37 @@ +
+ + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @records.each do |record| %> + + + + + + + + <% end %> + +
+ <%= record.created_at.strftime("%Y/%m/%d") %> + + <%= record.get_title %> + + <%= record.event_title %> + + <%= record.hps_member.account %> + + Delete +
+ +<%= + content_tag :div, class: "bottomnav clearfix" do + content_tag :div, paginate(@records), class: "pagination pagination-centered" + link_to t("member_counselor.export"), export_records_admin_member_counselors_path(:format => "xlsx"), :class => "pull-right btn btn-info", :target => "_blank" + end +%> \ No newline at end of file diff --git a/app/views/admin/member_counselors/results.html.erb b/app/views/admin/member_counselors/results.html.erb new file mode 100644 index 0000000..1cd4210 --- /dev/null +++ b/app/views/admin/member_counselors/results.html.erb @@ -0,0 +1,39 @@ + + + + <% @table_fields.each do |f| %> + <%= thead(f) %> + <% end %> + + + + <% @files.each do |file| %> + + + + + + + + + <% end %> + +
+ <%= file.created_at.strftime("%Y/%m/%d") %> + + <%= file.title %> + + <%= file.download_count %> + + <%= file.hps_member.account %> + + <%= file.hps_member.get_user_type %> + + Delete +
+ +<%= + content_tag :div, class: "bottomnav clearfix" do + content_tag :div, paginate(@files), class: "pagination pagination-centered" + end +%> \ No newline at end of file diff --git a/app/views/admin/member_counselors/showrecord.html.erb b/app/views/admin/member_counselors/showrecord.html.erb new file mode 100644 index 0000000..fadf073 --- /dev/null +++ b/app/views/admin/member_counselors/showrecord.html.erb @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
新增日期<%= @record.created_at.strftime("%Y-%m-%d %H:%M:%S") %>
縣市 + <%= @record.get_city.name rescue "" %>/<%= @record.get_county.name rescue "" %> +
對象 + <%= @record.get_school.name rescue "" %> +
輔導日期 + <%= @record.counseling_date.strftime("%Y-%m-%d %H:%M:%S") %> +
方式 + <% @record.counseling_method.each do |methd| %> + <%= methd %> + <% if methd != "個別議題輔導" %> +
+ <% end %> + <% end %> + <% if @record.counseling_method.include?("個別議題輔導") %> + <%= @record.counseling_method_description %> + <% end %> +
會議/活動名稱 + <%= @record.event_title %> +
+ 縣市輔導項目(可複選) + + <% @record.purpose_for_county.each do |methd| %> + <%= methd %> + <% if methd != "(8)其他(請填寫):" %> +
+ <% end %> + <% end %> + <% if @record.purpose_for_county.include?("(8)其他(請填寫):") %> + <%= @record.purpose_for_county_extra %> + <% end %> +
學校輔導項目(可複選) + <% @record.purpose_for_school.each do |methd| %> + <%= methd %> + <% if methd != "(7)其他(請填寫):" %> +
+ <% end %> + <% end %> + <% if @record.purpose_for_school.include?("(7)其他(請填寫):") %> + <%= @record.purpose_for_school_extra %> + <% end %> +
內容記要(如:所輔導內容、所解決困難、所達成共識、待解決問題…):<%= @record.minutes_of_event %>
委員建議(如:對該縣市健康促進計畫推動、輔導學校之建議…):<%= @record.evaluation_of_event %>
+ Back +
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 12ffe2e..dfefab7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3,6 +3,9 @@ en: member_counselor: HPS Members new_user: Create User all_members: All Members + uploads: Uploads + results: Results + records: Counselor Records account: User Account password: Password confirm_password: Confirm Password @@ -10,7 +13,9 @@ en: name: Name organization: Organization title: Title + event_title: Event Title county: County + export: Export address: Address email: Email telephone: Telphone diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index de8b3d3..23330cb 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -3,6 +3,9 @@ zh_tw: member_counselor: HPS Members new_user: Create User all_members: All Members + uploads: Uploads + results: Results + records: Counselor Records account: 帳號 password: 密碼 confirm_password: 確認密碼 @@ -10,6 +13,8 @@ zh_tw: name: 姓名 organization: 服務機關 title: 職稱 + event_title: 會議/活動名稱 + export: Export county: 縣市 address: 地址 email: 電子信箱 diff --git a/config/routes.rb b/config/routes.rb index 178a1a8..ed35f69 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -6,10 +6,16 @@ Rails.application.routes.draw do resources :member_counselors do collection do get "uploads" + get "results" + get "records" + get "export_records" get "get_info" end member do delete "destroy_upload" + delete "destroy_result" + delete "destroy_record" + get "showrecord" end end end diff --git a/lib/member_counselor/engine.rb b/lib/member_counselor/engine.rb index 13d628a..e2402aa 100644 --- a/lib/member_counselor/engine.rb +++ b/lib/member_counselor/engine.rb @@ -19,12 +19,24 @@ module MemberCounselor active_for_controllers (['admin/member_counselors']) head_link_path "uploads_admin_member_counselors_path" - context_link 'all', + context_link 'member_counselor.uploads', :link_path=>"uploads_admin_member_counselors_path" , :priority=>1, :active_for_action=>{'admin/member_counselors'=>"uploads"}, :available_for => 'admin' + context_link 'member_counselor.results', + :link_path=>"results_admin_member_counselors_path" , + :priority=>1, + :active_for_action=>{'admin/member_counselors'=>"results"}, + :available_for => 'admin' + + context_link 'member_counselor.records', + :link_path=>"records_admin_member_counselors_path" , + :priority=>1, + :active_for_action=>{'admin/member_counselors'=>"records"}, + :available_for => 'admin' + context_link 'member_counselor.all_members', :link_path=>"admin_member_counselors_path" , :priority=>1,