Class: AssertedDistributionsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- AssertedDistributionsController
- Defined in:
- app/controllers/asserted_distributions_controller.rb
Constant Summary
Constants included from ProjectsHelper
ProjectsHelper::CLASSIFIER, ProjectsHelper::CLASSIFIER_ANNOTATION
Instance Method Summary collapse
- #api_index ⇒ Object
- #api_show ⇒ Object
- #asserted_distribution_params ⇒ Object private
- #autocomplete ⇒ Object
-
#batch_load ⇒ Object
GET /asserted_distributions/batch_load.
- #batch_params ⇒ Object private
-
#batch_update ⇒ Object
PATCH /asserted_distributions/batch_update.json?asserted_distributions_query=<>&asserted_distribution=taxon_name_id=123}.
-
#create ⇒ Object
POST /asserted_distributions POST /asserted_distributions.json.
- #create_simple_batch_load ⇒ Object
-
#destroy ⇒ Object
DELETE /asserted_distributions/1 DELETE /asserted_distributions/1.json.
-
#download ⇒ Object
GET /asserted_distributions/download.
-
#edit ⇒ Object
GET /asserted_distributions/1/edit.
-
#index ⇒ Object
GET /asserted_distributions GET /asserted_distributions.json.
- #list ⇒ Object
-
#new ⇒ Object
GET /asserted_distributions/new.
- #preview_simple_batch_load ⇒ Object
-
#search ⇒ Object
TODO: deprecate.
- #set_asserted_distribution ⇒ Object private
-
#show ⇒ Object
GET /asserted_distributions/1 GET /asserted_distributions/1.json.
-
#update ⇒ Object
PATCH/PUT /asserted_distributions/1 PATCH/PUT /asserted_distributions/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
#cumulative_gb_per_year, #document_cumulative_gb_per_year, #document_gb_per_year, #gb_per_year, #image_cumulative_gb_per_year, #image_gb_per_year, #invalid_object, #project_classification, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form, #taxonworks_classification, #week_in_review_graphs
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
#api_index ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'app/controllers/asserted_distributions_controller.rb', line 155 def api_index @asserted_distributions = ::Queries::AssertedDistribution::Filter.new(params.merge!(api: true)) .all .where(project_id: sessions_current_project_id) .includes(:citations, :otu, geographic_area: [:parent, :geographic_area_type], origin_citation: [:source]) .order('asserted_distributions.id') .page(params[:page]) .per(params[:per]) if @asserted_distributions.all.count > 50 params['extend']&.delete('geo_json') end render '/asserted_distributions/api/v1/index' end |
#api_show ⇒ Object
171 172 173 |
# File 'app/controllers/asserted_distributions_controller.rb', line 171 def api_show render '/asserted_distributions/api/v1/show' end |
#asserted_distribution_params ⇒ Object (private)
182 183 184 185 186 187 188 189 190 191 192 |
# File 'app/controllers/asserted_distributions_controller.rb', line 182 def asserted_distribution_params params.require(:asserted_distribution).permit( :otu_id, :geographic_area_id, :is_absent, otu_attributes: [:id, :_destroy, :name, :taxon_name_id], origin_citation_attributes: [:id, :_destroy, :source_id, :pages], citations_attributes: [:id, :is_original, :_destroy, :source_id, :pages, :citation_object_id, :citation_object_type], data_attributes_attributes: [ :id, :_destroy, :controlled_vocabulary_term_id, :type, :attribute_subject_id, :attribute_subject_type, :value ] ) end |
#autocomplete ⇒ Object
91 92 93 |
# File 'app/controllers/asserted_distributions_controller.rb', line 91 def autocomplete @asserted_distributions = ::Queries::AssertedDistribution::Autocomplete.new(params.require(:term), project_id: sessions_current_project_id).autocomplete end |
#batch_load ⇒ Object
GET /asserted_distributions/batch_load
113 114 |
# File 'app/controllers/asserted_distributions_controller.rb', line 113 def batch_load end |
#batch_params ⇒ Object (private)
194 195 196 |
# File 'app/controllers/asserted_distributions_controller.rb', line 194 def batch_params params.permit(:data_origin, :file, :import_level).merge(user_id: sessions_current_user_id, project_id: sessions_current_project_id).to_h.symbolize_keys end |
#batch_update ⇒ Object
PATCH /asserted_distributions/batch_update.json?asserted_distributions_query=<>&asserted_distribution=taxon_name_id=123}
117 118 119 120 121 122 123 124 125 126 127 |
# File 'app/controllers/asserted_distributions_controller.rb', line 117 def batch_update if r = AssertedDistribution.batch_update( preview: params[:preview], asserted_distribution: asserted_distribution_params.merge(by: sessions_current_user_id), asserted_distribution_query: params[:asserted_distribution_query], ) render json: r.to_json, status: :ok else render json: {}, status: :unprocessable_entity end end |
#create ⇒ Object
POST /asserted_distributions POST /asserted_distributions.json
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/controllers/asserted_distributions_controller.rb', line 43 def create @asserted_distribution = AssertedDistribution.new(asserted_distribution_params) respond_to do |format| if @asserted_distribution.save format.html { redirect_to @asserted_distribution, notice: 'Asserted distribution was successfully created.' } format.json { render :show, status: :created, location: @asserted_distribution } else format.html { render :new } format.json { render json: @asserted_distribution.errors, status: :unprocessable_entity } end end end |
#create_simple_batch_load ⇒ Object
140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/controllers/asserted_distributions_controller.rb', line 140 def create_simple_batch_load if params[:file] && (params[:file].tempfile, :batch_asserted_distributions_md5) @result = BatchLoad::Import::AssertedDistributions.new(**batch_params) if @result.create flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} asserted distributions were created." render 'asserted_distributions/batch_load/simple/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 |
#destroy ⇒ Object
DELETE /asserted_distributions/1 DELETE /asserted_distributions/1.json
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/controllers/asserted_distributions_controller.rb', line 72 def destroy @asserted_distribution.mark_citations_for_destruction @asserted_distribution.destroy respond_to do |format| if @asserted_distribution.destroyed? format.html { destroy_redirect @asserted_distribution, notice: 'Asserted distribution was successfully destroyed.' } format.json { head :no_content} else format.html { destroy_redirect @asserted_distribution, notice: 'Asserted distribution was not destroyed, ' + @asserted_distribution.errors..join('; ') } format.json { render json: @asserted_distribution.errors, status: :unprocessable_entity } end end end |
#download ⇒ Object
GET /asserted_distributions/download
105 106 107 108 109 110 |
# File 'app/controllers/asserted_distributions_controller.rb', line 105 def download send_data( Export::CSV.generate_csv(AssertedDistribution.where(project_id: sessions_current_project_id)), type: 'text', filename: "asserted_distributions_#{DateTime.now}.tsv") end |
#edit ⇒ Object
GET /asserted_distributions/1/edit
38 39 |
# File 'app/controllers/asserted_distributions_controller.rb', line 38 def edit end |
#index ⇒ Object
GET /asserted_distributions GET /asserted_distributions.json
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/controllers/asserted_distributions_controller.rb', line 9 def index respond_to do |format| format.html { @recent_objects = AssertedDistribution.recent_from_project_id(sessions_current_project_id) .order(updated_at: :desc) .limit(10) render '/shared/data/all/index' } format.json { @asserted_distributions = ::Queries::AssertedDistribution::Filter.new(params) .all .where(project_id: sessions_current_project_id) .page(params[:page]) .per(params[:per]) } end end |
#list ⇒ Object
87 88 89 |
# File 'app/controllers/asserted_distributions_controller.rb', line 87 def list @asserted_distributions = AssertedDistribution.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10) #.per(3) end |
#new ⇒ Object
GET /asserted_distributions/new
33 34 35 |
# File 'app/controllers/asserted_distributions_controller.rb', line 33 def new @asserted_distribution = AssertedDistribution.new(origin_citation: Citation.new) end |
#preview_simple_batch_load ⇒ Object
129 130 131 132 133 134 135 136 137 138 |
# File 'app/controllers/asserted_distributions_controller.rb', line 129 def preview_simple_batch_load if params[:file] @result = BatchLoad::Import::AssertedDistributions.new(**batch_params) (params[:file].tempfile, :batch_asserted_distributions_md5) render 'asserted_distributions/batch_load/simple/preview' else flash[:notice] = 'No file provided!' redirect_to action: :batch_load end end |
#search ⇒ Object
TODO: deprecate
96 97 98 99 100 101 102 |
# File 'app/controllers/asserted_distributions_controller.rb', line 96 def search if params[:id].blank? redirect_to asserted_distributions_path, alert: 'You must select an item from the list with a click or tab press before clicking show.' else redirect_to asserted_distribution_path(params[:id]) end end |
#set_asserted_distribution ⇒ Object (private)
177 178 179 180 |
# File 'app/controllers/asserted_distributions_controller.rb', line 177 def set_asserted_distribution @asserted_distribution = AssertedDistribution.where(project_id: sessions_current_project_id).find(params[:id]) @recent_object = @asserted_distribution end |
#show ⇒ Object
GET /asserted_distributions/1 GET /asserted_distributions/1.json
29 30 |
# File 'app/controllers/asserted_distributions_controller.rb', line 29 def show end |
#update ⇒ Object
PATCH/PUT /asserted_distributions/1 PATCH/PUT /asserted_distributions/1.json
58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/asserted_distributions_controller.rb', line 58 def update respond_to do |format| if @asserted_distribution.update(asserted_distribution_params) format.html { redirect_to @asserted_distribution, notice: 'Asserted distribution was successfully updated.' } format.json { render :show, status: :ok, location: @asserted_distribution } else format.html { render :edit } format.json { render json: @asserted_distribution.errors, status: :unprocessable_entity } end end end |