Sha256: a1439214df8c009e690872fe730fe1969c3fb479eced9796603dde36642f6d5e

Contents?: true

Size: 1.62 KB

Versions: 9

Compression:

Stored size: 1.62 KB

Contents

module PageflowScrolled
  module Editor
    # @api private
    class SectionsController < ActionController::Base
      include Pageflow::EditorController

      def create
        chapter = Chapter.all_for_revision(@entry.draft).find(params[:chapter_id])
        section = chapter.sections.create(section_params)

        render partial: 'pageflow_scrolled/sections/section',
               locals: {section: section},
               status: :created
      end

      def update
        section = Section.all_for_revision(@entry.draft).find(params[:id])
        section.update_attributes(section_params)

        head :no_content
      rescue ActiveRecord::RecordNotFound
        head :not_found
      end

      def destroy
        section = Section.all_for_revision(@entry.draft).find(params[:id])
        section.destroy

        head :no_content
      rescue ActiveRecord::RecordNotFound
        head :not_found
      end

      def order
        chapter = Chapter.all_for_revision(@entry.draft).find(params[:chapter_id])
        storyline = chapter.storyline

        params.require(:ids).each_with_index do |id, index|
          storyline.sections.update(id,
                                    chapter_id: chapter.id,
                                    position: index)
        end

        head :no_content
      rescue ActiveRecord::RecordNotFound
        head :not_found
      end

      private

      def section_params
        configuration = params.require(:section)[:configuration].try(:permit!) || {}
        params.require(:section)
              .permit(:position)
              .merge(configuration: configuration)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pageflow-16.0.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.8.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.7.1 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.7.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.6.1 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.6.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.5.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.4.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb
pageflow-15.3.0 entry_types/scrolled/app/controllers/pageflow_scrolled/editor/sections_controller.rb