forked from saurabh/orbit4-5
218 lines
7.4 KiB
Ruby
218 lines
7.4 KiB
Ruby
class MembersController < ApplicationController
|
|
def index
|
|
statuses = OrbitHelper.page_categories
|
|
@statuses = []
|
|
if statuses.first == "all"
|
|
module_app = OrbitHelper.this_module_app
|
|
@statuses = module_app.role_status.collect do |stat|
|
|
{
|
|
"status" => stat.title,
|
|
"id" => stat.id.to_s,
|
|
"status-role" => stat.role.title,
|
|
"rs" => stat
|
|
}
|
|
end
|
|
else
|
|
statuses.each do |stat|
|
|
s = RoleStatus.find(stat)
|
|
@statuses << {"status" => s.title, "id" => s.id.to_s, "rs" => s, "status-role" => s.role.title}
|
|
end
|
|
end
|
|
stats = @statuses.collect do |status|
|
|
members = status["rs"].member_profiles
|
|
member_list = members.collect do |member|
|
|
if member.avatar.present?
|
|
image = member.avatar.thumb.url
|
|
else
|
|
image = "http://placehold.it/100x100"
|
|
end
|
|
roles = member.roles.collect do |role|
|
|
{
|
|
"role" => role.title
|
|
}
|
|
end
|
|
{
|
|
"name" => member.name,
|
|
"roles" => roles,
|
|
"img_src" => image,
|
|
"email" => member.email,
|
|
"link_to_show" => OrbitHelper.url_to_show(member.to_param)
|
|
}
|
|
|
|
end
|
|
{
|
|
"status-title" => status["status"],
|
|
"role-title" => status["status-role"],
|
|
"members" => member_list
|
|
}
|
|
end
|
|
{
|
|
"stats" => stats,
|
|
"extras" => {"widget-title" => "Members"}
|
|
}
|
|
end
|
|
|
|
def show
|
|
params = OrbitHelper.params
|
|
|
|
member = MemberProfile.find_by(uid: params[:uid])
|
|
|
|
plugins = OrbitApp::Plugin::Registration.all rescue nil
|
|
plugin_list = plugins.collect do |plugin|
|
|
intro = PersonalPluginIntro.find_by(member_profile_id: member.id, _type: "#{plugin.app_name}Intro") rescue nil
|
|
|
|
if intro.nil?
|
|
plugin_data = plugin.app_name.constantize.where(member_profile_id: member) rescue nil
|
|
pd = plugin_data.collect do |p|
|
|
{
|
|
"data_title" => p.slug_title,
|
|
"link_to_show" => OrbitHelper.url_to_plugin_show(p.to_param,plugin.module_app_name.underscore)
|
|
}
|
|
end
|
|
{
|
|
"plugin_data" => pd,
|
|
"plugin_title" => plugin.app_name.titleize
|
|
}
|
|
elsif intro.complete_list == true
|
|
plugin_data = plugin.app_name.constantize.where(member_profile_id: member) rescue nil
|
|
pd = plugin_data.collect do |p|
|
|
{
|
|
"data_title" => p.slug_title,
|
|
"link_to_show" => OrbitHelper.url_to_plugin_show(p.to_param,plugin.module_app_name.underscore)
|
|
}
|
|
end
|
|
{
|
|
"plugin_data" => pd,
|
|
"plugin_title" => plugin.app_name.titleize
|
|
}
|
|
# end
|
|
elsif intro.brief_intro == true
|
|
pd = []
|
|
pd << {"data_title" => intro.text.html_safe}
|
|
{
|
|
"plugin_data" => pd,
|
|
"plugin_title" => plugin.app_name.titleize
|
|
}
|
|
end
|
|
end
|
|
|
|
if member.avatar.present?
|
|
image = member.avatar.thumb.url
|
|
else
|
|
image = "http://placehold.it/100x100"
|
|
end
|
|
|
|
custom_fields = member.member_profile_field_values.collect do |cf|
|
|
if (cf.member_profile_field.markup.eql?("text_field") || cf.member_profile_field.markup.eql?("text_area"))
|
|
custom_field_value = cf.value[I18n.locale]
|
|
elsif (cf.member_profile_field.markup.eql?("select") || cf.member_profile_field.markup.eql?("radio_button"))
|
|
custom_field_value = cf.member_profile_field.markup_value["#{cf.value}"][I18n.locale] rescue nil
|
|
elsif cf.member_profile_field.markup.eql?("address")
|
|
custom_field_value = cf[:address_key][I18n.locale].map{|k,v| v}.delete_if(&:blank?).join(', ')
|
|
elsif cf.member_profile_field.markup.eql?("date")
|
|
|
|
case cf.member_profile_field.typeC['format']
|
|
when 'format1'
|
|
custom_field_value = cf.value.to_date.strftime("%Y/%m/%d")
|
|
when 'format2'
|
|
custom_field_value = cf.value.to_date.strftime("%Y/%m/%d")
|
|
when 'format3'
|
|
custom_field_value = cf.value.to_date.strftime("%Y/%m")
|
|
when 'format4'
|
|
custom_field_value = cf.value.to_date.strftime("%Y")
|
|
end
|
|
elsif cf.member_profile_field.markup.eql?("checkbox")
|
|
custom_field_value = cf.value.map {|v| cf.member_profile_field.markup_value["#{v}"][I18n.locale]}.join(', ') rescue nil
|
|
end
|
|
if !custom_field_value.blank?
|
|
{
|
|
"custom_field_title" => cf.member_profile_field.title,
|
|
"custom_field_value" => custom_field_value
|
|
}
|
|
else
|
|
{
|
|
"custom_field_title" => "",
|
|
"custom_field_value" => ""
|
|
}
|
|
end
|
|
end
|
|
custom_fields_final = custom_fields.map {|c| c.delete_if {|k,v| (v.nil? || v.blank?)}}.delete_if(&:blank?)
|
|
|
|
role_fields = member.attribute_values.collect do |rf|
|
|
if (rf.attribute_field.markup.eql?("text_field") || rf.attribute_field.markup.eql?("text_area"))
|
|
role_field_value = rf.value[I18n.locale]
|
|
elsif (rf.attribute_field.markup.eql?("select") || rf.attribute_field.markup.eql?("radio_button"))
|
|
role_field_value = rf.attribute_field.markup_value["#{rf.value}"][I18n.locale] rescue nil
|
|
elsif rf.attribute_field.markup.eql?("address")
|
|
role_field_value = rf[:address_key][I18n.locale].map{|k,v| v}.delete_if(&:blank?).join(', ')
|
|
elsif rf.attribute_field.markup.eql?("date")
|
|
|
|
case rf.attribute_field.typeC['format']
|
|
when 'format1'
|
|
role_field_value = rf.value.to_date.strftime("%Y/%m/%d")
|
|
when 'format2'
|
|
role_field_value = rf.value.to_date.strftime("%Y/%m/%d")
|
|
when 'format3'
|
|
role_field_value = rf.value.to_date.strftime("%Y/%m")
|
|
when 'format4'
|
|
role_field_value = rf.value.to_date.strftime("%Y")
|
|
end
|
|
elsif rf.attribute_field.markup.eql?("checkbox")
|
|
role_field_value = rf.value.map {|v| rf.attribute_field.markup_value["#{v}"][I18n.locale]}.join(', ') rescue nil
|
|
end
|
|
if !role_field_value.blank?
|
|
{
|
|
"role_field_title" => rf.attribute_field.title,
|
|
"role_field_value" => role_field_value
|
|
}
|
|
else
|
|
{
|
|
"role_field_title" => "",
|
|
"role_field_value" => ""
|
|
}
|
|
end
|
|
end
|
|
role_fields_final = role_fields.map {|r| r.delete_if {|k,v| (v.nil? || v.blank?)}}.delete_if(&:blank?)
|
|
|
|
roles = member.roles.collect do |role|
|
|
{
|
|
"role" => role.title
|
|
}
|
|
end
|
|
data = []
|
|
member.values_for_show.each do |key,value|
|
|
data << {"key" => key.humanize, "value" => value}
|
|
end
|
|
autobiography = []
|
|
if !member.get_autobiography_for_show.blank?
|
|
autobiography << {"key" => "#{member.get_autobiography_for_show.first[0].capitalize}", "value" => member.get_autobiography_for_show["autobiography"]}
|
|
end
|
|
image = member.get_image_for_show["img_src"]
|
|
{
|
|
"roles" => roles,
|
|
"plugins" => plugin_list,
|
|
"custom_fields_final" => custom_fields_final,
|
|
"role_fields_final" => role_fields_final,
|
|
"member_data" => data,
|
|
"autobiography_data" => autobiography,
|
|
"data" => {
|
|
"img_src" => image,
|
|
"name" => member.name
|
|
}
|
|
}
|
|
end
|
|
|
|
def personal_plugin
|
|
params = OrbitHelper.params
|
|
plugin_class = params[:plugin_name].constantize
|
|
plugin_value = plugin_class.find_by(uid: params[:uid])
|
|
data = []
|
|
plugin_value.values_for_view.each do |key,value|
|
|
data << {"key" => key.humanize, "value" => value}
|
|
end
|
|
{
|
|
"plugin_data" => data
|
|
}
|
|
end
|
|
end
|