wice_grid 3.4.14 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG +38 -0
  4. data/README.rdoc +219 -210
  5. data/SAVED_QUERIES_HOWTO.rdoc +13 -13
  6. data/app/views/kaminari/wice_grid/_next_page.html.erb +1 -1
  7. data/app/views/kaminari/wice_grid/_page.html.erb +1 -1
  8. data/app/views/kaminari/wice_grid/_prev_page.html.erb +1 -1
  9. data/lib/generators/wice_grid/install_generator.rb +2 -2
  10. data/lib/generators/wice_grid/templates/{wice_grid.css.scss → wice_grid.scss} +0 -0
  11. data/lib/generators/wice_grid/templates/wice_grid.yml +87 -1
  12. data/lib/generators/wice_grid/templates/wice_grid_config.rb +21 -7
  13. data/lib/wice/active_record_column_wrapper.rb +0 -1
  14. data/lib/wice/columns.rb +0 -1
  15. data/lib/wice/columns/column_action.rb +13 -8
  16. data/lib/wice/columns/column_boolean.rb +0 -1
  17. data/lib/wice/columns/column_custom_dropdown.rb +0 -1
  18. data/lib/wice/columns/column_date.rb +1 -2
  19. data/lib/wice/columns/column_datetime.rb +33 -7
  20. data/lib/wice/columns/column_float.rb +0 -1
  21. data/lib/wice/columns/column_integer.rb +0 -1
  22. data/lib/wice/columns/column_processor_index.rb +0 -1
  23. data/lib/wice/columns/column_range.rb +0 -1
  24. data/lib/wice/columns/column_string.rb +0 -1
  25. data/lib/wice/grid_output_buffer.rb +0 -1
  26. data/lib/wice/grid_renderer.rb +4 -2
  27. data/lib/wice/helpers/bs_calendar_helpers.rb +67 -0
  28. data/lib/wice/helpers/wice_grid_misc_view_helpers.rb +0 -1
  29. data/lib/wice/helpers/wice_grid_serialized_queries_view_helpers.rb +16 -17
  30. data/lib/wice/helpers/wice_grid_view_helpers.rb +52 -54
  31. data/lib/wice/kaminari_monkey_patching.rb +0 -1
  32. data/lib/wice/table_column_matrix.rb +0 -1
  33. data/lib/wice/wice_grid_controller.rb +5 -7
  34. data/lib/wice/wice_grid_core_ext.rb +0 -2
  35. data/lib/wice/wice_grid_misc.rb +0 -1
  36. data/lib/wice/wice_grid_serialized_queries_controller.rb +0 -1
  37. data/lib/wice/wice_grid_serialized_query.rb +0 -1
  38. data/lib/wice/wice_grid_spreadsheet.rb +0 -1
  39. data/lib/wice_grid.rb +24 -14
  40. data/release_notes/RELEASE_NOTES_3.2.pre1.rdoc +1 -2
  41. data/vendor/assets/javascripts/wice_grid_init.js.coffee +58 -24
  42. data/vendor/assets/javascripts/wice_grid_processor.js.coffee +1 -1
  43. data/wice_grid.gemspec +16 -30
  44. metadata +22 -21
@@ -46,8 +46,8 @@ It is also possible to initialize a grid with an initial saved query providing t
46
46
  itself to parameter <tt>saved_query</tt>:
47
47
 
48
48
  @products_grid = initialize_grid(Product,
49
- :name => 'prod_grid',
50
- :saved_query => SavedQuery.find_by_id_and_grid_name(12, 'prod_grid') )
49
+ name: 'prod_grid',
50
+ saved_query: SavedQuery.find_by_id_and_grid_name(12, 'prod_grid') )
51
51
 
52
52
 
53
53
  == Adding Application Specific Logic to Saving/Restoring Queries
@@ -61,14 +61,14 @@ After renaming the model to SavedQuery it looks like this:
61
61
  class SavedQuery < ActiveRecord::Base #:nodoc:
