Class: Renalware::HD::SessionsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- ApplicationController
- BaseController
- BaseController
- Renalware::HD::SessionsController
- Includes:
- PresenterHelper, Concerns::Pageable
- Defined in:
- app/controllers/renalware/hd/sessions_controller.rb
Instance Method Summary collapse
- #create ⇒ Object
- #destroy ⇒ Object
- #edit ⇒ Object
- #index ⇒ Object
- #new ⇒ Object
- #save_failure(session) ⇒ Object
- #save_session ⇒ Object
- #save_success(_session) ⇒ Object
- #show ⇒ Object
- #update ⇒ Object
Methods included from PresenterHelper
Methods inherited from BaseController
Instance Method Details
#create ⇒ Object
42 43 44 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 42 def create save_session end |
#destroy ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 59 def destroy session = Session.for_patient(patient).find(params[:id]) session session.destroy! = t(".success", model_name: "HD session") redirect_to patient_hd_dashboard_path(patient), notice: end |
#edit ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 46 def edit session = Session.for_patient(patient).find(params[:id]) session render :edit, locals: locals(session) rescue Pundit::NotAuthorizedError flash[:warning] = t(".session_is_immutable") redirect_to patient_hd_session_path(session, patient_id: patient) end |
#index ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 14 def index query = sessions_query sessions = query .call .includes(:hospital_unit, :patient, :signed_on_by, :signed_off_by) .page(page) .per(per_page || 15) sessions presenter = CollectionPresenter.new(sessions, SessionPresenter, view_context) @q = query.search render :index, locals: { sessions: presenter } end |
#new ⇒ Object
34 35 36 37 38 39 40 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 34 def new session = SessionFactory.new(patient: patient, user: current_user, type: params[:type]).build session render :new, locals: locals(session) end |
#save_failure(session) ⇒ Object
82 83 84 85 86 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 82 def save_failure(session) flash.now[:error] = t(".failed", model_name: "HD session") action = action_name.to_sym == :create ? :new : :edit render action, locals: locals(session) end |
#save_session ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 67 def save_session command = Sessions::SaveSession.new(patient: patient, current_user: current_user) command.subscribe(self) command.call(params: session_params, id: params[:id], signing_off: params[:signoff].present?) end |
#save_success(_session) ⇒ Object
76 77 78 79 80 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 76 def save_success(_session) url = patient_hd_dashboard_path(patient) = t(".success", model_name: "HD session") redirect_to url, notice: end |
#show ⇒ Object
27 28 29 30 31 32 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 27 def show session = Session.for_patient(patient).find(params[:id]) session presenter = SessionPresenter.new(session, view_context) render :show, locals: { session: presenter, patient: patient } end |
#update ⇒ Object
55 56 57 |
# File 'app/controllers/renalware/hd/sessions_controller.rb', line 55 def update save_session end |