Class: Carnival::GenericDatatable
- Inherits:
-
Object
- Object
- Carnival::GenericDatatable
- Defined in:
- app/datatable/carnival/generic_datatable.rb
Constant Summary collapse
- RENDER_TABLE =
0- RENDER_CSV =
1- RENDER_PDF =
2
Instance Attribute Summary collapse
-
#model ⇒ Object
Returns the value of attribute model.
-
#presenter ⇒ Object
Returns the value of attribute presenter.
Instance Method Summary collapse
- #as_csv(options = {}) ⇒ Object
- #as_json(options = {}) ⇒ Object
- #as_pdf(options = {}) ⇒ Object
- #filters ⇒ Object
-
#initialize(view, model, controller, presenter, items = nil) ⇒ GenericDatatable
constructor
A new instance of GenericDatatable.
Constructor Details
#initialize(view, model, controller, presenter, items = nil) ⇒ GenericDatatable
Returns a new instance of GenericDatatable.
13 14 15 16 17 18 19 20 |
# File 'app/datatable/carnival/generic_datatable.rb', line 13 def initialize(view, model, controller, presenter, items=nil) @view = view @model = model @controller = controller @presenter = presenter @items = items @filters = [] end |
Instance Attribute Details
#model ⇒ Object
Returns the value of attribute model.
6 7 8 |
# File 'app/datatable/carnival/generic_datatable.rb', line 6 def model @model end |
#presenter ⇒ Object
Returns the value of attribute presenter.
6 7 8 |
# File 'app/datatable/carnival/generic_datatable.rb', line 6 def presenter @presenter end |
Instance Method Details
#as_csv(options = {}) ⇒ Object
22 23 24 |
# File 'app/datatable/carnival/generic_datatable.rb', line 22 def as_csv( = {}) data_to_csv(data(RENDER_CSV)) end |
#as_json(options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/datatable/carnival/generic_datatable.rb', line 26 def as_json( = {}) if(params[:scope].present? && params[:scope] != "all") @model = @model.send(params[:scope]) end date_filter_field = @presenter.date_filter_field if(date_filter_field.present? && params[:from].present? && params[:from] != "" && params[:to].present? && params[:to] != "") @model = @model.where("#{@presenter.table_name}.#{date_filter_field.name} between ? and ?", "#{params[:from]} 00:00:00", "#{params[:to]} 23:59:59") end count = @model.count return_data = {} return_data[:data] = data { sEcho: params[:sEcho].to_i, iTotalRecords: count, iTotalDisplayRecords: records.total_entries, aaData: return_data[:data] } end |
#as_pdf(options = {}) ⇒ Object
48 49 50 |
# File 'app/datatable/carnival/generic_datatable.rb', line 48 def as_pdf( = {}) fetch_records end |
#filters ⇒ Object
52 53 54 |
# File 'app/datatable/carnival/generic_datatable.rb', line 52 def filters @filters end |