experiment/app/controllers/experiments_controller.rb

180 lines
5.8 KiB
Ruby

class ExperimentsController < ApplicationController
def index
params = OrbitHelper.params
page = Page.where(:page_id => params[:page_id]).first rescue nil
member_page = Page.where(:module => "member").first rescue nil
subjects = Subject.can_display.order_by(:order_position => "asc").filter_by_categories
f = subjects.collect do |subject|
statuses = subject.statuses_with_classname.collect do |status|
{
"status" => status["name"],
"status-class" => "status-#{status['classname']}"
}
end
members = subject.email_members.collect do |member|
url = !member_page.nil? ? "/" + I18n.locale.to_s + member_page.url + "/" + member.to_param : "#"
{
"name" => member.name,
"id_to_show" => url
}
end
co_professors = subject.co_professors.collect do |member|
url = !member_page.nil? ? "/" + I18n.locale.to_s + member_page.url + "/" + member.to_param : "#"
{
"name" => member.name,
"id_to_show" => url
}
end
{
"link_to_show" => OrbitHelper.url_to_show(subject.to_param),
"subject" => subject.title,
"img_src" => subject.image.thumb.url || "/assets/experiment-default.jpg",
"category" => subject.category.title,
"direction" => subject.direction,
"statuses" => statuses,
"members" => members,
"co_professors" => co_professors
}
end
{
"subjects" => f,
"extras" => {
"widget-title"=>"Experiment",
"th_image" => t('image'),
"th_category" => t('category'),
"th_subject" => t('experiment.subject'),
"th_direction" => t('experiment.direction'),
"th_professor1" => t('experiment.professor1'),
"th_professor2" => t('experiment.professor2')
},
"total_pages" => subjects.total_pages
}
end
def show
params = OrbitHelper.params
subject = Subject.find_by(:uid => params[:uid])
member_page = Page.where(:module => "member").first rescue nil
url_to_edit = OrbitHelper.user_can_edit?(subject) ? "/admin/experiments/#{subject.id.to_s}/edit" : ""
return {} if (subject.category.disable rescue false)
statuses = subject.statuses_with_classname.collect do |status|
{
"status" => status["name"],
"status-class" => "status-#{status['classname']}"
}
end
subject_links = subject.subject_links.collect do |f|
{
"link_url" => f.url,
"link_title" => f.title
}
end
members = subject.email_members.collect do |member|
url = !member_page.nil? ? "/" + I18n.locale.to_s + member_page.url + "/" + member.to_param : "#"
{
"name" => member.name,
"id_to_show" => url
}
end
co_professors = subject.co_professors.collect do |member|
url = !member_page.nil? ? "/" + I18n.locale.to_s + member_page.url + "/" + member.to_param : "#"
{
"name" => member.name,
"id_to_show" => url
}
end
tags = subject.tags.map{|tag| { "tag" => tag.name } } rescue []
{
"data" => {
"subject" => subject.title,
"img_src" => subject.image.thumb.url || "/assets/experiment-default.jpg",
"display" => subject.image.thumb.url.nil? ? "display:none;" : "",
"category" => subject.category.title,
"facility" => subject.facility,
"direction" => subject.direction,
"student" => subject.student,
"venue" => subject.venue,
"tel" => subject.tel,
"th_image" => t('image'),
"th_category" => t('category'),
"th_subject" => t('experiment.subject'),
"th_direction" => t('experiment.direction'),
"th_tel" => t('experiment.tel'),
"th_venue" => t('experiment.venue'),
"th_facility" => t('experiment.facility'),
"th_student" => t('experiment.student'),
"th_link" => t('link'),
"th_professor1" => t('experiment.professor1'),
"th_professor2" => t('experiment.professor2'),
"th_area" => t('experiment.area'),
"area" => tags.map{|t| t['tag']}.join(' / ')
},
"tags" => tags,
"subject_links" => subject_links,
"members" => members,
"co_professors" => co_professors,
"url_to_edit" => url_to_edit,
"statuses" => statuses
}
end
def widget
subjects = Subject.filter_by_widget_categories.collect do |subject|
statuses = subject.statuses_with_classname.collect do |status|
{
"status" => status["name"],
"status-class" => "status-#{status['classname']}"
}
end
subject_links = subject.subject_links.collect do |f|
{
"link_url" => f.url,
"link_title" => f.title
}
end
members = subject.email_members.collect do |member|
{
"name" => member.name
}
end
co_professors = subject.co_professors.collect do |member|
url = !member_page.nil? ? "/" + I18n.locale.to_s + member_page.url + "/" + member.to_param : "#"
{
"name" => member.name,
"id_to_show" => url
}
end
{
"link_to_show" => OrbitHelper.widget_item_url(subject.to_param),
"subject" => subject.title,
"img_src" => subject.image.thumb.url || "/assets/experiment-default.jpg",
"category" => subject.category.title,
"direction" => subject.direction,
"statuses" => statuses,
"postdate" => subject.created_at.strftime('%Y-%m-%d'),
"members" => members,
"co_professors" => co_professors
}
end
{
"subjects" => subjects,
"extras" => {
"widget-title"=>"Subjects",
"more_url"=>OrbitHelper.widget_more_url,
"th_subject" => t('experiment.subject'),
"th_direction" => t('experiment.direction'),
"th_postdate" =>t('date_'),
"th_category" => t('category')
}
}
end
end