Class: Effective::Datatable
- Inherits:
 - 
      Object
      
        
- Object
 - Effective::Datatable
 
 
- Extended by:
 - EffectiveDatatable::Dsl
 
- Includes:
 - EffectiveDatatable::Attributes, EffectiveDatatable::Collection, EffectiveDatatable::Compute, EffectiveDatatable::Cookie, EffectiveDatatable::Format, EffectiveDatatable::Hooks, EffectiveDatatable::Params, EffectiveDatatable::Resource, EffectiveDatatable::State
 
- Defined in:
 - app/models/effective/datatable.rb
 
Direct Known Subclasses
Constant Summary
Constants included from EffectiveDatatable::Resource
EffectiveDatatable::Resource::AGGREGATE_SQL_FUNCTIONS
Constants included from EffectiveDatatable::Format
EffectiveDatatable::Format::BLANK, EffectiveDatatable::Format::NONVISIBLE, EffectiveDatatable::Format::SPACER, EffectiveDatatable::Format::SPACER_TEMPLATE
Constants included from EffectiveDatatable::Compute
EffectiveDatatable::Compute::BLANK
Instance Attribute Summary collapse
- 
  
    
      #_aggregates  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Hashes of DSL options.
 - 
  
    
      #_bulk_actions  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute _bulk_actions.
 - 
  
    
      #_charts  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute _charts.
 - 
  
    
      #_collection  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The collection itself.
 - 
  
    
      #_collection_apply_belongs_to  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute _collection_apply_belongs_to.
 - 
  
    
      #_collection_apply_scope  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
Returns the value of attribute _collection_apply_scope.
 - 
  
    
      #_columns  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute _columns.
 - 
  
    
      #_filters  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute _filters.
 - 
  
    
      #_form  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute _form.
 - 
  
    
      #_scopes  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute _scopes.
 - 
  
    
      #attributes  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Anything that we initialize our table with.
 - 
  
    
      #effective_resource  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute effective_resource.
 - 
  
    
      #state  ⇒ Object 
    
    
  
  
  
  
    
      readonly
    
    
  
  
  
  
  
  
    
Returns the value of attribute state.
 - 
  
    
      #view  ⇒ Object 
    
    
  
  
  
  
    
    
  
  
  
  
  
  
    
The view.
 
Instance Method Summary collapse
- 
  
    
      #_filters_form_required?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Whether the filters must be rendered as a <form> or we can keep the normal <div> behaviour.
 - #blank?(view = nil) ⇒ Boolean
 - #collection ⇒ Object
 - #columns ⇒ Object
 - #default_visibility ⇒ Object
 - #dsl_tool ⇒ Object
 - #fallback_effective_resource ⇒ Object
 - #html_class ⇒ Object
 - 
  
    
      #initialize(view = nil, attributes = nil)  ⇒ Datatable 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    
A new instance of Datatable.
 - 
  
    
      #inline?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Inline crud.
 - #present?(view = nil) ⇒ Boolean
 - 
  
    
      #reorder?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
Reordering.
 - #resource ⇒ Object
 - #sortable? ⇒ Boolean
 - #to_json ⇒ Object
 - #to_param ⇒ Object
 
Methods included from EffectiveDatatable::Dsl
bulk_actions, charts, datatable, filters
Methods included from EffectiveDatatable::State
#display_length, #display_start, #filter, #offset, #order_direction, #order_index, #order_name, #page, #per_page, #scope, #search
Methods included from EffectiveDatatable::Resource
#admin_namespace?, #association_macros, #controller_namespace
Methods included from EffectiveDatatable::Hooks
Methods included from EffectiveDatatable::Cookie
Methods included from EffectiveDatatable::Collection
#active_record_array_collection?, #active_record_collection?, #active_record_polymorphic_array_collection?, #array_collection?, #collection_class
Constructor Details
#initialize(view = nil, attributes = nil) ⇒ Datatable
Returns a new instance of Datatable.
      36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54  | 
    
      # File 'app/models/effective/datatable.rb', line 36 def initialize(view = nil, attributes = nil) (attributes = view; view = nil) if view.kind_of?(Hash) @attributes = (attributes || {}) @state = initial_state @_aggregates = {} @_bulk_actions = [] @_charts = {} @_columns = {} @_filters = {} @_form = {} @_scopes = {} raise 'expected a hash of arguments' unless @attributes.kind_of?(Hash) raise 'collection is defined as a method. Please use the collection do ... end syntax.' unless collection.nil? self.view = view if view end  | 
  
Instance Attribute Details
#_aggregates ⇒ Object (readonly)
Hashes of DSL options
      8 9 10  | 
    
      # File 'app/models/effective/datatable.rb', line 8 def _aggregates @_aggregates end  | 
  
#_bulk_actions ⇒ Object (readonly)
Returns the value of attribute _bulk_actions.
      9 10 11  | 
    
      # File 'app/models/effective/datatable.rb', line 9 def _bulk_actions @_bulk_actions end  | 
  
#_charts ⇒ Object (readonly)
Returns the value of attribute _charts.
      10 11 12  | 
    
      # File 'app/models/effective/datatable.rb', line 10 def _charts @_charts end  | 
  
#_collection ⇒ Object
The collection itself. Only evaluated once.
      17 18 19  | 
    
      # File 'app/models/effective/datatable.rb', line 17 def _collection @_collection end  | 
  
#_collection_apply_belongs_to ⇒ Object
Returns the value of attribute _collection_apply_belongs_to.
      18 19 20  | 
    
      # File 'app/models/effective/datatable.rb', line 18 def _collection_apply_belongs_to @_collection_apply_belongs_to end  | 
  
