This repository was archived by the owner on Jan 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
Expand file tree
/
Copy pathgenotypes_controller.rb
More file actions
90 lines (76 loc) · 2.51 KB
/
Copy pathgenotypes_controller.rb
File metadata and controls
90 lines (76 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# frozen_string_literal: true
class GenotypesController < ApplicationController
before_filter :require_user, except: [ :show, :feed,:index,:dump_download ]
helper_method :sort_column, :sort_direction
def index
@title = "Listing all genotypings"
@genotypes = Genotype
.successfully_parsed
.includes(:user)
.order("#{sort_column} #{sort_direction}")
@genotypes_paginate = @genotypes.paginate(page: params[:page], per_page: 20)
end
def new
@genotype = Genotype.new
@title = 'Add Genotype-File'
end
def create
@genotype = Genotype.new(genotype_params)
@genotype.user = current_user
@genotype.parse_status = 'queued'
if @genotype.valid? && @genotype.save
Preparsing.perform_async(@genotype.id)
# award for genotyping-upload
@award = Achievement.find_by_award('Published genotyping')
user_achievement_attrs = { achievement_id: @award.id,
user_id: current_user.id }
if UserAchievement.where(user_achievement_attrs).count.zero?
UserAchievement.create(user_achievement_attrs)
flash[:achievement] = 'Congratulations! You\'ve unlocked an achievement:' +
" <a href=\"#{url_for(@award)}\">#{@award.award}</a>"
end
if current_user.has_sequence == false
current_user.toggle!(:has_sequence)
end
redirect_to(
edit_user_path(current_user, anchor: 'genotypes'),
notice: t('.uploaded_successfully')
)
else
render action: 'new'
end
end
def show
@genotype = Genotype.find(params[:id])
@user = @genotype.user
@title = 'Genotypes'
end
def feed
# for rss-feeds
@genotypes = Genotype.order('created_at DESC').limit(20)
render action: 'rss', layout: false
end
def destroy
genotype = current_user.genotypes.find(params[:id])
DeleteGenotype.perform_async(genotype_id: genotype.id)
flash[:notice] = 'Your Genotyping will be deleted. This may take a few minutes...'
redirect_to current_user
end
def download
genotype = Genotype.find(params[:id])
send_data(
File.open(genotype.genotype.path),
filename: genotype.genotype_file_name
)
end
private
def sort_column
Genotype.column_names.include?(params[:sort]) ? params[:sort] : 'created_at'
end
def sort_direction
%w[desc asc].include?(params[:direction]) ? params[:direction] : 'desc'
end
def genotype_params
params.require(:genotype).permit(:genotype, :filetype)
end
end