Permalink
Browse files

Merge branch 'master' of github.com:fesplugas/typus

  • Loading branch information...
2 parents 86dc0b4 + 74cbef2 commit 7e51a28213b017e82cd893c94c3d5ae4dba276d5 Francesc Esplugas committed Feb 9, 2010
Showing with 23 additions and 23 deletions.
  1. +23 −23 lib/typus/active_record.rb
@@ -163,15 +163,13 @@ def typus_order_by
fields = typus_defaults_for(:order_by)
- order = if fields.empty?
- "#{table_name}.id ASC"
- else
- fields.map do |field|
- field.include?('-') ? "#{table_name}.#{field.delete('-')} DESC" : "#{table_name}.#{field} ASC"
- end.join(', ')
- end
-
- return order
+ if fields.empty?
+ "#{table_name}.id ASC"
+ else
+ fields.map do |field|
+ field.include?('-') ? "#{table_name}.#{field.delete('-')} DESC" : "#{table_name}.#{field} ASC"
+ end.join(', ')
+ end
end
@@ -206,9 +204,18 @@ def typus_date_format(attribute = :default)
# We are able to define which template to use to render the attribute
# within the form
def typus_template(attribute)
- Typus::Configuration.config[name]['fields']['options']['templates'][attribute.to_s] rescue nil
+ Typus::Configuration.config[name]['fields']['options']['templates'][attribute.to_s]
+ rescue
+ nil
end
+ ##
+ # Sidebar filters:
+ #
+ # - Booleans: true, false
+ # - Datetime: today, last_few_days, last_7_days, last_30_days
+ # - Integer & String: *_id and "selectors" (p.ej. category_id)
+ #
def build_conditions(params)
conditions, joins = merge_conditions, []
@@ -228,32 +235,25 @@ def build_conditions(params)
filter_type = model_fields[key.to_sym] || model_relationships[key.to_sym]
- ##
- # Sidebar filters:
- #
- # - Booleans: true, false
- # - Datetime: today, last_few_days, last_7_days, last_30_days
- # - Integer & String: *_id and "selectors" (p.ej. category_id)
- #
case filter_type
when :boolean
condition = { key => (value == 'true') ? true : false }
conditions = merge_conditions(conditions, condition)
when :datetime
interval = case value
- when 'today' then Time.new.midnight..Time.new.midnight.tomorrow
+ when 'today' then Time.new.midnight..Time.new.midnight.tomorrow
when 'last_few_days' then 3.days.ago.midnight..Time.new.midnight.tomorrow
- when 'last_7_days' then 6.days.ago.midnight..Time.new.midnight.tomorrow
- when 'last_30_days' then Time.new.midnight.last_month..Time.new.midnight.tomorrow
+ when 'last_7_days' then 6.days.ago.midnight..Time.new.midnight.tomorrow
+ when 'last_30_days' then Time.new.midnight.last_month..Time.new.midnight.tomorrow
end
condition = ["#{key} BETWEEN ? AND ?", interval.first.to_s(:db), interval.last.to_s(:db)]
conditions = merge_conditions(conditions, condition)
when :date
interval = case value
- when 'today' then nil
+ when 'today' then nil
when 'last_few_days' then 3.days.ago.to_date..Date.tomorrow
- when 'last_7_days' then 6.days.ago.midnight..Date.tomorrow
- when 'last_30_days' then (Date.today << 1)..Date.tomorrow
+ when 'last_7_days' then 6.days.ago.midnight..Date.tomorrow
+ when 'last_30_days' then (Date.today << 1)..Date.tomorrow
end
if interval
condition = ["#{key} BETWEEN ? AND ?", interval.first.to_s, interval.last.to_s]

0 comments on commit 7e51a28

Please sign in to comment.