mirror of
https://github.com/chenasraf/snpr.git
synced 2026-05-18 01:39:01 +00:00
first picture phenotype-implementation
This commit is contained in:
46
app/controllers/picture_phenotype_comments_controller.rb
Normal file
46
app/controllers/picture_phenotype_comments_controller.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
class PicturePhenotypeCommentsController < ApplicationController
|
||||
before_filter :require_user
|
||||
|
||||
def new
|
||||
@phenotype_comment = PicturePhenotypeComment.new
|
||||
@title = "Add comment"
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml { render :xml => @phenotype }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@phenotype_comment = PicturePhenotypeComment.new(params[:picture_phenotype_comment])
|
||||
if @phenotype_comment.comment_text.index(/\A(\@\#\d*\:)/) == nil
|
||||
@phenotype_comment.reply_to_id = -1
|
||||
else
|
||||
|
||||
@potential_reply_id = @phenotype_comment.comment_text.split()[0].chomp(":").gsub("@#","").to_i
|
||||
if PicturePhenotypeComment.find_by_id(@potential_reply_id) != nil
|
||||
@phenotype_comment.reply_to_id = @potential_reply_id
|
||||
else
|
||||
@phenotype_comment.reply_to_id = -1
|
||||
end
|
||||
|
||||
@phenotype_comment.comment_text = @phenotype_comment.comment_text.gsub(/\A(\@\#\d*\:)/,"")
|
||||
end
|
||||
@phenotype_comment.user_id = current_user.id
|
||||
@phenotype_comment.picture_phenotype_id = params[:picture_phenotype_comment][:picture_phenotype_id]
|
||||
if @phenotype_comment.save
|
||||
if @phenotype_comment.reply_to_id != -1
|
||||
@reply_user = PicturePhenotypeComment.find_by_id(@phenotype_comment.reply_to_id).user
|
||||
if@reply_user != nil
|
||||
if @reply_user.message_on_phenotype_comment_reply == true
|
||||
UserMailer.new_picture_phenotype_comment(@phenotype_comment,@reply_user).deliver
|
||||
end
|
||||
end
|
||||
end
|
||||
redirect_to "/picture_phenotypes/"+@phenotype_comment.picture_phenotype_id.to_s+"#comments", :notice => 'Comment succesfully created.'
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
161
app/controllers/picture_phenotypes_controller.rb
Normal file
161
app/controllers/picture_phenotypes_controller.rb
Normal file
@@ -0,0 +1,161 @@
|
||||
class PicturePhenotypesController < ApplicationController
|
||||
before_filter :require_user, only: [ :new, :create, ]
|
||||
helper_method :sort_column, :sort_direction
|
||||
|
||||
def index
|
||||
@title = "Listing all phenotypes"
|
||||
@phenotypes = PicturePhenotype.order(sort_column + " " + sort_direction)
|
||||
@phenotypes_paginate = @phenotypes.paginate(:page => params[:page],:per_page => 10)
|
||||
#@phenotypes_json = []
|
||||
#@phenotypes.each do |p|
|
||||
# @phenotype = {}
|
||||
# @phenotype["id"] = p.id
|
||||
# @phenotype["characteristic"] = p.characteristic
|
||||
# @phenotype["known_variations"] = p.known_phenotypes
|
||||
# @phenotype["number_of_users"] = p.user_phenotypes.length
|
||||
# @phenotypes_json << @phenotype
|
||||
#end
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml
|
||||
#format.json {render :json => @phenotypes_json}
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@phenotype = PicturePhenotype.new
|
||||
@user_phenotype = UserPicturePhenotype.new
|
||||
@title = "Create a new picture phenotype"
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
unless @phenotype = PicturePhenotype.find_by_characteristic(params[:picture_phenotype][:characteristic])
|
||||
puts params[:picture_phenotype]
|
||||
@phenotype = PicturePhenotype.create(params[:picture_phenotype])
|
||||
|
||||
# award: created one (or more) phenotypes
|
||||
current_user.update_attributes(:phenotype_creation_counter => (current_user.phenotype_creation_counter + 1) )
|
||||
|
||||
check_and_award_new_phenotypes(1, "Created a new phenotype")
|
||||
check_and_award_new_phenotypes(5, "Created 5 new phenotypes")
|
||||
check_and_award_new_phenotypes(10, "Created 10 new phenotypes")
|
||||
end
|
||||
|
||||
if params[:picture_phenotype][:characteristic] == ""
|
||||
flash[:warning] = "Phenotype characteristic may not be empty"
|
||||
redirect_to :action => "new"
|
||||
else
|
||||
|
||||
@phenotype.save
|
||||
@phenotype = PicturePhenotype.find_by_characteristic(params[:picture_phenotype][:characteristic])
|
||||
#Resque.enqueue(Mailnewphenotype, @phenotype.id,current_user.id)
|
||||
|
||||
if UserPicturePhenotype.find_by_picture_phenotype_id_and_user_id(@phenotype.id,current_user.id).nil?
|
||||
|
||||
@user_phenotype = current_user.user_picture_phenotypes.new(
|
||||
phenotype_picture: params[:user_picture_phenotype][:phenotype_picture])
|
||||
@user_phenotype.picture_phenotype = @phenotype
|
||||
|
||||
if @user_phenotype.save
|
||||
@phenotype.number_of_users = UserPicturePhenotype.find_all_by_picture_phenotype_id(@phenotype.id).length
|
||||
@phenotype.save
|
||||
flash[:notice] = "Picture Phenotype sucessfully saved."
|
||||
|
||||
# check for additional phenotype awards
|
||||
current_user.update_attributes(:phenotype_additional_counter => (current_user.user_phenotypes.length))
|
||||
|
||||
check_and_award_additional_phenotypes(1, "Entered first phenotype")
|
||||
check_and_award_additional_phenotypes(5, "Entered 5 additional phenotypes")
|
||||
check_and_award_additional_phenotypes(10, "Entered 10 additional phenotypes")
|
||||
check_and_award_additional_phenotypes(20, "Entered 20 additional phenotypes")
|
||||
check_and_award_additional_phenotypes(50, "Entered 50 additional phenotypes")
|
||||
check_and_award_additional_phenotypes(100, "Entered 100 additional phenotypes")
|
||||
|
||||
#Resque.enqueue(Recommendvariations)
|
||||
#Resque.enqueue(Recommendphenotypes)
|
||||
|
||||
redirect_to current_user
|
||||
else
|
||||
flash[:warning] = "Something went wrong in creating the phenotype"
|
||||
redirect_to :action => "new"
|
||||
end
|
||||
else
|
||||
flash[:warning] = "You have already entered your variation at this phenotype"
|
||||
redirect_to :action => "new"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
#@phenotypes = Phenotype.where(:user_id => current_user.id).all
|
||||
#@title = "Phenotypes"
|
||||
@phenotype = PicturePhenotype.find(params[:id]) || not_found
|
||||
@comments = PicturePhenotypeComment.where(:picture_phenotype_id => params[:id]).all(:order => "created_at ASC")
|
||||
@phenotype_comment = PicturePhenotypeComment.new
|
||||
if current_user and UserPicturePhenotype.find_by_user_id_and_picture_phenotype_id(current_user.id,@phenotype.id)
|
||||
@user_phenotype = UserPicturePhenotype.find_by_user_id_and_picture_phenotype_id(current_user.id,@phenotype.id)
|
||||
else
|
||||
@user_phenotype = UserPicturePhenotype.new
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.xml
|
||||
end
|
||||
end
|
||||
|
||||
def feed
|
||||
@phenotype = PicturePhenotype.find(params[:id])
|
||||
@user_phenotypes = @phenotype.user_picture_phenotypes
|
||||
@genotypes = []
|
||||
@user_phenotypes.each do |up|
|
||||
if up.user.genotypes[0] != nil
|
||||
@genotypes << up.user.genotypes[0]
|
||||
end
|
||||
end
|
||||
|
||||
@genotypes.sort!{ |b,a| a.created_at <=> b.created_at }
|
||||
|
||||
render :action => "rss", :layout => false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sort_column
|
||||
PicturePhenotype.column_names.include?(params[:sort]) ? params[:sort] : "number_of_users"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def sort_column
|
||||
PicturePhenotype.column_names.include?(params[:sort]) ? params[:sort] : "number_of_users"
|
||||
end
|
||||
|
||||
def sort_direction
|
||||
%w[desc asc].include?(params[:direction]) ? params[:direction] : "desc"
|
||||
end
|
||||
|
||||
def check_and_award_new_phenotypes(amount, achievement_string)
|
||||
@achievement = Achievement.find_by_award(achievement_string)
|
||||
if current_user.phenotype_creation_counter >= amount and UserAchievement.find_by_achievement_id_and_user_id(@achievement.id,current_user.id) == nil
|
||||
|
||||
UserAchievement.create(:achievement_id => @achievement.id, :user_id => current_user.id)
|
||||
flash[:achievement] = %(Congratulations! You've unlocked an achievement: <a href="#{url_for(@achievement)}">#{@achievement.award}</a>).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
def check_and_award_additional_phenotypes(amount, achievement_string)
|
||||
@achievement = Achievement.find_by_award(achievement_string)
|
||||
if current_user.phenotype_additional_counter >= amount and UserAchievement.find_by_achievement_id_and_user_id(@achievement.id,current_user.id) == nil
|
||||
UserAchievement.create(:user_id => current_user.id, :achievement_id => @achievement.id)
|
||||
flash[:achievement] = %(Congratulations! You've unlocked an achievement: <a href="#{url_for(@achievement)}">#{@achievement.award}</a>).html_safe
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
104
app/controllers/user_picture_phenotypes_controller.rb
Normal file
104
app/controllers/user_picture_phenotypes_controller.rb
Normal file
@@ -0,0 +1,104 @@
|
||||
class UserPicturePhenotypesController < ApplicationController
|
||||
before_filter :require_user
|
||||
|
||||
def new
|
||||
@user_phenotype = UserPicturePhenotype.new
|
||||
@title = "Add variation"
|
||||
|
||||
if params[:phenotype]
|
||||
@phenotype = PicturePhenotype.find(params[:picture_phenotype])
|
||||
end
|
||||
|
||||
if params[:js_modal]
|
||||
@js_modal = true
|
||||
end
|
||||
|
||||
respond_to do |format|
|
||||
format.js
|
||||
format.html
|
||||
format.xml { render :xml => @phenotype }
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@user_phenotype = UserPicturePhenotype.find_by_user_id_and_picture_phenotype_id(current_user.id,params[:user_picture_phenotype][:picture_phenotype_id])
|
||||
@user_phenotype.phenotype_picture = params[:user_picture_phenotype][:phenotype_picture]
|
||||
@user_phenotype.save()
|
||||
redirect_to "/picture_phenotypes/"+@user_phenotype.picture_phenotype_id.to_s, :notice => 'Variation successfully updated'
|
||||
end
|
||||
|
||||
def delete
|
||||
@user_phenotype = UserPicturePhenotype.find_by_id(params[:id])
|
||||
@phenotype = @user_phenotype.picture_phenotype
|
||||
if @user_phenotype.user_id == current_user.id
|
||||
@user_phenotype.delete()
|
||||
@phenotype.number_of_users = @phenotype.user_picture_phenotypes.length
|
||||
@phenotype.save()
|
||||
redirect_to "/picture_phenotypes/"+@user_phenotype.picture_phenotype_id.to_s, :notice => 'Variation successfully deleted'
|
||||
else
|
||||
redirect_to "/picture_phenotypes/"+@user_phenotype.picture_phenotype_id.to_s, :notice => 'Whops, something went wrong!'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def create
|
||||
@user_phenotype = current_user.user_picture_phenotypes.new(
|
||||
phenotype_picture: params[:user_picture_phenotype][:phenotype_picture])
|
||||
@user_phenotype.phenotype_picture = params[:user_picture_phenotype][:phenotype_picture]
|
||||
@user_phenotype.user_id = current_user.id
|
||||
@user_phenotype.picture_phenotype_id = params[:user_picture_phenotype][:picture_phenotype_id]
|
||||
|
||||
if params[:js_modal]
|
||||
@js_modal = true
|
||||
else
|
||||
@js_modal = false
|
||||
end
|
||||
|
||||
if UserPicturePhenotype.find_by_picture_phenotype_id_and_user_id(@user_phenotype.picture_phenotype_id,@user_phenotype.user_id) == nil
|
||||
|
||||
@phenotype = PicturePhenotype.find_by_id(params[:user_picture_phenotype][:picture_phenotype_id])
|
||||
|
||||
if @user_phenotype.save
|
||||
|
||||
#check for new achievements
|
||||
current_user.update_attributes(:phenotype_additional_counter => (current_user.user_phenotypes.length))
|
||||
check_and_award_additional_phenotypes(1, "Entered first phenotype")
|
||||
check_and_award_additional_phenotypes(5, "Entered 5 additional phenotypes")
|
||||
check_and_award_additional_phenotypes(10, "Entered 10 additional phenotypes")
|
||||
check_and_award_additional_phenotypes(20, "Entered 20 additional phenotypes")
|
||||
check_and_award_additional_phenotypes(50, "Entered 50 additional phenotypes")
|
||||
check_and_award_additional_phenotypes(100, "Entered 100 additional phenotypes")
|
||||
|
||||
|
||||
@phenotype.number_of_users = UserPicturePhenotype.find_all_by_picture_phenotype_id(@phenotype.id).length
|
||||
@phenotype.save
|
||||
|
||||
if @js_modal == true
|
||||
redirect_to "/users/"+current_user.id.to_s
|
||||
else
|
||||
redirect_to "/picture_phenotypes/"+@user_phenotype.picture_phenotype_id.to_s, :notice => 'Variation successfully saved'
|
||||
end
|
||||
else
|
||||
flash[:warning] = "Please enter a variation."
|
||||
redirect_to "/users/"+current_user.id.to_s
|
||||
end
|
||||
else
|
||||
redirect_to "/picture_phenotypes/"+@user_phenotype.picture_phenotype_id.to_s, :notice => 'You already have a variation entered'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_and_award_new_phenotypes(amount, achievement_string)
|
||||
if current_user.phenotype_creation_counter >= amount and UserAchievement.find_by_achievement_id_and_user_id(Achievement.find_by_award(achievement_string).id,current_user.id) == nil
|
||||
UserAchievement.create(:achievement_id => Achievement.find_by_award(achievement_string).id, :user_id => current_user.id)
|
||||
end
|
||||
end
|
||||
|
||||
def check_and_award_additional_phenotypes(amount, achievement_string)
|
||||
if current_user.phenotype_additional_counter >= amount and UserAchievement.find_by_achievement_id_and_user_id(Achievement.find_by_award(achievement_string).id,current_user.id) == nil
|
||||
UserAchievement.create(:user_id => current_user.id, :achievement_id => Achievement.find_by_award(achievement_string).id)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -52,6 +52,12 @@ default :from => "donotreply@opensnp.org"
|
||||
mail(:subject => "openSNP.org: You've got a reply to one of your phenotype-comments", :to => @user.email)
|
||||
end
|
||||
|
||||
def new_picture_phenotype_comment(phenotype_comment,to_user)
|
||||
@user = to_user
|
||||
@phenotype_comment = phenotype_comment
|
||||
mail(:subject => "openSNP.org: You've got a reply to one of your phenotype-comments", :to => @user.email)
|
||||
end
|
||||
|
||||
def new_phenotype(phenotype,user)
|
||||
@user = user
|
||||
@phenotype = phenotype
|
||||
|
||||
12
app/models/picture_phenotype.rb
Normal file
12
app/models/picture_phenotype.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class PicturePhenotype < ActiveRecord::Base
|
||||
has_many :user_picture_phenotypes, dependent: :destroy
|
||||
has_many :picture_phenotype_comments, dependent: :destroy
|
||||
#has_and_belongs_to_many :phenotype_sets
|
||||
|
||||
validates_presence_of :characteristic
|
||||
|
||||
searchable do
|
||||
text :characteristic
|
||||
end
|
||||
|
||||
end
|
||||
8
app/models/picture_phenotype_comment.rb
Normal file
8
app/models/picture_phenotype_comment.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class PicturePhenotypeComment < ActiveRecord::Base
|
||||
belongs_to :picture_phenotype
|
||||
belongs_to :user
|
||||
|
||||
searchable do
|
||||
text :comment_text, :subject
|
||||
end
|
||||
end
|
||||
@@ -18,6 +18,8 @@ class User < ActiveRecord::Base
|
||||
# dependent so stuff gets destroyed on delete
|
||||
has_many :user_phenotypes, :dependent => :destroy
|
||||
has_many :phenotypes, :through => :user_phenotypes
|
||||
has_many :user_picture_phenotypes, :dependent => :destroy
|
||||
has_many :picture_phenotypes, :through => :user_picture_phenotypes
|
||||
has_many :genotypes, :dependent => :destroy
|
||||
has_many :user_snps
|
||||
has_many :snps, :through => :user_snps
|
||||
@@ -27,6 +29,7 @@ class User < ActiveRecord::Base
|
||||
has_many :achievements, :through => :user_achievements
|
||||
has_many :snp_comments # these shouldn't be deleted, but orphaned
|
||||
has_many :phenotype_comments
|
||||
has_many :picture_phenotype_comments
|
||||
has_one :fitbit_profile
|
||||
|
||||
# needed to edit several user_phenotypes at once, add and delete, and not empty
|
||||
|
||||
23
app/models/user_picture_phenotype.rb
Normal file
23
app/models/user_picture_phenotype.rb
Normal file
@@ -0,0 +1,23 @@
|
||||
class UserPicturePhenotype < ActiveRecord::Base
|
||||
belongs_to :picture_phenotype
|
||||
belongs_to :user
|
||||
|
||||
has_attached_file :phenotype_picture, :styles => {:maximum => "1000x1000>", :medium => "300x300>", :thumb => "100x100>#", :head => "32x32#" }, :default_url => '/images/standard_picture_phenotype_:style.png'
|
||||
attr_accessible :picture_phenotype_id,:phenotype_picture
|
||||
validates_attachment_size :phenotype_picture, :less_than=>1.megabyte
|
||||
validates_attachment_content_type :phenotype_picture , :content_type=>['image/jpeg', 'image/png', 'image/gif']
|
||||
|
||||
searchable do
|
||||
integer :picture_phenotype_id
|
||||
end
|
||||
|
||||
def give_me_user_phenotype(phenotype_id, user_id)
|
||||
# needed for the phenotype_set_forms
|
||||
@to_return = UserPicturePhenotype.find_by_phenotype_id_and_user_id(phenotype_id, user_id)
|
||||
if @to_return == nil
|
||||
""
|
||||
else
|
||||
@to_return.phenotype_picture
|
||||
end
|
||||
end
|
||||
end
|
||||
17
app/views/picture_phenotype_comments/_form.html.erb
Normal file
17
app/views/picture_phenotype_comments/_form.html.erb
Normal file
@@ -0,0 +1,17 @@
|
||||
<h3>Comment on this picture phenotype</h3>
|
||||
<%= form_for @phenotype_comment, :html => {:class => "form-stacked",:name => "new_comment"} do |f| %>
|
||||
<%= render 'shared/error_messages', :target => @phenotype %>
|
||||
<%= f.hidden_field :picture_phenotype_id, :value => @phenotype.id %>
|
||||
<div class="well">
|
||||
<div class="clearfix">
|
||||
<%= f.label :subject%>
|
||||
<%= f.text_field :subject %>
|
||||
</div>
|
||||
<div class="clearfix">
|
||||
<%= f.label :comment_text %>
|
||||
<%= f.text_area :comment_text, :size => "20x5" %>
|
||||
</div>
|
||||
|
||||
<%= f.submit "Comment", :class => "btn btn-primary" %>
|
||||
<% end %>
|
||||
</div>
|
||||
24
app/views/picture_phenotype_comments/_show.html.erb
Normal file
24
app/views/picture_phenotype_comments/_show.html.erb
Normal file
@@ -0,0 +1,24 @@
|
||||
<script language="JavaScript" type="text/JavaScript">
|
||||
function sendCommentId(e, text)
|
||||
{
|
||||
e.value = text + e.value
|
||||
}
|
||||
</script>
|
||||
|
||||
<% @comments.each do |c|%>
|
||||
|
||||
|
||||
<div id="<%="comment"+c.id.to_s%>">
|
||||
<b><%= c.subject %></b> by <%if c.user != nil %><%= link_to c.user.name, c.user%><%else%>Deleted User<%end%> on <%= c.created_at %><br/>
|
||||
<div class="well">
|
||||
<a href="#" rel="comment_tooltip" title="<%if c.reply_to_id != -1 and c.reply_to_id != nil%><%if PicturePhenotypeComment.find_by_id(c.reply_to_id).user != nil%><b><%=PhenotypeComment.find_by_id(c.reply_to_id).user.name%><%else%>Deleted User<%end%></b> wrote:"data-content="<%=PicturePhenotypeComment.find_by_id(c.reply_to_id).comment_text%><%end%>"><% if c.reply_to_id != -1 and c.reply_to_id != nil%><%if PicturePhenotypeComment.find_by_id(c.reply_to_id).user%>@<%=PicturePhenotypeComment.find_by_id(c.reply_to_id).user.name%><%else%>@Deleted User<%end%><% end %></a>
|
||||
<%if c.user != nil%><%=image_tag c.user.avatar.url(:head),:style => "vertical-align:middle;margin: 10px;float:left"%><%end%> <%= simple_format(c.comment_text) %><br/><%=link_to_function "reply to", "sendCommentId(document.new_comment.picture_phenotype_comment_comment_text,'@#"+c.id.to_s+": ')"%>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$("[rel=comment_tooltip]").popover({placement:'right'});
|
||||
});
|
||||
</script>
|
||||
7
app/views/picture_phenotype_comments/create.html.erb
Normal file
7
app/views/picture_phenotype_comments/create.html.erb
Normal file
@@ -0,0 +1,7 @@
|
||||
<h2>Write a comment</h2>
|
||||
|
||||
<%= form_for @phenotype_comment do |f| %>
|
||||
<div class="actions">
|
||||
<%= f.submit "Send" %>
|
||||
</div>
|
||||
<% end %>
|
||||
3
app/views/picture_phenotype_comments/new.html.erb
Normal file
3
app/views/picture_phenotype_comments/new.html.erb
Normal file
@@ -0,0 +1,3 @@
|
||||
<h2>Write a comment</h2>
|
||||
<%= render 'shared/warning' %>
|
||||
<%= render 'form' %>
|
||||
33
app/views/picture_phenotypes/index.html.erb
Normal file
33
app/views/picture_phenotypes/index.html.erb
Normal file
@@ -0,0 +1,33 @@
|
||||
<legend>Listing all Picture Phenotypes</legend>
|
||||
<%if current_user%>
|
||||
<div class="row">
|
||||
<div class="span10">
|
||||
<h4>
|
||||
<%=link_to(image_tag("/images/addphenotype_small.png",:style => "vertical-align:middle" ),:action =>"new")%> <%=link_to "The picture phenotype of your interest is missing? Add a new one!",:action => "new"%>
|
||||
</h4>
|
||||
</div>
|
||||
</div>
|
||||
<%end%>
|
||||
<br/>
|
||||
<table class="table table-striped" id="no_snp_overview">
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th><%= sortable "id", "ID"%></th>
|
||||
<th><%= sortable "characteristic","Phenotype"%></th>
|
||||
<th><%= sortable "number_of_users","Number of users"%></th>
|
||||
<th><%= sortable "created_at", "Created"%>
|
||||
</tr>
|
||||
<% @phenotypes_paginate.each do |s| %>
|
||||
<tr>
|
||||
<td><%= PicturePhenotype.all.sort! { |a,b| a.id <=> b.id}.index(s) + 1%></td>
|
||||
<td><%= s.id %></td>
|
||||
<td><%= link_to(s.characteristic, s) %></td>
|
||||
<td><%=s.number_of_users%></td>
|
||||
<td><%=s.created_at%></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
<div class="pagination">
|
||||
<%= will_paginate(@phenotypes_paginate) %>
|
||||
</div>
|
||||
|
||||
38
app/views/picture_phenotypes/new.html.erb
Normal file
38
app/views/picture_phenotypes/new.html.erb
Normal file
@@ -0,0 +1,38 @@
|
||||
<legend>Create a new picture phenotype</legend>
|
||||
<div class="row span6">
|
||||
<%= form_for(@phenotype,:html => { :class => "form-stacked",:multipart => true }) do |f| %>
|
||||
<%= render 'shared/error_messages', :target => @phenotype %>
|
||||
<%phenotype_array = []%>
|
||||
<%PicturePhenotype.find(:all).each do |p| phenotype_array << p.characteristic end%>
|
||||
<div class="clearfix">
|
||||
<div class="inline-inputs">
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
$("#picture_phenotype_characteristic").autocomplete({
|
||||
source: <%=raw(phenotype_array.to_json)%>
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
<%= f.label :characteristic %> <%= f.text_field :characteristic %>
|
||||
<span class="help-block">Hair colour, Blood type, Skin colour etc. <br/>Please <b>enter only one phenotypic characteristic at once</b> and <b>make use of the auto-completion</b>, as this phenotype might be already in our database.</span>
|
||||
|
||||
<%= f.label :description %> <%= f.text_area :description, :rows => 10%>
|
||||
<span class="help-block">Give users some more details:<ul><li>What are different variations of this phenotype?</li><li>Why this phenotype is interesting?</li><li>Some links to web resources on the topic?</li></ul></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="clearfix">
|
||||
<div class="inline-inputs">
|
||||
<%= fields_for @user_phenotype do |up| %>
|
||||
<%= up.label :phenotype_picture, "Upload picture of your phenotype"%>
|
||||
<%= up.file_field :phenotype_picture%>
|
||||
|
||||
<span class="help-block">Blonde, 00, Caucasian etc.<br/><b>Only enter your variation</b> for this phenotype, don't list all possible answers (you can use the description for this). Again: <b>Please use the auto-completion.</b></span>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= f.submit :class => "btn btn-primary" %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
20
app/views/picture_phenotypes/rss.rxml
Normal file
20
app/views/picture_phenotypes/rss.rxml
Normal file
@@ -0,0 +1,20 @@
|
||||
xml.instruct! :xml, :version => "1.0"
|
||||
xml.rss :version => "2.0" do
|
||||
xml.channel do
|
||||
xml.title "Genotyping-files for "+@phenotype.characteristic
|
||||
xml.description "A RSS-feed which contains the newest genotyping files of users who have entered their variation for "+@phenotype.characteristic
|
||||
xml.link phenotype_url(@phenotype)
|
||||
|
||||
for genotype in @genotypes
|
||||
xml.item do
|
||||
xml.title User.find_by_id(genotype.user_id).name + "'s Genotype"
|
||||
xml.description "The user "+genotype.user.name+" has uploaded a picture for the phenotype "+@phenotype.characteristic+": "+image_tag("http://opensnp.org"+genotype.user.user_picture_phenotypes.find_by_picture_phenotype_id(@phenotype).phenotype_picture.url(:medium))+" "+link_to("Download",'/data/' + genotype.fs_filename)
|
||||
xml.picture genotype.user.user_picture_phenotypes.find_by_picture_phenotype_id(@phenotype).phenotype_picture.url(:maximum)
|
||||
xml.dlink 'http://opensnp.org/data/' + genotype.fs_filename
|
||||
xml.pubDate genotype.created_at.to_s(:rfc822)
|
||||
xml.link genotype_url(genotype)
|
||||
xml.guid genotype_url(genotype)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
53
app/views/picture_phenotypes/show.html.erb
Normal file
53
app/views/picture_phenotypes/show.html.erb
Normal file
@@ -0,0 +1,53 @@
|
||||
<%=auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "RSS for #{@phenotype.characteristic}"})%>
|
||||
|
||||
<div class="row">
|
||||
<div class="span6 columns"><h1>Picture Phenotype: <%= @phenotype.characteristic %></h1> </div>
|
||||
</div>
|
||||
|
||||
<% if current_user %>
|
||||
<%if UserPicturePhenotype.find_by_user_id_and_picture_phenotype_id(current_user.id,@phenotype.id) == nil%>
|
||||
|
||||
<%= render 'user_picture_phenotypes/form' %>
|
||||
<%else%>
|
||||
<%= render 'user_picture_phenotypes/edit'%>
|
||||
<%end%>
|
||||
<% end %>
|
||||
<div class="container">
|
||||
<%=link_to(image_tag("/images/rss_small.png"),:action =>"feed")%>
|
||||
|
||||
<div id="tab-container">
|
||||
<ul class="nav nav-tabs">
|
||||
<li><a href="#description">Description</a></li>
|
||||
<li><a href="#users">Users sharing this phenotype (<%=@phenotype.user_picture_phenotypes.length%>)</a></li>
|
||||
<li><a href="#comments">Comments (<%=@phenotype.picture_phenotype_comments.length%>)</a></li>
|
||||
</ul>
|
||||
|
||||
<div id="description">
|
||||
<div class="well">
|
||||
<%= simple_format(@phenotype.description) %>
|
||||
</div>
|
||||
</div>
|
||||
<div id="users">
|
||||
<table class="table table-striped">
|
||||
<tr>
|
||||
<th>User</th>
|
||||
<th>Variation</th>
|
||||
</tr>
|
||||
<% @phenotype.user_picture_phenotypes.each do |up| %>
|
||||
<tr>
|
||||
<td><%=image_tag up.user.avatar.url(:head),:style => "vertical-align:middle"%> <%= link_to up.user.name, up.user%></td>
|
||||
<td><% if up.variation != "" %><%= link_to image_tag(up.phenotype_picture.url(:thumb), :style => "vertical-align:middle"), up.phenotype_picture.url(:maximum) %><% else %>Undescribed.<% end %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div id="comments">
|
||||
<%= render 'picture_phenotype_comments/show' %>
|
||||
<%if current_user%>
|
||||
<%= render 'picture_phenotype_comments/form' %>
|
||||
<%end%>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
18
app/views/user_mailer/new_picture_phenotype_comment.text.erb
Normal file
18
app/views/user_mailer/new_picture_phenotype_comment.text.erb
Normal file
@@ -0,0 +1,18 @@
|
||||
Hello <%=@user.name%>,
|
||||
<%=@phenotype_comment.user.name%> just replied to a phenotype comment on the Picture Phenotype <%=@phenotype_comment.picture_phenotype.characteristic%> from you.
|
||||
|
||||
This is the text of the reply:
|
||||
|
||||
--- SNIP ---
|
||||
|
||||
<%=@phenotype_comment.comment_text%>
|
||||
|
||||
--- SNAP ---
|
||||
|
||||
You can read and reply to this comment by clicking this link: <%=picture_phenotype_url(@phenotype_comment.picture_phenotype)%>#comments
|
||||
|
||||
Cheers,
|
||||
your openSNP-team
|
||||
|
||||
--
|
||||
You receive this email because you enabled the phenotype-notification-settings. To change your notification-settings you can visit <%=edit_user_url(@user)%>#notifications
|
||||
23
app/views/user_picture_phenotypes/_edit.html.erb
Normal file
23
app/views/user_picture_phenotypes/_edit.html.erb
Normal file
@@ -0,0 +1,23 @@
|
||||
<%= form_for(@user_phenotype, :url => {:controller => :user_picture_phenotypes, :action => :edit,:js_modal => @js_modal}, :html => {:class => "form-horizontal", :name => "new_user_picture_phenotype",:multipart => true}) do |f| %>
|
||||
<%= render 'shared/error_messages', :target => @phenotype %>
|
||||
<%= f.hidden_field :picture_phenotype_id, :value => @phenotype.id %>
|
||||
<%if @js_modal != true%>
|
||||
<div class="alert-message block-message info">
|
||||
<%end%>
|
||||
<p>This is your picture for this phenotype: </p><%= image_tag @user_phenotype.phenotype_picture.url(:thumb), :style => "vertical-align:middle" %>
|
||||
|
||||
<div class="clearfix">
|
||||
<div id="enter-order"><%= f.label :phenotype_picture, "You can replace your phenotype picture"%>
|
||||
<%= f.file_field :phenotype_picture%></div>
|
||||
|
||||
|
||||
</div><br/>
|
||||
|
||||
|
||||
<div class="alert-actions">
|
||||
<%= f.submit "Update Picture", :class => "btn btn-primary" %> <a href="/user_picture_phenotypes/<%=@user_phenotype.id%>/delete" class="btn btn-danger">Delete</a>
|
||||
</p></div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
23
app/views/user_picture_phenotypes/_form.html.erb
Normal file
23
app/views/user_picture_phenotypes/_form.html.erb
Normal file
@@ -0,0 +1,23 @@
|
||||
<%= form_for(@user_phenotype, :url => {:controller => :user_picture_phenotypes, :action => :create,:js_modal => @js_modal}, :html => {:class => "form-horizontal", :name => "new_user_picture_phenotype",:multipart => true}) do |f| %>
|
||||
<%= render 'shared/error_messages', :target => @phenotype %>
|
||||
<%= f.hidden_field :picture_phenotype_id, :value => @phenotype.id %>
|
||||
<%if @js_modal != true%>
|
||||
<div class="alert-message block-message info">
|
||||
<%end%>
|
||||
<p><b>Want to help?</b> You did not enter your variation at this phenotype yet. By adding your phenotypic information about <em><%=@phenotype.characteristic%></em> to openSNP you could help (amateur-)researchers with their work and find other people with a similar variance. <b>Please make use of the auto-completion as your variation might be already in our database.</b></p>
|
||||
|
||||
<div class="clearfix">
|
||||
<div id="enter-order"><%= f.label :phenotype_picture, "Upload picture of your phenotype"%>
|
||||
<%= f.file_field :phenotype_picture%></div>
|
||||
|
||||
|
||||
</div><br/>
|
||||
|
||||
|
||||
<div class="alert-actions">
|
||||
<%= f.submit "Submit your variation", :class => "btn btn-primary" %>
|
||||
</p></div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -6,6 +6,12 @@ Snpr::Application.routes.draw do
|
||||
get :get_genotypes
|
||||
end
|
||||
end
|
||||
resources :picture_phenotypes do
|
||||
member do
|
||||
get :feed
|
||||
end
|
||||
end
|
||||
resources :user_picture_phenotypes
|
||||
resources :genotypes
|
||||
resources :user_phenotypes
|
||||
resources :snps
|
||||
@@ -17,6 +23,7 @@ Snpr::Application.routes.draw do
|
||||
resources :messages
|
||||
resources :snp_comments
|
||||
resources :phenotype_comments
|
||||
resources :picture_phenotype_comments
|
||||
resources :search_results
|
||||
resources :achievements
|
||||
resources :user_achievements
|
||||
@@ -62,6 +69,8 @@ Snpr::Application.routes.draw do
|
||||
match '/recommend_phenotype/:id/', :to => 'phenotypes#recommend_phenotype'
|
||||
match '/press', :to => 'static#press'
|
||||
match '/blog' => redirect("http://opensnp.wordpress.com")
|
||||
match '/user_picture_phenotypes/:id/edit', :to => 'user_picture_phenotypes#edit'
|
||||
match '/user_picture_phenotypes/:id/delete', :to => 'user_picture_phenotypes#delete'
|
||||
|
||||
root :to => 'index#index' # change thisi, maybe
|
||||
# The priority is based upon order of creation:
|
||||
|
||||
14
db/migrate/20121123234958_create_picture_phenotypes.rb
Normal file
14
db/migrate/20121123234958_create_picture_phenotypes.rb
Normal file
@@ -0,0 +1,14 @@
|
||||
class CreatePicturePhenotypes < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :picture_phenotypes do |p|
|
||||
p.string :characteristic # e.g. haircolor
|
||||
p.string :description # longer text explaining what people should upload & why it's interesting
|
||||
p.integer :number_of_users, :default => 0
|
||||
p.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :picture_phenotypes
|
||||
end
|
||||
end
|
||||
19
db/migrate/20121123235228_add_user_picture_phenotype.rb
Normal file
19
db/migrate/20121123235228_add_user_picture_phenotype.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
class AddUserPicturePhenotype < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :user_picture_phenotypes do |up|
|
||||
up.belongs_to :user
|
||||
up.belongs_to :picture_phenotype
|
||||
up.string :variation
|
||||
up.string :phenotype_picture_file_name
|
||||
up.string :phenotype_picture_content_type
|
||||
up.integer :phenotype_picture_file_size
|
||||
up.datetime :phenotype_picture_updated_at
|
||||
|
||||
up.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :user_picture_phenotypes
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
class CreatePicturePhenotypeComments < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :picture_phenotype_comments do |t|
|
||||
t.text :comment_text
|
||||
t.text :subject
|
||||
t.belongs_to :user
|
||||
t.belongs_to :picture_phenotype
|
||||
t.integer :reply_to_id
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :picture_phenotype_comments
|
||||
end
|
||||
end
|
||||
32
db/schema.rb
32
db/schema.rb
@@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20121023032404) do
|
||||
ActiveRecord::Schema.define(:version => 20121124201111) do
|
||||
|
||||
create_table "achievements", :force => true do |t|
|
||||
t.text "award"
|
||||
@@ -184,6 +184,24 @@ ActiveRecord::Schema.define(:version => 20121023032404) do
|
||||
t.text "description"
|
||||
end
|
||||
|
||||
create_table "picture_phenotype_comments", :force => true do |t|
|
||||
t.text "comment_text"
|
||||
t.text "subject"
|
||||
t.integer "user_id"
|
||||
t.integer "picture_phenotype_id"
|
||||
t.integer "reply_to_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "picture_phenotypes", :force => true do |t|
|
||||
t.string "characteristic"
|
||||
t.string "description"
|
||||
t.integer "number_of_users", :default => 0
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "plos_papers", :force => true do |t|
|
||||
t.text "first_author"
|
||||
t.text "title"
|
||||
@@ -248,6 +266,18 @@ ActiveRecord::Schema.define(:version => 20121023032404) do
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "user_picture_phenotypes", :force => true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "picture_phenotype_id"
|
||||
t.string "variation"
|
||||
t.string "phenotype_picture_file_name"
|
||||
t.string "phenotype_picture_content_type"
|
||||
t.integer "phenotype_picture_file_size"
|
||||
t.datetime "phenotype_picture_updated_at"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "user_snps", :force => true do |t|
|
||||
t.string "local_genotype"
|
||||
t.integer "genotype_id"
|
||||
|
||||
Reference in New Issue
Block a user