Module: Binda::FieldGroupsHelper

Defined in:
app/helpers/binda/field_groups_helper.rb

Instance Method Summary collapse

Instance Method Details

#get_entries_numberObject

Retrieve the number of records present in the database for the current structure



29
30
31
32
33
34
35
36
# File 'app/helpers/binda/field_groups_helper.rb', line 29

def get_entries_number
  instance_type = @structure.instance_type
  if ['board', 'component'].include? instance_type
    "Binda::#{instance_type.classify}".constantize.where(structure_id:@structure.id).count 
  else
    0
  end
end

#get_form_field_group_urlObject

Returns the right path for “new” or “edit” action



5
6
7
8
# File 'app/helpers/binda/field_groups_helper.rb', line 5

def get_form_field_group_url
	return structure_field_groups_path if action_name == 'new'
	return structure_field_group_path  if action_name == 'edit'
end

#get_relationable_boards(field_setting) ⇒ Object

Get all boards related to a “relation” field setting



20
21
22
23
24
25
26
# File 'app/helpers/binda/field_groups_helper.rb', line 20

def get_relationable_boards(field_setting)
	if @instance.class.to_s == 'Binda::Component'
		Board.where(structure_id: Structure.where(id: field_setting.accepted_structure_ids))
	elsif @instance.class.to_s == 'Binda::Board' 
		Board.where(structure_id: Structure.where(id: field_setting.accepted_structure_ids)).where.not(id: @instance.id)
	end
end

#get_relationable_components(field_setting) ⇒ Object

Get all components related to a “relation” field setting



11
12
13
14
15
16
17
# File 'app/helpers/binda/field_groups_helper.rb', line 11

def get_relationable_components(field_setting)
	if @instance.class.to_s == 'Binda::Component'
		Component.where(structure_id: Structure.where(id: field_setting.accepted_structure_ids)).where.not(id: @instance.id)
	elsif @instance.class.to_s == 'Binda::Board' 
		Component.where(structure_id: Structure.where(id: field_setting.accepted_structure_ids))
	end
end