Permalink
Browse files

Remove trailing whitespace

  • Loading branch information...
kaapa committed Jul 3, 2011
1 parent dd5d03e commit cc9c2fb96a8e5e6524fe9c01890a502ff27475bd
Showing with 169 additions and 173 deletions.
  1. +37 −37 app/controllers/rails_admin/main_controller.rb
  2. +9 −9 app/helpers/rails_admin/application_helper.rb
  3. +2 −2 app/models/rails_admin/history.rb
  4. +1 −1 config/initializers/active_record_extensions.rb
  5. +2 −2 config/routes.rb
  6. +1 −1 lib/rails_admin/abstract_model.rb
  7. +4 −4 lib/rails_admin/adapters/active_record.rb
  8. +4 −4 lib/rails_admin/config/fields/association.rb
  9. +12 −12 lib/rails_admin/config/fields/base.rb
  10. +1 −1 lib/rails_admin/config/fields/group.rb
  11. +4 −4 lib/rails_admin/config/fields/types/belongs_to_association.rb
  12. +1 −1 lib/rails_admin/config/fields/types/datetime.rb
  13. +4 −4 lib/rails_admin/config/fields/types/enum.rb
  14. +2 −2 lib/rails_admin/config/fields/types/has_many_association.rb
  15. +1 −1 lib/rails_admin/config/fields/types/has_one_association.rb
  16. +1 −1 lib/rails_admin/config/fields/types/integer.rb
  17. +3 −3 lib/rails_admin/config/fields/types/paperclip_file.rb
  18. +3 −3 lib/rails_admin/config/fields/types/polymorphic_association.rb
  19. +1 −1 lib/rails_admin/config/fields/types/string.rb
  20. +1 −1 lib/rails_admin/config/fields/types/text.rb
  21. +2 −2 lib/rails_admin/config/fields/types/virtual.rb
  22. +5 −5 lib/rails_admin/config/has_fields.rb
  23. +2 −2 lib/rails_admin/config/model.rb
  24. +2 −2 lib/rails_admin/config/sections/list.rb
  25. +2 −2 lib/rails_admin/support/core_extensions.rb
  26. +14 −14 lib/rails_admin/support/csv_converter.rb
  27. +2 −2 spec/dummy_app/app/models/player.rb
  28. +1 −1 spec/dummy_app/app/models/team.rb
  29. +1 −1 spec/lib/uninstall_spec.rb
  30. +1 −1 spec/requests/basic/bulk_action/rails_admin_basic_bulk_action_spec.rb
  31. +2 −2 spec/requests/basic/create/rails_admin_basic_create_spec.rb
  32. +9 −9 spec/requests/basic/export/rails_admin_basic_export_spec.rb
  33. +9 −9 spec/requests/basic/list/rails_admin_basic_list_spec.rb
  34. +20 −22 spec/requests/config/edit/rails_admin_config_edit_spec.rb
  35. +3 −3 spec/requests/config/navigation/rails_admin_config_navigation_spec.rb
  36. +0 −2 spec/requests/rails_admin_spec.rb
