Class: SequencesController

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



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/sequences_controller.rb', line 79

def autocomplete
  @sequences = Sequence.where(project_id: sessions_current_project_id).where('sequence ILIKE ?', "#{params[:term]}%")

  data = @sequences.collect do |t|
    {id:              t.id,
     label:           t.sequence,
     gid:             t.to_global_id.to_s,
     response_values: {
       params[:method] => t.id
     },
     label_html:      t.sequence
    }
  end

  render :json => data
end

- (Object) batch_load



96
97
# File 'app/controllers/sequences_controller.rb', line 96

def batch_load
end

- (Object) batch_params (private)



188
189
190
# File 'app/controllers/sequences_controller.rb', line 188

def batch_params
  params.permit(:namespace, :file, :import_level, :files => []).merge(user_id: sessions_current_user_id, project_id: sessions_current_project_id).symbolize_keys
end

- (Object) create

POST /sequences POST /sequences.json



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

def create
  @sequence = Sequence.new(sequence_params)

  respond_to do |format|
    if @sequence.save
      format.html { redirect_to @sequence, notice: 'Sequence was successfully created.' }
      format.json { render :show, status: :created, location: @sequence }
    else
      format.html { render :new }
      format.json { render json: @sequence.errors, status: :unprocessable_entity }
    end
  end
end

- (Object) create_genbank_batch_file_load



110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'app/controllers/sequences_controller.rb', line 110

def create_genbank_batch_file_load
  if params[:files] && digested_cookie_exists?(params[:files][0].tempfile, :batch_file_load_genbank_sequences_md5)
    @result = BatchFileLoad::Import::Sequences::GenbankInterpreter.new(batch_params)
    if @result.create
      flash[:notice] = "Successfully processed #{@result.total_files_processed} file(s), #{@result.total_records_created} sequences were created."
      render 'sequences/batch_file_load/genbank/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) create_genbank_batch_load



136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'app/controllers/sequences_controller.rb', line 136

def create_genbank_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :Genbank_sequences_md5)
    @result = BatchLoad::Import::Sequences::GenbankInterpreter.new(batch_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} sequences were created."
      render 'sequences/batch_load/genbank/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) create_primers_batch_load



162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'app/controllers/sequences_controller.rb', line 162

def create_primers_batch_load
  if params[:file] && digested_cookie_exists?(params[:file].tempfile, :Primers_sequences_md5)
    @result = BatchLoad::Import::Sequences::PrimersInterpreter.new(batch_params)
    if @result.create
      flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} sequences were created."
      render 'sequences/batch_load/primers/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 /sequences/1 DELETE /sequences/1.json



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

def destroy
  @sequence.destroy
  respond_to do |format|
    format.html { redirect_to sequences_url, notice: 'Sequence was successfully destroyed.' }
    format.json { head :no_content }
  end
end

- (Object) edit

GET /sequences/1/edit



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

def edit
end

- (Object) index

GET /sequences GET /sequences.json



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

def index
  @recent_objects = Sequence.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/sequences_controller.rb', line 27

def list
  @sequences = Sequence.with_project_id(sessions_current_project_id).page(params[:page])
end

- (Object) new

GET /sequences/new



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

def new
  @sequence = Sequence.new
end

- (Object) preview_genbank_batch_file_load



99
100
101
102
103
104
105
106
107
108
# File 'app/controllers/sequences_controller.rb', line 99

def preview_genbank_batch_file_load 
  if params[:files] 
    @result = BatchFileLoad::Import::Sequences::GenbankInterpreter.new(batch_params)
    digest_cookie(params[:files][0].tempfile, :batch_file_load_genbank_sequences_md5)
    render 'sequences/batch_file_load/genbank/preview'
  else
    flash[:notice] = "No file(s) provided!"
    redirect_to action: :batch_load 
  end
end

- (Object) preview_genbank_batch_load



125
126
127
128
129
130
131
132
133
134
# File 'app/controllers/sequences_controller.rb', line 125

def preview_genbank_batch_load 
  if params[:file] 
    @result = BatchLoad::Import::Sequences::GenbankInterpreter.new(batch_params)
    digest_cookie(params[:file].tempfile, :Genbank_sequences_md5)
    render 'sequences/batch_load/genbank/preview'
  else
    flash[:notice] = "No file provided!"
    redirect_to action: :batch_load 
  end
end

- (Object) preview_primers_batch_load



151
152
153
154
155
156
157
158
159
160
# File 'app/controllers/sequences_controller.rb', line 151

def preview_primers_batch_load 
  if params[:file] 
    @result = BatchLoad::Import::Sequences::PrimersInterpreter.new(batch_params)
    digest_cookie(params[:file].tempfile, :Primers_sequences_md5)
    render 'sequences/batch_load/primers/preview'
  else
    flash[:notice] = "No file provided!"
    redirect_to action: :batch_load 
  end
end

- (Object) search



71
72
73
74
75
76
77
# File 'app/controllers/sequences_controller.rb', line 71

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

- (Object) sequence_params (private)

Never trust parameters from the scary internet, only allow the white list through.



184
185
186
# File 'app/controllers/sequences_controller.rb', line 184

def sequence_params
  params.require(:sequence).permit(:name, :sequence, :sequence_type, :created_by_id, :updated_by_id, :project_id)
end

- (Object) set_sequence (private)

Use callbacks to share common setup or constraints between actions.



179
180
181
# File 'app/controllers/sequences_controller.rb', line 179

def set_sequence
  @sequence = Sequence.find(params[:id])
end

- (Object) show

GET /sequences/1 GET /sequences/1.json



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

def show
end

- (Object) update

PATCH/PUT /sequences/1 PATCH/PUT /sequences/1.json



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

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