Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List activities for subscriptions/digest #2058

Merged
merged 9 commits into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/controllers/subscription_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class SubscriptionController < ApplicationController

respond_to :html, :xml, :json
before_filter :require_user, :only => [:create, :delete, :index]
before_filter :require_user, :only => [:create, :delete, :index, :digest]
Copy link
Member Author

@grvsachdeva grvsachdeva Feb 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is the line for checking current_user


def index
@title = "Subscriptions"
Expand Down Expand Up @@ -110,6 +110,11 @@ def delete
end
end

def digest
@wikis = current_user.content_followed_in_period(Time.now - 1.week, Time.now)
render :template => "subscriptions/digest"
end

private

def set_following(value,type,id)
Expand Down
11 changes: 8 additions & 3 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,13 @@ def questions
Node.questions.where(status: 1, uid: id)
end

def content_followed_in_past_period(time_period)
self.node.where("created >= #{time_period.to_i} AND changed >= #{time_period.to_i}")
def content_followed_in_period(start_time, end_time)
tagnames = TagSelection.where(following: true, user_id: uid)
node_ids = []
tagnames.each do |tagname|
node_ids = node_ids + NodeTag.where(tid: tagname.tid).collect(&:nid)
end
Node.where(nid: node_ids).where("created >= #{start_time.to_i} OR changed >= #{start_time.to_i} AND created <= #{end_time.to_i} AND changed <= #{end_time.to_i}")
end

def social_link(site)
Expand Down Expand Up @@ -345,4 +350,4 @@ def self.contributor_count_for(start_time,end_time)
contributors
end

end
end
3 changes: 3 additions & 0 deletions app/views/subscriptions/digest.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h2>Content you've subscribed to in the past week</h2>

<%= render partial: "wiki/wikis" %>
8 changes: 6 additions & 2 deletions app/views/wiki/_wikis.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
<% @wikis.each do |wiki| %>
<tr>
<td style="width:50%"><i class="fa fa-file"></i> <a href="<%= wiki.path %>"><%= wiki.latest.title %></a></td>
<td><%= distance_of_time_in_words(Time.at(wiki.latest.created_at), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= raw t('wiki._wikis.by') %>
<% if params["action"] == "digest" %>
<td><%= distance_of_time_in_words(Time.at(wiki.updated_at), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= raw t('wiki._wikis.by') %>
<% else %>
<td><%= distance_of_time_in_words(Time.at(wiki.latest.created_at), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= raw t('wiki._wikis.by') %>
<% end %>
<a href="/profile/<%= wiki.latest.author.name %>"><%= wiki.latest.author.name %></a></td>
<td><%= wiki.revisions.length %></td>
<td class="hidden-xs"><%= number_with_delimiter(wiki.totalviews) %></td>
<td><%= number_with_delimiter(wiki.cached_likes) %></td>
</tr>
<% end %>
</table>
<%= will_paginate @wikis, :renderer => BootstrapPagination::Rails if @paginated %>
<%= will_paginate @wikis, :renderer => BootstrapPagination::Rails if @paginated %>
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
put 'subscribe/:type/:name' => 'subscription#add'
get 'subscribe/:type/:name' => 'subscription#add'
get 'subscriptions' => 'subscription#index'
get 'subscriptions/digest' => 'subscription#digest'

get 'wiki/stale' => 'wiki#stale'
get 'wiki/new' => 'wiki#new'
Expand Down
12 changes: 8 additions & 4 deletions test/unit/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,14 @@ class UserTest < ActiveSupport::TestCase
assert !users(:bob).has_tag('test:no')
end

test 'returns nodes created in past given period of time' do
lurker = users(:lurker)
node2 = users(:lurker).node.find_by_nid(20)
assert_equal [node2], lurker.content_followed_in_past_period(2.hours.ago)
test 'returns nodes created in given period of time' do
bob = users(:bob)
node_count = 6
nodes_fix = [1,2,8,9,10,15]
count_return = bob.content_followed_in_period(2.hours.ago,Time.now).count
nodes_time = bob.content_followed_in_period(2.hours.ago,Time.now).pluck(:nid)
assert_equal node_count, count_return
assert_equal nodes_fix,nodes_time.sort
end

test 'returns value of power tag' do
Expand Down