62
62
  serialize :query
63
63
 
64
- validates_uniqueness_of :name, :scope => :grid_name, :on => :create,
65
- :message => 'A query with this name already exists'
64
+ validates_uniqueness_of :name, scope: :grid_name, on: :create,
65
+ message: 'A query with this name already exists'
66
66
 
67
- validates_presence_of :name, :message => 'Please submit the name of the custom query'
67
+ validates_presence_of :name, message: 'Please submit the name of the custom query'
68
68
 
69
69
  def self.list(name, controller)
70
- conditions = {:grid_name => name}
71
- self.find(:all, :conditions => conditions)
70
+ conditions = {grid_name: name}
71
+ self.find(:all, conditions: conditions)
72
72
  end
73
73
  end
74
74
 
@@ -79,19 +79,19 @@ store queries for each user, we could add +user_id+ to the table and modify the
79
79
  class SavedQuery < ActiveRecord::Base
80
80
  serialize :query
81
81
 
82
- validates_uniqueness_of :name, :scope => :grid_name, :on => :create,
83
- :message => 'A query with this name already exists'
82
+ validates_uniqueness_of :name, scope: :grid_name, on: :create,
83
+ message: 'A query with this name already exists'
84
84
 
85
- validates_presence_of :name, :message => 'Please submit the name of the custom query'
85
+ validates_presence_of :name, message: 'Please submit the name of the custom query'
86
86
 
87
87
  belongs_to :identity # !
88
88
 
89
89
  def self.list(name, controller)
90
- conditions = {:grid_name => name}
90
+ conditions = {grid_name: name}
91
91
  if controller.current_user # !
92
92
  conditions[:user_id] = controller.current_user.id # provided that method current_user is defined in ApplicationController and returns the currrent user.
93
93
  end
94
- self.find(:all, :conditions => conditions)
94
+ self.find(:all, conditions: conditions)
95
95
  end
96
96
  end
97
97
 
@@ -99,7 +99,7 @@ The following step is to make sure that a new query is saved with the correct +u
99
99
  <tt>saved_queries_panel(@grid_object)</tt> to the following:
100
100
 
101
101
 
102
- <%= saved_queries_panel(@identities_grid, :extra_parameters => {:user_id => @current_user.id}) %>
102
+ <%= saved_queries_panel(@identities_grid, extra_parameters: {user_id: @current_user.id}) %>
103
103
 
104
104
  For every key in has :extra_parameters there must exist a field in the model - this hash will be used as a parameter to
105
105
  <tt>attributes=</tt> method of the query object.
