Class: TrkDatatables::Neo4j

Inherits:
Base
  • Object
show all
Defined in:
lib/trk_datatables/neo4j.rb

Instance Attribute Summary

Attributes inherited from Base

#column_key_options

Instance Method Summary collapse

Methods inherited from Base

#additional_data_for_json, #all_items, #all_items_count, #as_json, #columns, #default_order, #default_page_length, #dt_orders_or_default_index_and_direction, #dt_per_page_or_default, #filtered_items, #filtered_items_count, #global_search_columns, #index_by_column_key, #initialize, #link_to_rdoc, #ordered_paginated_filtered_items, #param_get, #predefined_date_ranges, #predefined_datetime_ranges, #predefined_ranges, #preferences_field, #preferences_holder, #render_html, #rows

Methods included from BaseHelpers

#form_field_name, #order_set, #param_set, #range_string

Constructor Details

This class inherits a constructor from TrkDatatables::Base

Instance Method Details

#filter_by_columns(all) ⇒ Object



14
15
16
# File 'lib/trk_datatables/neo4j.rb', line 14

def filter_by_columns(all)
  all
end

#filter_by_search_all(filtered) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'lib/trk_datatables/neo4j.rb', line 3

def filter_by_search_all(filtered)
  return filtered unless @dt_params.search_all.present?

  # https://neo4jrb.readthedocs.io/en/stable/QueryClauseMethods.html?highlight=where#where
  sql = @column_key_options.searchable_and_global_search.map do |column_key_option|
    "#{column_key_option[:column_key]} =~ ?"
  end.join(" or ")

  filtered.where sql, ".*#{@dt_params.search_all}.*"
end

#order_and_paginate_items(filtered) ⇒ Object



18
19
20
21
# File 'lib/trk_datatables/neo4j.rb', line 18

def order_and_paginate_items(filtered)
  filtered = order_items filtered
  filtered.offset(@dt_params.dt_offset).limit(dt_per_page_or_default)
end

#order_items(filtered) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/trk_datatables/neo4j.rb', line 23

def order_items(filtered)
  order_by = dt_orders_or_default_index_and_direction.each_with_object([]) do |(index, direction), queries|
    column_key_option = @column_key_options[index]
    next if column_key_option[:column_options][ColumnKeyOptions::ORDER_OPTION] == false

    queries << "#{column_key_option[:column_key]} #{direction}"
  end
  filtered.order(order_by.join(", "))
end