Module: Labimotion::SearchHelpers
- Extended by:
- Grape::API::Helpers
- Defined in:
- lib/labimotion/helpers/search_helpers.rb
Overview
ElementHelpers
Instance Method Summary collapse
- #gl_elements_search(col, params) ⇒ Object
- #serialization_elements(result, page, page_size, element_ids, params) ⇒ Object
Instance Method Details
#gl_elements_search(col, params) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/labimotion/helpers/search_helpers.rb', line 31 def gl_elements_search(col, params) # element_scope = Element.joins(:collections_elements).where( # 'collections_elements.collection_id = ? and collections_elements.element_type = (?)', collection.id, params[:selection][:genericElName] # ) # if params[:selection][:searchName].present? # element_scope = element_scope.where('name like (?)', # "%#{params[:selection][:searchName]}%") # end # if params[:selection][:searchShowLabel].present? # element_scope = element_scope.where('short_label like (?)', "%#{params[:selection][:searchShowLabel]}%") # end # if params[:selection][:searchProperties].present? # params[:selection][:searchProperties] && params[:selection][:searchProperties][:layers] && params[:selection][:searchProperties][:layers].keys.each do |lk| # layer = params[:selection][:searchProperties][:layers][lk] # qs = layer[:fields].select { |f| f[:value].present? || f[:type] == 'input-group' } # qs.each do |f| # if f[:type] == 'input-group' # sfs = f[:sub_fields].map { |e| { id: e[:id], value: e[:value] } } # query = { "#{lk}": { fields: [{ field: f[:field].to_s, sub_fields: sfs }] } } if sfs.length > 0 # elsif f[:type] == 'checkbox' || f[:type] == 'integer' || f[:type] == 'system-defined' # query = { "#{lk}": { fields: [{ field: f[:field].to_s, value: f[:value] }] } } # else # query = { "#{lk}": { fields: [{ field: f[:field].to_s, value: f[:value].to_s }] } } # end # element_scope = element_scope.where('properties @> ?', query.to_json) # end # end # end # element_scope end |
#serialization_elements(result, page, page_size, element_ids, params) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/labimotion/helpers/search_helpers.rb', line 9 def serialization_elements(result, page, page_size, element_ids, params) # klasses = Labimotion::ElementKlass.where(is_active: true, is_generic: true) # klasses.each do |klass| # element_ids_for_klass = Element.where(id: element_ids, element_klass_id: klass.id).pluck(:id) # paginated_element_ids = Kaminari.paginate_array(element_ids_for_klass).page(page).per(page_size) # serialized_elements = Element.find(paginated_element_ids).map do |element| # Labimotion::ElementEntity.represent(element, displayed_in_list: true).serializable_hash # end # result["#{klass.name}s"] = { # elements: serialized_elements, # totalElements: element_ids_for_klass.size, # page: page, # pages: pages(element_ids_for_klass.size), # perPage: page_size, # ids: element_ids_for_klass, # } # end # result end |