lot of changes in hpsgovt and hpsschool
This commit is contained in:
parent
ab7dfbdec4
commit
e14923b47c
|
@ -5,31 +5,82 @@ class MemberCounselorsController < CUserController
|
|||
def index
|
||||
idx = 0
|
||||
params = OrbitHelper.params
|
||||
pcity = nil
|
||||
page = Page.where(:page_id => params[:page_id]).first
|
||||
schoolmembers = HpsMember.where(:user_type => 0).pluck(:id)
|
||||
if params[:page_id] == "hpsschool"
|
||||
members = HpsMember.where(:user_type => 0).pluck(:id)
|
||||
type = ""
|
||||
elsif params[:page_id] == "hpsgovt"
|
||||
members = HpsMember.where(:user_type => 1).pluck(:id)
|
||||
type = "&type=proposals"
|
||||
end
|
||||
data = {}
|
||||
cities = HpsCity.all.collect do |city|
|
||||
total = city.hps_files.where(:hps_member_id.in => schoolmembers).count
|
||||
pcity = city if idx == 0
|
||||
total = city.hps_files.where(:hps_member_id.in => members).count
|
||||
idx = idx + 1
|
||||
{
|
||||
"name" => city.name,
|
||||
"total" => total,
|
||||
"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}#{type}"
|
||||
}
|
||||
end
|
||||
if params[:page_id] == "hpsschool"
|
||||
data = get_school_data(params, schoolmembers, page)
|
||||
data = get_school_data(params, members, page)
|
||||
elsif params[:page_id] == "hpsgovt"
|
||||
data = get_govt_data(params, members, page)
|
||||
end
|
||||
data["cities"] = cities
|
||||
data
|
||||
end
|
||||
|
||||
def get_govt_data(params, members, page)
|
||||
data = {}
|
||||
if params[:city_id].present?
|
||||
files = []
|
||||
city = HpsCity.find(params[:city_id])
|
||||
if !params[:type].present? || params[:type] == "proposals"
|
||||
hpsfiles = HpsFile.where(:hps_member_id.in => members).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
|
||||
elsif params[:type] == "results"
|
||||
hpsfiles = HpsResult.where(:hps_member_id.in => members).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
|
||||
end
|
||||
hpsfiles.each do |file|
|
||||
files << {
|
||||
"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["files"] = files
|
||||
data["data"] = {
|
||||
"city-name" => city.name,
|
||||
"back-url" => "/" + I18n.locale.to_s + page.url
|
||||
}
|
||||
data["total_pages"] = hpsfiles.total_pages
|
||||
else
|
||||
if !params[:type].present? || params[:type] == "proposals"
|
||||
hpsfiles = HpsFile.where(:hps_member_id.in => members).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
|
||||
type = "proposals"
|
||||
elsif params[:type] == "results"
|
||||
hpsfiles = HpsResult.where(:hps_member_id.in => members).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
|
||||
type = "results"
|
||||
end
|
||||
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
|
||||
end
|
||||
data["tabs"] = get_tabs(page, params)
|
||||
data
|
||||
end
|
||||
|
||||
def get_school_data(params, schoolmembers, page)
|
||||
data = {}
|
||||
if params[:city_id].present?
|
||||
if params[:city_id].present?
|
||||
pcity = HpsCity.find(params[:city_id])
|
||||
total = 0
|
||||
schools = pcity.hps_schools.collect do |school|
|
||||
|
@ -48,43 +99,23 @@ class MemberCounselorsController < CUserController
|
|||
}
|
||||
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
|
||||
hpsfiles = HpsFile.where(:hps_member_id.in => schoolmembers).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
|
||||
type = "proposals"
|
||||
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
|
||||
hpsfiles = HpsResult.where(:hps_member_id.in => schoolmembers).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
|
||||
type = "results"
|
||||
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
|
||||
|
||||
data["files"] = hpsfiles.collect do |file|
|
||||
{
|
||||
"name" => tab,
|
||||
"link" => "/" + I18n.locale.to_s + "#{page.url}?type=#{type}",
|
||||
"klass" => klass
|
||||
"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=#{type}"
|
||||
}
|
||||
end
|
||||
data["total_pages"] = hpsfiles.total_pages
|
||||
data["tabs"] = get_tabs(page, params)
|
||||
end
|
||||
data
|
||||
end
|
||||
|
@ -100,7 +131,7 @@ class MemberCounselorsController < CUserController
|
|||
def proposals
|
||||
params = OrbitHelper.params
|
||||
school = HpsSchool.where(:uid => params[:uid]).first
|
||||
members = HpsMember.where(:hps_school_id => school.id.to_s)
|
||||
members = HpsMember.where(:hps_school_id => school.id.to_s).pluck(:id)
|
||||
page = Page.where(:page_id => params[:page_id]).first
|
||||
schoolmembers = HpsMember.where(:user_type => 0).pluck(:id)
|
||||
|
||||
|
@ -113,26 +144,59 @@ class MemberCounselorsController < CUserController
|
|||
"url" => "/" + I18n.locale.to_s + page.url + "?city_id=#{city.id.to_s}"
|
||||
}
|
||||
end
|
||||
members.each do |member|
|
||||
member.hps_files.desc(:created_at).each do |file|
|
||||
files << {
|
||||
"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
|
||||
if !params[:type].present? || params[:type] == "proposals"
|
||||
hpsfiles = HpsFile.where(:hps_member_id.in => members).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
|
||||
type = "proposals"
|
||||
elsif params[:type] == "results"
|
||||
hpsfiles = HpsResult.where(:hps_member_id.in => members).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
|
||||
type = "results"
|
||||
end
|
||||
hpsfiles.each do |file|
|
||||
files << {
|
||||
"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=#{type}"
|
||||
}
|
||||
end
|
||||
{
|
||||
"files" => files,
|
||||
"tabs" => get_tabs(page, params, school),
|
||||
"cities" => cities,
|
||||
"data" => {
|
||||
"school-name" => school.name,
|
||||
"back-url" => "/" + I18n.locale.to_s + page.url
|
||||
}
|
||||
},
|
||||
"total_pages" => hpsfiles.total_pages
|
||||
}
|
||||
end
|
||||
|
||||
def get_tabs(page, params, school=nil)
|
||||
["執行計劃書", "成果報告"].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
|
||||
|
||||
city_param = params[:city_id].present? ? "&city_id=#{params[:city_id]}" : ""
|
||||
|
||||
if !school.nil?
|
||||
link = "/" + I18n.locale.to_s + "#{page.url}/#{school.to_param}?type=#{type}#{city_param}&method=proposals"
|
||||
else
|
||||
link = "/" + I18n.locale.to_s + "#{page.url}?type=#{type}#{city_param}"
|
||||
end
|
||||
|
||||
{
|
||||
"name" => tab,
|
||||
"link" => link,
|
||||
"klass" => klass
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def download
|
||||
file_id = params[:file_id]
|
||||
if params[:type] == "proposals"
|
||||
|
|
|
@ -6,4 +6,6 @@
|
|||
<% else %>
|
||||
<%= render_view "school_default" %>
|
||||
<% end %>
|
||||
<% elsif data["page_id"] == "hpsgovt" %>
|
||||
<%= render_view "govt_main" %>
|
||||
<% end %>
|
||||
|
|
Loading…
Reference in New Issue