Module: Matestack::Ui::VueJs::Components::Collection::Helper
- Defined in:
- lib/matestack/ui/vue_js/components/collection/helper.rb
Instance Method Summary collapse
- #_set_collection(id: nil, init_offset: 0, init_limit: nil, base_count: nil, filtered_count: nil, data: nil) ⇒ Object
- #controller_params ⇒ Object
- #get_collection_filter(collection_id, key = nil) ⇒ Object
- #get_collection_order(collection_id, key = nil) ⇒ Object
-
#set_collection(options_hash) ⇒ Object
since ruby 3 changed hash <-> keyword argument transformation, we need to adjust this method call in order to stay compatible with ruby 2.x and ruby 3.x.
Instance Method Details
#_set_collection(id: nil, init_offset: 0, init_limit: nil, base_count: nil, filtered_count: nil, data: nil) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 40 def _set_collection id: nil, init_offset: 0, init_limit: nil, base_count: nil, filtered_count: nil, data: nil @collections = {} if @collections.nil? collection_config = CollectionConfig.new( id, init_offset, init_limit, filtered_count, base_count, data, controller_params, get_collection_filter(id) ) @collections[id.to_sym] = collection_config return collection_config end |
#controller_params ⇒ Object
59 60 61 62 |
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 59 def controller_params return params.to_unsafe_h if defined? params raise 'collection component is missing access to params or context' end |
#get_collection_filter(collection_id, key = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 4 def get_collection_filter collection_id, key=nil filter_hash = {} controller_params.each do |param_key, param_value| if param_key.start_with?("#{collection_id}-filter-") param_key.gsub("#{collection_id}-filter-", "") filter_hash[param_key.gsub("#{collection_id}-filter-", "").to_sym] = JSON.parse(param_value) end end if key.nil? return filter_hash else return filter_hash[key] end end |
#get_collection_order(collection_id, key = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 19 def get_collection_order collection_id, key=nil order_hash = {} controller_params.each do |param_key, param_value| if param_key.start_with?("#{collection_id}-order-") param_key.gsub("#{collection_id}-order-", "") order_hash[param_key.gsub("#{collection_id}-order-", "").to_sym] = param_value end end if key.nil? return order_hash else return order_hash[key] end end |
#set_collection(options_hash) ⇒ Object
since ruby 3 changed hash <-> keyword argument transformation, we need to adjust this method call in order to stay compatible with ruby 2.x and ruby 3.x
36 37 38 |
# File 'lib/matestack/ui/vue_js/components/collection/helper.rb', line 36 def set_collection _set_collection ** end |