rich_table_component 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -179,6 +179,32 @@ module ComponentHelper
179
179
  render partial: 'rich_table_component/rtc/recapitulation_matrix', locals: options
180
180
  end
181
181
 
182
+ def row_selection local_var_assignments, options = {}
183
+ obj = local_var_assignments["#{local_var_assignments[:rtc_partial]}".to_sym]
184
+ options[:visible] = true if options[:visible].nil?
185
+ result = '<td class="numeric rtc_row_select_cell">'
186
+ if options[:visible]
187
+ result << (check_box_tag "#{obj.class.name.tableize}[]", obj.id, false, class: 'rtc_row_select', style: 'height: 0px; margin-top: 0px; margin-right: 7px;')
188
+ end
189
+ result << '</td>'
190
+
191
+ result.html_safe
192
+ end
193
+
194
+ def row_number local_var_assignments
195
+ counter = local_var_assignments["#{local_var_assignments[:rtc_partial]}_counter".to_sym].presence || 0
196
+ offset = local_var_assignments[:offset]
197
+ result = '<td class="numeric rtc_row_number">'
198
+ if offset
199
+ result << "#{counter + offset + 1}."
200
+ else
201
+ result << '(baru)'
202
+ end
203
+ result << '</td>'
204
+
205
+ result.html_safe
206
+ end
207
+
182
208
  end
183
209
 
184
210
 
@@ -2,7 +2,10 @@
2
2
  <% controller_name_singular = rtc_controller_name.singularize %>
3
3
  <% @controller_name = instance_variable_get("@#{controller_name_singular}") %>
4
4
 
5
- var $new_item = $('<%= j(render :partial => params[:rtc_partial].presence || controller_name_singular, locals: {"#{controller_name_singular}".to_sym => @controller_name}) %>').st_formatRow().addClass('created');
5
+ <% partial = params[:rtc_partial].presence || controller_name_singular %>
6
+ <% partial_variable = partial.split('/').last %>
7
+
8
+ var $new_item = $('<%= j(render partial, partial_variable.to_sym => @controller_name, rtc_partial: partial_variable) %>').st_formatRow().addClass('created');
6
9
 
7
10
  var $rtc = $('.rich_table_component.showing_new_form');
8
11
  $rtc.removeClass('showing_new_form');
@@ -2,7 +2,15 @@
2
2
  <% controller_name_singular = rtc_controller_name.singularize %>
3
3
  <% @controller_name = instance_variable_get("@#{controller_name_singular}") %>
4
4
 
5
- var $new_item = $('<%= j(render :partial => params[:rtc_partial].presence || controller_name_singular, locals: {"#{(params[:rtc_partial].presence || controller_name_singular).split('/').last}".to_sym => @controller_name}) %>').st_formatRow().addClass('updated');
5
+ <% partial = params[:rtc_partial].presence || controller_name_singular %>
6
+ <% partial_variable = partial.split('/').last %>
7
+
8
+ var $new_item = $('<%= j(render partial, partial_variable.to_sym => @controller_name, rtc_partial: partial_variable) %>').st_formatRow().addClass('updated');
9
+
10
+ // copy row number
11
+ $row_number = $('.lvr_entry_edited').find('.rtc_row_number').html();
12
+ $new_item.find('.rtc_row_number').html($row_number);
13
+ // update (insert new, remove old)
6
14
  $('.lvr_entry_edited').after($new_item).remove();
7
15
  $('.lvr_entry_edited').removeClass('lvr_entry_edited');
8
16
 
@@ -10,6 +18,5 @@ $('.modal').modal('hide');
10
18
 
11
19
  showGlobalNotification('<%= flash[:notice] %>', {type: SUCCESS});
12
20
 
13
-
14
21
  <% flash[:error].try(:clear) %>
15
22
  <% flash[:notice].try(:clear) %>
@@ -11,13 +11,16 @@
11
11
  - add_form_remote = true if add_form_remote.nil?
12
12
  - rtc_empty_data_message = sanitize "Data #{t(rtc_controller_name)} kosong" if rtc_empty_data_message.nil?
13
13
  - rtc_button_new = true if rtc_button_new.nil?
14
- - rtc_selection_checkbox ||= nil
14
+ - rtc_multiple_selection ||= nil
15
15
  - advanced_search_attributes ||= nil
16
16
  - columns_width = columns_width.presence || []
17
17
  - rtc_actions ||= nil
18
18
  - export_attributes ||= nil
19
19
  - recapitulation_matrix ||= nil
20
20
  - table_title ||= nil
21
+ - row_number = false if row_number.nil?
22
+ - multiple_selection = false if multiple_selection.nil?
23
+ - multiple_selection_actions ||= nil
21
24
 
22
25
  .component.rich_table_component{class: "#{rtc_controller_name}_component"}
23
26
  - if rtc_title.present? || rtc_button_new.present?
@@ -32,6 +35,7 @@
32
35
  add_form_remote: add_form_remote,
33
36
  rtc_button_new: rtc_button_new,
34
37
  rtc_actions: rtc_actions,
38
+ multiple_selection_actions: multiple_selection_actions,
35
39
  export_attributes: export_attributes
36
40
 
37
41
  = render "rich_table_component/rtc/component_content",
@@ -49,13 +53,15 @@
49
53
  advanced_search_attributes: advanced_search_attributes,
50
54
  columns_width: columns_width,
51
55
  table_title: table_title,
56
+ row_number: row_number,
57
+ multiple_selection: multiple_selection,
52
58
  params: params
53
59
 
54
- - if rtc_selection_checkbox
55
- - if rtc_selection_checkbox[:action]
56
- %form{action: rtc_selection_checkbox[:action], class: "rtc_selection_checkbox", id: "rtc_selection_checkbox_#{rtc_controller_name}"}
57
- - if rtc_selection_checkbox[:label]
58
- %input{type: 'submit', class: 'button', value: rtc_selection_checkbox[:label]}
60
+ / - if rtc_multiple_selection
61
+ / - if rtc_multiple_selection[:action]
62
+ / %form{action: rtc_multiple_selection[:action], class: "rtc_multiple_selection", id: "rtc_multiple_selection_#{rtc_controller_name}"}
63
+ / - if rtc_multiple_selection[:label]
64
+ / %input{type: 'submit', class: 'button', value: rtc_multiple_selection[:label]}
59
65
 
60
66
 
61
67
  - if recapitulation_matrix
@@ -9,6 +9,14 @@
9
9
  - rtc_actions ||= nil
10
10
 
11
11
  .rtc_actions
12
+
13
+ - if multiple_selection_actions.present?
14
+ - multiple_selection_actions = [multiple_selection_actions].flatten
15
+ - multiple_selection_actions.each do |sa|
16
+ = form_tag sa[:form][:path], sa[:form][:options].merge({class: 'multiple_selection_form'}) do
17
+ = submit_tag sa[:action_button][:value], sa[:action_button][:options]
18
+
19
+
12
20
  - if rtc_button_new.eql?(true) || rtc_button_new.eql?('true')
13
21
  - if rtc_controller_name != controller_name || instance_variable_get("@#{controller_name.singularize}").nil?
14
22
  = link_to icon('plus', 'Tambah ' + t("#{the_klass_name.tableize.singularize}").titleize).html_safe,
@@ -23,8 +31,6 @@
23
31
 
24
32
 
25
33
 
26
-
27
-
28
34
  - if rtc_actions.present?
29
35
  - rtc_actions = [rtc_actions].flatten
30
36
  - rtc_actions.each do |rtc_action|
@@ -31,6 +31,8 @@
31
31
  rtc_column_header: rtc_column_header,
32
32
  rtc_partial: rtc_partial,
33
33
  rtc_empty_data_message: rtc_empty_data_message,
