added member counselor changes

This commit is contained in:
Harry Bomrah 2017-08-18 18:51:32 +08:00
parent ebb90e12b7
commit ab7dfbdec4
2 changed files with 89 additions and 17 deletions

View File

@ -8,6 +8,7 @@ class MemberCounselorsController < CUserController
pcity = nil pcity = nil
page = Page.where(:page_id => params[:page_id]).first page = Page.where(:page_id => params[:page_id]).first
schoolmembers = HpsMember.where(:user_type => 0).pluck(:id) schoolmembers = HpsMember.where(:user_type => 0).pluck(:id)
data = {}
cities = HpsCity.all.collect do |city| cities = HpsCity.all.collect do |city|
total = city.hps_files.where(:hps_member_id.in => schoolmembers).count total = city.hps_files.where(:hps_member_id.in => schoolmembers).count
pcity = city if idx == 0 pcity = city if idx == 0
@ -18,24 +19,81 @@ class MemberCounselorsController < CUserController
"url" => "/" + I18n.locale.to_s + page.url + "?city_id=#{city.id.to_s}" "url" => "/" + I18n.locale.to_s + page.url + "?city_id=#{city.id.to_s}"
} }
end end
if params[:city_id].present? if params[:page_id] == "hpsschool"
data = get_school_data(params, schoolmembers, page)
elsif params[:page_id] == "hpsgovt"
end
data["cities"] = cities
data
end
def get_school_data(params, schoolmembers, page)
data = {}
if params[:city_id].present?
pcity = HpsCity.find(params[:city_id]) pcity = HpsCity.find(params[:city_id])
end total = 0
total = 0 schools = pcity.hps_schools.collect do |school|
schools = pcity.hps_schools.collect do |school| members = HpsMember.where(:hps_school_id => school.id.to_s).pluck(:id)
members = HpsMember.where(:hps_school_id => school.id.to_s).pluck(:id) count = HpsFile.where(:hps_member_id.in => members).count
count = HpsFile.where(:hps_member_id.in => members).count total = count + total
total = count + total {
{ "name" => school.name,
"name" => school.name, "url_to_show" => OrbitHelper.url_to_show(school.to_param) + "?method=proposals",
"url_to_show" => OrbitHelper.url_to_show(school.to_param) + "?method=proposals", "count" => count
"count" => count }
end
data["schools"] = schools
data["extras"] = {
"current_city_name" => pcity.name
} }
else
if !params[:type].present? || params[:type] == "proposals"
hpsfiles = HpsFile.where(:hps_member_id.in => schoolmembers).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
data["files"] = hpsfiles.collect do |file|
{
"date" => file.created_at.strftime("%Y/%m/%d"),
"title" => file.title,
"download_count" => file.download_count,
"url" => "/cuser/download?file_id=#{file.id.to_s}&type=proposals"
}
end
data["total_pages"] = hpsfiles.total_pages
elsif params[:type] == "results"
hpsreults = HpsResult.where(:hps_member_id.in => schoolmembers).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
data["files"] = hpsreults.collect do |file|
{
"date" => file.created_at.strftime("%Y/%m/%d"),
"title" => file.title,
"download_count" => file.download_count,
"url" => "/cuser/download?file_id=#{file.id.to_s}&type=results"
}
end
data["total_pages"] = hpsreults.total_pages
end
data["tabs"] = ["執行計劃書", "成果報告"].collect do |tab|
type = tab == "執行計劃書" ? "proposals" : "results"
klass = ""
if (tab == "執行計劃書" && !params[:type].present?) || (tab == "執行計劃書" && params[:type] == "proposals")
klass = "active"
elsif params[:type] == "results" && tab == "成果報告"
klass ="active"
end
{
"name" => tab,
"link" => "/" + I18n.locale.to_s + "#{page.url}?type=#{type}",
"klass" => klass
}
end
end end
data
end
def decide_template
params = OrbitHelper.params
{ {
"cities" => cities, "page_id" => params[:page_id],
"schools" => schools, "city_id_present" => params[:city_id].present?
"extras" => {"current_city_name" => pcity.name}
} }
end end
@ -61,7 +119,7 @@ class MemberCounselorsController < CUserController
"date" => file.created_at.strftime("%Y/%m/%d"), "date" => file.created_at.strftime("%Y/%m/%d"),
"title" => file.title, "title" => file.title,
"download_count" => file.download_count, "download_count" => file.download_count,
"url" => "/cuser/download?file_id=#{file.id.to_s}" "url" => "/cuser/download?file_id=#{file.id.to_s}&type=proposals"
} }
end end
end end
@ -69,6 +127,7 @@ class MemberCounselorsController < CUserController
"files" => files, "files" => files,
"cities" => cities, "cities" => cities,
"data" => { "data" => {
"school-name" => school.name,
"back-url" => "/" + I18n.locale.to_s + page.url "back-url" => "/" + I18n.locale.to_s + page.url
} }
} }
@ -76,7 +135,11 @@ class MemberCounselorsController < CUserController
def download def download
file_id = params[:file_id] file_id = params[:file_id]
file = HpsFile.find(file_id) rescue nil if params[:type] == "proposals"
file = HpsFile.find(file_id) rescue nil
elsif params[:type] == "results"
file = HpsResult.find(file_id) rescue nil
end
if !file.nil? if !file.nil?
file.download_count = file.download_count + 1 file.download_count = file.download_count + 1
file.save file.save
@ -85,6 +148,7 @@ class MemberCounselorsController < CUserController
render :nothing => true render :nothing => true
end end
def login def login
if !current_counselor_user.nil? if !current_counselor_user.nil?
redirect_to member_dash_path(current_counselor_user.account) redirect_to member_dash_path(current_counselor_user.account)

View File

@ -1 +1,9 @@
<%= render_view %> <% data = action_data "decide_template" %>
<% if data["page_id"] == "hpsschool" %>
<% if data["city_id_present"] %>
<%= render_view %>
<% else %>
<%= render_view "school_default" %>
<% end %>
<% end %>