lot of changes in hpsgovt and hpsschool

This commit is contained in:
Harry Bomrah 2017-08-21 16:14:12 +08:00
parent ab7dfbdec4
commit e14923b47c
2 changed files with 116 additions and 50 deletions

View File

@ -5,31 +5,82 @@ class MemberCounselorsController < CUserController
def index def index
idx = 0 idx = 0
params = OrbitHelper.params params = OrbitHelper.params
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) 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 = {} 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 => members).count
pcity = city if idx == 0
idx = idx + 1 idx = idx + 1
{ {
"name" => city.name, "name" => city.name,
"total" => total, "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 end
if params[:page_id] == "hpsschool" if params[:page_id] == "hpsschool"
data = get_school_data(params, schoolmembers, page) data = get_school_data(params, members, page)
elsif params[:page_id] == "hpsgovt" elsif params[:page_id] == "hpsgovt"
data = get_govt_data(params, members, page)
end end
data["cities"] = cities data["cities"] = cities
data data
end 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) def get_school_data(params, schoolmembers, page)
data = {} data = {}
if params[:city_id].present? if params[:city_id].present?
pcity = HpsCity.find(params[:city_id]) pcity = HpsCity.find(params[:city_id])
total = 0 total = 0
schools = pcity.hps_schools.collect do |school| schools = pcity.hps_schools.collect do |school|
@ -48,43 +99,23 @@ class MemberCounselorsController < CUserController
} }
else else
if !params[:type].present? || params[:type] == "proposals" 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) 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| type = "proposals"
{
"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" elsif params[:type] == "results"
hpsreults = HpsResult.where(:hps_member_id.in => schoolmembers).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10) hpsfiles = 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| type = "results"
{
"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 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, "date" => file.created_at.strftime("%Y/%m/%d"),
"link" => "/" + I18n.locale.to_s + "#{page.url}?type=#{type}", "title" => file.title,
"klass" => klass "download_count" => file.download_count,
"url" => "/cuser/download?file_id=#{file.id.to_s}&type=#{type}"
} }
end end
data["total_pages"] = hpsfiles.total_pages
data["tabs"] = get_tabs(page, params)
end end
data data
end end
@ -100,7 +131,7 @@ class MemberCounselorsController < CUserController
def proposals def proposals
params = OrbitHelper.params params = OrbitHelper.params
school = HpsSchool.where(:uid => params[:uid]).first 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 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)
@ -113,26 +144,59 @@ 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
members.each do |member| if !params[:type].present? || params[:type] == "proposals"
member.hps_files.desc(:created_at).each do |file| hpsfiles = HpsFile.where(:hps_member_id.in => members).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
files << { type = "proposals"
"date" => file.created_at.strftime("%Y/%m/%d"), elsif params[:type] == "results"
"title" => file.title, hpsfiles = HpsResult.where(:hps_member_id.in => members).order_by([:year, :desc],[:created_at, :desc]).page(params[:page]).per(10)
"download_count" => file.download_count, type = "results"
"url" => "/cuser/download?file_id=#{file.id.to_s}&type=proposals" end
} hpsfiles.each do |file|
end 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 end
{ {
"files" => files, "files" => files,
"tabs" => get_tabs(page, params, school),
"cities" => cities, "cities" => cities,
"data" => { "data" => {
"school-name" => school.name, "school-name" => school.name,
"back-url" => "/" + I18n.locale.to_s + page.url "back-url" => "/" + I18n.locale.to_s + page.url
} },
"total_pages" => hpsfiles.total_pages
} }
end 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 def download
file_id = params[:file_id] file_id = params[:file_id]
if params[:type] == "proposals" if params[:type] == "proposals"

View File

@ -6,4 +6,6 @@
<% else %> <% else %>
<%= render_view "school_default" %> <%= render_view "school_default" %>
<% end %> <% end %>
<% elsif data["page_id"] == "hpsgovt" %>
<%= render_view "govt_main" %>
<% end %> <% end %>