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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #11331: Created random generator to fetch nodes randomly as cards #11332
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -60,6 +60,11 @@ def show | |||||||||||||||||||||||||||||||||||||||||||
if !@node.nil? # it's a place page! | ||||||||||||||||||||||||||||||||||||||||||||
@tags = @node.tags | ||||||||||||||||||||||||||||||||||||||||||||
@tags += [Tag.find_by(name: params[:id])] if Tag.find_by(name: params[:id]) | ||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
tag1, tag2 = @node.normal_tags(:followers).includes(:tag).pluck(:name).first(2) | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trailing whitespace detected. |
||||||||||||||||||||||||||||||||||||||||||||
# get recommendations | ||||||||||||||||||||||||||||||||||||||||||||
@recommendations = Tag.get_recommendations(tag1, tag2) | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @KarishmaVanwari, since you want the random cards to be displayed in the dashboard's sidebar shouldn't this be in plots2/app/controllers/home_controller.rb Lines 39 to 59 in ca319fc
Please let me know if I'm wrong or missing something. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if we put it in a reusable named methodin application_controller so it can be used in multiple places? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried placing this piece of code on line 54 in |
||||||||||||||||||||||||||||||||||||||||||||
else # it's a new wiki page! | ||||||||||||||||||||||||||||||||||||||||||||
@title = I18n.t('wiki_controller.new_wiki_page') | ||||||||||||||||||||||||||||||||||||||||||||
if current_user | ||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -478,4 +478,34 @@ def span(start, fin) | |
def range(fin, week) | ||
(fin.to_i - week.weeks.to_i).to_s..(fin.to_i - (week - 1).weeks.to_i).to_s | ||
end | ||
|
||
def self.get_recommendations(tag1, tag2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
tag1_content_nids = find_recommended_nodes(tag1) | ||
tag2_content_nids = find_recommended_nodes(tag2) | ||
|
||
random_content_nids = tag1_content_nids.sample(3) + tag2_content_nids.sample(3) | ||
|
||
Node.where("nid IN (?)", random_content_nids) | ||
end | ||
|
||
def self.find_recommended_nodes(tagnames, limit = 10) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
date_ranges = [1.years.ago..3.years.ago, 4.years.ago..6.years.ago, 7.years.ago..9.years.ago] | ||
|
||
selected_date_range = date_ranges.sample(1) | ||
|
||
nodes = Node.where("cached_likes > 20 AND views > 100", status: 1) | ||
.where(created: selected_date_range) | ||
.includes(:tag) | ||
.references(:term_data) | ||
.where('term_data.name IN (?)', tagnames) | ||
|
||
Node.where('node.nid IN (?)', nodes.collect(&:nid)) | ||
.includes(:revision, :tag) | ||
.references(:node_revisions) | ||
.where(status: 1) | ||
.limit(limit) | ||
.pluck(:nid) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -55,7 +55,20 @@ | |||||
</div> | ||||||
</div> | ||||||
</div> | ||||||
|
||||||
<div> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we move this into its own partial - to load with |
||||||
<% if !@recommendations.nil? %> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jywarren, I tried this out, but it still doesn't seem to work as I am unable to find cards as expected on the dashboard. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That may be because you don't have nodes with those tags in your local development environment? Can you try tagging a note (not a wiki, i think this is just returning notes, right?) with "water-quality" or "air-quality"? If that doesn't work I will try running this code to debug. No worries!! Did you want to accept this suggestion and commit it? |
||||||
<% @recommendations.each do |node| %> | ||||||
<div class="card" style="width: 18rem;"> | ||||||
<img class="card-img-top" src="#" alt="Card image cap"> | ||||||
<div class="card-body"> | ||||||
<h5 class="card-title"><%= node.nid %></h5> | ||||||
<p class="card-text">Post content here</p> | ||||||
<a href="#" class="btn btn-primary">Read more button here</a> | ||||||
</div> | ||||||
</div> | ||||||
<% end %> | ||||||
<% end %> | ||||||
</div> | ||||||
|
||||||
<style> | ||||||
|
||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected.