Class: Renalware::HD::Scheduling::DiarySlotsController
- Inherits:
-
BaseController
- Object
- ApplicationController
- ApplicationController
- BaseController
- BaseController
- Renalware::HD::Scheduling::DiarySlotsController
- Defined in:
- app/controllers/renalware/hd/scheduling/diary_slots_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST create js Here we may be adding a slot to the weekly or master diary.
-
#destroy ⇒ Object
DELETE js Delete the slot (we don’t know if its on the master or weekly diary).
- #edit ⇒ Object
-
#new ⇒ Object
GET html - renders a form Here we will have been passed in the query string: - the unit id - the dirunal_period_code id - the week and year (and thus the diary) and from that lot we could look up the master and weekly diaries.
-
#show ⇒ Object
GET .js refresh a slot in a weekly diary See comment on #create.
-
#update ⇒ Object
PATCH js See also comments in #create and #destroy.
Methods inherited from BaseController
Instance Method Details
#create ⇒ Object
POST create js Here we may be adding a slot to the weekly or master diary. That should be transparent to us - we make the change and render create.js.erb which, on the client, will cause an ajax js call to #show. That secondary call is the one that refreshes the slot in the table with its latest state. We do this to avoid having to to a check (in each action in this controller) to see if we are on the master or weekly diary; if we always refresh the diary slot in the ui after any action, then it will always update correctly.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/renalware/hd/scheduling/diary_slots_controller.rb', line 38 def create diary = Diary.find(params[:diary_id]) slot = diary.slots.new(slot_params) slot.patient_id = posted_patient_id slot if slot.save_by(current_user) render locals: { diary: diary, slot: diary.decorate_slot(slot) } else render :new, locals: { slot: DiarySlotPresenter.new(slot) }, layout: false end end |
#destroy ⇒ Object
DELETE js Delete the slot (we don’t know if its on the master or weekly diary). NB as per #create and #update, the rendered js file (destroy.js.erb) will make a secondary call back into #show to refresh the UI (i.e. we don’t attempt to update the UI in destroy.js.erb)
75 76 77 78 79 |
# File 'app/controllers/renalware/hd/scheduling/diary_slots_controller.rb', line 75 def destroy slot slot.destroy! render locals: { slot: DiarySlotPresenter.new(slot) } end |
#edit ⇒ Object
65 66 67 68 |
# File 'app/controllers/renalware/hd/scheduling/diary_slots_controller.rb', line 65 def edit slot render layout: false, locals: { slot: DiarySlotPresenter.new(slot) } end |
#new ⇒ Object
GET html - renders a form Here we will have been passed in the query string:
-
the unit id
-
the dirunal_period_code id
-
the week and year (and thus the diary)
and from that lot we could look up the master and weekly diaries
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/renalware/hd/scheduling/diary_slots_controller.rb', line 16 def new # Be default this assume we are going to add a slot to the weekly diary # but in which button is clicked in the modal dialog determines which diary # (master or weekly) the slot will be added to. slot = DiarySlot.new( diary: weekly_diary, station_id: params[:station_id], day_of_week: params[:day_of_week], diurnal_period_code_id: params[:diurnal_period_code_id] ) slot render locals: locals_for(slot), layout: false end |
#show ⇒ Object
GET .js refresh a slot in a weekly diary See comment on #create. See show.js.erb where we refresh the slot in the diary To get here we will have manufactured a url like this
hd/diaries/2/slots/day/1/period/1/station/1
as those bit are will we know. Basically we are saying find for this weekly diary, find the matching slot for the station/day/period combo and render the weekly slot if there is one, or the master behind it if there is one of those, otherwise render an Add button.
59 60 61 62 63 |
# File 'app/controllers/renalware/hd/scheduling/diary_slots_controller.rb', line 59 def show DiarySlot, :show? slot = weekly_then_master_then_empty_slot render layout: false, locals: { slot: DiarySlotPresenter.new(slot) } end |
#update ⇒ Object
PATCH js See also comments in #create and #destroy.
83 84 85 86 87 88 89 |
# File 'app/controllers/renalware/hd/scheduling/diary_slots_controller.rb', line 83 def update slot slot.patient_id = slot_params[:patient_id] slot.save_by!(current_user) diary = slot.diary render locals: { diary: diary, slot: diary.decorate_slot(slot) } end |