Class: AssertedDistributionsController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/asserted_distributions_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#is_data_controller, #is_task_controller, #meta_data, #meta_description, #meta_keywords, #meta_title, #page_title, #site_name

Instance Method Summary (collapse)

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#polymorphic_filter_params

Methods inherited from ApplicationController

#clear_project_and_user_variables, #digest_cookie, #digested_cookie_exists?, #disable_turbolinks, #intercept_api, #invalid_object, #is_data_controller?, #is_task_controller?, #log_user_recent_route, #notice_user, #project_matches, #record_not_found, #set_project_and_user_variables, #set_project_from_params, #token_authenticate

Methods included from ProjectsHelper

#project_link, #project_tag, #projects_list, #projects_search_form

Instance Method Details

- (Object) asserted_distribution_params (private)



138
139
140
141
142
143
# File 'app/controllers/asserted_distributions_controller.rb', line 138

def asserted_distribution_params
  params.require(:asserted_distribution).permit(:otu_id, :geographic_area_id, :source_id, :is_absent,
                                                otu_attributes: [:id, :_destroy, :name, :taxon_name_id],
                                                origin_citation_attributes: [:id, :_destroy, :source_id, :pages] 
                                               )
end

- (Object) autocomplete



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/controllers/asserted_distributions_controller.rb', line 74

def autocomplete
  @asserted_distributions = AssertedDistribution.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)) # in model
  data                    = @asserted_distributions.collect do |t|
    {id:              t.id,
     label:           AssertedDistributionsHelper.asserted_distribution_tag(t), # in helper
     response_values: {
       params[:method] => t.id
     },
     label_html:      AssertedDistributionsHelper.asserted_distribution_tag(t) #  render_to_string(:partial => 'shared/autocomplete/taxon_name.html', :object => t)
    }
  end
  render :json => data
end

- (Object) batch_load

GET /asserted_distributions/batch_load



102
103
# File 'app/controllers/asserted_distributions_controller.rb', line 102

def batch_load
end

- (Object) batch_params (private)



145
146
147
# File 'app/controllers/asserted_distributions_controller.rb', line 145

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

- (Object) create

POST /asserted_distributions POST /asserted_distributions.json



31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/asserted_distributions_controller.rb', line 31

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

- (Object) create_simple_batch_load



116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/controllers/asserted_distributions_controller.rb', line 116

def create_simple_batch_load
  if params[:file] && digested_cookie_exists?(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

- (Object) destroy

DELETE /asserted_distributions/1 DELETE /asserted_distributions/1.json



60
61
62
63
64
65
66
67
68
# File 'app/controllers/asserted_distributions_controller.rb', line 60

def destroy
  @asserted_distribution.mark_citations_for_destruction
  @asserted_distribution.destroy

  respond_to do |format|
    format.html { redirect_to asserted_distributions_url, notice: 'Asserted distribution was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) download

GET /asserted_distributions/download



97
98
99
# File 'app/controllers/asserted_distributions_controller.rb', line 97

def download
  send_data AssertedDistribution.generate_download(AssertedDistribution.where(project_id: sessions_current_project_id)), type: 'text', filename: "asserted_distributions_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /asserted_distributions/1/edit



25
26
27
# File 'app/controllers/asserted_distributions_controller.rb', line 25

def edit
  @asserted_distribution.origin_citation.source = Source.new if !@asserted_distribution.origin_citation.source
end

- (Object) index

GET /asserted_distributions GET /asserted_distributions.json



8
9
10
11
# File 'app/controllers/asserted_distributions_controller.rb', line 8

def index
  @recent_objects = AssertedDistribution.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
  render '/shared/data/all/index'
end

- (Object) list



70
71
72
# File 'app/controllers/asserted_distributions_controller.rb', line 70

def list
  @asserted_distributions = AssertedDistribution.with_project_id(sessions_current_project_id).order(:id).page(params[:page]) #.per(10) #.per(3)
end

- (Object) new

GET /asserted_distributions/new



20
21
22
# File 'app/controllers/asserted_distributions_controller.rb', line 20

def new
  @asserted_distribution = AssertedDistribution.new(origin_citation: Citation.new)
end

- (Object) preview_simple_batch_load



105
106
107
108
109
110
111
112
113
114
# File 'app/controllers/asserted_distributions_controller.rb', line 105

def preview_simple_batch_load 
  if params[:file]
    @result =  BatchLoad::Import::AssertedDistributions.new(batch_params)
    digest_cookie(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

- (Object) search



88
89
90
91
92
93
94
# File 'app/controllers/asserted_distributions_controller.rb', line 88

def search
  if params[:id].blank?
    redirect_to asserted_distributions_path, notice: '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

- (Object) set_asserted_distribution (private)



133
134
135
136
# File 'app/controllers/asserted_distributions_controller.rb', line 133

def set_asserted_distribution
  @asserted_distribution = AssertedDistribution.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object         = @asserted_distribution
end

- (Object) show

GET /asserted_distributions/1 GET /asserted_distributions/1.json



15
16
17
# File 'app/controllers/asserted_distributions_controller.rb', line 15

def show
  # @asserted_distribution = AssertedDistribution.find(params[:id])
end

- (Object) update

PATCH/PUT /asserted_distributions/1 PATCH/PUT /asserted_distributions/1.json



46
47
48
49
50
51
52
53
54
55
56
# File 'app/controllers/asserted_distributions_controller.rb', line 46

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