2014-07-03 04:53:38 +00:00
|
|
|
class PersonalHonorsController < ApplicationController
|
|
|
|
def index
|
2016-03-21 11:02:08 +00:00
|
|
|
params = OrbitHelper.params
|
2019-11-04 02:52:20 +00:00
|
|
|
filter_value = params[:honors_filter_value]
|
|
|
|
honors = nil
|
|
|
|
|
2019-11-04 03:02:23 +00:00
|
|
|
if filter_value.nil? || filter_value == t("personal_honor.honor_types_all") || filter_value.empty?
|
2019-11-04 02:52:20 +00:00
|
|
|
honors = Honor.where(:award_name.ne => nil).or(:award_name.ne => "").sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
|
|
|
|
else
|
|
|
|
honor_type_id = HonorType.or({ 'title.en' => filter_value }, { 'title.zh_tw' => filter_value }).first.id
|
|
|
|
honors = Honor.where(honor_type_id: honor_type_id).sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
|
|
|
|
end
|
|
|
|
|
2016-03-21 11:02:08 +00:00
|
|
|
fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue []
|
|
|
|
|
|
|
|
if fields_to_show.blank?
|
|
|
|
fields_to_show = [
|
|
|
|
"honor_type",
|
|
|
|
"year",
|
|
|
|
"award_name",
|
|
|
|
"authors",
|
|
|
|
"awarding_unit"
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
honor_list = []
|
|
|
|
honors.each do |honor|
|
|
|
|
t = []
|
|
|
|
fields_to_show.each do |fs|
|
2019-11-04 02:40:59 +00:00
|
|
|
case fs
|
|
|
|
when "award_name"
|
|
|
|
t << {"value" => "<a href='#{OrbitHelper.url_to_show(honor.to_param)}'>" + (honor.send(fs) rescue "") + "</a>"}
|
|
|
|
when "honor_type"
|
|
|
|
t << {"value" => (honor.send("honor_type").title rescue "")}
|
|
|
|
when "authors"
|
2019-12-30 03:40:52 +00:00
|
|
|
member_profile = honor.send(:member_profile)
|
|
|
|
role_status_id = member_profile.role_status_ids.first.to_s
|
2019-12-31 07:18:40 +00:00
|
|
|
link = OrbitHelper.url_to_plugin_show(member_profile.to_param, 'member') rescue '#'
|
2019-12-30 03:40:52 +00:00
|
|
|
t << {"value" => "<a href='#{link}'>" + (member_profile.name rescue "") + "</a>" }
|
2019-11-04 02:40:59 +00:00
|
|
|
when "award_date"
|
|
|
|
t << {"value" => (honor.send(fs).strftime("%Y/%m") rescue "")}
|
|
|
|
else
|
|
|
|
t << {"value" => (honor.send(fs) rescue "")}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
honor_list << {"personal_honors" => t}
|
2016-03-21 11:02:08 +00:00
|
|
|
end
|
2019-11-04 02:40:59 +00:00
|
|
|
|
2016-03-21 11:02:08 +00:00
|
|
|
headers = []
|
|
|
|
fields_to_show.each do |fs|
|
|
|
|
col = 2
|
|
|
|
col = 3 if fs == "award_name"
|
|
|
|
header = fs == "authors" ? t("users.name") : t("personal_honor.#{fs}")
|
|
|
|
headers << {
|
|
|
|
"head-title" => header,
|
|
|
|
"col" => col
|
2014-07-03 04:53:38 +00:00
|
|
|
}
|
|
|
|
end
|
2016-03-21 11:02:08 +00:00
|
|
|
|
2019-11-04 02:52:20 +00:00
|
|
|
current_locale = I18n.locale
|
|
|
|
honor_types = HonorType.all.pluck(:title).map { |title| { 'honor_type' => title[current_locale] } }
|
2019-11-04 03:02:23 +00:00
|
|
|
honor_types.unshift({ 'honor_type' => t("personal_honor.honor_types_all") })
|
2019-11-04 02:52:20 +00:00
|
|
|
|
2014-07-03 04:53:38 +00:00
|
|
|
{
|
|
|
|
"honors" => honor_list,
|
2019-11-04 02:52:20 +00:00
|
|
|
"honor_types" => honor_types,
|
|
|
|
"extras" => { "widget-title" => t("module_name.personal_honor"),
|
|
|
|
"url" => '/' + current_locale.to_s + params[:url] },
|
2016-03-21 11:02:08 +00:00
|
|
|
"headers" => headers,
|
2014-07-18 07:03:24 +00:00
|
|
|
"total_pages" => honors.total_pages
|
2014-07-03 04:53:38 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
params = OrbitHelper.params
|
2014-08-01 11:47:43 +00:00
|
|
|
plugin = Honor.where(:is_hidden=>false).find_by(uid: params[:uid])
|
|
|
|
fields_to_show = [
|
2015-01-09 07:44:32 +00:00
|
|
|
"year",
|
|
|
|
"honor_type",
|
2014-08-01 11:47:43 +00:00
|
|
|
"award_name",
|
2016-04-05 18:09:04 +00:00
|
|
|
"award_date",
|
|
|
|
"country",
|
2014-08-01 11:47:43 +00:00
|
|
|
"honoree",
|
|
|
|
"awarding_unit",
|
|
|
|
"keywords",
|
|
|
|
"url",
|
|
|
|
"note"
|
|
|
|
]
|
2014-07-03 04:53:38 +00:00
|
|
|
|
2014-08-01 11:47:43 +00:00
|
|
|
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
|
2014-07-03 04:53:38 +00:00
|
|
|
end
|
2016-03-21 11:02:08 +00:00
|
|
|
|
|
|
|
def get_fields_for_index
|
2019-11-04 02:40:59 +00:00
|
|
|
@page = Page.find(params[:page_id]) rescue nil
|
|
|
|
@fields_to_show = [
|
|
|
|
"year",
|
|
|
|
"award_name",
|
|
|
|
"awarding_unit",
|
|
|
|
"honor_type",
|
|
|
|
"award_date",
|
|
|
|
"country",
|
|
|
|
"keywords",
|
|
|
|
"url",
|
|
|
|
"note",
|
|
|
|
"authors",
|
|
|
|
"award_winner"
|
|
|
|
]
|
|
|
|
@fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_honor.#{fs}")), fs]}
|
|
|
|
@default_fields_to_show = [
|
|
|
|
"honor_type",
|
|
|
|
"year",
|
|
|
|
"award_name",
|
|
|
|
"authors",
|
|
|
|
"awarding_unit"
|
|
|
|
]
|
|
|
|
render :layout => false
|
2016-03-21 11:02:08 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def save_index_fields
|
2019-11-04 02:40:59 +00:00
|
|
|
page = Page.find(params[:page_id]) rescue nil
|
|
|
|
page.custom_array_field = params[:keys]
|
|
|
|
page.save
|
|
|
|
render :json => {"success" => true}.to_json
|
2016-03-21 11:02:08 +00:00
|
|
|
end
|
2019-11-04 02:40:59 +00:00
|
|
|
end
|