forked from saurabh/personal-honor
Merge branch 'master' into 'master'
add honor types filter let honor index page return honors by types See merge request !1
This commit is contained in:
commit
f76098aad6
|
@ -1,7 +1,16 @@
|
||||||
class PersonalHonorsController < ApplicationController
|
class PersonalHonorsController < ApplicationController
|
||||||
def index
|
def index
|
||||||
params = OrbitHelper.params
|
params = OrbitHelper.params
|
||||||
honors = Honor.where(:award_name.ne => nil).or(:award_name.ne => "").sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
|
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 []
|
fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue []
|
||||||
|
|
||||||
if fields_to_show.blank?
|
if fields_to_show.blank?
|
||||||
|
@ -18,20 +27,20 @@ class PersonalHonorsController < ApplicationController
|
||||||
honors.each do |honor|
|
honors.each do |honor|
|
||||||
t = []
|
t = []
|
||||||
fields_to_show.each do |fs|
|
fields_to_show.each do |fs|
|
||||||
case fs
|
case fs
|
||||||
when "award_name"
|
when "award_name"
|
||||||
t << {"value" => "<a href='#{OrbitHelper.url_to_show(honor.to_param)}'>" + (honor.send(fs) rescue "") + "</a>"}
|
t << {"value" => "<a href='#{OrbitHelper.url_to_show(honor.to_param)}'>" + (honor.send(fs) rescue "") + "</a>"}
|
||||||
when "honor_type"
|
when "honor_type"
|
||||||
t << {"value" => (honor.send("honor_type").title rescue "")}
|
t << {"value" => (honor.send("honor_type").title rescue "")}
|
||||||
when "authors"
|
when "authors"
|
||||||
t << {"value" => (honor.send(:member_profile).name rescue "")}
|
t << {"value" => (honor.send(:member_profile).name rescue "")}
|
||||||
when "award_date"
|
when "award_date"
|
||||||
t << {"value" => (honor.send(fs).strftime("%Y/%m") rescue "")}
|
t << {"value" => (honor.send(fs).strftime("%Y/%m") rescue "")}
|
||||||
else
|
else
|
||||||
t << {"value" => (honor.send(fs) rescue "")}
|
t << {"value" => (honor.send(fs) rescue "")}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
honor_list << {"personal_honors" => t}
|
honor_list << {"personal_honors" => t}
|
||||||
end
|
end
|
||||||
|
|
||||||
headers = []
|
headers = []
|
||||||
|
@ -45,9 +54,15 @@ class PersonalHonorsController < ApplicationController
|
||||||
}
|
}
|
||||||
end
|
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,
|
"honors" => honor_list,
|
||||||
"extras" => {"widget-title" => t("module_name.personal_honor")},
|
"honor_types" => honor_types,
|
||||||
|
"extras" => { "widget-title" => t("module_name.personal_honor"),
|
||||||
|
"url" => '/' + current_locale.to_s + params[:url] },
|
||||||
"headers" => headers,
|
"headers" => headers,
|
||||||
"total_pages" => honors.total_pages
|
"total_pages" => honors.total_pages
|
||||||
}
|
}
|
||||||
|
@ -73,35 +88,35 @@ class PersonalHonorsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_fields_for_index
|
def get_fields_for_index
|
||||||
@page = Page.find(params[:page_id]) rescue nil
|
@page = Page.find(params[:page_id]) rescue nil
|
||||||
@fields_to_show = [
|
@fields_to_show = [
|
||||||
"year",
|
"year",
|
||||||
"award_name",
|
"award_name",
|
||||||
"awarding_unit",
|
"awarding_unit",
|
||||||
"honor_type",
|
"honor_type",
|
||||||
"award_date",
|
"award_date",
|
||||||
"country",
|
"country",
|
||||||
"keywords",
|
"keywords",
|
||||||
"url",
|
"url",
|
||||||
"note",
|
"note",
|
||||||
"authors",
|
"authors",
|
||||||
"award_winner"
|
"award_winner"
|
||||||
]
|
]
|
||||||
@fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_honor.#{fs}")), fs]}
|
@fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("personal_honor.#{fs}")), fs]}
|
||||||
@default_fields_to_show = [
|
@default_fields_to_show = [
|
||||||
"honor_type",
|
"honor_type",
|
||||||
"year",
|
"year",
|
||||||
"award_name",
|
"award_name",
|
||||||
"authors",
|
"authors",
|
||||||
"awarding_unit"
|
"awarding_unit"
|
||||||
]
|
]
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_index_fields
|
def save_index_fields
|
||||||
page = Page.find(params[:page_id]) rescue nil
|
page = Page.find(params[:page_id]) rescue nil
|
||||||
page.custom_array_field = params[:keys]
|
page.custom_array_field = params[:keys]
|
||||||
page.save
|
page.save
|
||||||
render :json => {"success" => true}.to_json
|
render :json => {"success" => true}.to_json
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -9,6 +9,7 @@ en:
|
||||||
awarding_unit : "Awarding Unit"
|
awarding_unit : "Awarding Unit"
|
||||||
honor_category : "Honor Category"
|
honor_category : "Honor Category"
|
||||||
honor_type: "Honor Category"
|
honor_type: "Honor Category"
|
||||||
|
honor_types_all: "All Honor Types"
|
||||||
extracted_chapters : "Extracted Chapters"
|
extracted_chapters : "Extracted Chapters"
|
||||||
publishers : "Publishers"
|
publishers : "Publishers"
|
||||||
honoree: "Honoree"
|
honoree: "Honoree"
|
||||||
|
|
|
@ -9,6 +9,7 @@ zh_tw:
|
||||||
awarding_unit : "頒獎單位"
|
awarding_unit : "頒獎單位"
|
||||||
honor_category : "類別"
|
honor_category : "類別"
|
||||||
honor_type: "類別"
|
honor_type: "類別"
|
||||||
|
honor_types_all: "所有榮譽項目"
|
||||||
honoree: "受獎人"
|
honoree: "受獎人"
|
||||||
authors : "作者"
|
authors : "作者"
|
||||||
tags : "領域"
|
tags : "領域"
|
||||||
|
|
Loading…
Reference in New Issue