Skip to content

Commit

Permalink
Pages ancestry form
Browse files Browse the repository at this point in the history
  • Loading branch information
Bramjetten committed Jul 24, 2017
1 parent a0edd31 commit 90ed1cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/helpers/spina/admin/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ 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
pages = pages.where.not(id: page.subtree.ids) unless page.new_record?

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.compact
end

def option_label(part, value)
t(['options',part.name,value].compact.join('.'))
end
Expand Down
7 changes: 7 additions & 0 deletions app/views/spina/admin/pages/_form_advanced.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@
.select-dropdown.page-template{data: {page_parts: @page.view_template_config(current_theme)[:page_parts]}}
- options = options_for_select(current_theme.view_templates.map { |template| [template[:title], template[:name], {'data-page-parts' => template[:page_parts]}] }, @page.view_template)
= f.select :view_template, options

.horizontal-form-group
.horizontal-form-label
= Spina::Page.human_attribute_name :ancestry
.horizontal-form-content
.select-dropdown.ancestry
= f.select :parent_id, page_ancestry_options(f.object), include_blank: Spina::Page.human_attribute_name(:no_parent)

0 comments on commit 90ed1cd

Please sign in to comment.