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 %>
Date | @@ -28,5 +29,36 @@ <% end %>
---|
Date | +Title | +Action | +
---|---|---|
<%= file.created_at.strftime("%y/%m/%d") %> | +<%= file.title %> | ++ Download + Edit + Delete + | +
No files uploaded. | +
新增日期 | +輔導縣市/地區/學校 | +功能 | +
---|---|---|
<%= record.created_at.strftime("%y/%m/%d") %> | +<%= record.get_title %> | ++ Edit + View + Delete + | +
No records found. | +
新增日期 | ++ |
*縣市 | ++ <%= 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 + | +
學年度 | ++ <% + 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 + | +
新增日期 | +<%= @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 + | +