Module: Wice

Defined in:
lib/wice/columns.rb,
lib/wice_grid.rb,
lib/wice/grid_renderer.rb,
lib/wice/wice_grid_misc.rb,
lib/wice/grid_output_buffer.rb,
lib/wice/wice_grid_core_ext.rb,
lib/wice/table_column_matrix.rb,
lib/wice/columns/column_float.rb,
lib/wice/columns/column_range.rb,
lib/wice/wice_grid_controller.rb,
lib/wice/columns/column_action.rb,
lib/wice/columns/column_string.rb,
lib/wice/wice_grid_spreadsheet.rb,
lib/wice/columns/column_boolean.rb,
lib/wice/columns/column_integer.rb,
lib/wice/helpers/bs_calendar_helpers.rb,
lib/wice/helpers/js_calendar_helpers.rb,
lib/wice/active_record_column_wrapper.rb,
lib/wice/columns/column_custom_dropdown.rb,
lib/wice/columns/column_processor_index.rb,
lib/wice/helpers/wice_grid_view_helpers.rb,
lib/wice/columns/column_html5_datepicker.rb,
lib/wice/columns/column_jquery_datepicker.rb,
lib/wice/columns/column_rails_date_helper.rb,
lib/wice/columns/common_date_datetime_mixin.rb,
lib/wice/columns/column_bootstrap_datepicker.rb,
lib/wice/helpers/wice_grid_misc_view_helpers.rb,
lib/wice/columns/column_rails_datetime_helper.rb,
lib/wice/columns/common_js_date_datetime_mixin.rb,
lib/wice/wice_grid_serialized_queries_controller.rb,
lib/wice/helpers/wice_grid_serialized_queries_view_helpers.rb,
lib/wice/columns/common_standard_helper_date_datetime_mixin.rb,
lib/wice/columns/common_js_date_datetime_conditions_generator_mixin.rb,
lib/wice/columns/common_rails_date_datetime_conditions_generator_mixin.rb

Overview

:nodoc:

Defined Under Namespace

Modules: BsCalendarHelpers, Columns, ConfigurationProvider, Controller, Defaults, ExceptionsMixin, GridTools, GridViewHelper, JsCalendarHelpers, NlMessage, SerializedQueriesControllerMixin, WgArray, WgEnumerable, WgHash, WiceGridExtentionToActiveRecordColumn Classes: ActiveRecordColumnWrapper, GridOutputBuffer, GridRenderer, Spreadsheet, TableColumnMatrix, WiceGrid, WiceGridArgumentError, WiceGridEngine, WiceGridException, WiceGridMissingConfigurationConstantException

Constant Summary collapse

@@model_validated =

a flag storing whether the saved query class is a valid storage for saved queries

false

Class Method Summary collapse

Class Method Details

.assoc_list_to_hash(assocs) ⇒ Object

:nodoc:



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/wice/wice_grid_misc.rb', line 7

def assoc_list_to_hash(assocs) #:nodoc:
  head = assocs[0]
  tail = assocs[1..-1]

  if tail.blank?
    head
  elsif tail.size == 1
    {head => tail[0]}
  else
    {head => assoc_list_to_hash(tail)}
  end
end

.build_includes(existing_includes, new_assocs) ⇒ Object

:nodoc:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/wice/wice_grid_misc.rb', line 20

def build_includes(existing_includes, new_assocs) #:nodoc:
  new_includes = if new_assocs.blank?
    existing_includes
  else
    existing_includes = if existing_includes.is_a?(Symbol)
      [existing_includes]
    elsif existing_includes.nil?
      []
    else
      existing_includes
    end

    assocs_as_hash = assoc_list_to_hash(new_assocs)
    build_includes_int(existing_includes, assocs_as_hash)
  end

  if new_includes.is_a?(Array) && new_includes.size == 1
    new_includes[0]
  else
    new_includes
  end
end

.build_includes_includes_is_array(includes, assocs) ⇒ Object

:nodoc:



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/wice/wice_grid_misc.rb', line 79

def build_includes_includes_is_array(includes, assocs) #:nodoc:

  hash_keys = Hash[
    *(
      includes
      .each_with_index
      .to_a
      .select{ |e, _idx| e.is_a?(Hash)}
      .map{ |hash, idx| [ hash.keys[0], idx ] }
      .flatten
    )
  ]

  key_to_search, finished = if assocs.is_a?(Hash)
    [assocs.keys[0], false]
  else
    [assocs, true]
  end

  if idx = includes.index(key_to_search)
    if finished #  [:a, :b, :c]  vs  :a
      includes
    else        #  [:a, :b, :c]  vs  {:a => x}
      includes[idx] = assocs
      includes
    end

  elsif hash_keys.key?(key_to_search)
    if finished # [{a: :x}, :b, :c, :d, :e] vs :a
      includes
    else
      hash_idx = hash_keys[key_to_search]
      assocs_value = assocs[key_to_search]
      includes[hash_idx] = build_includes_int(includes[hash_idx], assocs_value)
      includes
    end

  else  # [:a, :b, :c]  vs  :x
        # [:a, :b, :c]  vs  {:x => y}
    includes + [assocs]
  end

end

.build_includes_includes_is_hash(includes, assocs) ⇒ Object

TODO: refactor



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/wice/wice_grid_misc.rb', line 52

