Class: Wice::GridRenderer

Inherits:
Object show all
Includes:
ActionView::Helpers::AssetTagHelper, ActionView::Helpers::CaptureHelper, ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::TagHelper, ActionView::Helpers::TextHelper, Enumerable
Defined in:
lib/wice/grid_renderer.rb

Overview

Instance of ‘GridRenderer` is injected into the top level block of the `grid` helper. `g.column`, `g.action_column` are all examples of methods of `GridRenderer`

Constant Summary collapse

ORDER_PARAMETER_NAME =

HTTP parameter for the order field

'order'
ORDER_DIRECTION_PARAMETER_NAME =

HTTP parameter for the order direction (asc/desc)

'order_direction'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ActionView::Helpers::TagHelper

#public_tag_options

Constructor Details

#initialize(grid, view) ⇒ GridRenderer

:nodoc:



39
40
41
42
43
44
45
46
# File 'lib/wice/grid_renderer.rb', line 39

def initialize(grid, view)  #:nodoc:
  @grid                  = grid
  @grid.renderer         = self
  @columns               = []
  @columns_table         = {}
  @action_column_present = false
  @view                  = view
end

Instance Attribute Details

#after_row_handlerObject (readonly)

a Proc object for the after_row block



13
14
15
# File 'lib/wice/grid_renderer.rb', line 13

def after_row_handler
  @after_row_handler
end

#before_row_handlerObject (readonly)

a Proc object for the before_row block



16
17
18
# File 'lib/wice/grid_renderer.rb', line 16

def before_row_handler
  @before_row_handler
end

#blank_slate_handlerObject (readonly)

Configuration or a Proc object for the blank_slate block



22
23
24
# File 'lib/wice/grid_renderer.rb', line 22

def blank_slate_handler
  @blank_slate_handler
end

#gridObject (readonly)

reference to the WiceGrid instance



28
29
30
# File 'lib/wice/grid_renderer.rb', line 28

def grid
  @grid
end

#kaptionObject (readonly)

Contents of <caption></caption>



31
32
33
# File 'lib/wice/grid_renderer.rb', line 31

def kaption
  @kaption
end

#last_row_handlerObject (readonly)

a Proc object which returns contents of the last row



25
26
27
# File 'lib/wice/grid_renderer.rb', line 25

def last_row_handler
  @last_row_handler
end

#replace_row_handlerObject (readonly)

a Proc object for the replace_row block



19
20
21
# File 'lib/wice/grid_renderer.rb', line 19

def replace_row_handler
  @replace_row_handler
end

Instance Method Details

#[](k) ⇒ Object

:nodoc:



61
62
63
# File 'lib/wice/grid_renderer.rb', line 61

def [](k)  #:nodoc:
  @columns_table[k]
end

#action_column(opts = {}, &block) ⇒ Object

Adds a column with checkboxes for each record. Useful for actions with multiple records, for example, deleting selected records. Please note that action_column only creates the checkboxes and the ‘Select All’ and ‘Deselect All’ buttons, and the form itelf as well as processing the parameters should be taken care of by the application code.

  • :param_name - The name of the HTTP parameter. The complete HTTP parameter is "#{grid_name}[#{param_name}][]". The default param_name is ‘selected’.

  • :html - a hash of HTML attributes to be included into the td tag.

  • :select_all_buttons - show/hide buttons ‘Select All’ and ‘Deselect All’ in the column header. The default is true.

  • :object_property - a method used to obtain the value for the HTTP parameter. The default is id.

  • :html_check_box - can be used to switch from a real check box to two images. The default is true.

You can hide a certain action checkbox if you add the usual block to g.action_column, just like with the g.column definition. If the block returns nil or false no checkbox will be rendered.



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/wice/grid_renderer.rb', line 158

def action_column(opts = {}, &block)
  if @action_column_present
    raise Wice::WiceGridException.new('There can be only one action column in a WiceGrid')
  end

  options = {
    param_name:          :selected,
    html:                {},
    select_all_buttons:  true,
    object_property:     :id,
    html_check_box:      true
  }

  opts.assert_valid_keys(options.keys)
  options.merge!(opts)
  @action_column_present = true
  column_processor_klass = Columns.get_view_column_processor(:action)

  @columns << column_processor_klass.new(
    @grid,
    options[:html],
    options[:param_name],
    options[:select_all_buttons],
    options[:object_property],
    options[:html_check_box],
    @view,
    block
  )
end

#add_column(vc) ⇒ Object

:nodoc:



56
57
58
59
# File 'lib/wice/grid_renderer.rb', line 56

def add_column(vc)  #:nodoc:
  @columns_table[vc.fully_qualified_attribute_name] = vc if vc.attribute
  @columns << vc
end

#after_row(&block) ⇒ Object

Can be used to add HTML code (another row, for example) right after each grid row. Nothing is added if the block return false or nil.



480
481
482
# File 'lib/wice/grid_renderer.rb', line 480

def after_row(&block)
  @after_row_handler = block
end

:nodoc:



538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/wice/grid_renderer.rb', line 538

def base_link_for_filter(controller, extra_parameters = {})   #:nodoc:
  new_params = Wice::WgHash.deep_clone controller.params
  new_params.merge!(extra_parameters)

  if new_params[@grid.name]
    new_params[@grid.name].delete(:page) # we reset paging here
    new_params[@grid.name].delete(:f)    # no filter for the base url
    new_params[@grid.name].delete(:foc)  # nullify the focus
    new_params[@grid.name].delete(:q)    # and no request for the saved query
  end

  new_params[:only_path] = false
  base_link_with_pp_info = omit_empty_query controller.url_for(new_params)

  if new_params[@grid.name]
    new_params[@grid.name].delete(:pp)    # and reset back to pagination if show all mode is on
  end
  [base_link_with_pp_info, omit_empty_query(controller.url_for(new_params))]
end

#before_row(&block) ⇒ Object

Can be used to add HTML code (another row, for example) right before each grid row. Nothing is added if the block return false or nil.



486
487
488
# File 'lib/wice/grid_renderer.rb', line 486

def before_row(&block)
  @before_row_handler = block
end

#blank_slate(opts = nil, &block) ⇒ Object

The output of the block submitted to blank_slate is rendered instead of the whole grid if no filters are active and there are no records to render. In addition to the block style two other variants are accepted:

  • g.blank_slate "some text to be rendered"

  • g.blank_slate partial: "partial_name"



507
508
509
510
511
512
513
514
515
# File 'lib/wice/grid_renderer.rb', line 507

def blank_slate(opts = nil, &block)
  if (opts.is_a?(Hash) && opts.key?(:partial) && block.nil?) || (opts.is_a?(String) && block.nil?)
    @blank_slate_handler = opts
  elsif opts.nil? && block
    @blank_slate_handler = block
  else
    raise WiceGridArgumentError.new("blank_slate accepts only a string, a block, or template: 'path_to_template' ")
  end
end

#caption(kaption) ⇒ Object

Takes one argument and adds the <caption></caption> tag to the table with the argument value as the contents of <caption>.



137
138
139
# File 'lib/wice/grid_renderer.rb', line 137

def caption(kaption)
  @kaption = kaption
end

#column(opts = {}, &block) ⇒ Object

Defines everything related to a column in a grid - column name, filtering, rendering cells, etc.

column is only used inside the block of the grid method. See documentation for the grid method for more details.

The only parameter is a hash of options. None of them is optional. If no options are supplied, the result will be a column with no name, no filtering and no sorting.

  • :name - Name of the column.

  • :html - a hash of HTML attributes to be included into the td tag.

  • :class - a shortcut for html: {class: 'css_class'}

  • :attribute - name of a database column (which normally correspond to a model attribute with the same name). By default the field is assumed to belong to the default table (see documentation for the initialize_grid method). Parameter :assoc (association) allows to specify another joined table. Presence of this parameter

    • adds sorting capabilities by this field

    • automatically creates a filter based on the type of the field unless parameter :filter is set to false. The following filters exist for the following types:

      • string - a text field

      • integer and float - two text fields to specify the range. Both limits or only one can be specified

      • boolean - a dropdown list with ‘yes’, ‘no’, or ‘-’. These labels can be changed in lib/wice_grid_config.rb.

      • date - two sets of standard date dropdown lists so specify the time range.

      • datetime - two sets of standard datetime dropdown lists so specify the time range. This filter is far from being user-friendly due to the number of dropdown lists.

  • :filter - Disables filters when set to false. This is needed if sorting is required while filters are not.

  • :filter_type - Using a column filter different from the default filter chosen automatically based on the data type or the :custom_filter argument. See lib/columns/column_processor_index.rb for the list of available filters.

  • :ordering - Enable/disable ordering links in the column titles. The default is true (i.e. if :attribute is defined, ordering is enabled)

  • :assoc - Name of the model association. :attribute belongs to the table joined via this association.

  • :table_alias - In case there are two joined assocations both referring to the same table, ActiveRecord constructs a query where the second join provides an alias for the joined table. Setting :table_alias to this alias will enable WiceGrid to order and filter by columns belonging to different associatiations but originating from the same table without confusion. See README for an example.

  • :custom_filter - Allows to construct a custom dropdown filter. Depending on the value of :custom_filter different modes are available:

    • array of strings and/or numbers - this is a direct definition of possible values of the dropdown. Every item will be used both as the value of the select option and as its label.

    • Array of two-element arrays - Every first item of the two-element array is used for the label of the select option while the second element is the value of the select option

    • Hash - The keys of the hash become the labels of the generated dropdown list, while the values will be values of options of the dropdown list:

    • :auto - a powerful option which populates the dropdown list with all unique values of the field specified by :attribute and :model. :attribute throughout all pages. In other words, this runs an SQL query without offset and limit clauses and with distinct(table.field) instead of distinct(*)

    • any other symbol name (method name) - The dropdown list is populated by all unique value returned by the method with this name sent to all ActiveRecord objects throughout all pages. The main difference from :auto is that this method does not have to be a field in the result set, it is just some value computed in the method after the database call and ActiveRecord instantiation.

      But here lies the major drawback - this mode requires additional query without offset and limit clauses to instantiate all ActiveRecord objects, and performance-wise it brings all the advantages of pagination to nothing. Thus, memory- and performance-wise this can be really bad for some queries and tables and should be used with care.

      If the method returns a atomic value like a string or an integer, it is used for both the value and the label of the select option element. However, if the retuned value is a two element array, the first element is used for the option label and the second - for the value. Read more in README, section ‘Custom dropdown filters’

    • An array of symbols (method names) - similar to the mode with a single symbol name. The first method name is sent to the ActiveRecord object if it responds to this method, the second method name is sent to the returned value unless it is nil, and so on. In other words, a single symbol mode is a case of an array of symbols where the array contains just one element. Thus the warning about the single method name mode applies here as well.

      If the last method returns a atomic value like a string or an integer, it is used for both the value and the label of the select option element. However, if the retuned value is a two element array, the first element is used for the option label and the second - for the value. Read more in README, section ‘Custom dropdown filters’

  • :boolean_filter_true_label - overrides the label for true in the boolean filter (wice_grid.boolean_filter_true_label in wice_grid.yml).

  • :boolean_filter_false_label - overrides the label for false in the boolean filter (wice_grid.boolean_filter_false_label in wice_grid.yml).

  • :allow_multiple_selection - enables or disables switching between single and multiple selection modes for custom dropdown boxes. true by default (see ALLOW_MULTIPLE_SELECTION in the configuration file).

  • :filter_all_label - overrides the default value for BOOLEAN_FILTER_FALSE_LABEL (‘--’) in the config. Has effect in a column with a boolean filter or a custom filter.

  • :detach_with_id - allows to detach the filter and render it after or before the grid with the grid_filter helper. The value is an arbitrary unique identifier of the filter. Read section ‘Detached Filters’ in README for details. Has effect in a column with a boolean filter or a custom filter.

  • :in_csv - When CSV export is enabled, all columns are included into the export. Setting :in_csv to false will prohibit the column from inclusion into the export.

  • :in_html - When CSV export is enabled and it is needed to use a column for CSV export only and ignore it in HTML, set this parameter to false.

  • :negation - turn on/off the negation checkbox in string filters

  • :auto_reload - a boolean value specifying if a change in a filter triggers reloading of the grid. Works with all filter types including the JS calendar, the only exception is the standard Rails date/datetime filters. The default is false. (see AUTO_RELOAD in the configuration file).

The block parameter is an ActiveRecord instance. This block is called for every ActiveRecord shown, and the return value of the block is a string which becomes the contents of one table cell, or an array of two elements where the first element is the cell contents and the second is a hash of HTML attributes to be added for the <td> tag of the current cell.

In case of an array output, please note that if you need to define HTML attributes for all <td>‘s in a column, use html. Also note that if the method returns a hash with a :class or 'class' element, it will not overwrite the class defined in html, or classes added by the grid itself (active-filter and sorted), instead they will be all concatenated: <td class="sorted user_class_for_columns user_class_for_this_specific_cell">

It is up to the developer to make sure that what in rendered in column cells corresponds to sorting and filtering specified by parameters :attribute and :model.



295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/wice/grid_renderer.rb', line 295

def column(opts = {}, &block)
  options = {
    allow_multiple_selection:    ConfigurationProvider.value_for(:ALLOW_MULTIPLE_SELECTION),
    assoc:                       nil,
    attribute:                   nil,
    auto_reload:                 ConfigurationProvider.value_for(:AUTO_RELOAD),
    boolean_filter_false_label:  NlMessage['boolean_filter_false_label'],
    boolean_filter_true_label:   NlMessage['boolean_filter_true_label'],
    class:                       nil,
    custom_filter:               nil,
    detach_with_id:              nil,
    filter:                      true,
    filter_all_label:            ConfigurationProvider.value_for(:CUSTOM_FILTER_ALL_LABEL),
    filter_type:                 nil,
    html:                        {},
    in_csv:                      true,
    in_html:                     true,
    model:                       nil, # will throw an exception with instructions
    name:                        '',
    negation:                    ConfigurationProvider.value_for(:NEGATION_IN_STRING_FILTERS),
    ordering:                    true,
    table_alias:                 nil
  }

  opts.assert_valid_keys(options.keys)
  options.merge!(opts)

  assocs = nil

  if options[:model]
    raise WiceGridArgumentError.new('Instead of specifying a model of a joined table please use assoc: :name_of_association')
  end

  unless options[:assoc].nil?

    unless options[:assoc].is_a?(Symbol) ||
          (options[:assoc].is_a?(Array) && ! options[:assoc].empty? && options[:assoc].all?{ |assoc| assoc.is_a?(Symbol)})

      raise WiceGridArgumentError.new('Option :assoc can only be a symbol or an array of symbols')
    end

    assocs = options[:assoc].is_a?(Symbol) ? [options[:assoc]] : options[:assoc]

    options[:model] = get_model_from_associations(@grid.klass, assocs)
  end

  if options[:attribute].nil? && options[:model]
    raise WiceGridArgumentError.new('Option :assoc is only used together with :attribute')
  end

  if options[:attribute] && options[:attribute].index('.')
    raise WiceGridArgumentError.new("Invalid attribute name #{options[:attribute]}. An attribute name must not contain a table name!")
  end


  if options[:class]
    options[:html] ||= {}
    Wice::WgHash.add_or_append_class_value!(options[:html], options[:class])
    options.delete(:class)
  end

  if block.nil?
    if !options[:attribute].blank?
      if assocs.nil?
        block = ->(obj) { obj.send(options[:attribute]) }
      else
        messages = assocs + [ options[:attribute] ]
        block = ->(obj) { obj.deep_send(*messages) }
      end
    else
      raise WiceGridArgumentError.new(
        'Missing column block without attribute defined. You can only omit the block if attribute is present.')
    end
  end

  klass = Columns::ViewColumn
  if options[:attribute] &&
    col_type_and_table_name = @grid.declare_column(
      column_name:          options[:attribute],
      model:                options[:model],
      custom_filter_active: options[:custom_filter],
      table_alias:          options[:table_alias],
      filter_type:          options[:filter_type],
      assocs:               assocs
    )

    # [ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter::Column, String, Boolean]
    db_column, table_name, main_table = col_type_and_table_name
    col_type = db_column.type

    if options[:custom_filter]

      custom_filter = if options[:custom_filter] == :auto
        -> { @grid.distinct_values_for_column(db_column) } # Thank God Ruby has higher order functions!!!

      elsif options[:custom_filter].class == Symbol
        -> { @grid.distinct_values_for_column_in_resultset([options[:custom_filter]]) }

      elsif options[:custom_filter].class == Hash
        options[:custom_filter].keys

        options[:custom_filter].to_a

      elsif options[:custom_filter].class == Array
        if options[:custom_filter].empty?
          []
        elsif Wice::WgEnumerable.all_items_are_of_class(options[:custom_filter], Symbol)
          -> { @grid.distinct_values_for_column_in_resultset(options[:custom_filter]) }

        elsif Wice::WgEnumerable.all_items_are_of_class(options[:custom_filter], String) || WgEnumerable.all_items_are_of_class(options[:custom_filter], Numeric)
          options[:custom_filter].map { |i| [i, i] }

        elsif Wice::WgEnumerable.all_items_are_of_class(options[:custom_filter], Array)
          options[:custom_filter]
        else
          raise WiceGridArgumentError.new(
            ':custom_filter can equal :auto, an array of string and/or numbers (direct values for the dropdown), ' \
            'a homogeneous array of symbols (a sequence of methods to send to AR objects in the result set to ' \
            'retrieve unique values for the dropdown), a Symbol (a shortcut for a one member array of symbols), ' \
            'a hash where keys are labels and values are values for the dropdown option, or an array of two-item arrays, ' \
            'each of which contains the label (first element) and the value (second element) for a dropdown option'
            )
        end
      end

      klass = Columns.get_view_column_processor(:custom)
    elsif options[:filter_type]
      klass = Columns.get_view_column_processor(options[:filter_type])
    else

      col_type = case col_type
      when :date
        Wice::Defaults::DEFAULT_FILTER_FOR_DATE
      when :datetime
        Wice::Defaults::DEFAULT_FILTER_FOR_DATETIME
      when :timestamp
        Wice::Defaults::DEFAULT_FILTER_FOR_DATETIME
      else
        col_type
      end

      klass = Columns.get_view_column_processor(col_type)
    end # custom_filter

  end # attribute

  vc = klass.new(block, options, @grid, table_name, main_table, custom_filter, @view)

  vc.negation = options[:negation] if vc.respond_to? :negation=

  vc.filter_all_label = options[:filter_all_label] if vc.is_a?(Columns.get_view_column_processor(:custom))
  if vc.is_a?(Columns.get_view_column_processor(:boolean))
    vc.boolean_filter_true_label = options[:boolean_filter_true_label]
    vc.boolean_filter_false_label = options[:boolean_filter_false_label]
  end
  add_column(vc)
end

#column_labels(filter = nil) ⇒ Object

:nodoc:



73
74
75
# File 'lib/wice/grid_renderer.rb', line 73

def column_labels(filter = nil)  #:nodoc:
  filter_columns(filter).collect(&:name)
end

:nodoc:



569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/wice/grid_renderer.rb', line 569

def column_link(column, direction, params, extra_parameters = {})   #:nodoc:
  column_attribute_name = if column.attribute.index('.') || column.main_table
    column.attribute
  else
    column.table_alias_or_table_name + '.' + column.attribute
  end

  query_params = { @grid.name => {
    ORDER_PARAMETER_NAME           => column_attribute_name,
    ORDER_DIRECTION_PARAMETER_NAME => direction
  } }

  cleaned_params = Wice::WgHash.deep_clone params
  cleaned_params.merge!(extra_parameters)

  cleaned_params.delete(:controller)
  cleaned_params.delete(:action)

  query_params = Wice::WgHash.rec_merge(cleaned_params, query_params)

  '?' + query_params.to_query
end

#configObject

:nodoc:



48
49
50
# File 'lib/wice/grid_renderer.rb', line 48

def config  #:nodoc:
  @view.config
end

#controllerObject

:nodoc:



52
53
54
# File 'lib/wice/grid_renderer.rb', line 52

def controller  #:nodoc:
  @view.controller
end

#csv_export_iconObject

:nodoc:



106
107
108
109
110
111
112
113
# File 'lib/wice/grid_renderer.rb', line 106

def csv_export_icon #:nodoc:
  (
    :div,
    (:i, '', class: 'fa fa-file-excel-o'),
    title: NlMessage['csv_export_tooltip'],
    class: 'clickable export-to-csv-button'
  )
end

#each_column(filter = nil) ⇒ Object Also known as: each

:nodoc:



77
78
79
# File 'lib/wice/grid_renderer.rb', line 77

def each_column(filter = nil)  #:nodoc:
  filter_columns(filter).each { |col| yield col }
end

#each_column_aware_of_one_last_one(filter = nil) {|cols.last, true| ... } ⇒ Object

:nodoc:

Yields:

  • (cols.last, true)


81
82
83
84
85
# File 'lib/wice/grid_renderer.rb', line 81

def each_column_aware_of_one_last_one(filter = nil)  #:nodoc:
  cols = filter_columns(filter)
  cols[0..-2].each { |col| yield col, false }
  yield cols.last, true
end

#each_column_label(filter = nil) ⇒ Object

:nodoc:



69
70
71
# File 'lib/wice/grid_renderer.rb', line 69

def each_column_label(filter = nil)  #:nodoc:
  filter_columns(filter).each { |col| yield col.name }
end

#each_column_with_attributeObject

:nodoc:



99
100
101
# File 'lib/wice/grid_renderer.rb', line 99

def each_column_with_attribute  #:nodoc:
  @columns.select(&:attribute).each { |col| yield col }
end

#find_one_for(filter) ⇒ Object

:nodoc:



95
96
97
# File 'lib/wice/grid_renderer.rb', line 95

def find_one_for(filter)  #:nodoc:
  filter_columns(filter).find { |col| yield col }
end

#get_model_from_associations(model, assocs) ⇒ Object

:nodoc:



453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File 'lib/wice/grid_renderer.rb', line 453

def get_model_from_associations(model, assocs) # :nodoc:
  if assocs.empty?
    model
  else
    head = assocs[0]
    tail = assocs[1..-1]

    if reflection = model.reflect_on_association(head)
      next_model = reflection.klass
      get_model_from_associations(next_model, tail)
    else
      raise WiceGridArgumentError.new("Association #{head} not found in #{model}")
    end
  end
end

#get_row_attributes(ar_object) ⇒ Object

:nodoc:



517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/wice/grid_renderer.rb', line 517

def get_row_attributes(ar_object) #:nodoc:
  if @row_attributes_handler
    row_attributes = @row_attributes_handler.call(ar_object)
    row_attributes = {} if row_attributes.blank?
    unless row_attributes.is_a?(Hash)
      raise WiceGridArgumentError.new("row_attributes block must return a hash containing HTML attributes. The returned value is #{row_attributes.inspect}")
    end
    row_attributes
  else
    {}
  end
end

#last_column_for_htmlObject

:nodoc:



87
88
89
# File 'lib/wice/grid_renderer.rb', line 87

def last_column_for_html  #:nodoc:
  filter_columns(:in_html).last
end

#last_row(&block) ⇒ Object

Can be used to add HTML code (calculation results, for example) after all rows. Nothing is added if the block return false or nil.



498
499
500
# File 'lib/wice/grid_renderer.rb', line 498

def last_row(&block)
  @last_row_handler = block
end

:nodoc:



558
559
560
561
562
563
564
565
566
567
# File 'lib/wice/grid_renderer.rb', line 558

def link_for_export(controller, format, extra_parameters = {})   #:nodoc:
  new_params = Wice::WgHash.deep_clone controller.params
  new_params.merge!(extra_parameters)

  new_params[@grid.name] = {} unless new_params[@grid.name]
  new_params[@grid.name][:export] = format

  new_params[:only_path] = false
  controller.url_for(new_params)
end

#no_filter_needed?Boolean

:nodoc:

Returns:

  • (Boolean)


530
531
532
# File 'lib/wice/grid_renderer.rb', line 530

def no_filter_needed?   #:nodoc:
  !@columns.inject(false) { |a, b| a || b.filter_shown? }
end

#no_filter_needed_in_main_table?Boolean

:nodoc:

Returns:

  • (Boolean)


534
535
536
# File 'lib/wice/grid_renderer.rb', line 534

def no_filter_needed_in_main_table?   #:nodoc:
  !@columns.inject(false) { |a, b| a || b.filter_shown_in_main_table? }
end

#number_of_columns(filter = nil) ⇒ Object

:nodoc:



65
66
67
# File 'lib/wice/grid_renderer.rb', line 65

def number_of_columns(filter = nil)  #:nodoc:
  filter_columns(filter).size
end

#pagination_panel(number_of_columns, hide_csv_button) ⇒ Object

:nodoc:



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/wice/grid_renderer.rb', line 115

def pagination_panel(number_of_columns, hide_csv_button)  #:nodoc:
  panel = yield

  render_csv_button = @grid.export_to_csv_enabled && !hide_csv_button

  if panel.nil?
    if render_csv_button
      "<tr><td colspan=\"#{number_of_columns}\"></td><td>#{csv_export_icon}</td></tr>"
    else
      ''
    end
  else
    if render_csv_button
      "<tr><td colspan=\"#{number_of_columns}\">#{panel}</td><td>#{csv_export_icon}</td></tr>"
    else
      "<tr><td colspan=\"#{number_of_columns + 1}\">#{panel}</td></tr>"
    end
  end
end

#replace_row(&block) ⇒ Object

Can be used to replace the HTML code (for example to make a multi-column spanning row) of a row. Nothing is replaced if the block return false or nil.



492
493
494
# File 'lib/wice/grid_renderer.rb', line 492

def replace_row(&block)
  @replace_row_handler = block
end

#row_attributes(&block) ⇒ Object

Optional method inside the grid block, to which every ActiveRecord instance is injected, just like column. Unlike column, it returns a hash which will be used as HTML attributes for the row with the given ActiveRecord instance.

Note that if the method returns a hash with a :class or 'class' element, it will not overwrite classes even and odd, instead they will be concatenated: <tr class="even highlighted_row_class_name">



474
475
476
# File 'lib/wice/grid_renderer.rb', line 474

def row_attributes(&block)
  @row_attributes_handler = block
end

#select_for(filter) ⇒ Object

:nodoc:



91
92
93
# File 'lib/wice/grid_renderer.rb', line 91

def select_for(filter)  #:nodoc:
  filter_columns(filter).select { |col| yield col }
end