34
+ row_number: row_number,
35
+ multiple_selection: multiple_selection,
34
36
  columns_width: columns_width
35
37
 
36
38
  - if rtc_footer.present?
@@ -6,15 +6,23 @@
6
6
 
7
7
  .rtc_content
8
8
  .rtc_grid_header{style: (rtc_column_header.present? ? '' : 'display: none !important')}
9
- - if columns_width.present?
10
- - headers.each_with_index do |header, i|
11
- .rtc_gh_item{'data-column-width' => columns_width[i]}
12
- = header.present? ? sort_link(header, rtc_controller_name: rtc_controller_name, params: params, rtc_partial: rtc_partial) : raw("&nbsp;")
13
- - else
14
- - headers.each do |header|
15
- .rtc_gh_item
16
- = header.present? ? sort_link(header, rtc_controller_name: rtc_controller_name, params: params, rtc_partial: rtc_partial) : raw("&nbsp;")
17
-
9
+ - columns_width ||= Array.new(headers.count, 1)
10
+
11
+
12
+ - if multiple_selection
13
+ .rtc_gh_item.numeric{'data-column-width' => columns_width.inject(:+) / 20.0}
14
+ %span{style: 'padding: 2px 0px'}
15
+ = check_box_tag 'rtc_select_all', nil, false, class: 'rtc_select_all', style: 'height: 0px; margin-top: 0px;'
16
+
17
+ - if row_number
18
+ .rtc_gh_item{'data-column-width' => columns_width.inject(:+) / 20.0}
19
+ %span
20
+ = 'No.'
21
+
22
+ - headers.each_with_index do |header, i|
23
+ .rtc_gh_item{'data-column-width' => columns_width[i]}
24
+ = header.present? ? sort_link(header, rtc_controller_name: rtc_controller_name, params: params, rtc_partial: rtc_partial) : raw("&nbsp;")
25
+
18
26
  .rtc_grid
19
27
  = render "rich_table_component/rtc/table",
20
28
  rtc_controller_name: rtc_controller_name,
@@ -8,13 +8,15 @@
8
8
  - params.select{|key, val| key != "action" && key != "controller" && key.to_s != "q"}.each_pair do |key, val|
9
9
  = hidden_field_tag key.to_s, val.to_s
10
10
 
11
+
11
12
  %table
12
13
  - if @controller_names.present?
14
+ - offset = (params[:page].to_i - 1) * params[:per_page].to_i
13
15
  - unless params[:list_view].eql? 'th'
14
- = render partial: rtc_partial, collection: @controller_names
16
+ = render partial: rtc_partial, collection: @controller_names, locals: {offset: offset, rtc_partial: rtc_partial}
15
17
  - else
16
18
  %ul
17
- = render partial: rtc_partial, collection: @controller_names
19
+ = render partial: rtc_partial, collection: @controller_names, locals: {offset: offset, rtc_partial: rtc_partial}
18
20
  - else
19
21
  .rtc_empty_message
20
22
  %br
@@ -1,3 +1,3 @@
1
1
  module RichTableComponent
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -87,6 +87,8 @@ module RichTableComponent
87
87
 
88
88
  # The result from Rich Table Component manipulation
89
89
  def rich_table_component(relation = {}, _sort_column = {}, _sort_direction = nil, pagination = true)
90
+
91
+ #puts 'RICH TABLE COMPONENT'
90
92
  case relation
91
93
  when Hash
92
94
  _sort_column = relation[:sort_column]
@@ -111,7 +113,7 @@ module RichTableComponent
111
113
  @sort_direction = _sort_direction
112
114
  sort = sort_column
113
115
  direction = sort_direction
114
- _relation_table_name = relation.respond_to?('klass') ? relation.klass.name.tableize : relation.name.tableize
116
+ _relation_table_name = relation.respond_to?('klass') ? relation.klass.table_name : relation.name.tableize
115
117
  @default_sort = nil
116
118
  @sort_direction = nil
117
119
 
