forked from saurabh/orbit4-5
192 lines
7.9 KiB
Ruby
192 lines
7.9 KiB
Ruby
class MembersController < ApplicationController
|
|
def index
|
|
page_roles = OrbitHelper.page_categories
|
|
page_role_status = OrbitHelper.page_role_status
|
|
fields_to_show = [
|
|
{"key"=>"job_title", "type"=>"role","sort_order"=>1},
|
|
{"key"=>"name", "type"=>"profile","sort_order"=>2,"link_to_show"=>true},
|
|
{"key"=>"discipline", "type"=>"role", "max_length"=>12},
|
|
{"key"=>"email", "type"=>"profile"},
|
|
{"key"=>"office_tel", "type"=>"profile"}
|
|
]
|
|
|
|
if OrbitHelper.member_sort_position
|
|
sort = "data['list_order']"
|
|
else
|
|
sort = fields_to_show
|
|
.collect.with_index{|field,idx| {'sort_order'=>field['sort_order'], 'index'=>idx}}
|
|
.select{|field|!field['sort_order'].blank?}
|
|
.sort_by{|field|field['sort_order']}
|
|
.collect.with_index{|field| "data['profile_data'][#{field['index']}]['sort_value'] rescue 0"}
|
|
|
|
sort = '[('+sort.join('),(')+')]'
|
|
end
|
|
if page_roles.include?("all")
|
|
roles = Role.all.collect do |role|
|
|
{ "title" => role.title, "id" => role.id }
|
|
end
|
|
else
|
|
page_role_status.each do |status_id|
|
|
page_roles << RoleStatus.find(status_id).role.id.to_s
|
|
end
|
|
|
|
roles = Role.find(page_roles.uniq).collect do |role|
|
|
{ "title" => role.title, "id" => role.id, "status" => RoleStatus.where(:role_id=>role, :_id.in=>page_role_status).to_a }
|
|
end
|
|
end
|
|
|
|
role_list = []
|
|
roles.each do |role|
|
|
status_list = []
|
|
if !role['status'].blank?
|
|
role['status'].each do |status|
|
|
member_profiles = get_members_by_status(status, sort, fields_to_show)
|
|
status_list << { "status-title" => status.title, "members" => member_profiles } if !member_profiles.blank?
|
|
end
|
|
else
|
|
# Members with status
|
|
role_status = RoleStatus.order_by(:id=>"asc").where(:role_id=>role['id'])
|
|
role_status_ids = role_status.collect{|status| status.id.to_s}
|
|
|
|
role_status.each do |status|
|
|
member_profiles = get_members_by_status(status, sort, fields_to_show)
|
|
next if member_profiles.blank?
|
|
status_list << { "status-title" => status.title, "members" => member_profiles }
|
|
end
|
|
|
|
# Members without status
|
|
member_profiles = []
|
|
MemberProfile.not_in(:role_status_ids.in=>role_status_ids).where(:role_ids.in=>[role['id']]).collect do |profile|
|
|
member_profiles << get_member_data(profile, fields_to_show)
|
|
end
|
|
member_profiles = member_profiles.sort_by{|data| eval(sort)} rescue member_profiles
|
|
status_list << { "status-title" => role['title'], "members" => member_profiles } if !member_profiles.blank?
|
|
end
|
|
role_list << { "role-title" => role['title'], "status-list" => status_list }
|
|
end
|
|
{
|
|
"roles" => role_list,
|
|
"extras" => {
|
|
"widget-title"=>t(:member_)
|
|
}
|
|
}
|
|
end
|
|
|
|
def get_members_by_status(status, sort, fields_to_show)
|
|
member_profiles = []
|
|
|
|
status.member_profiles.each do |member|
|
|
member_profiles<<get_member_data(member, fields_to_show)
|
|
end
|
|
|
|
return member_profiles.sort_by{|data| eval(sort)} rescue member_profiles
|
|
end
|
|
|
|
def get_member_data(member, fields_to_show)
|
|
image = member.avatar.present? ? member.avatar.thumb.url : ActionController::Base.helpers.asset_path('member-pic.png')
|
|
{
|
|
'profile_data'=>member_data(member, fields_to_show),
|
|
'list_order' => member.position,
|
|
'name' => member.name,
|
|
'image'=>image,
|
|
"link_to_show" => OrbitHelper.url_to_show(member.to_param)
|
|
}
|
|
end
|
|
|
|
def show
|
|
params = OrbitHelper.params
|
|
member = MemberProfile.find_by(uid: params[:uid])
|
|
|
|
fields_to_show = [
|
|
{"key"=>"job_title", "type"=>"role"},
|
|
{"key"=>"name", "type"=>"profile"},
|
|
{"key"=>"office_tel", "type"=>"profile"},
|
|
{"key"=>"fax", "type"=>"custom"},
|
|
{"key"=>"email", "type"=>"profile"},
|
|
{"key"=>"discipline", "type"=>"role"},
|
|
{"key"=>"research_expertise", "type"=>"role"},
|
|
{"key"=>"reference_website_of_individual_publication", "type"=>"role"},
|
|
{"key"=>"reference_website_of_individual_research", "type"=>"role"},
|
|
{"key"=>"autobiography", "type"=>"profile"},
|
|
{"key"=>"website", "type"=>"custom"},
|
|
{"key"=>"experience", "type"=>"custom"},
|
|
{"key"=>"mobile", "type"=>"custom"}
|
|
]
|
|
|
|
profile_data = member_data(member, fields_to_show)
|
|
|
|
roles = member.roles.collect{|role| {"role" => role.title} }
|
|
|
|
plugins = OrbitApp::Plugin::Registration.all rescue nil
|
|
plugin_list = plugins.collect.with_index do |plugin, idx|
|
|
intro = PersonalPluginIntro.find_by(member_profile_id: member.id, _type: "#{plugin.app_name}Intro") rescue nil
|
|
if intro.nil? or intro.complete_list
|
|
plugin_data = plugin.app_name.constantize.where(member_profile_id: member) rescue nil
|
|
pd = plugin_data.collect do |p|
|
|
slug_title = ["JournalPaper","WritingConference"].include?(plugin.app_name) ? p.create_link : p.slug_title
|
|
{
|
|
"data_title" => slug_title,
|
|
"link_to_show" => OrbitHelper.url_to_plugin_show(p.to_param,plugin.module_app_name.underscore)
|
|
}
|
|
end
|
|
elsif intro.brief_intro == true
|
|
pd = []
|
|
pd << {"data_title" => intro.text.html_safe}
|
|
end
|
|
|
|
{
|
|
"plugin_data" => pd,
|
|
"plugin_name" => plugin.module_app_name.underscore,
|
|
"plugin_title" => t('module_name.'+plugin.module_app_name.underscore),
|
|
"plugin_class" => idx==0 ? "active" : ""
|
|
}
|
|
end
|
|
plugin_list = plugin_list.reject{|plugin| plugin['plugin_data'].blank?}
|
|
|
|
{
|
|
"roles" => roles,
|
|
"plugins" => plugin_list,
|
|
"profile_data" => profile_data,
|
|
"data" => {
|
|
"image" => member.avatar.present? ? member.avatar.thumb.url : ActionController::Base.helpers.asset_path('member-pic.png'),
|
|
"name" => member.name
|
|
}
|
|
}
|
|
end
|
|
|
|
def member_data(member, fields_to_show)
|
|
profile_data = []
|
|
fields_to_show.each do |field|
|
|
# debugger
|
|
case field['type']
|
|
when 'profile'
|
|
field_data = member.get_attribute_data(field) rescue {}
|
|
when 'custom'
|
|
field_data = member.member_profile_field_values.find_by(:key=>field['key']).get_field_value rescue {}
|
|
when 'role'
|
|
field_data = member.attribute_values.find_by(:key=>field['key']).get_field_value rescue {}
|
|
end
|
|
next if field_data.blank? or field_data['value'].blank?
|
|
|
|
if field['sort_order']
|
|
field_data['sort_value'] = field_data['val'].blank? ? field_data['value'] : field_data['val']
|
|
field_data['sort_value'] = (field_data['sort_value'].is_i? ? field_data['sort_value'].to_i : field_data['sort_value'] rescue field_data['sort_value'])
|
|
end
|
|
|
|
if field['link_to_show']
|
|
field_data['value'] = "<a href='#{OrbitHelper.url_to_show(member.to_param)}'>#{field_data['value']}</a>"
|
|
end
|
|
|
|
if field['max_length']
|
|
field_data['value'] = (field_data['value'].length > field['max_length']) ? field_data['value'][0..field['max_length']]+'...' : field_data['value']
|
|
end
|
|
|
|
field_data['title_class'] = "member-data-title-"+field['key'].underscore.gsub('_','-')
|
|
field_data['value_class'] = "member-data-value-"+field['key'].underscore.gsub('_','-')
|
|
|
|
profile_data.push(field_data)
|
|
end
|
|
return profile_data
|
|
end
|
|
end
|