diff --git a/app/controllers/member_counselors_controller.rb b/app/controllers/member_counselors_controller.rb index 1fceef8..f5c5e21 100644 --- a/app/controllers/member_counselors_controller.rb +++ b/app/controllers/member_counselors_controller.rb @@ -106,10 +106,18 @@ class MemberCounselorsController < CUserController @hpsfile = HpsFile.new end + def resultupload + @hpsresult = HpsResult.new + end + def editfileupload @hpsfile = HpsFile.find(params[:id]) end + def editresultupload + @hpsresult = HpsResult.find(params[:id]) + end + def file_upload hpsfile = HpsFile.new(hps_file_params) hpsfile.hps_member = current_counselor_user @@ -119,20 +127,88 @@ class MemberCounselorsController < CUserController redirect_to member_dash_path(current_counselor_user.account) end + def result_upload + hpsresult = HpsResult.new(hps_result_params) + hpsresult.hps_member = current_counselor_user + city = HpsCity.find(current_counselor_user.hps_city_id) + hpsresult.hps_city = city + hpsresult.save + redirect_to member_dash_path(current_counselor_user.account) + end + def update_file_upload hpsfile = HpsFile.find(params[:id]) hpsfile.update_attributes(hps_file_params) redirect_to member_dash_path(current_counselor_user.account) end + def update_result_upload + hpsresult = HpsResult.find(params[:id]) + hpsresult.update_attributes(hps_result_params) + redirect_to member_dash_path(current_counselor_user.account) + end + def deletefileupload hpsfile = HpsFile.find(params[:id]) hpsfile.destroy redirect_to member_dash_path(current_counselor_user.account) end + def deleteresultupload + hpsresult = HpsResult.find(params[:id]) + hpsresult.destroy + redirect_to member_dash_path(current_counselor_user.account) + end + def show - @files = current_counselor_user.hps_files + if current_counselor_user.user_type == 0 || current_counselor_user.user_type == 1 + @files = current_counselor_user.hps_files + @results = current_counselor_user.hps_results + else + @records = current_counselor_user.hps_counseling_records + end + end + + def newrecord + @record = HpsCounselingRecord.new + end + + def new_record_upload + record = HpsCounselingRecord.new(hps_record_params) + record.hps_member = current_counselor_user + record.save + redirect_to member_dash_path(current_counselor_user.account) + end + + def get_info + @objects = [] + case params[:get_info] + when "counties" + @objects = HpsCity.find(params[:id]).hps_counties.asc(:old_id) + when "schools" + @objects = HpsCounty.find(params[:id]).hps_schools.asc(:old_id) + end + render :layout => false + end + + def editrecord + @record = HpsCounselingRecord.find(params[:id]) + end + + def update_record_upload + record = HpsCounselingRecord.find(params[:id]) + record.update_attributes(hps_record_params) + redirect_to member_dash_path(current_counselor_user.account) + end + + def showrecord + @record = HpsCounselingRecord.find(params[:id]) + end + + def deleterecord + record = HpsCounselingRecord.find(params[:id]) + record.destroy + redirect_to member_dash_path(current_counselor_user.account) end private @@ -141,4 +217,12 @@ class MemberCounselorsController < CUserController params.require(:hps_file).permit! end + def hps_result_params + params.require(:hps_result).permit! + end + + def hps_record_params + params.require(:hps_counseling_record).permit! + end + end \ No newline at end of file diff --git a/app/models/hps_counseling_record.rb b/app/models/hps_counseling_record.rb new file mode 100644 index 0000000..09b3ef2 --- /dev/null +++ b/app/models/hps_counseling_record.rb @@ -0,0 +1,46 @@ +class HpsCounselingRecord + include Mongoid::Document + include Mongoid::Timestamps + + field :hps_city_id + field :hps_county_id + field :hps_school_id + field :other_text + + field :counseling_date, type: DateTime + field :counseling_method, type: Array, default: [] + field :counseling_method_description + field :event_title + field :purpose_for_county, type: Array, default: [] + field :purpose_for_county_extra + field :purpose_for_school, type: Array, default: [] + field :purpose_for_school_extra + field :minutes_of_event + field :evaluation_of_event + + belongs_to :hps_member + + def get_title + city = HpsCity.find(self.hps_city_id) rescue nil + county = HpsCounty.find(self.hps_county_id) rescue nil + school = HpsSchool.find(self.hps_school_id) rescue nil + s = "" + s = s + city.name + "/" if !city.nil? + s = s + county.name + "/" if !county.nil? + s = s + school.name if !school.nil? + s + end + + def get_city + HpsCity.find(self.hps_city_id) rescue nil + end + + def get_county + HpsCounty.find(self.hps_county_id) rescue nil + end + + def get_school + HpsSchool.find(self.hps_school_id) rescue nil + end + +end \ No newline at end of file diff --git a/app/models/hps_member.rb b/app/models/hps_member.rb index a5e14fe..d004cc3 100644 --- a/app/models/hps_member.rb +++ b/app/models/hps_member.rb @@ -37,6 +37,8 @@ class HpsMember # validates :password, :on => [:create] has_many :hps_files, :dependent => :destroy + has_many :hps_results, :dependent => :destroy + has_many :hps_counseling_records, :dependent => :destroy def get_user_type case self.user_type diff --git a/app/models/hps_result.rb b/app/models/hps_result.rb new file mode 100644 index 0000000..803b74b --- /dev/null +++ b/app/models/hps_result.rb @@ -0,0 +1,14 @@ +class HpsResult + include Mongoid::Document + include Mongoid::Timestamps + + mount_uploader :file, AssetUploader + + field :title + field :download_count, type: Integer, :default => 0 + field :year, type: Integer + field :old_id + + belongs_to :hps_member + belongs_to :hps_city +end \ No newline at end of file diff --git a/app/views/member_counselors/_body.html.erb b/app/views/member_counselors/_body.html.erb index eb1bef2..9191eb5 100644 --- a/app/views/member_counselors/_body.html.erb +++ b/app/views/member_counselors/_body.html.erb @@ -1,6 +1,7 @@ <%= csrf_meta_tag %> + @@ -28,5 +29,36 @@ <% end %>
執行計畫書 Upload File
Date
+
-Upload File \ No newline at end of file +
+ + + + + + + + + + + <% if !@results.blank? %> + <% @results.each_with_index do |file,idx| %> + + + + + + <% end %> + <% else %> + + + + <% end %> + +
成果報告 Upload Result
DateTitleAction
<%= file.created_at.strftime("%y/%m/%d") %><%= file.title %> + Download + Edit + Delete +
No files uploaded.
+
\ No newline at end of file diff --git a/app/views/member_counselors/_counselor_body.html.erb b/app/views/member_counselors/_counselor_body.html.erb new file mode 100644 index 0000000..f36e792 --- /dev/null +++ b/app/views/member_counselors/_counselor_body.html.erb @@ -0,0 +1,32 @@ +<%= csrf_meta_tag %> + + + + + + + + + + + + <% if !@records.blank? %> + <% @records.each_with_index do |record,idx| %> + + + + + + <% end %> + <% else %> + + + + <% end %> + +
輔導記錄單 New Record
新增日期輔導縣市/地區/學校功能
<%= record.created_at.strftime("%y/%m/%d") %><%= record.get_title %> + Edit + View + Delete +
No records found.
+
diff --git a/app/views/member_counselors/_form.html.erb b/app/views/member_counselors/_form.html.erb index 1afe1cc..61c405a 100644 --- a/app/views/member_counselors/_form.html.erb +++ b/app/views/member_counselors/_form.html.erb @@ -32,18 +32,14 @@ <% case current_counselor_user.user_type %> <% when 0 %> <% title = HpsCity.find(current_counselor_user.hps_city_id).name + " " + HpsCounty.find(current_counselor_user.hps_county_id).name + " " + HpsSchool.find(current_counselor_user.hps_school_id).name %> -
<%= title %> 105推動計劃書
- + <% when 1 %> -
105健康促進縣市推動計劃書
- + <% when 2 %> <% end %> <% else %> - <% year = @hpsfile.title.scan(/\d/).join() %> -
<%= @hpsfile.title.gsub(year, "#{year}").html_safe %>
- + <% end %> @@ -58,8 +54,8 @@ \ No newline at end of file diff --git a/app/views/member_counselors/_new_record_form.html.erb b/app/views/member_counselors/_new_record_form.html.erb new file mode 100644 index 0000000..76f7e59 --- /dev/null +++ b/app/views/member_counselors/_new_record_form.html.erb @@ -0,0 +1,133 @@ + + <%= javascript_include_tag "lib/bootstrap-datetimepicker" %> + <%= javascript_include_tag "lib/datetimepicker/datetimepicker.js" %> + +

