Skip to content

Commit

Permalink
Merge pull request #330 from philippbayer/snp_update_feed
Browse files Browse the repository at this point in the history
Snp update feed
  • Loading branch information
philippbayer committed Feb 6, 2017
2 parents 65a3eaf + dc2eceb commit 21f19c2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def show
@title = @user.name + "'s page"
@first_name = @user.name.split.first
@user_phenotypes = @user.user_phenotypes
#@snps = @user.snps.order("#{sort_column} #{sort_direction}").paginate(:page => params[:page])
@received_messages = @user.messages.where(sent: false).order('created_at DESC')
@sent_messages = @user.messages.where(:sent => true).order('created_at DESC')
@phenotype_comments = PhenotypeComment.where(:user_id => @user.id).paginate(:page => params[:page])
Expand Down Expand Up @@ -113,6 +112,7 @@ def show
@phenotype_comment_replies.sort! { |b,a| a.created_at <=> b.created_at }
@paginated_phenotype_replies = @phenotype_comment_replies

@last_30_papers = LastUpdatedSnpsService.get_last_thirty_updated_snps(@user)
respond_to do |format|
format.html
end
Expand Down
9 changes: 9 additions & 0 deletions app/services/last_updated_snps_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class LastUpdatedSnpsService
def self.get_last_thirty_updated_snps(user)
[SnpediaPaper, MendeleyPaper, GenomeGovPaper, PlosPaper].flat_map do |papers|
papers.last(30).select do |paper|
paper.snps.any? { |s| s.users.exists?(user.id) }
end
end.sort_by(&:updated_at).reverse.take(30)
end
end
28 changes: 23 additions & 5 deletions app/views/users/_user_is_user.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
<a href="#unentered_variations">Variations you did not enter yet (<%= @unentered_phenotypes.length %>)</a>
</li>
<% end %>
<% if @user.has_sequence != true %>
<li>
<a href="#snps">Your SNPs</a>
</li>
<% end %>
<li><a href="#snps">Updates to your SNPs</a></li>
<li><a href="#variations">Your variations</a></li>
<li><a href="#messages">Your messages</a></li>
<li><a href="#comments">Replies to your comments</a></li>
Expand Down Expand Up @@ -78,6 +74,28 @@
<div id="snps">
<% if @user.genotypes.length == 0 %>
<h2>You haven't uploaded your SNP-set. <%= link_to("Please do so", :controller => "genotypes", :action => "new") %></h2>
<% else %>
<h4>Your 30 last updated SNPs</h4>
<% if @last_30_papers.empty? %>
We're sorry, it seems that nothing has recently been updated for your SNPs.
<% else %>
<table class="table table-striped">
<thead>
<tr>
<th>SNPs</th>
<th>Updated</th>
</tr>
</thead>
<% @last_30_papers.each do |paper| %>
<tbody>
<tr>
<td><% paper.snps.each do |s| %><%= link_to s.name, s %> <% end %></td>
<td>Received new data from <%= paper.class.to_s.gsub('Paper','') %> on <%= paper.updated_at.to_formatted_s(:short) %>!</td>
</tr>
</tbody>
<% end %>
</table>
<% end %>
<% end %>
</div>

Expand Down
28 changes: 28 additions & 0 deletions spec/features/arriving_as_user.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
RSpec.describe 'Arriving as user' do
let(:snp) { double('snp', name: 'rs1234', snpedia_papers: [snpedia_paper]) }
let!(:user) { create(:user, name: 'Potato Bill', snps: [snp]) }

let(:snpedia_paper) do
double(:snpedia_paper, url: 'http://www.snpedia.com/index.php/Rs1234(A;C)',
summary: 'Green hair',
snp_variation: 'AC',
created_at: '1969-07-20 20:17:40',
id: 1)
end

context 'as a signed-in user' do
before do
sign_in(user)
end

scenario 'the user arrives on landing page' do
visit root_path

expect(page).to have_content('Hello Potato!')
expect(page).to have_content('rs1234')

# Test Your last 30 updated SNPs feed
expect(page).to have_content('Received new data from SNPedia')
end
end
end

0 comments on commit 21f19c2

Please sign in to comment.