Class: RequestsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- RequestsController
- Defined in:
- app/controllers/requests_controller.rb
Overview
rubocop:todo Metrics/ClassLength
Constant Summary
Constants included from FlashTruncation
FlashTruncation::STRING_OVERHEAD
Instance Attribute Summary collapse
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
Instance Method Summary collapse
-
#additional ⇒ Object
rubocop:enable Metrics/MethodLength.
-
#cancel ⇒ Object
rubocop:todo Metrics/MethodLength.
- #change_decision ⇒ Object
- #copy ⇒ Object
- #edit ⇒ Object
- #filter_change_decision ⇒ Object
- #find_request ⇒ Object
-
#history ⇒ Object
Displays history of events.
-
#index ⇒ Object
rubocop:todo Metrics/PerceivedComplexity, Metrics/AbcSize.
- #list_inboxes ⇒ Object
- #reset ⇒ Object
- #reset_qc_information ⇒ Object
- #search_params ⇒ Object
- #set_permitted_params ⇒ Object
-
#show ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity.
-
#update ⇒ Object
rubocop:todo Metrics/MethodLength.
Methods inherited from ApplicationController
#block_api_access, #evil_parameter_hack!, #extract_header_info, #set_cache_disabled!
Methods included from FlashTruncation
#max_flash_size, #truncate_flash, #truncate_flash_array
Instance Attribute Details
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
13 14 15 |
# File 'app/controllers/requests_controller.rb', line 13 def parameters @parameters end |
Instance Method Details
#additional ⇒ Object
rubocop:enable Metrics/MethodLength
98 99 100 101 102 |
# File 'app/controllers/requests_controller.rb', line 98 def additional @request = Request.find(params[:id]) @additional = @request.request_type.create!(initial_study: @request.study, items: @request.items) redirect_to request_path(@additional) end |
#cancel ⇒ Object
rubocop:todo Metrics/MethodLength
116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'app/controllers/requests_controller.rb', line 116 def cancel # rubocop:todo Metrics/AbcSize @request = Request.find(params[:id]) if @request.try(:may_cancel_before_started?) if @request.cancel_before_started && @request.save flash[:notice] = "Request #{@request.id} has been cancelled" else flash[:error] = "Failed to cancel request #{@request.id}" end else flash[:error] = "Request #{@request.id} can't be cancelled" end redirect_to request_path(@request) end |
#change_decision ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'app/controllers/requests_controller.rb', line 173 def change_decision @change_decision = Request::ChangeDecision.new( { request: @request, user: @current_user }.merge(params[:change_decision] || {}) ).execute! flash[:notice] = 'Update. Below you find the new situation.' redirect_to filter_change_decision_request_path(params[:id]) rescue Request::ChangeDecision::InvalidDecision => e flash[:error] = 'Failed! Please, read the list of problem below.' @change_decision = e.object render(action: :filter_change_decision) end |
#copy ⇒ Object
146 147 148 149 150 151 |
# File 'app/controllers/requests_controller.rb', line 146 def copy old_request = Request.find(params[:id]) new_request = old_request.copy flash[:notice] = "Created request #{new_request.id}" redirect_to receptacle_path(new_request.asset) end |
#edit ⇒ Object
59 60 61 62 63 64 65 |
# File 'app/controllers/requests_controller.rb', line 59 def edit @request = Request.find(params[:id]) :update, @request @request_types = RequestType.where(asset_type: @request.request_type.asset_type) respond_to { |format| format.html } end |
#filter_change_decision ⇒ Object
168 169 170 171 |
# File 'app/controllers/requests_controller.rb', line 168 def filter_change_decision @change_decision = Request::ChangeDecision.new(request: @request, user: @current_user) respond_to { |format| format.html } end |
#find_request ⇒ Object
164 165 166 |
# File 'app/controllers/requests_controller.rb', line 164 def find_request @request = Request.find(params[:id]) end |
#history ⇒ Object
Displays history of events
133 134 135 136 137 138 139 140 |
# File 'app/controllers/requests_controller.rb', line 133 def history @request = Request.find(params[:id]) respond_to do |format| format.html format.xml { @request.events.to_xml } format.json { @request.events.to_json } end end |
#index ⇒ Object
rubocop:todo Metrics/PerceivedComplexity, Metrics/AbcSize
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/controllers/requests_controller.rb', line 18 def index # rubocop:todo Metrics/CyclomaticComplexity, Metrics/MethodLength @study, @item = nil, nil # Ok, here we pick the initial source for the Requests. They either come from Request (as in all Requests), or they # are limited by the Asset / Item. request_source = Request .includes(:request_type, :initial_study, :user, :events, asset: :barcodes) .order(id: :desc) .where(search_params) .paginate(per_page: 200, page: params[:page]) @asset = Receptacle.find(params[:asset_id]) if params[:asset_id] @request_type = RequestType.find(params[:request_type_id]) if params[:request_type_id] @study = Study.find(params[:study_id]) if params[:study_id] @subtitle = @study&.name || @asset&.display_name # Deprecated?: It would be great if we could remove this if params[:request_type] && params[:workflow] request_source = request_source.for_request_types(params[:request_type]).includes(:user) end # Now, here we go: find all of the requests! @requests = request_source respond_to { |format| format.html } end |
#list_inboxes ⇒ Object
142 143 144 |
# File 'app/controllers/requests_controller.rb', line 142 def list_inboxes @tasks = Task.all end |
#reset ⇒ Object
104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/requests_controller.rb', line 104 def reset @request = Request.find(params[:id]) @request.reset! flash[:notice] = "Request #{@request.id} was reset successfully" if params[:study_id] redirect_to study_requests_path(params[:study_id]) else redirect_to requests_path end end |
#reset_qc_information ⇒ Object
153 154 155 156 157 158 159 160 |
# File 'app/controllers/requests_controller.rb', line 153 def reset_qc_information @request = Request.find(params[:id]) @request.reset! @event = Event.find(params[:event_id]) flash[:notice] = "QC event #{@event.id} has been deleted" @event.destroy redirect_to request_path(@request) end |
#search_params ⇒ Object
186 187 188 189 190 |
# File 'app/controllers/requests_controller.rb', line 186 def search_params permitted = params.permit(:asset_id, :state, :request_type_id, :submission_id) permitted[:initial_study_id] = params[:study_id] if params[:study_id] permitted end |
#set_permitted_params ⇒ Object
10 11 12 |
# File 'app/controllers/requests_controller.rb', line 10 def set_permitted_params @parameters = params[:request].reject { |k, _v| ['request_metadata_attributes'].exclude?(k.to_s) } end |
#show ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/requests_controller.rb', line 49 def show @request = Request.find(params[:id]) @user = User.find(@request.user_id) if @request.user_id.present? respond_to do |format| format.html format.xml end end |
#update ⇒ Object
rubocop:todo Metrics/MethodLength
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'app/controllers/requests_controller.rb', line 68 def update # rubocop:todo Metrics/AbcSize @request = Request.find(params[:id]) :update, @request unless params[:request][:request_type_id].nil? unless @request.request_type_updatable?(params[:request][:request_type_id]) flash[:error] = 'You can not change the request type.' redirect_to request_path(@request) return end end begin if @request.update(parameters) flash[:notice] = 'Request details have been updated' redirect_to request_path(@request) else flash[:error] = 'Request was not updated. No change specified ?' render action: 'edit', id: @request.id end rescue => e = "An error has occurred, category:'#{e.class}'\ndescription:'#{e.}'" EventFactory.request_update_note_to_manager(@request, current_user, ) flash[:error] = 'Failed to update request. ' << render action: 'edit', id: @request.id end end |