Class: OtusController

Inherits:
ApplicationController show all
Includes:
DataControllerConfiguration::ProjectDataControllerConfiguration
Defined in:
app/controllers/otus_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 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) autocomplete



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/otus_controller.rb', line 85

def autocomplete
  @otus = Queries::OtuAutocompleteQuery.new(params.require(:term), project_id: sessions_current_project_id).all

  data = @otus.collect do |t|
    {
      id:              t.id,
      label:           ApplicationController.helpers.otu_autocomplete_selected_tag(t),
      gid:             t.to_global_id.to_s,
      response_values: {
        params[:method] => t.id
      },
      label_html:      ApplicationController.helpers.otu_tag(t)
    }
  end

  render :json => data
end

- (Object) batch_load



103
104
# File 'app/controllers/otus_controller.rb', line 103

def batch_load
end

- (Object) batch_params (private)



152
153
154
# File 'app/controllers/otus_controller.rb', line 152

def batch_params
  params.permit(:name, :file, :import_level).merge(user_id: sessions_current_user_id, project_id: sessions_current_project_id).symbolize_keys
end

- (Object) by_name

GET api/v1/otus/by_name/:name?token=:token&project_id=:id



136
137
138
139
# File 'app/controllers/otus_controller.rb', line 136

def by_name
  @otu_name = params.require(:name)
  @otu_ids = Queries::OtuAutocompleteQuery.new(@otu_name, project_id: params.require(:project_id)).all.pluck(:id)
end

- (Object) collection_objects

GET /api/v1/otus/1/collection_objects



73
74
75
# File 'app/controllers/otus_controller.rb', line 73

def collection_objects
  @collection_objects = Otu.find(params[:id]).collection_objects.pluck(:id)
end

- (Object) create

POST /otus POST /otus.json



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/otus_controller.rb', line 33

def create
  @otu = Otu.new(otu_params)

  respond_to do |format|
    if @otu.save
      format.html { redirect_to @otu,
                    notice: "Otu '#{@otu.name}' was successfully created." }
      format.json { render action: :show, status: :created, location: @otu }
    else
      format.html { render action: 'new' }
      format.json { render json: @otu.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) create_simple_batch_load



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

def create_simple_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :batch_otus_md5)
    @result = BatchLoad::Import::Otus.new(batch_params.merge(user_map))
    if @result.create
      flash[:notice] = "Successfully processed file, #{@result.total_records_created} otus were created."
      render('otus/batch_load/simple/create') and return
    else
      flash[:alert] = 'Batch import failed.'
    end
    render(:batch_load)
  end
end

- (Object) destroy

DELETE /otus/1 DELETE /otus/1.json



64
65
66
67
68
69
70
# File 'app/controllers/otus_controller.rb', line 64

def destroy
  @otu.destroy
  respond_to do |format|
    format.html { redirect_to otus_url }
    format.json { head :no_content }
  end
end

- (Object) download

GET /otus/download



131
132
133
# File 'app/controllers/otus_controller.rb', line 131

def download
  send_data Download.generate_csv(Otu.where(project_id: sessions_current_project_id)), type: 'text', filename: "otus_#{DateTime.now.to_s}.csv"
end

- (Object) edit

GET /otus/1/edit



24
25
# File 'app/controllers/otus_controller.rb', line 24

def edit
end

- (Object) index

GET /otus GET /otus.json



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

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

- (Object) list



27
28
29
# File 'app/controllers/otus_controller.rb', line 27

def list
  @otus = Otu.with_project_id(sessions_current_project_id).page(params[:page])
end

- (Object) new

GET /otus/new



19
20
21
# File 'app/controllers/otus_controller.rb', line 19

def new
  @otu = Otu.new
end

- (Object) otu_params (private)



148
149
150
# File 'app/controllers/otus_controller.rb', line 148

def otu_params
  params.require(:otu).permit(:name, :taxon_name_id)
end

- (Object) preview_simple_batch_load



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

def preview_simple_batch_load
  if params[:file]
    @result = BatchLoad::Import::Otus.new(batch_params.merge(user_map))
    digest_cookie(params[:file].tempfile, :batch_otus_md5)
    render('otus/batch_load/simple/preview')
  else
    flash[:notice] = 'No file provided!'
    redirect_to action: :batch_load
  end
end

- (Object) search



77
78
79
80
81
82
83
# File 'app/controllers/otus_controller.rb', line 77

def search
  if params[:id].blank?
    redirect_to otus_path, notice: 'You must select an item from the list with a click or tab press before clicking show.'
  else
    redirect_to otu_path(params[:id])
  end
end

- (Object) set_otu (private)



143
144
145
146
# File 'app/controllers/otus_controller.rb', line 143

def set_otu
  @otu = Otu.with_project_id(sessions_current_project_id).find(params[:id])
  @recent_object = @otu
end

- (Object) show

GET /otus/1 GET /otus/1.json



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

def show
end

- (Object) update

PATCH/PUT /otus/1 PATCH/PUT /otus/1.json



50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/otus_controller.rb', line 50

def update
  respond_to do |format|
    if @otu.update(otu_params)
      format.html { redirect_to @otu, notice: 'Otu was successfully updated.' }
      format.json { render :show, location: @otu }
    else
      format.html { render action: 'edit' }
      format.json { render json: @otu.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) user_map (private)



156
157
158
# File 'app/controllers/otus_controller.rb', line 156

def user_map
  {user_header_map: {'otu' => 'otu_name'}}
end