Sha256: c30b466f65eca0d7dc255dae40fa0c05d64c3105540ca872bf98f0f4891b56ea

Contents?: true

Size: 1.15 KB

Versions: 29

Compression:

Stored size: 1.15 KB

Contents

# frozen_string_literal: true

module PagesCore
  module PageModel
    module Sortable
      extend ActiveSupport::Concern

      included do
        acts_as_list scope: :parent_page
        after_save :check_list_position
      end

      module ClassMethods
        def order_by_tags(tags)
          joins(
            "LEFT JOIN taggings ON taggings.taggable_id = pages.id AND " \
            "taggings.tag_id IN (#{tags.map(&:id).join(',')}) AND " \
            "taggings.taggable_type = " \
            "#{ActiveRecord::Base.connection.quote('Page')}"
          )
            .group("pages.id, localizations.id")
            .reorder(Arel.sql("COUNT(taggings.id) DESC"))
        end
      end

      def reorderable_children?
        !news_page?
      end

      def reorderable?
        !parent || !parent.news_page?
      end

      def content_order
        if news_page?
          "pages.pinned DESC, published_at DESC"
        else
          "position ASC"
        end
      end

      private

      def check_list_position
        if deleted?
          remove_from_list
        elsif !position?
          assume_bottom_position
        end
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
pages_core-3.15.5 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.15.4 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.15.3 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.15.2 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.15.1 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.14.0 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.13.0 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.12.7 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.12.6 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.12.5 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.12.4 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.12.3 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.12.2 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.12.1 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.12.0 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.11.3 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.11.2 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.11.1 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.11.0 app/models/concerns/pages_core/page_model/sortable.rb
pages_core-3.10.2 app/models/concerns/pages_core/page_model/sortable.rb