forked from saurabh/personal-honor
126 lines
3.8 KiB
Ruby
126 lines
3.8 KiB
Ruby
class PersonalHonorsController < ApplicationController
|
|
def index
|
|
params = OrbitHelper.params
|
|
filter_value = params[:honors_filter_value]
|
|
honors = nil
|
|
|
|
if filter_value.nil? || filter_value == t("personal_honor.honor_types_all") || filter_value.empty?
|
|
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
|
|
|
|
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|
|
|
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"
|
|
member_profile = honor.send(:member_profile)
|
|
role_status_id = member_profile.role_status_ids.first.to_s
|
|
path = OrbitHelper.url_to_plugin_show(member_profile.to_param, 'member') rescue '#'
|
|
t << {"value" => "<a href='#{path}'>" + (member_profile.name rescue "") + "</a>" }
|
|
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}
|
|
end
|
|
|
|
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
|
|
}
|
|
end
|
|
|
|
current_locale = I18n.locale
|
|
honor_types = HonorType.all.pluck(:title).map { |title| { 'honor_type' => title[current_locale] } }
|
|
honor_types.unshift({ 'honor_type' => t("personal_honor.honor_types_all") })
|
|
|
|
{
|
|
"honors" => honor_list,
|
|
"honor_types" => honor_types,
|
|
"extras" => { "widget-title" => t("module_name.personal_honor"),
|
|
"url" => '/' + current_locale.to_s + params[:url] },
|
|
"headers" => headers,
|
|
"total_pages" => honors.total_pages
|
|
}
|
|
end
|
|
|
|
def show
|
|
params = OrbitHelper.params
|
|
plugin = Honor.where(:is_hidden=>false).find_by(uid: params[:uid])
|
|
fields_to_show = [
|
|
"year",
|
|
"honor_type",
|
|
"award_name",
|
|
"award_date",
|
|
"country",
|
|
"honoree",
|
|
"awarding_unit",
|
|
"keywords",
|
|
"url",
|
|
"note"
|
|
]
|
|
|
|
{"plugin_datas"=>plugin.get_plugin_data(fields_to_show)}
|
|
end
|
|
|
|
def get_fields_for_index
|
|
@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
|
|
end
|
|
|
|
def save_index_fields
|
|
page = Page.find(params[:page_id]) rescue nil
|
|
page.custom_array_field = params[:keys]
|
|
page.save
|
|
render :json => {"success" => true}.to_json
|
|
end
|
|
end
|