Class: Spina::Admin::PagesController
- Inherits:
-
AdminController
- Object
- ActionController::Base
- AdminController
- Spina::Admin::PagesController
- Defined in:
- app/controllers/spina/admin/pages_controller.rb
Instance Method Summary collapse
- #children ⇒ Object
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #edit_content ⇒ Object
- #edit_template ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #sort ⇒ Object
- #sort_one ⇒ Object
- #update ⇒ Object
Methods inherited from AdminController
Instance Method Details
#children ⇒ Object
100 101 102 103 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 100 def children @children = @page.children.active.sorted render layout: false end |
#create ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 26 def create @page = Page.new(page_params.merge(draft: true)) if @page.save redirect_to spina.edit_admin_page_url(@page) else render turbo_stream: turbo_stream.update(view_context.dom_id(@page, :new_page_form), partial: "new_page_form") end end |
#destroy ⇒ Object
105 106 107 108 109 110 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 105 def destroy flash[:info] = t("spina.pages.deleted") @page.destroy redirect_to spina.admin_pages_url(resource_id: @page.resource_id) end |
#edit ⇒ Object
35 36 37 38 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 35 def edit @page.title end |
#edit_content ⇒ Object
40 41 42 43 44 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 40 def edit_content @parts = current_theme.view_templates.find do |view_template| view_template[:name].to_s == @page.view_template.to_s end&.dig(:parts) || [] end |
#edit_template ⇒ Object
46 47 48 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 46 def edit_template render layout: false end |
#index ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 8 def index I18n.t("spina.website.pages"), spina.admin_pages_path if params[:resource_id] @resource = Resource.find(params[:resource_id]) @page_templates = Spina::Current.theme.new_page_templates(resource: @resource) @pages = @resource.pages.active.roots.includes(:translations).page(params[:page]).per(Spina.config.resource_pages_limit_value) else @pages = Page.active.sorted.roots.main.includes(:translations) @page_templates = Spina::Current.theme.new_page_templates end end |
#new ⇒ Object
21 22 23 24 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 21 def new resource = Resource.find_by(id: params[:resource_id]) @page = Page.new(view_template: params[:view_template], resource: resource) end |
#sort ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 69 def sort params[:ids].each.with_index do |id, index| Page.where(id: id).update_all(position: index + 1) end flash.now[:info] = t("spina.pages.sorting_saved") render_flash end |
#sort_one ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 78 def sort_one current_position = @page.position if params[:direction] == "up" @bottom_page = @page @top_page = @target_page = @page.siblings.where(resource_id: @page.resource_id).sorted.where("position < ?", current_position).last else @bottom_page = @target_page = @page.siblings.where(resource_id: @page.resource_id).sorted.where("position > ?", current_position).first @top_page = @page end if @target_page @page.transaction do @page.update(position: @target_page.position) @target_page.update(position: current_position) end flash.now[:info] = t("spina.pages.sorting_saved") else head :ok end end |
#update ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/controllers/spina/admin/pages_controller.rb', line 50 def update Mobility.locale = @locale if @page.update(page_params) if @page.saved_change_to_draft? && @page.live? flash[:confetti] = t("spina.pages.published") else flash[:success] = t("spina.pages.saved") end redirect_to spina.edit_admin_page_url(@page, params: {locale: @locale}) else Mobility.locale = I18n.locale @page.title flash.now[:error] = t("spina.pages.couldnt_be_saved") render :edit, status: :unprocessable_entity end end |