diff --git a/app/controllers/member_counselors_controller.rb b/app/controllers/member_counselors_controller.rb index ada6ba3..1a888a1 100644 --- a/app/controllers/member_counselors_controller.rb +++ b/app/controllers/member_counselors_controller.rb @@ -3,6 +3,67 @@ class MemberCounselorsController < CUserController before_filter :is_user_authorized?, :only => ["show"] def index + idx = 0 + cities = HpsCity.all.collect do |city| + total = 0 + idx = idx + 1 + schools = city.hps_schools.collect do |school| + count = HpsMember.where(:hps_school_id => school.id.to_s).count + total = count + total + { + "name" => school.name, + "url_to_show" => OrbitHelper.url_to_show(school.to_param) + "?method=proposals", + "count" => count + } + end + { + "name" => city.name, + "total" => total, + "id" => "tab#{idx}", + "schools" => schools + } + end + { + "cities" => cities, + "extras" => {} + } + end + + def proposals + params = OrbitHelper.params + school = HpsSchool.where(:uid => params[:uid]).first + members = HpsMember.where(:hps_school_id => school.id.to_s) + page = Page.where(:page_id => params[:page_id]).first + files = [] + members.each do |member| + member.hps_files.each do |file| + files << { + "title" => file.title, + "download_count" => file.download_count, + "url" => "/cuser/download?file_id=#{file.id.to_s}" + } + end + end + { + "files" => files, + "data" => { + "back-url" => "/" + I18n.locale.to_s + page.url + } + } + end + + def download + file_id = params[:file_id] + file = HpsFile.find(file_id) rescue nil + if !file.nil? + file.download_count = file.download_count + 1 + file.save + redirect_to file.file.url and return + end + render :nothing => true + end + + def login if !current_counselor_user.nil? redirect_to member_dash_path(current_counselor_user.account) end diff --git a/app/models/hps_school.rb b/app/models/hps_school.rb index ec4fe60..16c5118 100644 --- a/app/models/hps_school.rb +++ b/app/models/hps_school.rb @@ -1,9 +1,10 @@ class HpsSchool include Mongoid::Document include Mongoid::Timestamps + include Slug field :old_id - field :name + field :name, as: :slug_title field :address field :telephone field :land diff --git a/app/views/member_counselors/_form.html.erb b/app/views/member_counselors/_form.html.erb index 1b8c7f8..ebb763b 100644 --- a/app/views/member_counselors/_form.html.erb +++ b/app/views/member_counselors/_form.html.erb @@ -31,9 +31,9 @@ <% if @hpsfile.new_record? %> <% case current_counselor_user.user_type %> <% when 0 %> - -
中正區 國立臺北商業技術學院 105推動計劃書
- + <% 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健康促進縣市推動計劃書
diff --git a/app/views/member_counselors/index.html.erb b/app/views/member_counselors/index.html.erb index 02c2c61..648b75c 100644 --- a/app/views/member_counselors/index.html.erb +++ b/app/views/member_counselors/index.html.erb @@ -1,25 +1 @@ -<%#= csrf_meta_tag %> -<% if params[:error] == "invld" %> -
Invalid username or password.
-<% end %> -<% if params[:error] == "dsbld" %> -
Your account is disabled.
-<% end %> - -
-
- - -
-
- - -
-
- <%= hidden_field_tag :authenticity_token, form_authenticity_token %> - -
- -
- - +<%= render_view %> \ No newline at end of file diff --git a/app/views/member_counselors/login.html.erb b/app/views/member_counselors/login.html.erb new file mode 100644 index 0000000..02c2c61 --- /dev/null +++ b/app/views/member_counselors/login.html.erb @@ -0,0 +1,25 @@ +<%#= csrf_meta_tag %> +<% if params[:error] == "invld" %> +
Invalid username or password.
+<% end %> +<% if params[:error] == "dsbld" %> +
Your account is disabled.
+<% end %> + +
+
+ + +
+
+ + +
+
+ <%= hidden_field_tag :authenticity_token, form_authenticity_token %> + +
+ +
+ + diff --git a/app/views/member_counselors/proposals.html.erb b/app/views/member_counselors/proposals.html.erb new file mode 100644 index 0000000..648b75c --- /dev/null +++ b/app/views/member_counselors/proposals.html.erb @@ -0,0 +1 @@ +<%= render_view %> \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 26c33d4..28e9275 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,7 +14,8 @@ Rails.application.routes.draw do end end scope "cuser" do - get "/member_login", to: "member_counselors#index", as: "member_login" + 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/:id/editfileupload", to: "member_counselors#editfileupload", as: "edit_upload_cuser_file" delete "/member/:id/deletefileupload", to: "member_counselors#deletefileupload", as: "delete_upload_cuser_file"