Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed error in partner custom form #2223

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 46 additions & 45 deletions app/helpers/custom_field_properties_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def mapping_custom_field_values(field_props)

def display_custom_formable_name(klass_object)
case klass_object.class.name.downcase
when 'family', 'community'
when 'family', 'community', 'partner'
klass_object.display_name
when 'user'
klass_object.name
Expand All @@ -81,61 +81,62 @@ def display_custom_formable_lebel(klass_object)
end

private
def form_builder_selection_options_custom_form(custom_field)
field_types = group_field_types_custom_form(custom_field)
@select_field_custom_form = field_types["select"]
@checkbox_field_custom_form = field_types["checkbox-group"]
@radio_field_custom_form = field_types["radio-group"]
end

def group_field_types_custom_form(custom_field)
group_field_types = Hash.new{|h,k| h[k] = []}
group_by_option_type_label = form_builder_group_by_options_type_label_custom_form(custom_field)
group_selection_field_types = group_selection_field_types_custom_form(custom_field)
if group_selection_field_types.present?
group_selection_field_types&.compact.each do |selection_field_types|
group_by_option_type_label.each do |type,labels|
next unless labels.present?
labels.each do |label|
next if selection_field_types[label].blank?
group_field_types[type] << selection_field_types[label]
end
def form_builder_selection_options_custom_form(custom_field)
field_types = group_field_types_custom_form(custom_field)
@select_field_custom_form = field_types['select']
@checkbox_field_custom_form = field_types['checkbox-group']
@radio_field_custom_form = field_types['radio-group']
end

def group_field_types_custom_form(custom_field)
group_field_types = Hash.new { |h, k| h[k] = [] }
group_by_option_type_label = form_builder_group_by_options_type_label_custom_form(custom_field)
group_selection_field_types = group_selection_field_types_custom_form(custom_field)
if group_selection_field_types.present?
group_selection_field_types&.compact.each do |selection_field_types|
group_by_option_type_label.each do |type, labels|
next unless labels.present?
labels.each do |label|
next if selection_field_types[label].blank?
group_field_types[type] << selection_field_types[label]
end
end
end
group_field_types = group_field_types.transform_values(&:flatten)
group_field_types.transform_values(&:uniq)
end
group_field_types = group_field_types.transform_values(&:flatten)
group_field_types.transform_values(&:uniq)
end

def group_selection_field_types_custom_form(custom_field)
group_value_field_types = []
custom_field.custom_field_properties.each do |custom_field_property|
group_value_field_types << custom_field_property.properties if custom_field_property.properties.present?
end
return group_value_field_types
def group_selection_field_types_custom_form(custom_field)
group_value_field_types = []
custom_field.custom_field_properties.each do |custom_field_property|
group_value_field_types << custom_field_property.properties if custom_field_property.properties.present?
end
return group_value_field_types
end

def form_builder_group_by_options_type_label_custom_form(custom_field)
group_options_type_label = Hash.new{|h,k| h[k] = []}
form_builder_option = form_builder_options_custom_form(custom_field)
form_builder_option["type"].each_with_index do |type_option,i|
group_options_type_label[type_option] << form_builder_option["label"][i]
end
group_options_type_label
def form_builder_group_by_options_type_label_custom_form(custom_field)
group_options_type_label = Hash.new { |h, k| h[k] = [] }
form_builder_option = form_builder_options_custom_form(custom_field)
form_builder_option['type'].each_with_index do |type_option, i|
group_options_type_label[type_option] << form_builder_option['label'][i]
end
group_options_type_label
end

def form_builder_options_custom_form(custom_field)
form_builder_options = Hash.new{|h,k| h[k] = []}
custom_field.fields.each do |field|
field.each do |k,v|
next unless k[/^(type|label)$/i]
form_builder_options[k] << v
end
def form_builder_options_custom_form(custom_field)
form_builder_options = Hash.new { |h, k| h[k] = [] }
custom_field.fields.each do |field|
field.each do |k, v|
next unless k[/^(type|label)$/i]
form_builder_options[k] << v
end
return form_builder_options
end
return form_builder_options
end

def is_custom_field_property_editable?(custom_field_property)
Organization.ratanak? && !current_user.admin? ? custom_field_editable?(@custom_field) && custom_field_property.is_editable? : custom_field_editable?(@custom_field)
end
def is_custom_field_property_editable?(custom_field_property)
Organization.ratanak? && !current_user.admin? ? custom_field_editable?(@custom_field) && custom_field_property.is_editable? : custom_field_editable?(@custom_field)
end
end
29 changes: 16 additions & 13 deletions app/models/partner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ class Partner < ActiveRecord::Base

has_paper_trail

scope :name_like, ->(value) { where('name iLIKE ?', "%#{value.squish}%") }
scope :contact_person_name_like, ->(value) { where('contact_person_name iLIKE ?', "%#{value.squish}%") }
scope :contact_person_email_like, ->(value) { where('contact_person_email iLIKE ?', "%#{value.squish}%") }
scope :contact_person_mobile_like, ->(value) { where('contact_person_mobile iLIKE ?', "%#{value.squish}%") }
scope :affiliation_like, ->(value) { where('affiliation iLIKE ?', "%#{value.squish}%") }
scope :engagement_like, ->(value) { where('engagement iLIKE ?', "%#{value.squish}%") }
scope :background_like, ->(value) { where('background iLIKE ?', "%#{value.squish}%") }
scope :address_like, ->(value) { where('address iLIKE ?', "%#{value.squish}%") }
scope :organization_type_are, -> { joins(:organization_type).order('lower(organization_types.name)').pluck('organization_types.name', 'organization_types.id').uniq }
scope :province_are, -> { joins(:province).pluck('provinces.name', 'provinces.id').uniq }
scope :NGO, -> { joins(:organization_type).where(organization_types: { name: 'NGO' }) }
scope :local_goverment, -> { joins(:organization_type).where(organization_types: { name: 'Local Goverment' }) }
scope :church, -> { joins(:organization_type).where(organization_types: { name: 'Church' }) }
scope :name_like, -> (value) { where('name iLIKE ?', "%#{value.squish}%") }
scope :contact_person_name_like, -> (value) { where('contact_person_name iLIKE ?', "%#{value.squish}%") }
scope :contact_person_email_like, -> (value) { where('contact_person_email iLIKE ?', "%#{value.squish}%") }
scope :contact_person_mobile_like, -> (value) { where('contact_person_mobile iLIKE ?', "%#{value.squish}%") }
scope :affiliation_like, -> (value) { where('affiliation iLIKE ?', "%#{value.squish}%") }
scope :engagement_like, -> (value) { where('engagement iLIKE ?', "%#{value.squish}%") }
scope :background_like, -> (value) { where('background iLIKE ?', "%#{value.squish}%") }
scope :address_like, -> (value) { where('address iLIKE ?', "%#{value.squish}%") }
scope :organization_type_are, -> { joins(:organization_type).order('lower(organization_types.name)').pluck('organization_types.name', 'organization_types.id').uniq }
scope :province_are, -> { joins(:province).pluck('provinces.name', 'provinces.id').uniq }
scope :NGO, -> { joins(:organization_type).where(organization_types: { name: 'NGO' }) }
scope :local_goverment, -> { joins(:organization_type).where(organization_types: { name: 'Local Goverment' }) }
scope :church, -> { joins(:organization_type).where(organization_types: { name: 'Church' }) }

def contact_person_name=(contact_person_name)
write_attribute(:contact_person_name, contact_person_name.try(:strip))
end

def display_name
"#{name} || Partner ##{id}"
end
end