@@ -1 +1 @@
1
- <li><%= link_to_unless current_page.last?, ::Wice::NlMessage['next_label'], url, :rel => 'next', :remote => remote %></li>
1
+ <li><%= link_to_unless current_page.last?, ::Wice::NlMessage['next_label'], url, rel: 'next', remote: remote %></li>
@@ -1 +1 @@
1
- <li <%if page.current?%>class="active"<%end%>><%= link_to page, url, {:remote => remote, :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %></li>
1
+ <li <%if page.current?%>class="active"<%end%>><%= link_to page, url, {remote: remote, rel: page.next? ? 'next' : page.prev? ? 'prev' : nil} %></li>
@@ -1 +1 @@
1
- <li><%= link_to_unless current_page.first?, ::Wice::NlMessage['previous_label'], url, :rel => 'prev', :remote => remote %></li>
1
+ <li><%= link_to_unless current_page.first?, ::Wice::NlMessage['previous_label'], url, rel: 'prev', remote: remote %></li>
@@ -3,7 +3,7 @@ module WiceGrid #:nodoc:
3
3
  class InstallGenerator < Rails::Generators::Base #:nodoc:
4
4
 
5
5
  desc 'Copy WiceGrid wice_grid_config.rb to config/initializers, ' +
6
- 'wice_grid.yml to config/locales/, and wice_grid.css.scss to assets/stylesheets'
6
+ 'wice_grid.yml to config/locales/, and wice_grid.scss to assets/stylesheets'
7
7
 
8
8
  source_root File.expand_path('../templates', __FILE__)
9
9
 
@@ -12,7 +12,7 @@ module WiceGrid #:nodoc:
12
12
 
13
13
  copy_file 'wice_grid.yml', 'config/locales/wice_grid.yml'
14
14
 
15
- copy_file 'wice_grid.css.scss', 'app/assets/stylesheets/wice_grid.css.scss'
15
+ copy_file 'wice_grid.scss', 'app/assets/stylesheets/wice_grid.scss'
16
16
 
17
17
  end
18
18
  end
@@ -46,6 +46,53 @@ en:
46
46
  expand: Expand
47
47
  collapse: Collapse
48
48
 
49
+ es:
50
+ date:
51
+ order:
52
+ - :day
53
+ - :month
54
+ - :year
55
+ wice_grid:
56
+ show_filter_tooltip: Mostrar filtro
57
+ hide_filter_tooltip: Ocultar filtro
58
+ csv_export_tooltip: Exportar a CSV
59
+ filter_tooltip: Filtro
60
+ reset_filter_tooltip: Reset
61
+ boolean_filter_true_label: "Si"
62
+ boolean_filter_false_label: "No"
63
+ previous_label: «
64
+ next_label: »
65
+ # Title of the icon clicking on which will show the calendar to set the FROM date.
66
+ date_selector_tooltip_from: Desde
67
+ # Title of the icon clicking on which will show the calendar to set the TO date.
68
+ date_selector_tooltip_to: Hasta
69
+ # The title of the checkox to turn on negation
70
+ negation_checkbox_title: Excluir
71
+ # link to switch to show all records
72
+ show_all_records_label: mostrar todos
73
+ # tooltip for the link to switch to show all records
74
+ show_all_records_tooltip: Mostrar todos los registros
75
+ # Warning message shown when the user wants to switch to all-records mode
76
+ all_queries_warning: ¿Estás seguro que quieres mostrar todos los registros?
77
+ # link to paginated view
78
+ switch_back_to_paginated_mode_label: volver a la vista paginada
79
+ # tooltip for the link to paginated view
80
+ switch_back_to_paginated_mode_tooltip: Cambiar atrás a la vista con páginas
81
+ # Title of the date string.
82
+ date_string_tooltip: Click en borrar
83
+ saved_query_panel_title: Consultas salvadas
84
+ save_query_button_label: Salvar el estado de los filtros
85
+ saved_query_deletion_confirmation: ¿Estás seguro?
86
+ saved_query_deletion_link_title: Borrar consulta
87
+ saved_query_link_title: Cargar consulta
88
+ validates_uniqueness_error: Una consulta con este nombre ya existe
89
+ validates_presence_error: Por favor tramita el nombre la consulta modificada
90
+ query_deleted_message: Salvada la consulta borrado.
91
+ query_saved_message: Consulta salvada.
92
+ select_all: Selecciona todo
93
+ deselect_all: Borra la selección
94
+ expand: Expandir
95
+ collapse: Contraer
49
96
 
50
97
  is:
51
98
  date:
@@ -547,4 +594,43 @@ ja:
547
594
  select_all: 全てを選択
548
595
  deselect_all: 選択を解除
549
596
  expand: 開く
550
- collapse: 閉じる
597
+ collapse: 閉じる
598
+
599
+ it:
600
+ date:
601
+ order:
602
+ - :day
603
+ - :month
604
+ - :year
605
+ wice_grid:
606
+ show_filter_tooltip: Mostra filtri
607
+ hide_filter_tooltip: Nascondi filtri
608
+ csv_export_tooltip: Esporta in CSV
609
+ filter_tooltip: Filtri
610
+ reset_filter_tooltip: Cancella
611
+ boolean_filter_true_label: "si"
612
+ boolean_filter_false_label: "no"
613
+ previous_label: «
614
+ next_label: »
615
+ date_selector_tooltip_from: Da
616
+ date_selector_tooltip_to: A
617
+ negation_checkbox_title: Escludi
618
+ show_all_records_label: Tutti i risultati
619
+ show_all_records_tooltip: Mostra tutti i risultati
620
+ all_queries_warning: Sei sicuro di voler mostrare tutti i risultati?
621
+ switch_back_to_paginated_mode_label: torna alla vista paginata
622
+ switch_back_to_paginated_mode_tooltip: Per tornare alla paginazione
623
+ date_string_tooltip: Clicca per cancellare
624
+ saved_query_panel_title: Ricerche salvate
625
+ save_query_button_label: Salva il valore dei filtri
626
+ saved_query_deletion_confirmation: Sei sicuro?
627
+ saved_query_deletion_link_title: Cancella la ricerca
628
+ saved_query_link_title: Carica ricerca
629
+ validates_uniqueness_error: Una ricerca con questo nome già esiste
630
+ validates_presence_error: Per favore inserisci il nome per questa ricerca personalizzata
631
+ query_deleted_message: Ricerca cancellata
632
+ query_saved_message: Ricerca salvata
633
+ select_all: Seleziona tutti
634
+ deselect_all: Deseleziona tutti
635
+ expand: Espandi
636
+ collapse: Chiudi
@@ -53,7 +53,7 @@ if defined?(Wice::Defaults)
53
53
  # when you connect to two databases one of which is MySQL and the other is Postgresql.
54
54
  # If the key for an adapter is missing it will fall back to Wice::Defaults::STRING_MATCHING_OPERATOR
55
55
  Wice::Defaults::STRING_MATCHING_OPERATORS = {
56
- 'ActiveRecord::ConnectionAdapters::MysqlAdapter' => 'LIKE',
56
+ 'ActiveRecord::ConnectionAdapters::MysqlAdapter' => 'LIKE',
57
57
  'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' => 'ILIKE'
58
58
  }
59
59
 
@@ -90,18 +90,22 @@ if defined?(Wice::Defaults)
90
90
 
91
91
 
92
92
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
93
- # Showing All Queries #
93
+ # Showing All Records #
94
94
 
95
95
  # Enable or disable showing all records (non-paginated table)
96
- Wice::Defaults::ALLOW_SHOWING_ALL_QUERIES = true
96
+ Wice::Defaults::ALLOW_SHOWING_ALL_RECORDS = true
97
97
 
98
98
  # If number of all queries is more than this value, the user will be given a warning message
99
99
  Wice::Defaults::START_SHOWING_WARNING_FROM = 100
100
100
 
101
-
102
101
  # Hide the "show all" link if the number of all records is more than...
103
- # set to nil to shows it always
104
- Wice::Defaults::HIDE_ALL_LINK_FROM = nil
102
+ # Force-resets back to pagination starting from this value.
103
+ # Set to nil to always show it
104
+ Wice::Defaults::SHOW_ALL_ALLOWED_UP_TO = nil
105
+
106
+ #
107
+ # set to nil to skip the check
108
+ Wice::Defaults::SWITCH_BACK_TO_PAGINATION_FROM = nil
105
109
 
106
110
 
107
111
  # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
@@ -119,6 +123,7 @@ if defined?(Wice::Defaults)
119
123
  # * <tt>:calendar</tt> - JS calendar
120
124
  # * <tt>:html5</tt> - HTML5 date input field
121
125
  # * <tt>:standard</tt> - standard Rails date and datetime helpers
126
+ # * <tt>:bootstrap</tt> - Bootstrap datepicker helper
122
127
  Wice::Defaults::HELPER_STYLE = :calendar
123
128
 
124
129
  # Format of the datetime displayed.
@@ -134,6 +139,11 @@ if defined?(Wice::Defaults)
134
139
  Wice::Defaults::DATE_FORMAT_JQUERY = "yy-mm-dd"
135
140
 
136
141
 
142
+ # Format of the date displayed in Bootstrap's Datepicker
143
+ # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
144
+ Wice::Defaults::DATE_FORMAT_BOOTSTRAP = "yyyy-mm-dd"
145
+
146
+
137
147
  # With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the
138
148
  # format defined by +DATETIME_FORMAT+ and must generate a DateTime object.
139
149
  # In many cases <tt>Time.zone.parse</tt> is enough, for instance, <tt>%Y-%m-%d</tt>. If you change the format, make sure to check this code
@@ -162,7 +172,11 @@ if defined?(Wice::Defaults)
162
172
  if date_string.blank?
163
173
  nil
164
174
  else
165
- Date.parse(date_string)
175
+ begin
176
+ Date.parse(date_string)
177
+ rescue ArgumentError
178
+ nil
179
+ end
166
180
  end
167
181
  }
