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

Display "activity from past day" in a list at /subscriptions/digest #2027

Closed
jywarren opened this issue Jan 16, 2018 · 3 comments
Closed

Display "activity from past day" in a list at /subscriptions/digest #2027

jywarren opened this issue Jan 16, 2018 · 3 comments
Labels
enhancement explains that the issue is to improve upon one of our existing features help wanted requires help by anyone willing to contribute Ruby

Comments

@jywarren
Copy link
Member

jywarren commented Jan 16, 2018

We have a new feature in the User model called user.content_followed_in_past_period(time_period)

plots2/app/models/user.rb

Lines 313 to 315 in c6b2d34

def content_followed_in_past_period(time_period)
self.node.where("created >= #{time_period.to_i} AND changed >= #{time_period.to_i}")
end

Let's adjust this to be user.content_followed_in_period(start, end) so we can use it like:

user.content_followed_in_period(Time.now - 1.day, Time.now)

And make it not use self.node.where() but Node.where() so it returns /all/ content, not just the user's own content -- adjusting both the test and the model function, and the test description on this line:

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)
end


Follow-up task

Then, let's make a new controller method in https://github.com/publiclab/plots2/blob/master/app/controllers/subscription_controller.rb to display this content. It can just be in a table, like this template:

https://github.com/publiclab/plots2/blob/master/app/views/wiki/_wikis.html.erb

I'm not sure, but it may be possible to simply render that template with a collection, so the overall /app/views/subscriptions/digest.html.erb file could be just:

<h2>Content you've subscribed to in the past week</h2>

<%= render partial: "wiki/wikis" %>

And the controller method could be:

# display the past day's followed nodes on one page
def digest
  # note these won't be wikis but we'll use the wiki partial template to display a list of nodes
  @wiki = current_user.content_followed_in_period(Time.now - 1.week, Time.now)
end

This may not work on the first try, but I'm happy to help troubleshoot!


Follow-up task

Then, let's make a method to send the digest in an email!

@jywarren jywarren added enhancement explains that the issue is to improve upon one of our existing features help wanted requires help by anyone willing to contribute Ruby labels Jan 16, 2018
@jywarren jywarren added this to the Email notifications overhaul milestone Jan 16, 2018
@grvsachdeva
Copy link
Member

Hi @jywarren I want to try this

@jywarren
Copy link
Member Author

jywarren commented Jan 17, 2018 via email

@grvsachdeva
Copy link
Member

We want to display the nodes to which user is subscribed to on the digest page or all the nodes created and changed between the start and end time? As changes suggested by you @jywarren in user.content_followed_in_past_period are not sufficient to display nodes subscribed/followed by the user, so I was little confused about the aim of the page.Its ready and working for showing all the nodes in the previous week, once you clarify above point, I will change the query in content_followed function accordingly. Also, Thank you, Jeff, your suggested changes have made this task easier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement explains that the issue is to improve upon one of our existing features help wanted requires help by anyone willing to contribute Ruby
Projects
None yet
Development

No branches or pull requests

2 participants