Sha256: 9d6f55a3e8933ae2042e642b35ae4acf49c79cadd323cd2f8535f9296521e25b

Contents?: true

Size: 708 Bytes

Versions: 8

Compression:

Stored size: 708 Bytes

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Elections
    # Common logic to sorting resources
    module Orderable
      extend ActiveSupport::Concern

      included do
        include Decidim::Orderable

        private

        # Available orders based on enabled settings
        def available_orders
          @available_orders ||= %w(recent older)
        end

        def default_order
          "recent"
        end

        def reorder(elections)
          case order
          when "recent"
            elections.order(start_time: :asc)
          else
            elections.order(start_time: :desc)
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
decidim-elections-0.23.6 app/controllers/concerns/decidim/elections/orderable.rb
decidim-elections-0.23.5 app/controllers/concerns/decidim/elections/orderable.rb
decidim-elections-0.23.4 app/controllers/concerns/decidim/elections/orderable.rb
decidim-elections-0.23.3 app/controllers/concerns/decidim/elections/orderable.rb
decidim-elections-0.23.2 app/controllers/concerns/decidim/elections/orderable.rb
decidim-elections-0.23.1 app/controllers/concerns/decidim/elections/orderable.rb
decidim-elections-0.23.1.rc1 app/controllers/concerns/decidim/elections/orderable.rb
decidim-elections-0.23.0 app/controllers/concerns/decidim/elections/orderable.rb