Skip to content

Commit

Permalink
use Wice::ConfigurationProvider.value_for
Browse files Browse the repository at this point in the history
  • Loading branch information
leikind committed Aug 27, 2015
1 parent 5660bc0 commit 83c2d7c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
5 changes: 3 additions & 2 deletions lib/generators/wice_grid/templates/wice_grid_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@

# The name of the page method (should correspond to Kaminari.config.page_method_name)
Wice::Defaults::PAGE_METHOD_NAME = :page

# by default Wice-Grid always use unscoped,set to true to force use of default_scope by default instead

# By default ActiveRecord calls are always executed inside Model.unscoped{}.
# Setting <tt>USE_DEFAULT_SCOPE</tt> to true will use the default scope for all queries.
Wice::Defaults::USE_DEFAULT_SCOPE = false

end
6 changes: 3 additions & 3 deletions lib/wice/active_record_column_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ def wg_generate_conditions #:nodoc:

filter_type = case column_type
when :date
Wice::Defaults::DEFAULT_FILTER_FOR_DATE
ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATE)
when :datetime
Wice::Defaults::DEFAULT_FILTER_FOR_DATETIME
ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATETIME)
when :timestamp
Wice::Defaults::DEFAULT_FILTER_FOR_DATETIME
ConfigurationProvider.value_for(:DEFAULT_FILTER_FOR_DATETIME)
else
column_type
end
Expand Down
14 changes: 7 additions & 7 deletions lib/wice/columns/column_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def generate_conditions(table_alias, opts) #:nodoc:
string_matching_operator = ::Wice.get_string_matching_operators(@column_wrapper.model)

comparator = if string_matching_operator == 'CI_LIKE'
" #{negation} UPPER(#{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name}) LIKE UPPER(?)"
else
" #{negation} #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} #{string_matching_operator} ?"
end
[
comparator, '%' + string_fragment + '%'
]
" #{negation} UPPER(#{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name}) LIKE UPPER(?)"
else
" #{negation} #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} #{string_matching_operator} ?"
end

[ comparator, '%' + string_fragment + '%' ]

end
end
end
Expand Down
8 changes: 4 additions & 4 deletions lib/wice/grid_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,24 +278,24 @@ def action_column(opts = {}, &block)

def column(opts = {}, &block)
options = {
allow_multiple_selection: Defaults::ALLOW_MULTIPLE_SELECTION,
allow_multiple_selection: ConfigurationProvider.value_for(:ALLOW_MULTIPLE_SELECTION),
assoc: nil,
attribute: nil,
auto_reload: Defaults::AUTO_RELOAD,
auto_reload: ConfigurationProvider.value_for(:AUTO_RELOAD),
boolean_filter_false_label: NlMessage['boolean_filter_false_label'],
boolean_filter_true_label: NlMessage['boolean_filter_true_label'],
class: nil,
custom_filter: nil,
detach_with_id: nil,
filter: true,
filter_all_label: Defaults::CUSTOM_FILTER_ALL_LABEL,
filter_all_label: ConfigurationProvider.value_for(:CUSTOM_FILTER_ALL_LABEL),
filter_type: nil,
html: {},
in_csv: true,
in_html: true,
model: nil, # will throw an exception with instructions
name: '',
negation: Defaults::NEGATION_IN_STRING_FILTERS,
negation: ConfigurationProvider.value_for(:NEGATION_IN_STRING_FILTERS),
ordering: true,
table_alias: nil
}
Expand Down
2 changes: 1 addition & 1 deletion lib/wice/wice_grid_misc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def get_query_store_model #:nodoc:

def get_string_matching_operators(model) #:nodoc:
if defined?(Wice::Defaults::STRING_MATCHING_OPERATORS) && (ops = Wice::ConfigurationProvider.value_for(:STRING_MATCHING_OPERATORS)) &&
ops.is_a?(Hash) && (str_matching_operator = ops[model.connection.class.to_s])
ops.is_a?(Hash) && (str_matching_operator = ops[model.connection.class.to_s])
str_matching_operator
else
Wice::ConfigurationProvider.value_for(:STRING_MATCHING_OPERATOR)
Expand Down
22 changes: 10 additions & 12 deletions lib/wice_grid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,23 @@ def initialize(klass_or_relation, controller, opts = {}) #:nodoc:
@options = {
conditions: nil,
csv_file_name: nil,
csv_field_separator: Defaults::CSV_FIELD_SEPARATOR,
csv_field_separator: ConfigurationProvider.value_for(:CSV_FIELD_SEPARATOR),
custom_order: {},
enable_export_to_csv: Defaults::ENABLE_EXPORT_TO_CSV,
enable_export_to_csv: ConfigurationProvider.value_for(:ENABLE_EXPORT_TO_CSV),
group: nil,
include: nil,
joins: nil,
name: Defaults::GRID_NAME,
name: ConfigurationProvider.value_for(:GRID_NAME),
order: nil,
order_direction: Defaults::ORDER_DIRECTION,
order_direction: ConfigurationProvider.value_for(:ORDER_DIRECTION),
page: 1,
page_method_name: Defaults::PAGE_METHOD_NAME,
per_page: Defaults::PER_PAGE,
page_method_name: ConfigurationProvider.value_for(:PAGE_METHOD_NAME),
per_page: ConfigurationProvider.value_for(:PER_PAGE),
saved_query: nil,
total_entries: nil,
with_paginated_resultset: nil,
with_resultset: nil,
use_default_scope: Defaults::USE_DEFAULT_SCOPE
use_default_scope: ConfigurationProvider.value_for(:USE_DEFAULT_SCOPE)
}
rescue NameError
raise NameError.new('A constant is missing in wice_grid_config.rb: ' + $ERROR_INFO.message +
Expand Down Expand Up @@ -626,13 +626,11 @@ def load_query(query_id) #:nodoc:
query
end

def use_default_or_unscoped
if @options[:use_default_scope] == true
def use_default_or_unscoped #:nodoc:
if @options[:use_default_scope]
yield
else
@klass.unscoped do
yield
end
@klass.unscoped { yield }
end
end

Expand Down

0 comments on commit 83c2d7c

Please sign in to comment.