Module: Dynflow::Web::FilteringHelpers
- Defined in:
- lib/dynflow/web/filtering_helpers.rb
Instance Method Summary collapse
- #filtering_options(show_all = false) ⇒ Object
- #find_execution_plans_options(show_all = false) ⇒ Object
- #load_worlds(executors_only = false) ⇒ Object
- #ordering_options ⇒ Object
- #page ⇒ Object
- #paginate? ⇒ Boolean
- #pagination_options ⇒ Object
- #per_page ⇒ Object
- #supported_filter?(filter_attr) ⇒ Boolean
- #supported_ordering?(ord_attr) ⇒ Boolean
Instance Method Details
#filtering_options(show_all = false) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/dynflow/web/filtering_helpers.rb', line 12 def (show_all = false) return @filtering_options if @filtering_options if params[:filters] params[:filters].map do |key, value| unless supported_filter?(key) halt 400, "Unsupported ordering" end end filters = params[:filters] elsif supported_filter?('state') excluded_states = show_all ? [] : ['stopped'] filters = { 'state' => ExecutionPlan.states.map(&:to_s) - excluded_states } else filters = {} end @filtering_options = Utils.indifferent_hash(filters: filters) return @filtering_options end |
#find_execution_plans_options(show_all = false) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/dynflow/web/filtering_helpers.rb', line 38 def (show_all = false) = Utils.indifferent_hash({}) .merge!((show_all)) .merge!() .merge!() end |
#load_worlds(executors_only = false) ⇒ Object
33 34 35 36 |
# File 'lib/dynflow/web/filtering_helpers.rb', line 33 def load_worlds(executors_only = false) @worlds = world.coordinator.find_worlds(executors_only) @executors, @clients = @worlds.partition(&:executor?) end |
#ordering_options ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dynflow/web/filtering_helpers.rb', line 74 def return @ordering_options if @ordering_options if params[:order_by] unless supported_ordering?(params[:order_by]) halt 400, "Unsupported ordering" end @ordering_options = { order_by: params[:order_by], desc: (params[:desc] == 'true') } elsif supported_ordering?('started_at') @ordering_options = { order_by: 'started_at', desc: true } else @ordering_options = {} end return @ordering_options end |
#page ⇒ Object
49 50 51 |
# File 'lib/dynflow/web/filtering_helpers.rb', line 49 def page (params[:page] || 0).to_i end |
#paginate? ⇒ Boolean
45 46 47 |
# File 'lib/dynflow/web/filtering_helpers.rb', line 45 def paginate? world.persistence.adapter.pagination? end |
#pagination_options ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/dynflow/web/filtering_helpers.rb', line 57 def if paginate? { page: page, per_page: per_page } else if params[:page] || params[:per_page] halt 400, "The persistence doesn't support pagination" end return {} end end |
#per_page ⇒ Object
53 54 55 |
# File 'lib/dynflow/web/filtering_helpers.rb', line 53 def per_page (params[:per_page] || 10).to_i end |
#supported_filter?(filter_attr) ⇒ Boolean
6 7 8 9 10 |
# File 'lib/dynflow/web/filtering_helpers.rb', line 6 def supported_filter?(filter_attr) world.persistence.adapter.filtering_by.any? do |attr| attr.to_s == filter_attr.to_s end end |
#supported_ordering?(ord_attr) ⇒ Boolean
68 69 70 71 72 |
# File 'lib/dynflow/web/filtering_helpers.rb', line 68 def supported_ordering?(ord_attr) world.persistence.adapter.ordering_by.any? do |attr| attr.to_s == ord_attr.to_s end end |