168
182
 
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Wice
3
2
 
4
3
  # to be mixed in into ActiveRecord::ConnectionAdapters::Column
data/lib/wice/columns.rb CHANGED
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Wice #:nodoc:
3
2
 
4
3
  module Columns #:nodoc:
@@ -1,12 +1,12 @@
1
- # encoding: UTF-8
2
1
  module Wice
3
2
 
4
3
  module Columns #:nodoc:
5
4
 
6
5
 
7
6
  class ViewColumnAction < ViewColumn #:nodoc:
8
- def initialize(grid_obj, html, param_name, select_all_buttons, object_property, view, block = nil) #:nodoc:
7
+ def initialize(grid_obj, html, param_name, select_all_buttons, object_property, html_check_box, view, block = nil) #:nodoc:
9
8
  @view = view
9
+ @html_check_box = html_check_box
10
10
  @select_all_buttons = select_all_buttons
11
11
  self.grid = grid_obj
12
12
  self.html = html
@@ -34,12 +34,17 @@ module Wice
34
34
  def name #:nodoc:
35
35
  return '' unless @select_all_buttons
36
36
 
37
- content_tag(:div, '',
38
- class: 'clickable select-all',
39
- title: NlMessage['select_all']) + ' ' +
40
- content_tag(:div, '',
41
- class: 'clickable deselect-all',
42
- title: NlMessage['deselect_all'])
37
+ if @html_check_box
38
+ check_box_tag :select_all, 1, false, {class: 'wg-select-all'}
39
+ else
40
+ content_tag(:div, '',
41
+ class: 'clickable select-all',
42
+ title: NlMessage['select_all']) + ' ' +
43
+ content_tag(:div, '',
44
+ class: 'clickable deselect-all',
45
+ title: NlMessage['deselect_all'])
46
+ end
47
+
43
48
  end
