Class: DescriptorsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- DescriptorsController
- Defined in:
- app/controllers/descriptors_controller.rb
Instance Method Summary collapse
-
#annotations ⇒ Object
TODO: remove for shared end point GET /annotations.
- #autocomplete ⇒ Object
- #batch_load ⇒ Object
- #batch_params ⇒ Object private
-
#create ⇒ Object
POST /descriptors POST /descriptors.json.
- #create_modify_gene_descriptor_batch_load ⇒ Object
- #create_qualitative_descriptor_batch_load ⇒ Object
- #descriptor_params ⇒ Object private
-
#destroy ⇒ Object
DELETE /descriptors/1 DELETE /descriptors/1.json.
-
#edit ⇒ Object
GET /descriptors/1/edit.
-
#index ⇒ Object
GET /descriptors GET /descriptors.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /descriptors/new.
- #preview_modify_gene_descriptor_batch_load ⇒ Object
- #preview_qualitative_descriptor_batch_load ⇒ Object
- #search ⇒ Object
- #set_descriptor ⇒ Object private
-
#show ⇒ Object
GET /descriptors/1 GET /descriptors/1.json.
- #units ⇒ Object
-
#update ⇒ Object
PATCH/PUT /descriptors/1 PATCH/PUT /descriptors/1.json.
Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration
Methods included from RedirectHelper
Methods included from RequestType
Methods included from LogRecent
Methods included from Cookies
#digest_cookie, #digested_cookie_exists?
Methods included from Whitelist
Methods included from ProjectsHelper
#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form
Methods included from Api::Intercept
Methods included from TokenAuthentication
#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate
Instance Method Details
#annotations ⇒ Object
TODO: remove for shared end point GET /annotations
109 110 111 112 |
# File 'app/controllers/descriptors_controller.rb', line 109 def annotations @object = @descriptor render '/shared/data/all/annotations' end |
#autocomplete ⇒ Object
93 94 95 96 |
# File 'app/controllers/descriptors_controller.rb', line 93 def autocomplete @term = params[:term] @descriptors = Queries::Descriptor::Autocomplete.new(params.require(:term), project_id: sessions_current_project_id).all end |
#batch_load ⇒ Object
114 115 |
# File 'app/controllers/descriptors_controller.rb', line 114 def batch_load end |
#batch_params ⇒ Object (private)
195 196 197 198 199 |
# File 'app/controllers/descriptors_controller.rb', line 195 def batch_params params.permit(:file).merge( user_id: sessions_current_user_id, project_id: sessions_current_project_id).to_h.symbolize_keys end |
#create ⇒ Object
POST /descriptors POST /descriptors.json
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/descriptors_controller.rb', line 43 def create @descriptor = Descriptor.new(descriptor_params) respond_to do |format| if @descriptor.save format.html { redirect_to url_for(@descriptor.), notice: 'Descriptor was successfully created.' } format.json { render :show, status: :created, location: @descriptor. } else format.html { render :new } format.json { render json: @descriptor..errors, status: :unprocessable_entity } end end end |
#create_modify_gene_descriptor_batch_load ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'app/controllers/descriptors_controller.rb', line 139 def create_modify_gene_descriptor_batch_load if params[:file] && ( params[:file].tempfile, :modify_gene_descriptor_batch_load_descriptors_md5) @result = BatchLoad::Import::Descriptors::ModifyGeneDescriptorInterpreter.new(**batch_params) if @result.create flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} " \ 'Gene Descriptors were modified.' render 'descriptors/batch_load/modify_gene_descriptor/create' and return else flash[:alert] = 'Batch import failed.' end else flash[:alert] = 'File to batch upload must be supplied.' end render :batch_load end |
#create_qualitative_descriptor_batch_load ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'app/controllers/descriptors_controller.rb', line 158 def create_qualitative_descriptor_batch_load if params[:file] && ( params[:file].tempfile, :qualitative_descriptors_batch_load_md5) @result = BatchLoad::Import::Descriptors::QualitativeInterpreter.new(**batch_params) if @result.create flash[:notice] = "Successfully proccessed file, #{@result.total_records_created}." render 'descriptors/batch_load/qualitative_descriptor/create' and return else flash[:alert] = 'Batch import failed.' end else flash[:alert] = 'File to batch upload must be supplied.' end render :batch_load end |
#descriptor_params ⇒ Object (private)
186 187 188 189 190 191 192 193 |
# File 'app/controllers/descriptors_controller.rb', line 186 def descriptor_params params.require(:descriptor).permit( :name, :short_name, :key_name, :description_name, :description, :position, :type, :gene_attribute_logic, :default_unit, :weight, character_states_attributes: [:id, :descriptor_id, :_destroy, :label, :name, :position, :description_name, :key_name], gene_attributes_attributes: [:id, :_destroy, :sequence_id, :sequence_relationship_type, :controlled_vocabulary_term_id, :position ] ) end |
#destroy ⇒ Object
DELETE /descriptors/1 DELETE /descriptors/1.json
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/controllers/descriptors_controller.rb', line 80 def destroy @descriptor.destroy respond_to do |format| if @descriptor.destroyed? format.html { destroy_redirect @descriptor, notice: 'Descriptor was successfully destroyed.' } format.json { head :no_content } else format.html { destroy_redirect @descriptor, notice: 'Descriptor was not destroyed, ' + @descriptor.errors..join('; ') } format.json { render json: @descriptor.errors, status: :unprocessable_entity } end end end |
#edit ⇒ Object
GET /descriptors/1/edit
37 38 39 |
# File 'app/controllers/descriptors_controller.rb', line 37 def edit redirect_to new_descriptor_task_path(descriptor_id: @descriptor.id), notice: 'Editing in new interface.' end |
#index ⇒ Object
GET /descriptors GET /descriptors.json
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/controllers/descriptors_controller.rb', line 8 def index respond_to do |format| format.html do @recent_objects = Descriptor.recent_from_project_id(sessions_current_project_id) .order(updated_at: :desc).limit(10) render '/shared/data/all/index' end format.json { @descriptors = Descriptor.where(project_id: sessions_current_project_id).limit(20) } end end |
#list ⇒ Object
26 27 28 |
# File 'app/controllers/descriptors_controller.rb', line 26 def list @descriptor = Descriptor.with_project_id(sessions_current_project_id).page(params[:page]) end |
#new ⇒ Object
GET /descriptors/new
31 32 33 34 |
# File 'app/controllers/descriptors_controller.rb', line 31 def new @descriptor = Descriptor.new redirect_to new_descriptor_task_path(), notice: 'Using task interface.' end |
#preview_modify_gene_descriptor_batch_load ⇒ Object
117 118 119 120 121 122 123 124 125 126 |
# File 'app/controllers/descriptors_controller.rb', line 117 def preview_modify_gene_descriptor_batch_load if params[:file] @result = BatchLoad::Import::Descriptors::ModifyGeneDescriptorInterpreter.new(**batch_params) (params[:file].tempfile, :modify_gene_descriptor_batch_load_descriptors_md5) render 'descriptors/batch_load/modify_gene_descriptor/preview' else flash[:notice] = 'No file provided!' redirect_to action: :batch_load end end |
#preview_qualitative_descriptor_batch_load ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'app/controllers/descriptors_controller.rb', line 128 def preview_qualitative_descriptor_batch_load if params[:file] @result = BatchLoad::Import::Descriptors::QualitativeInterpreter.new(**batch_params) (params[:file].tempfile, :qualitative_descriptors_batch_load_md5) render 'descriptors/batch_load/qualitative_descriptor/preview' else flash[:notice] = 'No file provided!' redirect_to action: :batch_load end end |
#search ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'app/controllers/descriptors_controller.rb', line 98 def search if params[:id].blank? redirect_to descriptors_path, notice: 'You must select an item from the list with a click or ' \ 'tab press before clicking show.' else redirect_to descriptor_path(params[:id]) end end |
#set_descriptor ⇒ Object (private)
182 183 184 |
# File 'app/controllers/descriptors_controller.rb', line 182 def set_descriptor @descriptor = Descriptor.where(project_id: sessions_current_project_id).find(params[:id]) end |
#show ⇒ Object
GET /descriptors/1 GET /descriptors/1.json
23 24 |
# File 'app/controllers/descriptors_controller.rb', line 23 def show end |
#units ⇒ Object
176 177 178 |
# File 'app/controllers/descriptors_controller.rb', line 176 def units render json: UNITS end |
#update ⇒ Object
PATCH/PUT /descriptors/1 PATCH/PUT /descriptors/1.json
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/controllers/descriptors_controller.rb', line 59 def update respond_to do |format| begin if @descriptor.update(descriptor_params) format.html { redirect_to url_for(@descriptor.), notice: 'Descriptor was successfully updated.' } format.json { render :show, status: :ok, location: @descriptor. } else format.html { render :edit } format.json { render json: @descriptor..errors, status: :unprocessable_entity } end # Can not cascade destroy Observations rescue ActiveRecord::RecordNotDestroyed format.html { render :edit } format.json { render json: 'Could not destroy, do observations still exist?', status: :unprocessable_entity } end end end |