Class: SequencesController

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

Instance Method Summary collapse

Methods included from DataControllerConfiguration::ProjectDataControllerConfiguration

#annotator_params

Methods included from RedirectHelper

#destroy_redirect

Methods included from RequestType

#json_request?

Methods included from LogRecent

#log_user_recent_route

Methods included from Cookies

#digest_cookie, #digested_cookie_exists?

Methods included from Whitelist

#whitelist_constantize

Methods included from ProjectsHelper

#invalid_object, #project_link, #project_matches, #project_tag, #projects_list, #projects_search_form

Methods included from Api::Intercept

#intercept_api

Methods included from TokenAuthentication

#intercept_project, #intercept_user, #intercept_user_or_project, #project_token_authenticate, #token_authenticate

Instance Method Details

#autocompleteObject



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

def autocomplete
  t = "#{params[:term]}%"
  @sequences = Sequence.where(project_id: sessions_current_project_id).where('sequence ILIKE ? OR name ILIKE ?', t, t)
  data = @sequences.collect do |t|
    l = [t.name, t.sequence[0..10]].compact.join(': ')
    {id: t.id,
     label: l, 
     gid: t.to_global_id.to_s,
     response_values: {
       params[:method] => t.id
     },
     label_html: l      }
  end

  render json: data
end

#batch_loadObject



101
102
# File 'app/controllers/sequences_controller.rb', line 101

def batch_load
end

#batch_paramsObject (private)



197
198
199
# File 'app/controllers/sequences_controller.rb', line 197

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

#createObject

POST /sequences POST /sequences.json



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/sequences_controller.rb', line 38

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

#create_genbank_batch_file_loadObject



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

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

#create_genbank_batch_loadObject



141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'app/controllers/sequences_controller.rb', line 141

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

#create_primers_batch_loadObject



167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'app/controllers/sequences_controller.rb', line 167

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

#destroyObject

DELETE /sequences/1 DELETE /sequences/1.json



68
69
70
71
72
73
74
# File 'app/controllers/sequences_controller.rb', line 68

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

#editObject

GET /sequences/1/edit



29
30
# File 'app/controllers/sequences_controller.rb', line 29

def edit
end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
# File 'app/controllers/sequences_controller.rb', line 6

def index
  respond_to do |format|
    format.html do
      @recent_objects = Sequence.recent_from_project_id(sessions_current_project_id).order(updated_at: :desc).limit(10)
      render '/shared/data/all/index'
    end
    format.json {
      @sequences = Sequence.where(project_id: sessions_current_project_id).page(params[:page]).per(params[:per] || 500)
    }
  end
end

#listObject



32
33
34
# File 'app/controllers/sequences_controller.rb', line 32

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

#newObject

GET /sequences/new



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

def new
  @sequence = Sequence.new
end

#preview_genbank_batch_file_loadObject



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

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

#preview_genbank_batch_loadObject



130
131
132
133
134
135
136
137
138
139
# File 'app/controllers/sequences_controller.rb', line 130

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

#preview_primers_batch_loadObject



156
157
158
159
160
161
162
163
164
165
# File 'app/controllers/sequences_controller.rb', line 156

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

#searchObject



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

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

#select_optionsObject



182
183
184
# File 'app/controllers/sequences_controller.rb', line 182

def select_options
  @sequences = Sequence.select_optimized(sessions_current_user_id, sessions_current_project_id, params[:target])
end

#sequence_paramsObject (private)

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



193
194
195
# File 'app/controllers/sequences_controller.rb', line 193

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

#set_sequenceObject (private)

Use callbacks to share common setup or constraints between actions.



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

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

#showObject

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



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

def show
end

#updateObject

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



54
55
56
57
58
59
60
61
62
63
64
# File 'app/controllers/sequences_controller.rb', line 54

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