44
49
 
45
50
  end
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Wice
3
2
 
4
3
  module Columns #:nodoc:
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Wice
3
2
 
4
3
  module Columns #:nodoc:
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Wice
3
2
 
4
3
  module Columns #:nodoc:
@@ -29,7 +28,7 @@ module Wice
29
28
  end
30
29
 
31
30
  if opts[:to]
32
- conditions[0] << " #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} < ? "
31
+ conditions[0] << " #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} <= ? "
33
32
  conditions << (opts[:to].to_date + 1)
34
33
  end
35
34
 
@@ -1,10 +1,10 @@
1
- # encoding: UTF-8
2
1
  module Wice
3
2
 
4
3
  module Columns #:nodoc:
5
4
 
6
5
  class ViewColumnDatetime < ViewColumn #:nodoc:
7
6
  include ActionView::Helpers::DateHelper
7
+ include Wice::BsCalendarHelpers
8
8
  include Wice::JsCalendarHelpers
9
9
 
10
10
 
@@ -53,12 +53,37 @@ module Wice
53
53
  def render_html5_filter_internal(params) #:nodoc:
54
54
  css_class = 'form-control input-sm native-datepicker ' + (auto_reload ? 'auto-reload' : '')
55
55
  date_format = Wice::ConfigurationProvider.value_for(:DATE_FORMAT)
