personal-project/app/controllers/personal_projects_controlle...

110 lines
2.7 KiB
Ruby

class PersonalProjectsController < ApplicationController
def index
params = OrbitHelper.params
projects = Project.where(:project_title.ne => nil,:project_title.ne => "").sort_for_frontend.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 = [
"project_type",
"year",
"project_title",
"participator",
"job_title",
"period",
"unit"
]
end
project_list = []
projects.each do |project|
t = []
fields_to_show.each do |fs|
case fs
when "project_type"
t << {"value" => (project.send(fs).title rescue "")}
when "project_title"
t << {"value" => "<a href='#{OrbitHelper.url_to_show(project.to_param)}'>" + (project.send(fs) rescue "") + "</a>"}
when "period"
t << {"value" => (project.send("duration") rescue "")}
else
t << {"value" => (project.send(fs) rescue "")}
end
end
project_list << {"project" => t}
end
headers = []
fields_to_show.each do |fs|
col = 2
col = 3 if fs == "project_title"
headers << {
"head-title" => t("personal_project.#{fs}"),
"col" => col
}
end
{
"projects" => project_list,
"headers" => headers,
"extras" => {"widget-title" => t("module_name.personal_project")},
"total_pages" => projects.total_pages
}
end
def show
params = OrbitHelper.params
plugin = Project.where(:is_hidden=>false).find_by(uid: params[:uid])
fields_to_show = [
"year",
"project_type",
"project_title",
"participator",
"job_title",
"period",
"unit",
"abstract",
"url",
"file",
"language",
]
{"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",
"project_type",
"project_title",
"participator",
"job_title",
"period",
"unit",
"abstract",
"url",
"file",
"language",
]
@fields_to_show = @fields_to_show.map{|fs| [t("personal_project.#{fs}"), fs]}
@default_fields_to_show = [
"project_type",
"year",
"project_title",
"participator",
"job_title",
"period",
"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