Class: Symphonia::QueryColumns::AttributeColumn
- Inherits:
-
Object
- Object
- Symphonia::QueryColumns::AttributeColumn
- Defined in:
- lib/symphonia/query_columns/attribute_column.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#header ⇒ Object
writeonly
Sets the attribute header.
-
#includes ⇒ Object
readonly
Returns the value of attribute includes.
-
#joins ⇒ Object
readonly
Returns the value of attribute joins.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#no_header ⇒ Object
Returns the value of attribute no_header.
-
#preload ⇒ Object
readonly
Returns the value of attribute preload.
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#sort ⇒ Object
writeonly
Sets the attribute sort.
-
#sort_column_name ⇒ Object
writeonly
Sets the attribute sort_column_name.
- #sort_definition ⇒ Object
-
#sort_options ⇒ Object
Returns the value of attribute sort_options.
Instance Method Summary collapse
- #css_classes ⇒ Object
-
#format_value(view, entity) ⇒ Object
def header(table_header_tag) if @header === false table_header_tag.th(@name, ”, sort: false) else table_header_tag.th(@name, title, @sort.nil?, sort_options: (sort_options || {).merge(sort_column_name)}) end end.
- #header? ⇒ Boolean
-
#initialize(attribute, query, options = {}) ⇒ AttributeColumn
constructor
A new instance of AttributeColumn.
- #inspect ⇒ Object
- #reference? ⇒ Boolean
- #sort? ⇒ Boolean
- #sum ⇒ Object
- #sum_value(view) ⇒ Object
- #summarize? ⇒ Boolean
- #value(entity) ⇒ Object
Constructor Details
#initialize(attribute, query, options = {}) ⇒ AttributeColumn
Returns a new instance of AttributeColumn.
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 11 def initialize(attribute, query, = {}) @attribute = attribute @name = attribute.name @query = query @model = query.model @options = @includes = .delete(:includes) || reference? && [@name] || [] @preload = .delete(:preload) || reference? && [@name] || [] @joins = Array(.delete(:joins)) || [] @sort_definition = attribute.sort_column @sort = attribute.sort? end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
5 6 7 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 5 def attribute @attribute end |
#header=(value) ⇒ Object (writeonly)
Sets the attribute header
7 8 9 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 7 def header=(value) @header = value end |
#includes ⇒ Object (readonly)
Returns the value of attribute includes.
5 6 7 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 5 def includes @includes end |
#joins ⇒ Object (readonly)
Returns the value of attribute joins.
5 6 7 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 5 def joins @joins end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 5 def model @model end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 5 def name @name end |
#no_header ⇒ Object
Returns the value of attribute no_header.
6 7 8 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 6 def no_header @no_header end |
#preload ⇒ Object (readonly)
Returns the value of attribute preload.
5 6 7 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 5 def preload @preload end |
#query ⇒ Object (readonly)
Returns the value of attribute query.
5 6 7 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 5 def query @query end |
#sort=(value) ⇒ Object (writeonly)
Sets the attribute sort
7 8 9 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 7 def sort=(value) @sort = value end |
#sort_column_name=(value) ⇒ Object
Sets the attribute sort_column_name
7 8 9 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 7 def sort_column_name=(value) @sort_column_name = value end |
#sort_definition ⇒ Object
53 54 55 56 57 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 53 def sort_definition return nil unless sort? @sort_definition ||= SortableTable::SortColumnCustomDefinition.new(@name, { asc: "#{sort_column_name} asc", desc: "#{sort_column_name} desc" }) end |
#sort_options ⇒ Object
Returns the value of attribute sort_options.
6 7 8 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 6 def @sort_options end |
Instance Method Details
#css_classes ⇒ Object
73 74 75 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 73 def css_classes @name.to_s end |
#format_value(view, entity) ⇒ Object
def header(table_header_tag)
if @header === false
table_header_tag.th(@name, '', sort: false)
else
table_header_tag.th(@name, title, {sort: @sort.nil?, sort_options: ( || {}).merge({column: sort_column_name})})
end
end
37 38 39 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 37 def format_value(view, entity) @attribute.format(view, entity) end |
#header? ⇒ Boolean
45 46 47 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 45 def header? !(@header == false) end |
#inspect ⇒ Object
77 78 79 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 77 def inspect "#<#{self.class.name} name='#{name}' options=#{@options.inspect}>" end |
#reference? ⇒ Boolean
25 26 27 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 25 def reference? @attribute.is_a?(Symphonia::ModelAttributes::ReferenceAttribute) end |
#sort? ⇒ Boolean
49 50 51 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 49 def sort? !(@sort == false) end |
#sum ⇒ Object
67 68 69 70 71 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 67 def sum return nil unless summarize? @sum ||= query.entities.sum(name) end |
#sum_value(view) ⇒ Object
63 64 65 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 63 def sum_value(view) format_value(view, OpenStruct.new(name => sum)) end |
#summarize? ⇒ Boolean
41 42 43 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 41 def summarize? false end |
#value(entity) ⇒ Object
59 60 61 |
# File 'lib/symphonia/query_columns/attribute_column.rb', line 59 def value(entity) entity.send(name) end |