56
- '<div class="date-filter">' +
56
+ '<div class="date-filter wg-html5-datepicker">' +
57
57
  date_field_tag(@name1, params[:fr].try(:strftime, date_format), {class: css_class, id: @dom_id}) + '<br/>' +
58
58
  date_field_tag(@name2, params[:to].try(:strftime, date_format), {class: css_class, id: @dom_id2}) +
59
59
  '</div>'
60
60
  end
61
61
 
62
+ def render_bs_filter_internal(params) #:nodoc:
63
+ calendar_data_from = prepare_data_for_bscalendar(
64
+ initial_date: params[:fr],
65
+ name: @name1,
66
+ fire_event: auto_reload,
67
+ grid_name: self.grid.name
68
+ )
69
+
70
+ calendar_data_to = prepare_data_for_bscalendar(
71
+ initial_date: params[:to],
72
+ name: @name2,
73
+ fire_event: auto_reload,
74
+ grid_name: self.grid.name
75
+ )
76
+
77
+ calendar_data_from.the_other_datepicker_id_to = calendar_data_to.dom_id
78
+ calendar_data_to.the_other_datepicker_id_from = calendar_data_from.dom_id
79
+
80
+ html1 = date_calendar_bs calendar_data_from
81
+
82
+ html2 = date_calendar_bs calendar_data_to
83
+
84
+ %!<div class="date-filter wg-bootstrap-datepicker">#{html1}#{html2}</div>!
85
+ end
86
+
62
87
  def render_calendar_filter_internal(params) #:nodoc:
63
88
 
64
89
  calendar_data_from = prepare_data_for_calendar(
@@ -84,7 +109,7 @@ module Wice
84
109
 
85
110
  html2 = date_calendar_jquery calendar_data_to
86
111
 
87
- %!<div class="date-filter">#{html1}<br/>#{html2}</div>!
112
+ %!<div class="date-filter wg-jquery-datepicker">#{html1}<br/>#{html2}</div>!
88
113
  end
89
114
 
90
115
 
@@ -95,6 +120,9 @@ module Wice
95
120
  elsif helper_style == :html5
96
121
  prepare_for_calendar_filter
97
122
  render_html5_filter_internal(params)
123
+ elsif helper_style == :bootstrap
124
+ prepare_for_calendar_filter
125
+ render_bs_filter_internal(params)
98
126
  else # :calendar
99
127
  prepare_for_calendar_filter
100
128
  render_calendar_filter_internal(params)
@@ -111,13 +139,11 @@ module Wice
111
139
 
112
140
 
113
141
  def has_auto_reloading_calendar? #:nodoc:
114
- auto_reload && helper_style == :calendar
142
+ auto_reload && [:bootstrap, :calendar].include?(helper_style)
115
143
  end
116
144
 
117
145
  end
118
146
 
119
-
120
-
121
147
  class ConditionsGeneratorColumnDatetime < ConditionsGeneratorColumn #:nodoc:
122
148
 
123
149
  def generate_conditions(table_alias, opts) #:nodoc:
@@ -128,7 +154,7 @@ module Wice
128
154
  end
129
155
 
130
156
  if opts[:to]
131
- conditions[0] << " #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} < ? "
157
+ conditions[0] << " #{@column_wrapper.alias_or_table_name(table_alias)}.#{@column_wrapper.name} <= ? "
132
158
  conditions << (opts[:to])
133
159
  end
134
160
 
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Wice #:nodoc:
3
2
 
4
3
 
@@ -1,4 +1,3 @@
1
- # encoding: UTF-8
2
1
  module Wice
3
2
 
4
3
  module Columns #:nodoc: