wice_grid 3.5.0 → 3.6.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.inch.yml +3 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +181 -0
  5. data/.travis.yml +22 -0
  6. data/{CHANGELOG → CHANGELOG.md} +95 -31
  7. data/Gemfile +4 -1
  8. data/README.md +1517 -0
  9. data/Rakefile +51 -7
  10. data/{SAVED_QUERIES_HOWTO.rdoc → SAVED_QUERIES_HOWTO.md} +34 -31
  11. data/TODO.md +16 -0
  12. data/lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb +4 -6
  13. data/lib/generators/wice_grid/install_generator.rb +2 -5
  14. data/lib/generators/wice_grid/templates/create_wice_grid_serialized_queries.rb +1 -0
  15. data/lib/generators/wice_grid/templates/wice_grid_config.rb +29 -34
  16. data/lib/wice/active_record_column_wrapper.rb +36 -17
  17. data/lib/wice/columns.rb +53 -52
  18. data/lib/wice/columns/column_action.rb +11 -13
  19. data/lib/wice/columns/column_boolean.rb +9 -11
  20. data/lib/wice/columns/column_bootstrap_datepicker.rb +48 -0
  21. data/lib/wice/columns/column_custom_dropdown.rb +22 -23
  22. data/lib/wice/columns/column_float.rb +2 -6
  23. data/lib/wice/columns/column_html5_datepicker.rb +31 -0
  24. data/lib/wice/columns/column_integer.rb +9 -13
  25. data/lib/wice/columns/column_jquery_datepicker.rb +49 -0
  26. data/lib/wice/columns/column_processor_index.rb +18 -13
  27. data/lib/wice/columns/column_rails_date_helper.rb +41 -0
  28. data/lib/wice/columns/column_rails_datetime_helper.rb +40 -0
  29. data/lib/wice/columns/column_range.rb +7 -11
  30. data/lib/wice/columns/column_string.rb +24 -20
  31. data/lib/wice/columns/common_date_datetime_mixin.rb +20 -0
  32. data/lib/wice/columns/common_js_date_datetime_conditions_generator_mixin.rb +39 -0
  33. data/lib/wice/columns/common_js_date_datetime_mixin.rb +15 -0
  34. data/lib/wice/columns/{column_date.rb → common_rails_date_datetime_conditions_generator_mixin.rb} +4 -22
  35. data/lib/wice/columns/common_standard_helper_date_datetime_mixin.rb +22 -0
  36. data/lib/wice/grid_output_buffer.rb +19 -10
  37. data/lib/wice/grid_renderer.rb +146 -85
  38. data/lib/wice/helpers/bs_calendar_helpers.rb +6 -7
  39. data/lib/wice/helpers/js_calendar_helpers.rb +19 -17
  40. data/lib/wice/helpers/wice_grid_misc_view_helpers.rb +18 -18
  41. data/lib/wice/helpers/wice_grid_serialized_queries_view_helpers.rb +44 -49
  42. data/lib/wice/helpers/wice_grid_view_helpers.rb +131 -134
  43. data/lib/wice/kaminari_monkey_patching.rb +3 -1
  44. data/lib/wice/table_column_matrix.rb +23 -8
  45. data/lib/wice/wice_grid_controller.rb +12 -16
  46. data/lib/wice/wice_grid_core_ext.rb +12 -20
  47. data/lib/wice/wice_grid_misc.rb +131 -53
  48. data/lib/wice/wice_grid_serialized_queries_controller.rb +10 -11
  49. data/lib/wice/wice_grid_serialized_query.rb +4 -3
  50. data/lib/wice/wice_grid_spreadsheet.rb +19 -18
  51. data/lib/wice_grid.rb +144 -135
  52. data/spec/schema.rb +9 -0
  53. data/spec/spec_helper.rb +75 -0
  54. data/spec/support/active_record.rb +11 -0
  55. data/spec/support/wice_grid_test_config.rb +172 -0
  56. data/spec/wice/grid_output_buffer_spec.rb +41 -0
  57. data/spec/wice/table_column_matrix_spec.rb +38 -0
  58. data/spec/wice/wice_grid_misc_spec.rb +159 -0
  59. data/spec/wice/wice_grid_spreadsheet_spec.rb +14 -0
  60. data/test/readme.txt +1 -1
  61. data/vendor/assets/javascripts/wice_grid_init.js.coffee +14 -8
  62. data/vendor/assets/stylesheets/wice_grid.scss +84 -0
  63. data/wice_grid.gemspec +32 -16
  64. metadata +217 -25
  65. data/README.rdoc +0 -1325
  66. data/lib/generators/wice_grid/templates/wice_grid.scss +0 -140
  67. data/lib/wice/columns/column_datetime.rb +0 -171
  68. data/vendor/assets/images/icons/grid/arrow_down.gif +0 -0
  69. data/vendor/assets/images/icons/grid/arrow_up.gif +0 -0
  70. data/vendor/assets/images/icons/grid/calendar_view_month.png +0 -0
  71. data/vendor/assets/images/icons/grid/collapse.gif +0 -0
  72. data/vendor/assets/images/icons/grid/delete.png +0 -0
  73. data/vendor/assets/images/icons/grid/expand.gif +0 -0
  74. data/vendor/assets/images/icons/grid/page_white_excel.png +0 -0
  75. data/vendor/assets/images/icons/grid/page_white_find.png +0 -0
  76. data/vendor/assets/images/icons/grid/table.png +0 -0
  77. data/vendor/assets/images/icons/grid/table_refresh.png +0 -0
  78. data/vendor/assets/images/icons/grid/tick_all.png +0 -0
  79. data/vendor/assets/images/icons/grid/untick_all.png +0 -0
