Class: FiltrosPersonalizados::FieldsPadroes::Integer
- Inherits:
-
Field
- Object
- Field
- FiltrosPersonalizados::FieldsPadroes::Integer
show all
- Defined in:
- lib/filtros_personalizados/fields_padroes/integer.rb
Constant Summary
Constants inherited
from Field
Field::DIFERENTE, Field::ENTRE, Field::IGUAL, Field::MAIOR_QUE, Field::MENOR_QUE, Field::NENHUM, Field::TODOS
Instance Attribute Summary
Attributes inherited from Field
#association, #autocomplete_path, #collection, #collection_id, #collection_name, #field_name, #field_type, #is_open, #noactions, #options, #partial_name, #relation, #tipo_selecionado, #values
Instance Method Summary
collapse
Methods inherited from Field
#caption, #initialize
Instance Method Details
#acoes_disponiveis ⇒ Object
5
6
7
|
# File 'lib/filtros_personalizados/fields_padroes/integer.rb', line 5
def acoes_disponiveis
[IGUAL, DIFERENTE, ENTRE, NENHUM, TODOS] - self.noactions
end
|
#file ⇒ Object
20
21
22
|
# File 'lib/filtros_personalizados/fields_padroes/integer.rb', line 20
def file
"personalizaveis/#{ self.partial_name || 'integer'}.html.erb"
end
|
#selecao ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/filtros_personalizados/fields_padroes/integer.rb', line 24
def selecao
aux = ''
if collection.present? && ![NENHUM, TODOS].include?(self.tipo_selecionado)
aux += self.tipo_selecionado.to_s.downcase
collection.where(collection_id.to_s => values).each do |f|
aux += ', ' if aux != self.tipo_selecionado.to_s.downcase
aux += " #{f.send(collection_name)}"
end
elsif self.association.present? && [IGUAL, DIFERENTE].include?(self.tipo_selecionado)
aux = case self.tipo_selecionado
when IGUAL then self.values.present? ? " #{IGUAL.downcase} #{self.association.to_selecao(self.values)}" : ""
when DIFERENTE then self.values.present? ? " #{DIFERENTE.downcase} #{self.association.to_selecao(self.values)}" : ""
else ""
end
else
aux = case self.tipo_selecionado
when IGUAL then self.values.present? ? " #{IGUAL.downcase} #{self.values.first}" : ""
when DIFERENTE then self.values.present? ? " #{DIFERENTE.downcase} #{self.values.first}" : ""
when ENTRE then self.values.present? ? " #{ENTRE.downcase} #{values.first} e #{values.last}" : ""
when NENHUM then NENHUM.downcase
when TODOS then TODOS.downcase
else ""
end
end
aux.present? ? "#{self.caption}: #{aux}" : ""
end
|
#where ⇒ Object
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/filtros_personalizados/fields_padroes/integer.rb', line 9
def where
case self.tipo_selecionado
when IGUAL then self.values.present? ? "#{self.relation}.#{self.field_name} in (#{values.join(',')})" : ""
when DIFERENTE then self.values.present? ? "(#{self.relation}.#{self.field_name} not in (#{values.join(',')}) OR #{self.relation}.#{self.field_name} IS NULL)" : ""
when ENTRE then self.values.present? ? "#{self.relation}.#{self.field_name} between #{values.first} and #{values.last}" : ""
when NENHUM then "#{self.relation}.#{self.field_name} isnull "
when TODOS then "#{self.relation}.#{self.field_name} notnull "
else ""
end
end
|