added member counselor changes
This commit is contained in:
parent
ebb90e12b7
commit
ab7dfbdec4
|
@ -8,6 +8,7 @@ class MemberCounselorsController < CUserController
|
|||
pcity = nil
|
||||
page = Page.where(:page_id => params[:page_id]).first
|
||||
schoolmembers = HpsMember.where(:user_type => 0).pluck(:id)
|
||||
data = {}
|
||||
cities = HpsCity.all.collect do |city|
|
||||
total = city.hps_files.where(:hps_member_id.in => schoolmembers).count
|
||||
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}"
|
||||
}
|
||||
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])
|
||||
end
|
||||
total = 0
|
||||
schools = pcity.hps_schools.collect do |school|
|
||||
members = HpsMember.where(:hps_school_id => school.id.to_s).pluck(:id)
|
||||
count = HpsFile.where(:hps_member_id.in => members).count
|
||||
total = count + total
|
||||
{
|
||||
"name" => school.name,
|
||||
"url_to_show" => OrbitHelper.url_to_show(school.to_param) + "?method=proposals",
|
||||
"count" => count
|
||||
total = 0
|
||||
schools = pcity.hps_schools.collect do |school|
|
||||
members = HpsMember.where(:hps_school_id => school.id.to_s).pluck(:id)
|
||||
count = HpsFile.where(:hps_member_id.in => members).count
|
||||
total = count + total
|
||||
{
|
||||
"name" => school.name,
|
||||
"url_to_show" => OrbitHelper.url_to_show(school.to_param) + "?method=proposals",
|
||||
"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
|
||||
data
|
||||
end
|
||||
|
||||
def decide_template
|
||||
params = OrbitHelper.params
|
||||
{
|
||||
"cities" => cities,
|
||||
"schools" => schools,
|
||||
"extras" => {"current_city_name" => pcity.name}
|
||||
"page_id" => params[:page_id],
|
||||
"city_id_present" => params[:city_id].present?
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -61,7 +119,7 @@ class MemberCounselorsController < CUserController
|
|||
"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}"
|
||||
"url" => "/cuser/download?file_id=#{file.id.to_s}&type=proposals"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -69,6 +127,7 @@ class MemberCounselorsController < CUserController
|
|||
"files" => files,
|
||||
"cities" => cities,
|
||||
"data" => {
|
||||
"school-name" => school.name,
|
||||
"back-url" => "/" + I18n.locale.to_s + page.url
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +135,11 @@ class MemberCounselorsController < CUserController
|
|||
|
||||
def download
|
||||
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?
|
||||
file.download_count = file.download_count + 1
|
||||
file.save
|
||||
|
@ -85,6 +148,7 @@ class MemberCounselorsController < CUserController
|
|||
render :nothing => true
|
||||
end
|
||||
|
||||
|
||||
def login
|
||||
if !current_counselor_user.nil?
|
||||
redirect_to member_dash_path(current_counselor_user.account)
|
||||
|
|
|
@ -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 %>
|
||||
|
|
Loading…
Reference in New Issue