@@ -1,13 +1,9 @@
1
+ # encoding: utf-8
1
2
  module Wice #:nodoc:
2
-
3
-
4
3
  module Columns #:nodoc:
5
-
6
4
  class ViewColumnFloat < ViewColumnInteger #:nodoc:
7
5
  end
8
6
 
9
7
  ConditionsGeneratorColumnFloat = ConditionsGeneratorColumnInteger #:nodoc:
10
-
11
8
  end
12
-
13
- end
9
+ end
@@ -0,0 +1,31 @@
1
+ # encoding: utf-8
2
+ module Wice
3
+ module Columns #:nodoc:
4
+ class ViewColumnHtml5Datepicker < ViewColumn #:nodoc:
5
+
6
+ include Wice::Columns::CommonDateDatetimeMixin
7
+ include Wice::Columns::CommonJsDateDatetimeMixin
8
+
9
+ def do_render(params) #:nodoc:
10
+ css_class = 'form-control input-sm native-datepicker ' + (auto_reload ? 'auto-reload' : '')
11
+ date_format = Wice::ConfigurationProvider.value_for(:DATE_FORMAT)
12
+ '<div class="date-filter wg-html5-datepicker">' +
13
+ date_field_tag(@name1, params[:fr].try(:strftime, date_format), class: css_class, id: @dom_id) + '<br/>' +
14
+ date_field_tag(@name2, params[:to].try(:strftime, date_format), class: css_class, id: @dom_id2) +
15
+ '</div>'
16
+ end
17
+
18
+ def has_auto_reloading_calendar? #:nodoc:
19
+ # To be implemented
20
+ false
21
+ end
22
+
23
+ end
24
+
25
+ class ConditionsGeneratorColumnHtml5Datepicker < ConditionsGeneratorColumn #:nodoc:
26
+
27
+ include Wice::Columns::CommonJsDateDatetimeConditionsGeneratorMixin
28
+
29
+ end
30
+ end
31
+ end
@@ -1,15 +1,13 @@
1
+ # encoding: utf-8
1
2
  module Wice
2
-
3
3
  module Columns #:nodoc:
4
-
5
4
  class ViewColumnInteger < ViewColumn #:nodoc:
6
-
7
5
  def render_filter_internal(params) #:nodoc:
8
6
  @contains_a_text_input = true
9
7
 
10
8
  @query, _, parameter_name, @dom_id = form_parameter_name_id_and_query(eq: '')
