lib/finapps/utils/query_builder.rb in finapps-2.3.3 vs lib/finapps/utils/query_builder.rb in finapps-2.3.5
- old
+ new
@@ -2,14 +2,22 @@
module FinApps
module Utils
module QueryBuilder
def build_query_path(root_url, params)
- page = params[:page] ? "page=#{params[:page]}" : ''
- requested = params[:requested] ? "&requested=#{params[:requested]}" : ''
- sort = params[:sort] ? "&sort=#{ERB::Util.url_encode(params[:sort])}" : ''
- filter = params[:filter] ? "&filter=#{ERB::Util.url_encode(params[:filter])}" : ''
- "#{root_url}?#{page}#{requested}#{sort}#{filter}"
+ filter_obj = build_filter(params)
+ page = "page=#{params[:page]}" if params[:page]
+ requested = "requested=#{params[:requested]}" if params[:requested]
+ sort = "sort=#{ERB::Util.url_encode(params[:sort])}" if params[:sort]
+ filter = "filter=#{ERB::Util.url_encode(filter_obj.to_json)}" if filter_obj && !filter_obj.empty?
+ query_join(root_url, [page, requested, sort, filter])
+ end
+
+ private
+
+ def query_join(root_url, params_array)
+ query_string = params_array.compact.join('&')
+ !query_string.empty? ? [root_url, query_string].join('?') : nil
end
end
end
end