Sha256: 93b659221275fdaa64502ec8820952ab22747fce6940e6b41accbf2922577c34

Contents?: true

Size: 720 Bytes

Versions: 19

Compression:

Stored size: 720 Bytes

Contents

module Spina::Api
  class NavigationSerializer < BaseSerializer    
    set_type :navigation
    
    attributes :name, :label
    
    attribute :tree do |navigation|
      items_to_tree(navigation.navigation_items.sorted.roots.in_menu.live.joins(:page))
    end
    
    class << self
      
      def items_to_tree(collection)
        collection.map do |item|
          {
            depth: item.depth,
            page: {
              id: item.page_id,
              menu_title: item.menu_title,
              materialized_path: item.materialized_path
            },
            children: items_to_tree(item.children.sorted.in_menu.live.joins(:page))
          }
        end
      end
      
    end
    
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
spina-2.12.0 app/serializers/spina/api/navigation_serializer.rb
spina-2.11.0 app/serializers/spina/api/navigation_serializer.rb
spina-2.10.0 app/serializers/spina/api/navigation_serializer.rb
spina-2.9.1 app/serializers/spina/api/navigation_serializer.rb
spina-2.9.0 app/serializers/spina/api/navigation_serializer.rb
spina-2.8.1 app/serializers/spina/api/navigation_serializer.rb
spina-2.8.0 app/serializers/spina/api/navigation_serializer.rb
spina-2.7.0 app/serializers/spina/api/navigation_serializer.rb
spina-2.6.2 app/serializers/spina/api/navigation_serializer.rb
spina-2.6.1 app/serializers/spina/api/navigation_serializer.rb
spina-2.6.0 app/serializers/spina/api/navigation_serializer.rb
spina-2.5.0 app/serializers/spina/api/navigation_serializer.rb
spina-2.4.0 app/serializers/spina/api/navigation_serializer.rb
spina-2.3.5 app/serializers/spina/api/navigation_serializer.rb
spina-2.3.4 app/serializers/spina/api/navigation_serializer.rb
spina-2.3.3 app/serializers/spina/api/navigation_serializer.rb
spina-2.3.2 app/serializers/spina/api/navigation_serializer.rb
spina-2.3.1 app/serializers/spina/api/navigation_serializer.rb
spina-2.3.0 app/serializers/spina/api/navigation_serializer.rb