11
9
 
12
- opts = {size: 3, id: @dom_id, class: 'range-start'}
10
+ opts = { size: 3, id: @dom_id, class: 'range-start' }
13
11
 
14
12
  opts[:class] += ' form-control input-sm'
15
13
 
@@ -32,14 +30,13 @@ module Wice
32
30
  end
33
31
  end
34
32
 
35
-
36
33
  class ConditionsGeneratorColumnInteger < ConditionsGeneratorColumn #:nodoc:
37
- def get_op_and_value(val)
34
+ def get_op_and_value(val) #:nodoc:
38
35
  num = nil
39
36
  op = nil
40
37
 
41
38
  # remove spaces
42
- val = val.gsub(' ','')
39
+ val = val.gsub(' ', '')
43
40
 
44
41
  first_digit_or_dot_index = val =~ /[0-9.]/
45
42
  if first_digit_or_dot_index
@@ -47,21 +44,21 @@ module Wice
47
44
  op = '=' if op == ''
48
45
  num = Float(val[first_digit_or_dot_index..-1]) rescue nil
49
46
 
50
- op = nil unless ['<','>','<=','>=','='].include?(op)
47
+ op = nil unless ['<', '>', '<=', '>=', '='].include?(op)
51
48
  end
52
49
  [op, num]
53
50
  end
54
51
 
55
- def generate_conditions(table_alias, opts) #:nodoc:
56
- unless opts.kind_of? Hash
57
- Wice.log "invalid parameters for the grid integer filter - must be a hash"
52
+ def generate_conditions(table_alias, opts) #:nodoc:
53
+ unless opts.is_a? Hash
54
+ Wice.log 'invalid parameters for the grid integer filter - must be a hash'
58
55
  return false
59
56
  end
60
57
  conditions = [[]]
61
58
  if opts[:eq]
62
59
  op, num = get_op_and_value(opts[:eq])
63
60
  if op && num
64
- conditions[0] << " #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} " + op + " ? "
61
+ conditions[0] << " #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} " + op + ' ? '
65
62
  conditions << num
66
63
  else
67
64
  opts.delete(:eq)
@@ -77,6 +74,5 @@ module Wice
77
74
  conditions
78
75
  end
79
76
  end
80
-
81
77
  end
82
78
  end
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+ module Wice
3
+ module Columns #:nodoc:
4
+ class ViewColumnJqueryDatepicker < ViewColumn #:nodoc:
5
+
6
+ include Wice::JsCalendarHelpers
7
+ include Wice::Columns::CommonDateDatetimeMixin
8
+ include Wice::Columns::CommonJsDateDatetimeMixin
9
+
10
+ def do_render(params) #:nodoc:
11
+ calendar_data_from = prepare_data_for_calendar(
12
+ initial_date: params[:fr],
13
+ title: NlMessage['date_selector_tooltip_from'],
14
+ name: @name1,
15
+ fire_event: auto_reload,
16
+ grid_name: self.grid.name
17
+ )
18
+
19
+ calendar_data_to = prepare_data_for_calendar(
20
+ initial_date: params[:to],
21
+ title: NlMessage['date_selector_tooltip_to'],
22
+ name: @name2,
23
+ fire_event: auto_reload,
24
+ grid_name: self.grid.name
25
+ )
26
+
27
+ calendar_data_from.the_other_datepicker_id_to = calendar_data_to.dom_id
28
+ calendar_data_to.the_other_datepicker_id_from = calendar_data_from.dom_id
29
+
30
+ html1 = date_calendar_jquery calendar_data_from
31
+
32
+ html2 = date_calendar_jquery calendar_data_to
33
+
34
+ %(<div class="date-filter wg-jquery-datepicker">#{html1}<br/>#{html2}</div>)
35
+ end
36
+
37
+ def has_auto_reloading_calendar? #:nodoc:
38
+ auto_reload
39
+ end
40
+
41
+ end
42
+
43
+ class ConditionsGeneratorColumnJqueryDatepicker < ConditionsGeneratorColumn #:nodoc:
44
+
45
+ include Wice::Columns::CommonJsDateDatetimeConditionsGeneratorMixin
46
+
47
+ end
48
+ end
49
+ end
@@ -1,18 +1,23 @@
1
+ # encoding: utf-8
1
2
  module Wice #:nodoc:
2
3
  module Columns #:nodoc:
4
+ require 'active_support'
5
+
3
6
  COLUMN_PROCESSOR_INDEX = ActiveSupport::OrderedHash[ #:nodoc:
4
- :action , 'column_action', # Special processor for action column, columns with checkboxes
5
- :text , 'column_string',
6
- :string , 'column_string',
7
- :timestamp, 'column_datetime',
8
- :datetime , 'column_datetime',
9
- :date , 'column_date',
10
- :integer , 'column_integer',
11
- :range , 'column_range',
12
- :float , 'column_float',
13
- :decimal , 'column_float',
14
- :custom , 'column_custom_dropdown', # Special processor for custom filter columns
15
- :boolean , 'column_boolean'
7
+ :action, 'column_action', # Special processor for action column, columns with checkboxes
8
+ :text, 'column_string',
9
+ :string, 'column_string',
10
+ :rails_datetime_helper, 'column_rails_datetime_helper', # standard Rails datepicker helper
11
+ :rails_date_helper, 'column_rails_date_helper', # standard Rails date helper
12
+ :jquery_datepicker, 'column_jquery_datepicker',
13
+ :bootstrap_datepicker, 'column_bootstrap_datepicker',
14
+ :html5_datepicker, 'column_html5_datepicker', # not ready
15
+ :integer, 'column_integer',
16
+ :range, 'column_range',
17
+ :float, 'column_float',
18
+ :decimal, 'column_float',
19
+ :custom, 'column_custom_dropdown', # Special processor for custom filter columns
20
+ :boolean, 'column_boolean'
16
21
  ]
17
22
  end
18
- end
23
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ module Wice
3
+ module Columns #:nodoc:
4
+ class ViewColumnRailsDateHelper < ViewColumn #:nodoc:
5
+
6
+ include ActionView::Helpers::DateHelper
7
+ include Wice::Columns::CommonDateDatetimeMixin
8
+ include Wice::Columns::CommonStandardDateDatetimeMixin
9
+
10
+ def chunk_names #:nodoc:
11
+ %w(year month day)
12
+ end
13
+
14
+ def do_render(params) #:nodoc:
15
+ '<div class="date-filter">' +
16
+ select_date(params[:fr], include_blank: true, prefix: @name1, id: @dom_id) + '<br/>' +
17
+ select_date(params[:to], include_blank: true, prefix: @name2, id: @dom_id2) +
18
+ '</div>'
19
+ end
20
+
21
+ # name_and_id_from_options in Rails Date helper does not substitute '.' with '_'
22
+ # like all other simpler form helpers do. Thus, overriding it here.
23
+ def name_and_id_from_options(options, type) #:nodoc:
24
+ options[:name] = (options[:prefix] || DEFAULT_PREFIX) + (options[:discard_type] ? '' : "[#{type}]")
25
+ options[:id] = options[:name].gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '').gsub(/\./, '_').gsub(/_+/, '_')
26
+ end
27
+
28
+
29
+ def has_auto_reloading_calendar? #:nodoc:
30
+ false
31
+ end
32
+
33
+ end
34
+
35
+ class ConditionsGeneratorColumnRailsDateHelper < ConditionsGeneratorColumn #:nodoc:
36
+
37
+ include Wice::Columns::CommonJsDateDatetimeConditionsGeneratorMixin
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ module Wice
3
+ module Columns #:nodoc:
4
+ class ViewColumnRailsDatetimeHelper < ViewColumn #:nodoc:
5
+
6
+ include ActionView::Helpers::DateHelper
7
+ include Wice::Columns::CommonDateDatetimeMixin
8
+ include Wice::Columns::CommonStandardDateDatetimeMixin
9
+
10
+ def chunk_names #:nodoc:
11
+ %w(year month day hour minute)
12
+ end
13
+
14
+ def do_render(params) #:nodoc:
15
+ '<div class="date-filter">' +
16
+ select_datetime(params[:fr], include_blank: true, prefix: @name1) + '<br/>' +
17
+ select_datetime(params[:to], include_blank: true, prefix: @name2) +
18
+ '</div>'
19
+ end
20
+
21
+ # name_and_id_from_options in Rails Date helper does not substitute '.' with '_'
22
+ # like all other simpler form helpers do. Thus, overriding it here.
23
+ def name_and_id_from_options(options, type) #:nodoc:
24
+ options[:name] = (options[:prefix] || DEFAULT_PREFIX) + (options[:discard_type] ? '' : "[#{type}]")
25
+ options[:id] = options[:name].gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '').gsub(/\./, '_').gsub(/_+/, '_')
26
+ end
27
+
28
+ def has_auto_reloading_calendar? #:nodoc:
29
+ false
30
+ end
31
+
32
+ end
33
+
34
+ class ConditionsGeneratorColumnRailsDatetimeHelper < ConditionsGeneratorColumn #:nodoc:
35
+
36
+ include Wice::Columns::CommonJsDateDatetimeConditionsGeneratorMixin
37
+
38
+ end
39
+ end
40
+ end
@@ -1,17 +1,15 @@
1
+ # encoding: utf-8
1
2
  module Wice
2
-
3
3
  module Columns #:nodoc:
4
-
5
4
  class ViewColumnRange < ViewColumn #:nodoc:
6
-
7
5
  def render_filter_internal(params) #:nodoc:
8
6
  @contains_a_text_input = true
9
7
 
10
8
  @query, _, parameter_name, @dom_id = form_parameter_name_id_and_query(fr: '')
11
9
  @query2, _, parameter_name2, @dom_id2 = form_parameter_name_id_and_query(to: '')
12
10
 
13
- opts1 = {size: 2, id: @dom_id, class: 'form-control input-sm range-start'}
14
- opts2 = {size: 2, id: @dom_id2, class: 'form-control input-sm range-end'}
11
+ opts1 = { size: 2, id: @dom_id, class: 'form-control input-sm range-start' }
12
+ opts2 = { size: 2, id: @dom_id2, class: 'form-control input-sm range-end' }
15
13
 
16
14
  if auto_reload
17
15
  opts1[:class] += ' auto-reload'
@@ -36,12 +34,10 @@ module Wice
36
34
  end
37
35
  end
38
36
 
39
-
40
37
  class ConditionsGeneratorColumnRange < ConditionsGeneratorColumn #:nodoc:
41
-
42
- def generate_conditions(table_alias, opts) #:nodoc:
43
- unless opts.kind_of? Hash
44
- Wice.log "invalid parameters for the grid integer filter - must be a hash"
38
+ def generate_conditions(table_alias, opts) #:nodoc:
39
+ unless opts.is_a? Hash
40
+ Wice.log 'invalid parameters for the grid integer filter - must be a hash'
45
41
  return false
46
42
  end
47
43
  conditions = [[]]
@@ -73,4 +69,4 @@ module Wice
73
69
  end
74
70
  end
75
71
  end
76
- end
72
+ end
@@ -1,10 +1,13 @@
1
+ # encoding: utf-8
1
2
  module Wice
2
-
3
3
  module Columns #:nodoc:
4
-
5
4
  class ViewColumnString < ViewColumn #:nodoc:
6
5
 
7
- attr_accessor :negation, :auto_reloading_input_with_negation_checkbox
6
+ # whether the filter contains a negation checkbox
7
+ attr_accessor :negation
8
+
9
+ # whether the filter contains a negation checkbox and autoreloading is necessary
10
+ attr_accessor :auto_reloading_input_with_negation_checkbox
8
11
 
9
12
  def render_filter_internal(params) #:nodoc:
10
13
  @contains_a_text_input = true
@@ -18,15 +21,15 @@ module Wice
18
21
 
19
22
  '<div class="text-filter-container">' +