@@ -34,13 +34,13 @@ def index
def list
@authorization_adapter.authorize(:list, @abstract_model) if @authorization_adapter
-
+
@page_type = @abstract_model.pretty_name.downcase
@page_name = t("admin.list.select", :name => @model_config.label.downcase)
-
+
@objects, @current_page, @page_count, @record_count = list_entries
@schema ||= { :only => @model_config.list.visible_fields.map {|f| f.name } }
-
+
respond_to do |format|
format.html
format.js { render :layout => 'rails_admin/plain.html.erb' }
@@ -60,14 +60,14 @@ def list
output = @objects.to_xml(@schema)
if params[:send_data]
send_data output, :filename => "#{params[:model_name]} #{DateTime.now.strftime("%Y-%m-%d %H:%M:%S")}.xml"
- else
+ else
render :xml => output
end
end
format.csv do
header, encoding, output = CSVConverter.new(@objects, @schema).to_csv(params[:csv_options])
if params[:send_data]
- send_data output,
+ send_data output,
:type => "text/csv; charset=#{encoding}; #{"header=present" if header}",
:disposition => "attachment; filename=#{params[:model_name]} #{DateTime.now.strftime("%Y-%m-%d %H:%M:%S")}.csv"
else
@@ -176,20 +176,20 @@ def destroy
@authorization_adapter.authorize(:destroy, @abstract_model, @object) if @authorization_adapter
@object = @object.destroy
-
+
AbstractHistory.create_history_item("Destroyed #{@model_config.with(:object => @object).object_label}", @object, @abstract_model, _current_user)
redirect_to rails_admin_list_path(:model_name => @abstract_model.to_param), :notice => t("admin.flash.successful", :name => @model_config.label, :action => t("admin.actions.deleted"))
end
-
+
def export
# todo
# limitation: need to display at least one real attribute ('only') so that the full object doesn't get displayed, a way to fix this? maybe force :only => [""]
# model_config#with for :methods inside csv content? Perf-optimize it first? Optionnal? Right-now raw data is outputed.
# maybe
# n-levels (backend: possible with xml&json, frontend: not possible, injections check: quite easy)
@authorization_adapter.authorize(:export, @abstract_model) if @authorization_adapter
-
+
if format = params[:json] && :json || params[:csv] && :csv || params[:xml] && :xml
request.format = format
@schema = params[:schema].symbolize if params[:schema] # to_json and to_xml expect symbols for keys AND values.
@@ -198,37 +198,37 @@ def export
else
@page_name = t("admin.actions.export").capitalize + " " + @model_config.label.downcase
@page_type = @abstract_model.pretty_name.downcase
-
+
render :action => 'export'
end
end
-
+
def bulk_action
redirect_to rails_admin_list_path, :notice => t("admin.flash.noaction") and return if params[:bulk_ids].blank?
-
+
case params[:bulk_action]
when "delete" then bulk_delete
when "export" then export
else redirect_to(rails_admin_list_path(:model_name => @abstract_model.to_param), :notice => t("admin.flash.noaction"))
end
end
-
+
def bulk_delete
@authorization_adapter.authorize(:bulk_delete, @abstract_model) if @authorization_adapter
@page_name = t("admin.actions.delete").capitalize + " " + @model_config.label.downcase
@page_type = @abstract_model.pretty_name.downcase
-
+
@bulk_objects, @current_page, @page_count, @record_count = list_entries
-
+
render :action => 'bulk_delete'
end
def bulk_destroy
@authorization_adapter.authorize(:bulk_destroy, @abstract_model) if @authorization_adapter
-
+
scope = @authorization_adapter && @authorization_adapter.query(params[:action].to_sym, @abstract_model)
@destroyed_objects = @abstract_model.destroy(params[:bulk_ids], scope)
-
+
@destroyed_objects.each do |object|
message = "Destroyed #{@model_config.with(:object => object).object_label}"
AbstractHistory.create_history_item(message, object, @abstract_model, _current_user)
@@ -264,9 +264,9 @@ def get_sort_hash
params[:sort] ||= @model_config.list.sort_by.to_s
params[:sort_reverse] ||= 'false'
-
+
field = @model_config.list.fields.find{ |f| f.name.to_s == params[:sort] }
-
+
column = if field.nil? || field.sortable == true # use params[:sort] on the base table
"#{@abstract_model.model.table_name}.#{params[:sort]}"
elsif field.sortable == false # use default sort, asked field is not sortable
@@ -276,43 +276,43 @@ def get_sort_hash
else # use described column in the field conf.
"#{@abstract_model.model.table_name}.#{field.sortable}"
end
-
+
reversed_sort = (field ? field.sort_reverse? : @model_config.list.sort_reverse?)
{:sort => column, :sort_reverse => (params[:sort_reverse] == reversed_sort.to_s)}
end
def get_conditions_hash(query, filters)
-
+
# TODO for filtering engine
# use a hidden field to store serialized params and send them through post (pagination, export links, show all link, sort links)
# Tricky cases where:
# query can't be made on any of the avalaible attributes (will it happen a lot Error messages?)
# filter can't apply to the targetted attribute (should be sanitized front)
# extend engine to :
# belongs_to autocomplete id (optionnal)
-
+
# LATER
# find a way for complex request (OR/AND)?
# multiple words queries
- # find a way to force a column nonetheless?
-
+ # find a way to force a column nonetheless?
+
# TODO else
# searchable & filtering engine
# has_one ?
# polymorphic ?
-
-
+
+
return {} if query.blank? && filters.blank? # perf
-
+
@like_operator = "ILIKE" if ActiveRecord::Base.configurations[Rails.env]['adapter'] == "postgresql"
@like_operator ||= "LIKE"
-
+
query_statements = []
filters_statements = []
values = []
conditions = [""]
-
+
if query.present?
@queryable_fields = @model_config.list.fields.select(&:queryable?).map(&:searchable_columns).flatten
@queryable_fields.each do |field_infos|
@@ -323,12 +323,12 @@ def get_conditions_hash(query, filters)
end
end
end
-
+
unless query_statements.empty?
conditions[0] += " AND " unless conditions == [""]
conditions[0] += "(#{query_statements.join(" OR ")})" # any column field will do
end
-
+
if filters.present?
@filterable_fields = @model_config.list.fields.select(&:filterable?).inject({}){ |memo, field| memo[field.name] = field.searchable_columns; memo }
filters.each_pair do |field_name, filters_dump|
@@ -347,16 +347,16 @@ def get_conditions_hash(query, filters)
end
end
end
-
+
unless filters_statements.empty?
conditions[0] += " AND " unless conditions == [""]
conditions[0] += "#{filters_statements.join(" AND ")}" # filters should all be true
end
-
+
conditions += values.flatten
conditions != [""] ? { :conditions => conditions } : {}
end
-
+
def build_statement(column, type, value, operator)
case type
when :boolean
@@ -438,13 +438,13 @@ def check_for_cancel
def list_entries(other = {})
return [get_bulk_objects(params[:bulk_ids]), 1, 1, "unknown"] if params[:bulk_ids].present?
-
+
associations = @model_config.list.fields.select {|f| f.type == :belongs_to_association && !f.polymorphic? }.map {|f| f.association[:name] }
options = get_sort_hash.merge(get_conditions_hash(params[:query], params[:filters])).merge(other).merge(associations.empty? ? {} : { :include => associations })
scope = @authorization_adapter && @authorization_adapter.query(:list, @abstract_model)
current_page = (params[:page] || 1).to_i
-
+
if params[:all]
objects = @abstract_model.all(options, scope)
page_count = 1
@@ -472,7 +472,7 @@ def associations_hash
end
associations
end
-
+
def check_for_injections(schema)
check_injections_for(@model_config, (schema[:only] || []) + (schema[:methods] || []))
allowed_associations = @model_config.export.visible_fields.select{ |f| f.association? && !f.association[:options][:polymorphic] }.map(&:association)
@@ -483,7 +483,7 @@ def check_for_injections(schema)
check_injections_for(RailsAdmin.config(AbstractModel.new(associated_model)), (schema[:only] || []) + (schema[:methods] || []))
end
end
-
+
def check_injections_for(model_config, methods_name)
available_fields = model_config.export.visible_fields.select{ |f| !f.association? || f.association[:options][:polymorphic] }.map do |field|
if field.association? && field.association[:options][:polymorphic]
@@ -62,15 +62,15 @@ def javascript_fallback(primary, fallback, test)
end
html+"\n"
end
-
+
def action_button link, text, icon=nil, options={}
options.reverse_merge! :class => "button"
link_to link, options do
image = image_tag "/stylesheets/rails_admin/theme/activo/images/icons/#{icon}.png" if icon
[image, text].compact.join("\n").html_safe
end.html_safe
end
-
+
# the icon shown beside every entry in the list view
def action_icon link, icon, text
icon_path = "/stylesheets/rails_admin/theme/activo/images/icons/24/%s.png"
@@ -82,7 +82,7 @@ def action_icon link, icon, text
:onmouseover => (icon_change % "#{icon}-hover")
end.html_safe
end
-
+
# Used for the icons in the admins very top right.
def header_icon(image_name, title)
image_tag "/stylesheets/rails_admin/theme/activo/images/session/#{image_name}.png", :alt => title, :title => title
@@ -144,7 +144,7 @@ def paginate(current_page, page_count, options = {})
options[:remote] = true unless options.has_key?(:remote)
options[:page_param] ||= :page
options[:url] ||= {}
-
+
pages = {
:all => (1..page_count).to_a,
:left => [],
@@ -182,7 +182,7 @@ def paginate(current_page, page_count, options = {})
end
b = []
-
+
[pages[:left], pages[:center], pages[:right]].each do |p|
p.each do |page_number|
@@ -216,7 +216,7 @@ def home_link
t('home.name')
end
end
-
+
# Creative whitespace:
ViewType = Struct.new(:parent, :type, :authorization, :path_method)
VIEW_TYPES = {
@@ -230,7 +230,7 @@ def home_link
:list => ViewType.new(:dashboard, :model, :list),
:dashboard => ViewType.new
}
-
+
def breadcrumbs_for view, abstract_model_or_object
# create an array of all the names of the views we want breadcrumb links to
views = []
@@ -270,7 +270,7 @@ def breadcrumb_for view, abstract_model_or_object, active
abstract_model, object = abstract_model_and_object( abstract_model_or_object )
vt = VIEW_TYPES[view]
-
+
# TODO: write tests and enable authorization checking:
# if vt.authorization.nil? || authorized?(vt.authorization, abstract_model, object)
css_classes = []
@@ -284,7 +284,7 @@ def breadcrumb_for view, abstract_model_or_object, active
# end
end
-
+
end
end
@@ -12,12 +12,12 @@ def self.get_history_for_dates(mstart, mstop, ystart, ystop)
if mstart > mstop && mstart < 12
results = History.find_by_sql(["select count(*) as record_count, year, month from rails_admin_histories where month IN (?) and year = ? group by year, month",
((mstart + 1)..12).to_a, ystart])
- results_two = History.find_by_sql(["select count(*) as number, year, month from rails_admin_histories where month IN (?) and year = ? group by year, month",
+ results_two = History.find_by_sql(["select count(*) as number, year, month from rails_admin_histories where month IN (?) and year = ? group by year, month",
(1..mstop).to_a, ystop])
results.concat(results_two)
else
- results = History.find_by_sql(["select count(*) as record_count, year, month from rails_admin_histories where month IN (?) and year = ? group by year, month",
+ results = History.find_by_sql(["select count(*) as record_count, year, month from rails_admin_histories where month IN (?) and year = ? group by year, month",
((mstart == 12 ? 1 : mstart + 1)..mstop).to_a, ystop])
end
@@ -3,7 +3,7 @@ class ActiveRecord::Base
def rails_admin_default_object_label_method
"#{self.class.to_s} ##{self.try :id}"
end
-
+
def safe_send(value)
if self.attributes.find{ |k,v| k.to_s == value.to_s }
self.read_attribute(value)
View
@@ -10,8 +10,8 @@
match "/:model_name/:id", :to => :for_object, :as => "object"
end
end
-
- # Routes for rails_admin controller
+
+ # Routes for rails_admin controller
controller "main" do
match "/", :to => :index, :as => "dashboard"
get "/:model_name", :to => :list, :as => "list"
@@ -73,7 +73,7 @@ def initialize(model)
def model
@model_name.constantize
end
-
+
private
def self.superclasses(klass)
@@ -8,9 +8,9 @@ module ActiveRecord
DISABLED_COLUMN_TYPES = [:tsvector]
def self.extended(abstract_model)
-
- # ActiveRecord does not handle has_one relationships the way it does for has_many,
- # and does not create any association_id and association_id= methods.
+
+ # ActiveRecord does not handle has_one relationships the way it does for has_many,
+ # and does not create any association_id and association_id= methods.
# Added here for backward compatibility after a refactoring, but it does belong to ActiveRecord IMO.
# Support is hackish at best. Atomicity is respected for creation, but not while updating.
# It means a failed validation at update on the parent object could still modify target belongs_to foreign ids.
@@ -24,7 +24,7 @@ def self.extended(abstract_model)
end
end
end
-
+
def self.polymorphic_parents(name)
unless @polymorphic_parents
@polymorphic_parents = {}
Oops, something went wrong.

0 comments on commit cc9c2fb

Please sign in to comment.