127 lines
4.4 KiB
Ruby
127 lines
4.4 KiB
Ruby
class AcademicAdvisingsController < ApplicationController
|
|
def index
|
|
params = OrbitHelper.params
|
|
filter_value = params[:academic_advisings_filter_value]
|
|
academic_advisings = nil
|
|
|
|
if filter_value.nil? || filter_value == t("academic_advising.academic_advising_types_all") || filter_value.empty?
|
|
academic_advisings = Advising.where(:award_name.ne => nil).or(:award_name.ne => "").sort_for_frontend.page(OrbitHelper.params[:page_no]).per(OrbitHelper.page_data_count)
|
|
else
|
|
academic_advising_type_id = AdvisingType.or({ 'title.en' => filter_value }, { 'title.zh_tw' => filter_value }).first.id
|
|
academic_advisings = Advising.where(academic_advising_type_id: academic_advising_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 = [
|
|
"academic_advising_type",
|
|
"year",
|
|
"award_name",
|
|
"authors",
|
|
"awarding_unit",
|
|
"advising_students"
|
|
]
|
|
end
|
|
|
|
academic_advising_list = []
|
|
academic_advisings.each do |academic_advising|
|
|
t = []
|
|
fields_to_show.each do |fs|
|
|
case fs
|
|
when "award_name"
|
|
t << {"value" => "<a href='#{OrbitHelper.url_to_show(academic_advising.to_param)}'>" + (academic_advising.send(fs) rescue "") + "</a>"}
|
|
when "academic_advising_type"
|
|
t << {"value" => academic_advising.display_advising_type}
|
|
when "authors"
|
|
member_profile = academic_advising.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" => (academic_advising.send(fs).strftime("%Y/%m") rescue "")}
|
|
when "advising_students"
|
|
t << {"value" => academic_advising.advising_students_front_data}
|
|
when "year"
|
|
t << {"value" => academic_advising.display_year}
|
|
else
|
|
t << {"value" => (academic_advising.send(fs) rescue "")}
|
|
end
|
|
end
|
|
academic_advising_list << {"academic_advisings" => t}
|
|
end
|
|
|
|
headers = []
|
|
fields_to_show.each do |fs|
|
|
col = 2
|
|
col = 3 if fs == "award_name"
|
|
header = fs == "authors" ? t("academic_advising.academic_advisingee") : t("academic_advising.#{fs}")
|
|
headers << {
|
|
"head-title" => header,
|
|
"col" => col
|
|
}
|
|
end
|
|
|
|
current_locale = I18n.locale
|
|
academic_advising_types = AdvisingType.all.pluck(:title).map { |title| { 'academic_advising_type' => title.to_h[current_locale] } }
|
|
academic_advising_types.unshift({ 'academic_advising_type' => t("academic_advising.academic_advising_types_all") })
|
|
|
|
{
|
|
"advisings" => academic_advising_list,
|
|
"academic_advising_types" => academic_advising_types,
|
|
"extras" => { "widget-title" => t("module_name.academic_advising"),
|
|
"url" => '/' + current_locale.to_s + params[:url] },
|
|
"headers" => headers,
|
|
"total_pages" => academic_advisings.total_pages
|
|
}
|
|
end
|
|
|
|
def show
|
|
params = OrbitHelper.params
|
|
plugin = Advising.where(:is_hidden=>false).find_by(uid: params[:uid])
|
|
fields_to_show = [
|
|
"year",
|
|
"academic_advising_type",
|
|
"award_name",
|
|
"award_date",
|
|
"requirement",
|
|
"academic_advisingee",
|
|
"awarding_unit",
|
|
"advising_students"
|
|
]
|
|
|
|
{"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",
|
|
"academic_advising_type",
|
|
"award_date",
|
|
"requirement",
|
|
"authors",
|
|
"award_winner"
|
|
]
|
|
@fields_to_show = @fields_to_show.map{|fs| [(fs == "authors" ? t("users.name") : t("academic_advising.#{fs}")), fs]}
|
|
@default_fields_to_show = [
|
|
"academic_advising_type",
|
|
"year",
|
|
"award_name",
|
|
"authors",
|
|
"awarding_unit",
|
|
"advising_students"
|
|
]
|
|
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
|