Class: Renalware::HD::StationsController

Inherits:
BaseController show all
Includes:
PresenterHelper
Defined in:
app/controllers/renalware/hd/stations_controller.rb

Instance Method Summary collapse

Methods included from PresenterHelper

#present

Methods inherited from BaseController

#patient

Instance Method Details

#createObject



27
28
29
30
31
32
33
34
35
# File 'app/controllers/renalware/hd/stations_controller.rb', line 27

def create
  station = Station.new(station_params.merge!(hospital_unit_id: unit_id))
  authorize station
  if station.save_by(current_user)
    redirect_to hd_unit_stations_path(unit_id: unit_id), notice: success_msg_for("station")
  else
    render_new(station)
  end
end

#editObject



37
38
39
40
# File 'app/controllers/renalware/hd/stations_controller.rb', line 37

def edit
  authorize station
  render_edit(station)
end

#indexObject



11
12
13
14
15
16
17
18
# File 'app/controllers/renalware/hd/stations_controller.rb', line 11

def index
  stations = Station.for_unit(unit_id).includes(:location).ordered
  authorize stations
  render locals: {
    unit_id: unit_id,
    stations: present(stations, StationPresenter)
  }
end

#newObject



20
21
22
23
24
25
# File 'app/controllers/renalware/hd/stations_controller.rb', line 20

def new
  station = Station.new(hospital_unit_id: unit_id)
  station.by = current_user
  authorize station
  render_new(station)
end

#sortObject



51
52
53
54
55
56
# File 'app/controllers/renalware/hd/stations_controller.rb', line 51

def sort
  authorize Station, :sort?
  ids = params["hd-station"]
  Station.sort(ids)
  render json: ids
end

#updateObject



42
43
44
45
46
47
48
49
# File 'app/controllers/renalware/hd/stations_controller.rb', line 42

def update
  authorize station
  if station.update_by(current_user, station_params)
    redirect_to hd_unit_stations_path(unit_id: unit_id), notice: success_msg_for("station")
  else
    render_edit(station)
  end
end