#_collection_apply_scope ⇒ Object
Returns the value of attribute _collection_apply_scope.
      19 20 21  | 
    
      # File 'app/models/effective/datatable.rb', line 19 def _collection_apply_scope @_collection_apply_scope end  | 
  
#_columns ⇒ Object (readonly)
Returns the value of attribute _columns.
      11 12 13  | 
    
      # File 'app/models/effective/datatable.rb', line 11 def _columns @_columns end  | 
  
#_filters ⇒ Object (readonly)
Returns the value of attribute _filters.
      12 13 14  | 
    
      # File 'app/models/effective/datatable.rb', line 12 def _filters @_filters end  | 
  
#_form ⇒ Object (readonly)
Returns the value of attribute _form.
      13 14 15  | 
    
      # File 'app/models/effective/datatable.rb', line 13 def _form @_form end  | 
  
#_scopes ⇒ Object (readonly)
Returns the value of attribute _scopes.
      14 15 16  | 
    
      # File 'app/models/effective/datatable.rb', line 14 def _scopes @_scopes end  | 
  
#attributes ⇒ Object (readonly)
Anything that we initialize our table with. That’s it. Can’t be changed by state.
      3 4 5  | 
    
      # File 'app/models/effective/datatable.rb', line 3 def attributes @attributes end  | 
  
#effective_resource ⇒ Object (readonly)
Returns the value of attribute effective_resource.
      4 5 6  | 
    
      # File 'app/models/effective/datatable.rb', line 4 def effective_resource @effective_resource end  | 
  
#state ⇒ Object (readonly)
Returns the value of attribute state.
      5 6 7  | 
    
      # File 'app/models/effective/datatable.rb', line 5 def state @state end  | 
  
#view ⇒ Object
The view
      22 23 24  | 
    
      # File 'app/models/effective/datatable.rb', line 22 def view @view end  | 
  
Instance Method Details
#_filters_form_required? ⇒ Boolean
Whether the filters must be rendered as a <form> or we can keep the normal <div> behaviour
      142 143 144  | 
    
      # File 'app/models/effective/datatable.rb', line 142 def _filters_form_required? _form[:verb].present? end  | 
  
#blank?(view = nil) ⇒ Boolean
      104 105 106 107 108 109 110 111 112  | 
    
      # File 'app/models/effective/datatable.rb', line 104 def blank?(view = nil) unless (@view || view) raise 'unable to call blank? without an assigned view. In your view, either call render_datatable(@datatable) first, or use @datatable.blank?(self)' end self.view ||= view to_json[:recordsTotal] == 0 end  | 
  
#collection ⇒ Object
      158 159 160  | 
    
      # File 'app/models/effective/datatable.rb', line 158 def collection @_collection end  | 
  
#columns ⇒ Object
      154 155 156  | 
    
      # File 'app/models/effective/datatable.rb', line 154 def columns @_columns end  | 
  
#default_visibility ⇒ Object
      174 175 176  | 
    
      # File 'app/models/effective/datatable.rb', line 174 def default_visibility columns.values.inject({}) { |h, col| h[col[:index]] = col[:visible]; h } end  | 
  
#dsl_tool ⇒ Object
      162 163 164  | 
    
      # File 'app/models/effective/datatable.rb', line 162 def dsl_tool @dsl_tool ||= DatatableDslTool.new(self) end  | 
  
#fallback_effective_resource ⇒ Object
      170 171 172  | 
    
      # File 'app/models/effective/datatable.rb', line 170 def fallback_effective_resource @fallback_effective_resource ||= Effective::Resource.new('', namespace: controller_namespace) end  | 
  
#html_class ⇒ Object
      146 147 148  | 
    
      # File 'app/models/effective/datatable.rb', line 146 def html_class Array(attributes[:class] || EffectiveDatatables.html_class).join(' ').presence end  | 
  
#inline? ⇒ Boolean
Inline crud
      128 129 130  | 
    
      # File 'app/models/effective/datatable.rb', line 128 def inline? attributes[:inline] == true end  | 
  
#present?(view = nil) ⇒ Boolean
      94 95 96 97 98 99 100 101 102  | 
    
      # File 'app/models/effective/datatable.rb', line 94 def present?(view = nil) unless (@view || view) raise 'unable to call present? without an assigned view. In your view, either call render_datatable(@datatable) first, or use @datatable.present?(self)' end self.view ||= view to_json[:recordsTotal] > 0 end  | 
  
#reorder? ⇒ Boolean
Reordering
      133 134 135  | 
    
      # File 'app/models/effective/datatable.rb', line 133 def reorder? columns.key?(:_reorder) end  | 
  
#resource ⇒ Object
      166 167 168  | 
    
      # File 'app/models/effective/datatable.rb', line 166 def resource raise('depecated. Please use .effective_resource instead') end  | 
  
#sortable? ⇒ Boolean
      137 138 139  | 
    
      # File 'app/models/effective/datatable.rb', line 137 def sortable? !reorder? && attributes[:sortable] != false end  | 
  
#to_json ⇒ Object
      114 115 116 117 118 119 120 121 122 123 124 125  | 
    
      # File 'app/models/effective/datatable.rb', line 114 def to_json @json ||= ( { data: (compute || []), draw: (params[:draw] || 0), recordsTotal: (@total_records || 0), recordsFiltered: (@display_records || 0), aggregates: (@aggregates_data || []), charts: (@charts_data || {}) } ) end  | 
  
#to_param ⇒ Object
      150 151 152  | 
    
      # File 'app/models/effective/datatable.rb', line 150 def to_param "#{self.class.name.underscore.parameterize}-#{[self.class, attributes].hash.abs.to_s.last(12)}" end  |