Sha256: 14f6bcc71ec2f9af8824e865f2946ff275a44d371227aa077153f42aa97730d4

Contents?: true

Size: 1.47 KB

Versions: 24

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

module PandaCms
  module Admin
    class FormsController < ApplicationController
      before_action :set_initial_breadcrumb, only: %i[index show]
      # before_action :set_paper_trail_whodunnit, only: %i[create update]
      before_action :authenticate_admin_user!

      # Lists all forms
      # @type GET
      # @return ActiveRecord::Collection A list of all forms
      def index
        forms = PandaCms::Form.order(:name)
        render :index, locals: {forms: forms}
      end

      def show
        form = PandaCms::Form.find(params[:id])

        add_breadcrumb form.name, admin_form_path(form)
        submissions = form.form_submissions.order(created_at: :desc)
        # TODO: Set a whitelist of fields we allow to be submitted for the form, shown in this view
        # and a formatting array of how to display them... eventually?

        fields = if submissions.last
          submissions.last.data.keys.reverse.map { |field| [field, field.titleize] }
        else
          []
        end

        render :show, locals: {form: form, submissions: submissions, fields: fields}
      end

      private

      def set_initial_breadcrumb
        add_breadcrumb "Forms", admin_forms_path
      end

      private

      # Only allow a list of trusted parameters through
      # @type private
      # @return ActionController::StrongParameters
      def form_params
        params.require(:form).permit(:name, :completion_path)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
panda_cms-0.6.3 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.6.2 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.6.1 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.6.0 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.10 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.9 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.8 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.7 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.6 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.5 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.4 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.3 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.2 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.1 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.5.0 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.3.15 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.3.14 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.3.13 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.3.12 app/controllers/panda_cms/admin/forms_controller.rb
panda_cms-0.3.11 app/controllers/panda_cms/admin/forms_controller.rb