@@ -170,7 +172,7 @@ module RichTableComponent
170
172
  # Group methods for recapitulation
171
173
  # -------------------------------
172
174
  def get_group_db(splitter, splitter_attr, splitter_time, group_attr, join_model, recapitulation_model)
173
- group_db = [splitter.last.try('tableize'), group_attr].compact.join('.')
175
+ group_db = [splitter.last.try('classify').try('constantize').try('table_name'), group_attr].compact.join('.')
174
176
  group_db = (group_db.split('.').length > 1) ? group_db : [recapitulation_model.table_name, group_db].join('.')
175
177
 
176
178
  if splitter_time.present?
@@ -213,6 +215,8 @@ module RichTableComponent
213
215
  group = splitter.pop
214
216
  join_model = splitter.present? ? splitter.last.classify.constantize : recapitulation_model
215
217
  group_attr = join_model.columns_hash[group].present? ? group : group + '_id'
218
+ #puts group_attr
219
+ group_attr = join_model.columns_hash[group_attr].present? ? group_attr : group.classify.constantize.table_name.singularize + '_id'
216
220
  group_db = get_group_db(splitter, splitter_attr, splitter_time, group_attr, join_model, recapitulation_model)
217
221
  splitter_mapping = splitter_attr.find{|f| f.first(8).eql?('mapping.')}.try('split', '.')
218
222
 
@@ -230,6 +234,7 @@ module RichTableComponent
230
234
  end
231
235
 
232
236
  def get_label_record(group_data, join_table, as_group_db)
237
+ # puts 'GET LABEL RECORD'
233
238
  group_data[:is_id] ? group_data[:group].tableize.classify.constantize.where{id.in(join_table.select(group_data[:group_db]).order(group_data[:group_db].to_s + ' ASC').uniq.to_a.collect(&(group_data[:group_attr]).to_sym))} : join_table.select(group_data[:group_db] + ' AS ' + as_group_db).order(as_group_db + ' ASC').uniq
234
239
  end
235
240
 
@@ -260,6 +265,7 @@ module RichTableComponent
260
265
 
261
266
 
262
267
  def generate_recapitulation
268
+ #puts 'GENERATE RECAPITULATION'
263
269
  if params[:group_row].present? || params[:group_col].present?
264
270
  generate_recapitulation_start
265
271
  else
@@ -268,6 +274,7 @@ module RichTableComponent
268
274
  end
269
275
 
270
276
  def generate_recapitulation_start
277
+ #puts 'START RECAPITULATION'
271
278
  recapitulation_model = (params[:rtc_controller_name].presence || controller_name).classify.constantize
272
279
 
273
280
 
@@ -287,17 +294,25 @@ module RichTableComponent
287
294
  end
288
295
 
289
296
 
297
+ #puts 'JOIN TABLE'
290
298
  q_join_table = recapitulation_model
291
299
  .joins{gd_row[:splitter].inject((gd_row[:splitter].present? ? self : nil), :__send__)}
292
300
  .joins{gd_col[:splitter].inject((gd_col[:splitter].present? ? self : nil), :__send__)}
293
301
 
294
302
 
295
- params[:q] = params[:q].each_with_object({}){|i, memo| i.first.to_s.end_with?('_present') && i.last.eql?('0') ? memo[(i.first.to_s[0..-9] + '_blank').to_sym] = '1' : memo[i.first] = i.last}
296
- @q = q_join_table.search(params[:q])
297
- join_table = @q.result
303
+ #puts 'CONVERT PRESENT QUEUE'
304
+ if params[:q].present?
305
+ params[:q] = params[:q].each_with_object({}){|i, memo| i.first.to_s.end_with?('_present') && i.last.eql?('0') ? memo[(i.first.to_s[0..-9] + '_blank').to_sym] = '1' : memo[i.first] = i.last}
306
+ @q = q_join_table.search(params[:q])
307
+ join_table = @q.result
308
+ else
309
+ join_table = q_join_table
310
+ end
298
311
 