輔導記錄單

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
新增日期 
*縣市 + <%= f.select :hps_city_id, options_for_select(HpsCity.all.asc(:old_id).collect{|city| [city.name, city.id]}, @record.hps_city_id), {:prompt => "Select City"}, {:class => "selectable"} %> + <% + opts = [] + if !@record.new_record? + opts = HpsCity.find(@record.hps_city_id).hps_counties.asc(:old_id).collect{|sc| [sc.name, sc.id]} + end + %> + <%= f.select :hps_county_id, options_for_select(opts,@record.hps_county_id), {}, {:class => "selectable"} %> +
*對象 + <% + opts = [] + if !@record.new_record? + opts = HpsCounty.find(@record.hps_county_id).hps_schools.asc(:old_id).collect{|sc| [sc.name, sc.id]} + end + %> + 學校<%= f.select :hps_school_id, options_for_select(opts, @record.hps_school_id), {} %> 其他單位<%= f.text_field :other_text %> +
輔導日期 + <%= f.datetime_picker :counseling_date, :no_label => true, :new_record => @record.new_record? %> +
方式 + name="hps_counseling_record[counseling_method][]" value="整體規劃輔導">整體規劃輔導 + name="hps_counseling_record[counseling_method][]" value="個別議題輔導">個別議題輔導 + <%= f.text_field :counseling_method_description %> +
會議/活動名稱 + <%= f.text_field :event_title %> +
+ 縣市輔導項目(可複選) + + <% ["(1)參與縣市共識會議", "(2)協助縣市整體方向或策略規劃", "(3)縣市健康促進學校計畫書/報告審查與諮詢", "(4)協助縣市與社區資源連結", "(5)參與縣市增能研習或講座", "(6)參與縣市成果發表會", "(7)縣市成果報告審查與諮詢", "(8)其他(請填寫):"].each_with_index do |v, idx| %> + name="hps_counseling_record[purpose_for_county][]" value="<%= v %>"><%= v %> + <% if idx < 7 %> +
+ <% end %> + <% end %> + <%= f.text_area :purpose_for_county_extra %>
+
學校輔導項目(可複選) + <% ["(1)協助問題診斷/需求評估","(2)依據問題/診斷結果擬定策略與指標,討論資料蒐集方法", "(3)協助學校發展健康教學策略", "(4)協助學校發展互動式或參與式家長活動", "(5)協助學校發展社區結盟活動","(6)學校成果分析或報告撰寫諮詢", "(7)其他(請填寫):"].each_with_index do |v, idx| %> + name="hps_counseling_record[purpose_for_school][]" value="<%= v %>"><%= v %> + <% if idx < 6 %> +
+ <% end %> + <% end %> + <%= f.text_area :purpose_for_school_extra %>
+
內容記要(如:所輔導內容、所解決困難、所達成共識、待解決問題…):<%= f.text_area :minutes_of_event, :rows => 5, :cols => 100 %>
委員建議(如:對該縣市健康促進計畫推動、輔導學校之建議…):<%= f.text_area :evaluation_of_event, :rows => 5, :cols => 100 %>
+ <%= f.submit "Submit", :class => "btn btn-primary" %> + Back +
+ \ No newline at end of file diff --git a/app/views/member_counselors/_result_form.html.erb b/app/views/member_counselors/_result_form.html.erb new file mode 100644 index 0000000..5ea9fdb --- /dev/null +++ b/app/views/member_counselors/_result_form.html.erb @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + +
學年度 + <% + yearnow = Time.now.strftime("%Y").to_i - 1 + total = yearnow - 1911 + min = total - 10 + %> + <%= f.select :year, (0..10).collect{|i|[(total - i),(total - i)]} %> + <% if current_counselor_user.user_type == 0 %> + 此為學年度非年度,例如103年上半年為102學年度,103年下半年為103學年度,請注意填選 + <% end %> +
檔案來源 + <%= f.file_field :file %> + + <% if !@hpsresult.file.url.nil? %> +
+ <%= File.basename(@hpsresult.file.url) %> + <% end %> +
+
成果報告名稱 + <% if @hpsresult.new_record? %> + <% case current_counselor_user.user_type %> + <% when 0 %> + <% title = HpsCity.find(current_counselor_user.hps_city_id).name + " " + HpsCounty.find(current_counselor_user.hps_county_id).name + " " + HpsSchool.find(current_counselor_user.hps_school_id).name %> + + <% when 1 %> + + <% when 2 %> + + <% end %> + <% else %> + + <% end %> +
  + <%= f.submit "Submit", :class => "btn btn-primary" %> + Back +
+ + \ No newline at end of file diff --git a/app/views/member_counselors/editrecord.html.erb b/app/views/member_counselors/editrecord.html.erb new file mode 100644 index 0000000..d3c5301 --- /dev/null +++ b/app/views/member_counselors/editrecord.html.erb @@ -0,0 +1,3 @@ +<%= form_for @record, :url => "/cuser/member/#{@record.id}/update_record_upload" do |f| %> + <%= render :partial => "new_record_form", :locals => {:f => f} %> +<% end %> \ No newline at end of file diff --git a/app/views/member_counselors/editresultupload.html.erb b/app/views/member_counselors/editresultupload.html.erb new file mode 100644 index 0000000..68c848f --- /dev/null +++ b/app/views/member_counselors/editresultupload.html.erb @@ -0,0 +1,3 @@ +<%= form_for @hpsresult, :url => "/cuser/member/#{@hpsresult.id.to_s}/update_result_upload" do |f| %> + <%= render :partial => "result_form", :locals => {:f => f} %> +<% end %> \ No newline at end of file diff --git a/app/views/member_counselors/get_info.html.erb b/app/views/member_counselors/get_info.html.erb new file mode 100644 index 0000000..5e27b2e --- /dev/null +++ b/app/views/member_counselors/get_info.html.erb @@ -0,0 +1,10 @@ +<% case params[:get_info] %> +<% when "counties" %> + +<% when "schools" %> + +<% end %> +<%#= options_for_select(@objects.collect{|obj|[obj.name, obj.id]}) %> +<% @objects.each do |obj| %> + +<% end %> \ No newline at end of file diff --git a/app/views/member_counselors/newrecord.html.erb b/app/views/member_counselors/newrecord.html.erb new file mode 100644 index 0000000..3aaf0bb --- /dev/null +++ b/app/views/member_counselors/newrecord.html.erb @@ -0,0 +1,3 @@ +<%= form_for @record, :url => "/cuser/member/new_record_upload" do |f| %> + <%= render :partial => "new_record_form", :locals => {:f => f} %> +<% end %> \ No newline at end of file diff --git a/app/views/member_counselors/resultupload.html.erb b/app/views/member_counselors/resultupload.html.erb new file mode 100644 index 0000000..4fa911b --- /dev/null +++ b/app/views/member_counselors/resultupload.html.erb @@ -0,0 +1,3 @@ +<%= form_for @hpsresult, :url => "/cuser/member/result_upload" do |f| %> + <%= render :partial => "result_form", :locals => {:f => f} %> +<% end %> diff --git a/app/views/member_counselors/show.html.erb b/app/views/member_counselors/show.html.erb index 6806175..906f9f0 100644 --- a/app/views/member_counselors/show.html.erb +++ b/app/views/member_counselors/show.html.erb @@ -3,4 +3,5 @@ <% when 0,1 %> <%= render :partial => "body" %> <% when 2 %> + <%= render :partial => "counselor_body" %> <% end %> \ No newline at end of file diff --git a/app/views/member_counselors/showrecord.html.erb b/app/views/member_counselors/showrecord.html.erb new file mode 100644 index 0000000..243e7d7 --- /dev/null +++ b/app/views/member_counselors/showrecord.html.erb @@ -0,0 +1,88 @@ +

