Sha256: 4c796f38097cd77e87bf8fd9614c18569397c59f79f06f6988f50d548374b44a

Contents?: true

Size: 1.74 KB

Versions: 15

Compression:

Stored size: 1.74 KB

Contents

class ClarkKent::ReportColumnsController < ClarkKent::ApplicationController
  before_action :prepare_report_column
  before_action :prepare_report

  def new
    @report_column = ClarkKent::ReportColumn.new(report_id: @report.id)
    render partial: 'form', locals: {report_column: @report_column}
  end

  def create
    @report_column = ClarkKent::ReportColumn.new(report_column_params)
    @report_column.save
    if @report_column.errors.empty?
      render partial: 'show_wrapper', locals: {report_column: @report_column}
    else
      render partial: 'form', locals: {report_column: @report_column}, status: :conflict
    end
  end

  def show
    render partial: 'show', locals: {report_column: @report_column}
  end

  def edit
    render partial: 'form', locals: {report_column: @report_column}
  end

  def update
    @report_column.update_attributes(report_column_params)
    if @report_column.errors.empty?
      render json: {
        flash_message: "Your changes were saved.",
        html: render_to_string(partial: 'show', locals: {report_column: @report_column}) }
    else
      render partial: 'form', locals: {report_column: @report_column}, status: :conflict
    end
  end

  def destroy
    @report_column.destroy
    head :ok
  end

  protected
  def prepare_report_column
    @report_column = ClarkKent::ReportColumn.find(params[:id]) if params[:id]
  end

  def prepare_report
    report_id = params[:report_id]
    report_id ||= report_column_params[:report_id] if params[:report_column]
    @report = ClarkKent::Report.find(report_id) if report_id
    @report ||= @report_column.report if @report_column
  end

  def report_column_params
    params[:report_column].permit(:report_id, :column_name, :column_order, :report_sort, :summary_method)
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
clark_kent-0.11.3 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.11.2 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.11.1 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.11.0 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.10.4 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.10.2 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.10.1 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.10.0 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.9.9 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.9.8 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.9.7 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.9.6 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.9.5 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.9.4 app/controllers/clark_kent/report_columns_controller.rb
clark_kent-0.9.2 app/controllers/clark_kent/report_columns_controller.rb