299
312
  # executing query for counting record
313
+ #puts 'COUNTING RECORD'
300
314
  recapitulations = join_table.count(group: [gd_row[:group_db], gd_col[:group_db]].compact)
315
+ #puts 'END COUNTING RECORD'
301
316
 
302
317
 
303
318
  # executing query for value
@@ -312,6 +327,7 @@ module RichTableComponent
312
327
 
313
328
  # END DATA FETCHING
314
329
 
330
+ #puts 'END DATA FETCHING'
315
331
 
316
332
 
317
333
 
@@ -367,8 +383,7 @@ module RichTableComponent
367
383
  # DATA PROCESS
368
384
  # ----------------------------------------------------------------------------------------------------
369
385
  # ----------------------------------------------------------------------------------------------------
370
-
371
-
386
+ #puts 'DATA PROCESS'
372
387
 
373
388
  # iterate through rows and summing up matrix value simultanously
374
389
  # rows -> label top-bottom
@@ -294,6 +294,7 @@ var ajaxifyTableGrid = function(){
294
294
 
295
295
  initActiveTab();
296
296
  initRecapitulation();
297
+ initMultipleSelection();
297
298
  };
298
299
 
299
300
 
@@ -736,4 +737,49 @@ var initRecapitulation = function(){
736
737
  $recapitulation_result.st_recapitulationMatrix({recapitulation_matrix: recapitulation_matrix});
737
738
  }
738
739
  });
740
+ };
741
+
742
+
743
+ // Initialize Multiple Selection
744
+ var initMultipleSelection = function(){
745
+ //
746
+ $('.rtc_select_all').attr({checked: false});
747
+ $('.rtc_row_select').attr({checked: false});
748
+
749
+ $('.rtc_select_all').live('change', function(){
750
+ if($(this).attr('checked')){
751
+ $(this).parents('.rtc_content').find('> .rtc_grid table').find('tr .rtc_row_select').attr({checked: true});
752
+ }
753
+ else{
754
+ $(this).parents('.rtc_content').find('> .rtc_grid table').find('tr .rtc_row_select').attr({checked: false});
755
+ }
756
+
757
+ });
758
+
759
+
760
+ $('.rtc_row_select').live('change', function(){
761
+ if($(this).attr('checked')){
762
+ }
763
+ else{
764
+ console.log('unchecked');
765
+ $(this).parents('.rtc_content').find('> .rtc_grid_header').find('.rtc_select_all').attr({checked: false});
766
+ }
767
+ });
768
+
769
+
770
+ $(
771
+ 'form.multiple_selection_form'
772
+ ).live("ajax:before", function(){
773
+ var $this_form = $(this);
774
+ var $temp_multiple_selection_container = $('<div></div>').addClass('temp_multiple_selection_container hide');
775
+ $this_form.find('.temp_multiple_selection_container').remove();
776
+ $this_form.parents('.rich_table_component').find('.rtc_grid table tr .rtc_row_select').each(function(){
777
+ if($(this).attr('checked')){
778
+ var $cloned = $(this).clone();
779
+ $cloned.attr({checked: true});
780
+ $temp_multiple_selection_container.append($cloned);
781
+ }
782
+ });
783
+ $this_form.append($temp_multiple_selection_container);
784
+ });
739
785
  };
@@ -147,6 +147,7 @@ $separator_border_right: transparentize(white, 0.1)
147
147
  overflow: hidden
148
148
  display: block
149
149
  white-space: nowrap
150
+ line-height: 100%
150
151
 
151
152
  &.asc:after
152
153
  content: " \25B2"
@@ -493,3 +494,9 @@ $separator_border_right: transparentize(white, 0.1)
493
494
 
494
495
  .numeric
495
496
  text-align: right
497
+
498
+ .center
499
+ text-align: center
500
+
501
+ .multiple_selection_form
502
+ display: inline-block
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rich_table_component
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-15 00:00:00.000000000 Z
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sass-rails