wice_grid_ms 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.inch.yml +3 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +181 -0
  6. data/.travis.yml +22 -0
  7. data/CHANGELOG.md +714 -0
  8. data/Gemfile +4 -0
  9. data/MIT-LICENSE +20 -0
  10. data/README.md +1518 -0
  11. data/Rakefile +59 -0
  12. data/SAVED_QUERIES_HOWTO.md +113 -0
  13. data/TODO.md +16 -0
  14. data/app/views/kaminari/wice_grid/_gap.html.erb +1 -0
  15. data/app/views/kaminari/wice_grid/_next_page.html.erb +1 -0
  16. data/app/views/kaminari/wice_grid/_page.html.erb +1 -0
  17. data/app/views/kaminari/wice_grid/_paginator.html.erb +19 -0
  18. data/app/views/kaminari/wice_grid/_prev_page.html.erb +1 -0
  19. data/config/locales/cz.yml +45 -0
  20. data/config/locales/de.yml +47 -0
  21. data/config/locales/en.yml +47 -0
  22. data/config/locales/es.yml +47 -0
  23. data/config/locales/fr.yml +45 -0
  24. data/config/locales/is.yml +46 -0
  25. data/config/locales/it.yml +38 -0
  26. data/config/locales/ja.yml +47 -0
  27. data/config/locales/nl.yml +45 -0
  28. data/config/locales/pt-BR.yml +36 -0
  29. data/config/locales/pt.yml +45 -0
  30. data/config/locales/ru.yml +45 -0
  31. data/config/locales/sk.yml +45 -0
  32. data/config/locales/uk.yml +45 -0
  33. data/config/locales/zh.yml +45 -0
  34. data/lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb +20 -0
  35. data/lib/generators/wice_grid/install_generator.rb +14 -0
  36. data/lib/generators/wice_grid/templates/create_wice_grid_serialized_queries.rb +14 -0
  37. data/lib/generators/wice_grid/templates/wice_grid_config.rb +192 -0
  38. data/lib/wice/active_record_column_wrapper.rb +123 -0
  39. data/lib/wice/columns.rb +276 -0
  40. data/lib/wice/columns/column_action.rb +52 -0
  41. data/lib/wice/columns/column_boolean.rb +40 -0
  42. data/lib/wice/columns/column_bootstrap_datepicker.rb +48 -0
  43. data/lib/wice/columns/column_custom_dropdown.rb +115 -0
  44. data/lib/wice/columns/column_float.rb +9 -0
  45. data/lib/wice/columns/column_html5_datepicker.rb +31 -0
  46. data/lib/wice/columns/column_integer.rb +78 -0
  47. data/lib/wice/columns/column_jquery_datepicker.rb +49 -0
  48. data/lib/wice/columns/column_processor_index.rb +23 -0
  49. data/lib/wice/columns/column_rails_date_helper.rb +41 -0
  50. data/lib/wice/columns/column_rails_datetime_helper.rb +40 -0
  51. data/lib/wice/columns/column_range.rb +72 -0
  52. data/lib/wice/columns/column_string.rb +92 -0
  53. data/lib/wice/columns/common_date_datetime_mixin.rb +20 -0
  54. data/lib/wice/columns/common_js_date_datetime_conditions_generator_mixin.rb +42 -0
  55. data/lib/wice/columns/common_js_date_datetime_mixin.rb +15 -0
  56. data/lib/wice/columns/common_rails_date_datetime_conditions_generator_mixin.rb +26 -0
  57. data/lib/wice/columns/common_standard_helper_date_datetime_mixin.rb +22 -0
  58. data/lib/wice/grid_output_buffer.rb +49 -0
  59. data/lib/wice/grid_renderer.rb +609 -0
  60. data/lib/wice/helpers/bs_calendar_helpers.rb +66 -0
  61. data/lib/wice/helpers/js_calendar_helpers.rb +83 -0
  62. data/lib/wice/helpers/wice_grid_misc_view_helpers.rb +75 -0
  63. data/lib/wice/helpers/wice_grid_serialized_queries_view_helpers.rb +95 -0
  64. data/lib/wice/helpers/wice_grid_view_helpers.rb +718 -0
  65. data/lib/wice/kaminari_monkey_patching.rb +14 -0
  66. data/lib/wice/table_column_matrix.rb +65 -0
  67. data/lib/wice/wice_grid_controller.rb +223 -0
  68. data/lib/wice/wice_grid_core_ext.rb +142 -0
  69. data/lib/wice/wice_grid_misc.rb +209 -0
  70. data/lib/wice/wice_grid_serialized_queries_controller.rb +87 -0
  71. data/lib/wice/wice_grid_serialized_query.rb +14 -0
  72. data/lib/wice/wice_grid_spreadsheet.rb +20 -0
  73. data/lib/wice_grid.rb +676 -0
  74. data/release_notes/RELEASE_NOTES_3.2.pre1.rdoc +81 -0
  75. data/release_notes/RELEASE_NOTES_3.2.pre2.rdoc +6 -0
  76. data/release_notes/RELEASE_NOTES_3.3.0.rdoc +21 -0
  77. data/spec/schema.rb +9 -0
  78. data/spec/spec_helper.rb +75 -0
  79. data/spec/support/active_record.rb +11 -0
  80. data/spec/support/wice_grid_test_config.rb +175 -0
  81. data/spec/wice/grid_output_buffer_spec.rb +41 -0
  82. data/spec/wice/table_column_matrix_spec.rb +38 -0
  83. data/spec/wice/wice_grid_misc_spec.rb +159 -0
  84. data/spec/wice/wice_grid_spreadsheet_spec.rb +14 -0
  85. data/test/readme.txt +1 -0
  86. data/vendor/assets/javascripts/wice_grid.js +3 -0
  87. data/vendor/assets/javascripts/wice_grid_init.js.coffee +339 -0
  88. data/vendor/assets/javascripts/wice_grid_processor.js.coffee +133 -0
  89. data/vendor/assets/javascripts/wice_grid_saved_queries_init.js.coffee +103 -0
  90. data/vendor/assets/stylesheets/wice_grid.scss +81 -0
  91. data/wice_grid.gemspec +36 -0
  92. metadata +335 -0
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+ module Wice
3
+ module Columns #:nodoc:
4
+ class ViewColumnAction < ViewColumn #:nodoc:
5
+ def initialize(grid_obj, html, param_name, select_all_buttons, object_property, html_check_box, view, block = nil) #:nodoc:
6
+ @view = view
7
+ @html_check_box = html_check_box
8
+ @select_all_buttons = select_all_buttons
9
+ self.grid = grid_obj
10
+ self.html = html
11
+ Wice::WgHash.add_or_append_class_value!(self.html, 'sel')
12
+ grid_name = self.grid.name
13
+ @param_name = param_name
14
+ @cell_rendering_block = lambda do |object, params|
15
+ if block && !block.call(object)
16
+ ''
17
+ else
18
+ selected = params[grid_name] && params[grid_name][param_name] && params[grid_name][param_name].index(object.send(object_property).to_s)
19
+ check_box_tag("#{grid_name}[#{param_name}][]", object.send(object_property), selected, id: nil)
20
+ end
21
+ end
22
+ end
23
+
24
+ def in_html #:nodoc:
25
+ true
26
+ end
27
+
28
+ def capable_of_hosting_filter_related_icons? #:nodoc:
29
+ false
30
+ end
31
+
32
+ def name #:nodoc:
33
+ return '' unless @select_all_buttons
34
+
35
+ if @html_check_box
36
+ check_box_tag :select_all, 1, false, class: 'wg-select-all'
37
+ else
38
+ content_tag(:div,
39
+ content_tag(:i, '', class: 'fa fa-check-square-o'),
40
+ class: 'clickable select-all',
41
+ title: NlMessage['select_all']) + ' ' +
42
+ content_tag(:div,
43
+ content_tag(:i, '', class: 'fa fa-square-o'),
44
+ class: 'clickable deselect-all',
45
+ title: NlMessage['deselect_all'])
46
+ end
47
+ end
48
+ end
49
+
50
+ ConditionsGeneratorColumnAction = ConditionsGeneratorColumn #:nodoc:
51
+ end
52
+ end
@@ -0,0 +1,40 @@
1
+ # encoding: utf-8
2
+ module Wice
3
+ module Columns #:nodoc:
4
+ class ViewColumnBoolean < ViewColumnCustomDropdown #:nodoc:
5
+ include ActionView::Helpers::FormOptionsHelper
6
+
7
+ # Text for the true value
8
+ attr_accessor :boolean_filter_true_label
9
+
10
+ # Text for the false value
11
+ attr_accessor :boolean_filter_false_label
12
+
13
+ def render_filter_internal(params) #:nodoc:
14
+ @custom_filter = {
15
+ @filter_all_label => nil,
16
+ @boolean_filter_true_label => 't',
17
+ @boolean_filter_false_label => 'f'
18
+ }
19
+
20
+ @turn_off_select_toggling = true
21
+ super(params)
22
+ end
23
+ end
24
+
25
+ class ConditionsGeneratorColumnBoolean < ConditionsGeneratorColumn #:nodoc:
26
+ def generate_conditions(table_alias, opts) #:nodoc:
27
+ unless opts.is_a?(Array) && opts.size == 1
28
+ Wice.log "invalid parameters for the grid boolean filter - must be an one item array: #{opts.inspect}"
29
+ return false
30
+ end
31
+ opts = opts[0]
32
+ if opts == 'f'
33
+ [" (#{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} = ? or #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} is null) ", false]
34
+ elsif opts == 't'
35
+ [" #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} = ?", true]
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+ module Wice
3
+ module Columns #:nodoc:
4
+ class ViewColumnBootstrapDatepicker < ViewColumn #:nodoc:
5
+
6
+ include Wice::BsCalendarHelpers
7
+ include Wice::Columns::CommonDateDatetimeMixin
8
+ include Wice::Columns::CommonJsDateDatetimeMixin
9
+
10
+ def do_render(params) #:nodoc:
11
+ calendar_data_from = prepare_data_for_bscalendar(
12
+ initial_date: params[:fr],
13
+ name: @name1,
14
+ fire_event: auto_reload,
15
+ grid_name: self.grid.name
16
+ )
17
+
18
+ calendar_data_to = prepare_data_for_bscalendar(
19
+ initial_date: params[:to],
20
+ name: @name2,
21
+ fire_event: auto_reload,
22
+ grid_name: self.grid.name
23
+ )
24
+
25
+ calendar_data_from.the_other_datepicker_id_to = calendar_data_to.dom_id
26
+ calendar_data_to.the_other_datepicker_id_from = calendar_data_from.dom_id
27
+
28
+ html1 = date_calendar_bs calendar_data_from
29
+
30
+ html2 = date_calendar_bs calendar_data_to
31
+
32
+ %(<div class="date-filter wg-bootstrap-datepicker">#{html1}#{html2}</div>)
33
+ end
34
+
35
+
36
+ def has_auto_reloading_calendar? #:nodoc:
37
+ auto_reload
38
+ end
39
+
40
+ end
41
+
42
+ class ConditionsGeneratorColumnBootstrapDatepicker < ConditionsGeneratorColumn #:nodoc:
43
+
44
+ include Wice::Columns::CommonJsDateDatetimeConditionsGeneratorMixin
45
+
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,115 @@
1
+ # encoding: utf-8
2
+ module Wice
3
+ module Columns #:nodoc:
4
+ class ViewColumnCustomDropdown < ViewColumn #:nodoc:
5
+ include ActionView::Helpers::FormOptionsHelper
6
+
7
+ # text in the filter dropdown for an empty <option><option>
8
+ attr_accessor :filter_all_label
9
+
10
+ # contains an array of option label + option value pairs for the select, or a Proc object which returns this array
11
+ attr_accessor :custom_filter
12
+
13
+ def render_filter_internal(params) #:nodoc:
14
+ @query, @query_without_equals_sign, @parameter_name, @dom_id = form_parameter_name_id_and_query('')
15
+ @query_without_equals_sign += '%5B%5D='
16
+
17
+ @custom_filter = @custom_filter.call if @custom_filter.is_a? Proc
18
+
19
+ if @custom_filter.is_a? Array
20
+ @custom_filter = [[@filter_all_label, nil]] + @custom_filter.map do|label, value|
21
+ [label.to_s, value.to_s]
22
+ end
23
+ end
24
+
25
+ select_options = { name: @parameter_name + '[]', id: @dom_id, class: 'custom-dropdown form-control' }
26
+
27
+ if @turn_off_select_toggling
28
+ select_toggle = ''
29
+ else
30
+ if self.allow_multiple_selection
31
+ select_options[:multiple] = params.is_a?(Array) && params.size > 1
32
+
33
+ expand_icon_style, collapse_icon_style = nil, 'display: none'
34
+ expand_icon_style, collapse_icon_style = collapse_icon_style, expand_icon_style if select_options[:multiple]
35
+
36
+ select_toggle = content_tag(
37
+ :span,
38
+ content_tag(:i, '', class: 'fa fa-plus'),
39
+ title: NlMessage['expand'],
40
+ class: 'expand-multi-select-icon clickable',
41
+ style: expand_icon_style
42
+ ) +
43
+ content_tag(
44
+ :span,
45
+ content_tag(:i, '', class: 'fa fa-minus'),
46
+ title: NlMessage['collapse'],
47
+ class: 'collapse-multi-select-icon clickable',
48
+ style: collapse_icon_style
49
+ )
50
+ else
51
+ select_options[:multiple] = false
52
+ select_toggle = ''
53
+ end
54
+ end
55
+
56
+ if auto_reload
57
+ select_options[:class] += ' auto-reload'
58
+ end
59
+
60
+ params_for_select = (params.is_a?(Hash) && params.empty?) ? [nil] : params
61
+
62
+ '<div class="custom-dropdown-container">'.html_safe +
63
+ content_tag(:select,
64
+ options_for_select(@custom_filter, params_for_select),
65
+ select_options) + select_toggle.html_safe + '</div>'.html_safe
66
+ end
67
+
68
+ def yield_declaration_of_column_filter #:nodoc:
69
+ {
70
+ templates: [@query_without_equals_sign],
71
+ ids: [@dom_id]
72
+ }
73
+ end
74
+
75
+ def has_auto_reloading_select? #:nodoc:
76
+ auto_reload
77
+ end
78
+ end
79
+
80
+ class ConditionsGeneratorColumnCustomDropdown < ConditionsGeneratorColumn #:nodoc:
81
+ def generate_conditions(table_alias, opts) #:nodoc:
82
+ if opts.empty? || (opts.is_a?(Array) && opts.size == 1 && opts[0].blank?)
83
+ return false
84
+ end
85
+ opts = (opts.is_a?(Array) && opts.size == 1) ? opts[0] : opts
86
+
87
+ if opts.is_a?(Array)
88
+ opts_with_special_values, normal_opts = opts.partition { |v| ::Wice::GridTools.special_value(v) }
89
+
90
+ conditions_ar = if normal_opts.size > 0
91
+ [" #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} IN ( " + (['?'] * normal_opts.size).join(', ') + ' )'] + normal_opts
92
+ else
93
+ []
94
+ end
95
+
96
+ if opts_with_special_values.size > 0
97
+ special_conditions = opts_with_special_values.collect { |v| " #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} is " + v }.join(' or ')
98
+ if conditions_ar.size > 0
99
+ conditions_ar[0] = " (#{conditions_ar[0]} or #{special_conditions} ) "
100
+ else
101
+ conditions_ar = " ( #{special_conditions} ) "
102
+ end
103
+ end
104
+ conditions_ar
105
+ else
106
+ if ::Wice::GridTools.special_value(opts)
107
+ " #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} is " + opts
108
+ else
109
+ [" #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} = ?", opts]
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+ module Wice #:nodoc:
3
+ module Columns #:nodoc:
4
+ class ViewColumnFloat < ViewColumnInteger #:nodoc:
5
+ end
6
+
7
+ ConditionsGeneratorColumnFloat = ConditionsGeneratorColumnInteger #:nodoc:
8
+ 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
@@ -0,0 +1,78 @@
1
+ # encoding: utf-8
2
+ module Wice
3
+ module Columns #:nodoc:
4
+ class ViewColumnInteger < ViewColumn #:nodoc:
5
+ def render_filter_internal(params) #:nodoc:
6
+ @contains_a_text_input = true
7
+
8
+ @query, _, parameter_name, @dom_id = form_parameter_name_id_and_query(eq: '')
9
+
10
+ opts = { size: 3, id: @dom_id, class: 'range-start' }
11
+
12
+ opts[:class] += ' form-control input-sm'
13
+
14
+ if auto_reload
15
+ opts[:class] += ' auto-reload'
16
+ end
17
+
18
+ text_field_tag(parameter_name, params[:eq], opts)
19
+ end
20
+
21
+ def yield_declaration_of_column_filter #:nodoc:
22
+ {
23
+ templates: [@query],
24
+ ids: [@dom_id]
25
+ }
26
+ end
27
+
28
+ def has_auto_reloading_input? #:nodoc:
29
+ auto_reload
30
+ end
31
+ end
32
+
33
+ class ConditionsGeneratorColumnInteger < ConditionsGeneratorColumn #:nodoc:
34
+ def get_op_and_value(val) #:nodoc:
35
+ num = nil
36
+ op = nil
37
+
38
+ # remove spaces
39
+ val = val.gsub(' ', '')
40
+
41
+ start_of_num = val =~ /[0-9.-]/ # first digit, dot or negative sign
42
+ if start_of_num
43
+ op = val[0...start_of_num]
44
+ op = '=' if op == ''
45
+ num = Float(val[start_of_num..-1]) rescue nil
46
+
47
+ op = nil unless ['<', '>', '<=', '>=', '='].include?(op)
48
+ end
49
+ [op, num]
50
+ end
51
+
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'
55
+ return false
56
+ end
57
+ conditions = [[]]
58
+ if opts[:eq]
59
+ op, num = get_op_and_value(opts[:eq])
60
+ if op && num
61
+ conditions[0] << " #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} " + op + ' ? '
62
+ conditions << num
63
+ else
64
+ opts.delete(:eq)
65
+ end
66
+ end
67
+
68
+ if conditions.size == 1
69
+ return false
70
+ end
71
+
72
+ conditions[0] = conditions[0].join(' and ')
73
+
74
+ conditions
75
+ end
76
+ end
77
+ end
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
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ module Wice #:nodoc:
3
+ module Columns #:nodoc:
4
+ require 'active_support'
5
+
6
+ COLUMN_PROCESSOR_INDEX = ActiveSupport::OrderedHash[ #:nodoc:
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'
21
+ ]
22
+ end
23
+ end