Sha256: 0148925dde26702c61babf6972e59f7df3f61ee0741a6345f7850b5a23d99200

Contents?: true

Size: 1.75 KB

Versions: 44

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

module Renalware
  module Problems
    class NotesController < BaseController
      def index
        render_index
      end

      def new
        note = problem.notes.new
        authorize(note)
        render_form(
          note,
          url: patient_problem_notes_path(patient, problem)
        )
      end

      def create
        note = problem.notes.create(notes_params)
        authorize(note)
        if note.save
          render_index
        else
          render_form(
            note,
            url: patient_problem_notes_path(patient, problem)
          )
        end
      end

      def edit
        authorize note
        render_form(
          note,
          url: patient_problem_note_path(patient, problem, note)
        )
      end

      def update
        authorize note
        if note.update_by(current_user, notes_params)
          render_index
        else
          render_form(
            note,
            url: patient_problem_notes_path(patient, problem)
          )
        end
      end

      def destroy
        authorize note
        note.destroy!
        render_index
      end

      private

      def problem
        @problem ||= patient.problems.find(params[:problem_id])
      end

      def notes
        @notes ||= problem.notes.includes(:updated_by).ordered
      end

      def note
        notes.find(params[:id])
      end

      def render_index
        authorize(notes)
        render "index", locals: { problem: problem, notes: notes }
      end

      def render_form(note, url:)
        render "form", locals: { problem: problem, note: note, url: url }
      end

      def notes_params
        params.require(:problems_note).permit(:description).merge(by: current_user)
      end
    end
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
renalware-core-2.0.147 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.146 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.145 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.144 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.143 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.142 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.141 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.140 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.139 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.138 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.137 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.136 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.135 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.134 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.133 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.132 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.131 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.130 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.129 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.128 app/controllers/renalware/problems/notes_controller.rb