Sha256: a9068680661b7c877cace35331de49357eb5d8d3da87f167f0f091227ab5e39f

Contents?: true

Size: 1.84 KB

Versions: 29

Compression:

Stored size: 1.84 KB

Contents

require_dependency "renalware/hd/base_controller"
require "collection_presenter"

module Renalware
  module HD
    class StationsController < BaseController
      include PresenterHelper

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

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

      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

      def edit
        authorize station
        render_edit(station)
      end

      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

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

      private

      def render_new(station)
        render :new, locals: { unit_id: unit_id, station: station }
      end

      def render_edit(station)
        render :edit, locals: { unit_id: unit_id, station: station }
      end

      def unit_id
        params[:unit_id]
      end

      def station
        @station ||= Station.find(params[:id])
      end

      def station_params
        params.require(:hd_station).permit(:name, :location_id)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
renalware-core-2.0.16 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.15 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.14 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.13 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.12 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.11 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.9 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.8 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.7 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.5 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.4 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.3 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.2 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.1 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.0 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.0.pre.rc13 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.0.pre.rc11 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.0.pre.rc10 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.0.pre.rc9 app/controllers/renalware/hd/stations_controller.rb
renalware-core-2.0.0.pre.rc8 app/controllers/renalware/hd/stations_controller.rb