def build_includes_includes_is_hash(includes, assocs) #:nodoc:

  includes_key   = includes.keys[0]
  includes_value = includes.values[0]

  if assocs.is_a?(Hash)
    assocs_key   = assocs.keys[0]
    assocs_value = assocs.values[0]

    if includes_value.is_a?(Symbol) && includes_value == assocs_key
      {includes_key => assocs}
    elsif includes_value.is_a?(Hash)
      if includes_value.keys[0] == assocs_key
        if includes_value.values[0] == assocs_value
          {includes_key => assocs}
        else
          {includes_key => [includes_value.values[0], assocs_value]}
        end
      end
    end
  elsif includes_value == assocs
    {includes_key => assocs}
  else
    includes
  end
end

.build_includes_int(includes, assocs) ⇒ Object

:nodoc:



43
44
45
46
47
48
49
# File 'lib/wice/wice_grid_misc.rb', line 43

def build_includes_int(includes, assocs) #:nodoc:
  if includes.is_a?(Array)
    build_includes_includes_is_array(includes, assocs)
  elsif includes.is_a?(Hash)
    build_includes_includes_is_hash(includes, assocs)
  end
end

.define_routes(map, controller) ⇒ Object

Used in routes.rb to define routes to the query processing controller. Parameters:

  • map - the context of the routes execution (instance of ActionDispatch::Routing::Mapper). Normally use self for the first argument: Wice::define_routes(self, 'queries')

  • controller - name of the query processing controller, i.e. 'queries' if the controller is QueriesController .

Read section “Saving Queries How-To” in README for more details.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/wice/wice_grid_serialized_queries_controller.rb', line 9

def define_routes(map, controller)
  controller = controller.to_s

  map.post '/wice_grid_serialized_queries/:grid_name',
           to: "#{controller}#create_saved_query",
           as: 'create_serialized_query'

  map.post '/wice_grid_serialized_queries/:grid_name/:id',
           to: "#{controller}#delete_saved_query",
           as: 'delete_serialized_query'
end

.deprecated_call(old_name, new_name, opts) ⇒ Object

:nodoc:



153
154
155
156
157
158
159
# File 'lib/wice/wice_grid_misc.rb', line 153

def deprecated_call(old_name, new_name, opts) #:nodoc:
  if opts[old_name] && !opts[new_name]
    opts[new_name] = opts[old_name]
    opts.delete(old_name)
    STDERR.puts "WiceGrid: Parameter :#{old_name} is deprecated, use :#{new_name} instead!"
  end
end

.get_query_store_modelObject

Retrieves and constantizes (if needed ) the Query Store model



136
137
138
139
140
141
142
# File 'lib/wice/wice_grid_misc.rb', line 136

def get_query_store_model #:nodoc:
  query_store_model = Wice::ConfigurationProvider.value_for(:QUERY_STORE_MODEL)
  query_store_model = query_store_model.constantize if query_store_model.is_a? String
  raise ::Wice::WiceGridArgumentError.new('Defaults::QUERY_STORE_MODEL must be an ActiveRecord class or a string which can be constantized to an ActiveRecord class') unless query_store_model.is_a? Class
  validate_query_model(query_store_model) unless @@model_validated
  query_store_model
end

.get_string_matching_operators(model) ⇒ Object

:nodoc:



144
145
146
147
148
149
150
151
# File 'lib/wice/wice_grid_misc.rb', line 144

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])
    str_matching_operator
  else
    Wice::ConfigurationProvider.value_for(:STRING_MATCHING_OPERATOR)
  end
end

.log(message) ⇒ Object

:nodoc:



161
162
163
# File 'lib/wice/wice_grid_misc.rb', line 161

def log(message) #:nodoc:
  ActiveRecord::Base.logger.info('WiceGrid: ' + message) if ActiveRecord::Base.logger
end

.on_action_view_loadObject

:nodoc:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/wice_grid.rb', line 30

def self.on_action_view_load #:nodoc:
  ::ActionView::Base.class_eval { include Wice::GridViewHelper }
  [ActionView::Helpers::AssetTagHelper,
   ActionView::Helpers::TagHelper,
   ActionView::Helpers::JavaScriptHelper,
   ActionView::Helpers::FormTagHelper].each do |m|
    JsCalendarHelpers.send(:include, m)
  end

  Columns.load_column_processors
  require 'wice/wice_grid_serialized_query.rb'

  # It is here only because of this: https://github.com/amatsuda/kaminari/pull/267
  require 'wice/kaminari_monkey_patching.rb'

end

.validate_query_model(query_store_model) ⇒ Object

checks whether the class is a valid storage for saved queries



124
125
126
127
128
129
130
131
132
133
# File 'lib/wice/wice_grid_misc.rb', line 124

def validate_query_model(query_store_model)  #:nodoc:
  unless query_store_model.respond_to?(:list)
    raise ::Wice::WiceGridArgumentError.new("Model for saving queries #{query_store_model.class.name} is invalid - there is no class method #list defined")
  end
  arit = query_store_model.method(:list).arity
  unless arit == 2
    raise ::Wice::WiceGridArgumentError.new("Method list in the model for saving queries #{query_store_model.class.name} has wrong arity - it should be 2 instead of #{arit}")
  end
  @@model_validated = true
end