20
23
  text_field_tag(parameter_name, params[:v], size: 8, id: @dom_id, class: css_class) +
21
- if defined?(Wice::Defaults::NEGATION_CHECKBOX_LABEL) && ! Wice::ConfigurationProvider.value_for(:NEGATION_CHECKBOX_LABEL).blank?
24
+ if defined?(Wice::Defaults::NEGATION_CHECKBOX_LABEL) && !Wice::ConfigurationProvider.value_for(:NEGATION_CHECKBOX_LABEL).blank?
22
25
  Wice::ConfigurationProvider.value_for(:NEGATION_CHECKBOX_LABEL)
23
26
  else
24
27
  ''
25
28
  end +
26
29
  check_box_tag(parameter_name2, '1', (params[:n] == '1'),
27
- id: @dom_id2,
28
- title: NlMessage['negation_checkbox_title'],
29
- class: "negation-checkbox #{css_class}") +
30
+ id: @dom_id2,
31
+ title: NlMessage['negation_checkbox_title'],
32
+ class: "negation-checkbox #{css_class}") +
30
33
  '</div>'
31
34
  else
32
35
  @query, _, parameter_name, @dom_id = form_parameter_name_id_and_query('')
@@ -34,7 +37,6 @@ module Wice
34
37
  end
35
38
  end
36
39
 
37
-
38
40
  def yield_declaration_of_column_filter #:nodoc:
39
41
  if negation
40
42
  {
@@ -49,7 +51,6 @@ module Wice
49
51
  end
50
52
  end
51
53
 
52
-
53
54
  def has_auto_reloading_input? #:nodoc:
54
55
  auto_reload
55
56
  end
@@ -57,17 +58,14 @@ module Wice
57
58
  def auto_reloading_input_with_negation_checkbox? #:nodoc:
58
59
  self.auto_reloading_input_with_negation_checkbox
59
60
  end
60
-
61
61
  end
62
62
 
63
-
64
63
  class ConditionsGeneratorColumnString < ConditionsGeneratorColumn #:nodoc:
65
-
66
64
  def generate_conditions(table_alias, opts) #:nodoc:
67
- if opts.kind_of? String
65
+ if opts.is_a? String
68
66
  string_fragment = opts
69
67
  negation = ''
70
- elsif (opts.kind_of? Hash) && opts.has_key?(:v)
68
+ elsif (opts.is_a? Hash) && opts.key?(:v)
71
69
  string_fragment = opts[:v]
72
70
  negation = opts[:n] == '1' ? 'NOT' : ''
73
71
  else
@@ -77,12 +75,18 @@ module Wice
77
75
  if string_fragment.empty?
78
76
  return false
79
77
  end
80
- [
81
- " #{negation} #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} #{::Wice.get_string_matching_operators(@column_wrapper.model)} ?",
82
- '%' + string_fragment + '%'
83
- ]
84
- end
85
78
 
79
+ string_matching_operator = ::Wice.get_string_matching_operators(@column_wrapper.model)
80
+
81
+ comparator = if string_matching_operator == 'CI_LIKE'
82
+ " #{negation} UPPER(#{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name}) LIKE UPPER(?)"
83
+ else
84
+ " #{negation} #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} #{string_matching_operator} ?"
85
+ end
86
+
87
+ [ comparator, '%' + string_fragment + '%' ]
88
+
89
+ end
86
90
  end
87
91
  end
88
- end
92
+ end
@@ -0,0 +1,20 @@
1
+ # encoding: utf-8
2
+ module Wice
3
+ module Columns #:nodoc:
4
+ module CommonDateDatetimeMixin #:nodoc:
5
+
6
+ def render_filter_internal(params) #:nodoc:
7
+ prepare
8
+ do_render(params)
9
+ end
10
+
11
+ def yield_declaration_of_column_filter #:nodoc:
12
+ {
13
+ templates: @queris_ids.collect { |tuple| tuple[0] },
14
+ ids: @queris_ids.collect { |tuple| tuple[1] }
15
+ }
16
+ end
17
+
18
+ end
19
+ end
20
+ end