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.1.1 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.1.0 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.167 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.166 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.165 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.164 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.163 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.162 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.161 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.160 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.159 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.158 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.157 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.156 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.155 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.153 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.152 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.151 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.149 app/controllers/renalware/problems/notes_controller.rb
renalware-core-2.0.148 app/controllers/renalware/problems/notes_controller.rb