Sha256: c1ec5cf60d5faf0fd6eb5cf6c8b8a77d440932d39dcb2eddbdb35aa27d02c4d4

Contents?: true

Size: 1.33 KB

Versions: 56

Compression:

Stored size: 1.33 KB

Contents

module Pageflow
  module Editor
    class WidgetsController < Pageflow::ApplicationController
      respond_to :json

      before_action :authenticate_user!

      def index
        subject = find_subject
        authorize!(:index_widgets_for, subject.to_model)

        @widgets = subject.resolve_widgets(include_placeholders: true)
        respond_with(@widgets)
      end

      def batch
        subject = find_subject
        authorize!(:edit, subject.to_model)

        subject.widgets.batch_update!(widget_batch_params)
        render(json: {})
      end

      private

      def widget_batch_params
        widget_configurations = params.fetch(:widgets, []).map do |widget_params|
          widget_params[:configuration].try(:permit!)
        end

        params
          .permit(widgets: [:role, :type_name])
          .fetch(:widgets, [])
          .zip(widget_configurations)
          .map do |(widget_params, widget_configuration)|
            if widget_configuration
              widget_params.merge(configuration: widget_configuration)
            else
              widget_params
            end
          end
      end

      def find_subject
        if params[:collection_name] == 'entries'
          DraftEntry.find(params[:subject_id])
        else
          Theming.find(params[:subject_id])
        end
      end
    end
  end
end

Version data entries

56 entries across 56 versions & 1 rubygems

Version Path
pageflow-14.5.2 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.1.2 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.1.1 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.1.0 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.1.0.rc0 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.1.0.beta6 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.1.0.beta5 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.1.0.beta4 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.1.0.beta3 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.1.0.beta2 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.1.0.beta1 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.0.2 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.0.1 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.0.0 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-14.5.1 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-14.5.0 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.0.0.rc2 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.0.0.rc1 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.0.0.beta4 app/controllers/pageflow/editor/widgets_controller.rb
pageflow-15.0.0.beta3 app/controllers/pageflow/editor/widgets_controller.rb