Class: Symphonia::RendererHelper::QueryRender

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/symphonia/renderer_helper.rb

Constant Summary collapse

OPTIONS =
[:without_pagination, :show_checkboxes, :show_radios, :table_css_classes]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(helper, query, options = {}) ⇒ QueryRender

Returns a new instance of QueryRender.



23
24
25
26
27
28
29
# File 'app/helpers/symphonia/renderer_helper.rb', line 23

def initialize(helper, query, options = {})
  @_c = helper
  @query = query
  OPTIONS.each do |key|
    send("#{key}=", options[key])
  end
end

Instance Attribute Details

#queryObject (readonly)

Returns the value of attribute query.



18
19
20
# File 'app/helpers/symphonia/renderer_helper.rb', line 18

def query
  @query
end

#summarizeObject

Returns the value of attribute summarize.



19
20
21
# File 'app/helpers/symphonia/renderer_helper.rb', line 19

def summarize
  @summarize
end

Instance Method Details

#css_classes(entity) ⇒ Object



77
78
79
80
81
# File 'app/helpers/symphonia/renderer_helper.rb', line 77

def css_classes(entity)
  css = []
  css << "status--#{entity.status}" if entity.respond_to?(:status)
  css.join("__") + entity.try(:css_classes).to_s
end

#default_buttons(entity) ⇒ Object



56
57
58
# File 'app/helpers/symphonia/renderer_helper.rb', line 56

def default_buttons(entity)
  edit_link(entity) + delete_link(entity)
end


52
53
54
# File 'app/helpers/symphonia/renderer_helper.rb', line 52

def delete_link(entity)
  @_c.link_to(@_c.icon('del', t(:button_delete)), entity, method: 'DELETE', data: { remote: true, confirm: t(:text_are_you_sure) })
end


47
48
49
50
# File 'app/helpers/symphonia/renderer_helper.rb', line 47

def edit_link(entity)
  model = @_c.controller.try(:model) || @_c.controller_name
  @_c.link_to(@_c.icon('edit', t(:button_edit)), @_c.edit_polymorphic_path(entity, back_url: @_c.polymorphic_path(model, page: @_c.params[:page])))
end

#header_tag(column, options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/symphonia/renderer_helper.rb', line 60

def header_tag(column, options = {})
  return '' unless column.header?

  title = column.title
  return title unless column.sort?

  current_column = query.sort_column || SortableTable::SortColumn.new(nil, nil)
  prefix = options.delete(:prefix)
  is_current_column = column.sort_definition.column == current_column.column
  options_class = options.delete(:class)
  css_class = is_current_column ? "current #{current_column.direction} #{options_class}" : options_class
  direction = is_current_column && current_column.direction == 'asc' ? 'desc' : 'asc'
  sort_params = { "#{prefix}sort" => "#{column.sort_definition.column}:#{direction}",
                  "#{prefix}page" => nil }
  @_c.link_to title, query.to_params.merge(sort_params), options.merge({ class: css_class })
end

#show_checkboxes?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/helpers/symphonia/renderer_helper.rb', line 35

def show_checkboxes?
  !!@show_checkboxes
end


43
44
45
# File 'app/helpers/symphonia/renderer_helper.rb', line 43

def show_link(entity)
  @_c.link_to(@_c.icon('info-circle', t(:button_show)), entity)
end

#show_radios?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'app/helpers/symphonia/renderer_helper.rb', line 39

def show_radios?
  !!@show_radios
end

#show_summarize?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'app/helpers/symphonia/renderer_helper.rb', line 31

def show_summarize?
  !!summarize
end