Sha256: 40f60f70a36109f8925c1fbf9937d0b6352d9e08b35c4910d77d257e43ff9a74

Contents?: true

Size: 1.64 KB

Versions: 87

Compression:

Stored size: 1.64 KB

Contents

# frozen_string_literal: true

require_dependency "renalware/reporting"

module Renalware
  module Reporting
    class AuditsController < BaseController
      include PresenterHelper

      def index
        authorize Audit, :index?
        render locals: { audits: present(Audit.enabled, AuditPresenter) }
      end

      def show
        authorize audit
        respond_to do |format|
          format.html { render locals: { audit: audit } }
          format.json { render json: FetchAuditJson.call(audit.view_name) }
        end
      end

      def edit
        authorize audit
        render_edit
      end

      def update
        authorize audit
        if audit.update(audit_params)
          redirect_to reporting_audits_path, notice: success_msg_for("audit")
        else
          render_edit
        end
      end

      private

      def audit
        @audit ||= Audit.find(params[:id])
      end

      # Takes an array (rows) of arrays (cells) and replaces any nil elements
      # with an empty string so JS data tables does not baulk with 'nil undefined' error.
      def replace_nils_with_empty_string(values)
        values.map { |row| row.map { |cell| cell || "" } }
      end

      def render_edit
        render :edit, locals: {
          audit: audit,
          available_data_sources: Renalware::Reporting::Audit.available_audit_materialized_views
        }
      end

      def audit_params
        params.require(:reporting_audit)
              .permit(
                :name,
                :description,
                :view_name,
                :display_configuration,
                :refresh_schedule
              )
      end
    end
  end
end

Version data entries

87 entries across 87 versions & 1 rubygems

Version Path
renalware-core-2.1.1 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.1.0 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.167 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.166 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.165 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.164 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.163 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.162 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.161 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.160 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.159 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.158 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.157 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.156 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.155 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.153 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.152 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.151 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.149 app/controllers/renalware/reporting/audits_controller.rb
renalware-core-2.0.148 app/controllers/renalware/reporting/audits_controller.rb