輔導記錄單

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
新增日期<%= @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.created_at.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/routes.rb b/config/routes.rb index 28e9275..178a1a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,11 +16,32 @@ Rails.application.routes.draw do scope "cuser" do get "download", to: "member_counselors#download" get "/member_login", to: "member_counselors#login", as: "member_login" + get "/member/fileupload", to: "member_counselors#fileupload", as: "upload_cuser_file" + get "/member/resultupload", to: "member_counselors#resultupload", as: "upload_cuser_result" + get "/member/:id/editfileupload", to: "member_counselors#editfileupload", as: "edit_upload_cuser_file" + get "/member/:id/editresultupload", to: "member_counselors#editresultupload", as: "edit_upload_cuser_result" + delete "/member/:id/deletefileupload", to: "member_counselors#deletefileupload", as: "delete_upload_cuser_file" + delete "/member/:id/deleteresultupload", to: "member_counselors#deleteresultupload", as: "delete_upload_cuser_result" + post "/member/file_upload", to: "member_counselors#file_upload" + post "/member/result_upload", to: "member_counselors#result_upload" + patch "/member/:id/update_file_upload", to: "member_counselors#update_file_upload" + patch "/member/:id/update_result_upload", to: "member_counselors#update_result_upload" + + patch "/member/:id/update_record_upload", to: "member_counselors#update_record_upload" + + get "/member/newrecord", to: "member_counselors#newrecord", as: "new_counselor_record" + get "/member/get_info", to: "member_counselors#get_info" + get "/member/:id/editrecord", to: "member_counselors#editrecord", as: "edit_counselor_record" + get "/member/:id/showrecord", to: "member_counselors#showrecord", as: "show_counselor_record" + delete "/member/:id/deleterecord", to: "member_counselors#deleterecord", as: "delete_counselor_record" + + post "/member/new_record_upload", to: "member_counselors#new_record_upload" + get "/member/:account", to: "member_counselors#show", as: "member_dash" post "/member_counselor/login", to: "member_counselors#loginuser" get "/member_counselor/logout", to: "member_counselors#logoutuser", as: "member_logout"