module Dynflow::Web::FilteringHelpers

Public Instance Methods

filtering_options(show_all = false) click to toggle source
# File lib/dynflow/web/filtering_helpers.rb, line 10
def filtering_options(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) click to toggle source
# File lib/dynflow/web/filtering_helpers.rb, line 31
def find_execution_plans_options(show_all = false)
  options = Utils.indifferent_hash({})
  options.merge!(filtering_options(show_all))
  options.merge!(pagination_options)
  options.merge!(ordering_options)
end
ordering_options() click to toggle source
# File lib/dynflow/web/filtering_helpers.rb, line 67
def ordering_options
  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() click to toggle source
# File lib/dynflow/web/filtering_helpers.rb, line 42
def page
  (params[:page] || 0).to_i
end
paginate?() click to toggle source
# File lib/dynflow/web/filtering_helpers.rb, line 38
def paginate?
  world.persistence.adapter.pagination?
end
pagination_options() click to toggle source
# File lib/dynflow/web/filtering_helpers.rb, line 50
def pagination_options
  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() click to toggle source
# File lib/dynflow/web/filtering_helpers.rb, line 46
def per_page
  (params[:per_page] || 10).to_i
end
supported_filter?(filter_attr) click to toggle source
# File lib/dynflow/web/filtering_helpers.rb, line 4
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) click to toggle source
# File lib/dynflow/web/filtering_helpers.rb, line 61
def supported_ordering?(ord_attr)
  world.persistence.adapter.ordering_by.any? do |attr|
    attr.to_s == ord_attr.to_s
  end
end