Sha256: 0f03309b26004f74447459588bfcb4bc404356d87ffd25352d9e59cca34fb6dd

Contents?: true

Size: 1.04 KB

Versions: 34

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require "active_support/concern"

module Decidim
  module Initiatives
    # Common logic to ordering resources
    module Orderable
      extend ActiveSupport::Concern

      included do
        include Decidim::Orderable

        # Available orders based on enabled settings
        def available_orders
          @available_orders ||= begin
            available_orders = %w(random recent most_voted most_commented recently_published)
            available_orders
          end
        end

        def default_order
          "random"
        end

        def reorder(initiatives)
          case order
          when "most_voted"
            initiatives.order_by_supports
          when "most_commented"
            initiatives.order_by_most_commented
          when "recent"
            initiatives.order_by_most_recent
          when "recently_published"
            initiatives.order_by_most_recently_published
          else
            initiatives.order_randomly(random_seed)
          end
        end
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
decidim-initiatives-0.26.10 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.9 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.8 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.7 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.5 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.4 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.3 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.2 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.1 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.0 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.0.rc2 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.26.0.rc1 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.25.2 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.25.1 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.25.0 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.25.0.rc4 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.25.0.rc3 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.25.0.rc2 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.25.0.rc1 app/controllers/concerns/decidim/initiatives/orderable.rb
decidim-initiatives-0.24.3 app/controllers/concerns/decidim/initiatives/orderable.rb