app/helpers/spina/admin/pages_helper.rb in spina-1.2.0 vs app/helpers/spina/admin/pages_helper.rb in spina-2.0.0.alpha
- old
+ new
@@ -1,50 +1,52 @@
module Spina
module Admin
module PagesHelper
- def link_to_add_structure_item_fields(f, &block)
- item = StructureItem.new
- fields = f.fields_for(:structure_items, item, child_index: item.object_id) do |builder|
- build_structure_parts(f.object.page_part.name, item)
- render("spina/admin/structure_items/fields", f: builder)
+
+ def link_to_add_repeater_fields(f)
+ repeater_content = Spina::Parts::RepeaterContent.new(name: f.object.name, title: f.object.title)
+ fields = f.fields_for(:content, [repeater_content], child_index: repeater_content.object_id) do |builder|
+ render("spina/admin/parts/repeaters/fields", f: builder)
end
- link_to '#', class: "add_structure_item_fields button button-link", data: {id: item.object_id, fields: fields.gsub("\n", "")} do
+ link_to '#', class: "add_structure_item_fields button button-link", data: {id: repeater_content.object_id, fields: fields.gsub("\n", "")} do
icon('plus')
end
end
- def build_structure_parts(name, item)
- structure = current_theme.structures.find { |structure| structure[:name] == name }
- return item.parts unless structure.present?
- structure[:structure_parts].map do |attributes|
- part = item.parts.where(name: attributes[:name]).first_or_initialize(attributes)
- part.partable = part.partable_type.constantize.new if part.partable.blank?
- part.options = attributes[:options]
- part
+ def data_attrs_for_image_collection(f)
+ image = Spina::Parts::Image.new
+ fields = f.fields_for(:images, [image], child_index: image.object_id) do |builder|
+ render("spina/admin/parts/image_collections/fields", f: builder)
end
+ {fields: fields.gsub("\n", ""), id: image.object_id}
end
- def partable_partial_namespace(partable)
- partable_type_partial_namespace(partable.model_name.to_s)
+ def build_parts(partable, parts)
+ I18n.with_locale(@locale) do
+ parts.map do |part|
+ part_attributes = current_theme.parts.find{|p|p[:name].to_s == part.to_s}
+ partable.part(part_attributes)
+ end
+ end
end
- def partable_type_partial_namespace(partable_type)
- partable_type.tableize.sub(/\Aspina\//, '')
+ def parts_partial_namespace(part_type)
+ part_type.tableize.sub(/\Aspina\/parts\//, '')
end
def flatten_nested_hash(hash)
hash.flat_map{|k, v| [k, *flatten_nested_hash(v)]}
end
def page_ancestry_options(page)
- pages = Spina::Page.active.regular_pages
+ pages = Spina::Page.active.regular_pages.includes(:translations)
pages = pages.where.not(id: page.subtree.ids) unless page.new_record? || !page.methods.include?(:subtree)
(flatten_nested_hash(pages.arrange(order: :position)).map do |page|
next if page.depth >= Spina.config.max_page_depth - 1
page_menu_title = page.depth.zero? ? page.menu_title : " #{page.menu_title}".indent(page.depth, '-')
[page_menu_title, page.id]
- end << [page.parent&.menu_title, page&.parent_id].compact).uniq.compact
+ end << [page.parent&.menu_title, page&.parent_id].compact).map(&:presence).uniq.compact
end
def option_label(part, value)
t(['options',part.name,value].compact.join('.'))
end