mods for index fields modification

This commit is contained in:
Harry Bomrah 2017-02-24 17:58:40 +08:00
parent ec4929bf2d
commit 9e91349282
1 changed files with 53 additions and 16 deletions

View File

@ -1,6 +1,15 @@
class PersonalDiplomasController < ApplicationController class PersonalDiplomasController < ApplicationController
def index def index
diplomas = Diploma.where(:is_hidden=>false).order_by(:end_date=>'desc', :start_date=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count) diplomas = Diploma.where(:is_hidden=>false).order_by(:end_date=>'desc', :start_date=>'desc').page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
fields_to_show = Page.where(:page_id => params[:page_id]).first.custom_array_field rescue []
if fields_to_show.blank?
fields_to_show = [
"name",
"duration",
"school_name",
"degree"
]
end
diploma_list = diplomas.collect do |diploma| diploma_list = diplomas.collect do |diploma|
{ {
"member" => (diploma.member_profile.name rescue ""), "member" => (diploma.member_profile.name rescue ""),
@ -10,16 +19,39 @@ class PersonalDiplomasController < ApplicationController
"link_to_show" => OrbitHelper.url_to_show(diploma.to_param) "link_to_show" => OrbitHelper.url_to_show(diploma.to_param)
} }
end end
diploma_list = []
diplomas.each do |diploma|
t = []
fields_to_show.each do |fs|
case fs
when "name"
t << {"value" => (diploma.member_profile.name rescue "")}
when "degree"
t << {"value" => "<a href='#{OrbitHelper.url_to_show(diploma.to_param)}' target='_blank'>" + (diploma.send(fs) rescue "") + "</a>"}
when "start_date"
t << {"value" => (diploma.start_date.strftime("%Y/%m/%d") rescue "")}
when "end_date"
t << {"value" => (diploma.end_date.strftime("%Y/%m/%d") rescue "")}
else
t << {"value" => diploma.send(fs)}
end
end
diploma_list << {"diploma_list" => t}
end
headers = []
fields_to_show.each do |fs|
col = 2
col = 3 if fs == "degree"
headers << {
"head-title" => t("personal_diploma.#{fs}"),
"col" => col
}
end
{ {
"diplomas" => diploma_list, "journal_papers" => diploma_list,
"extras" => { "headers" => headers,
"widget-title" => t("module_name.personal_diploma"), "extras" => {"widget-title" => t("module_name.personal_diploma")},
"th_member" => t('users.name'),
"th_duration" => t('personal_diploma.duration'),
"th_school_name" => t('personal_diploma.school_name'),
"th_degree" => t('personal_diploma.degree'),
"th_detail" => t('detail')
},
"total_pages" => diplomas.total_pages "total_pages" => diplomas.total_pages
} }
end end
@ -50,17 +82,22 @@ class PersonalDiplomasController < ApplicationController
"country", "country",
"department", "department",
"degree", "degree",
"language",
"keywords",
"start_date",
"end_date",
"note",
"url" "url"
] ]
@fields_to_show = @fields_to_show.map{|fs| [t("personal_diploma.#{fs}"), fs]} @fields_to_show = @fields_to_show.map{|fs| [t("personal_diploma.#{fs}"), fs]}
@default_fields_to_show = [ @default_fields_to_show = [
"paper_title", "name",
"journal_title", "school_name",
"authors", "duration",
"year", "country",
"issue_no", "department",
"vol_no", "degree",
"level_type" "url"
] ]
render :layout => false render :layout => false
end end