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

feature-power tag for notes grid with specific tagname #3204

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def locale_name_pairs
end

def insert_extras(body)
body = NodeShared.notes_inline_grid(body)
Copy link
Member

Choose a reason for hiding this comment

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

Wow, this looks great... but I think there should be a lot of overlap with the notes_grid method... do you think we could consolidate those two? In theory it should be relatively close ActiveRecord queries, but displayed differently, don't you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, makes sense!! I see the methods notes_grid and notes_inline_grid differ only in rendering the templates. Both render different templates having same active-record queries. So, let's keep a single function with a parameter (say thumbnails=false by default) and change the template accordingly?

body = NodeShared.notes_grid(body)
body = NodeShared.questions_grid(body)
body = NodeShared.activities_grid(body)
Expand Down
36 changes: 36 additions & 0 deletions app/models/concerns/node_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,42 @@ def self.notes_map(body)
end
end

def self.notes_inline_grid(body)
body.gsub(/[^\>`](\<p\>)?\[notes\:grid\:(\S+)\]/) do |_tagname|
tagname = Regexp.last_match(2)
exclude = nil
if tagname.include?('!')
exclude = tagname.split('!') - [tagname.split('!').first]
tagname = tagname.split('!').first
end

nodes = Node.where(status: 1, type: 'note')
.includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name = ?', tagname)
.order('node_revisions.timestamp DESC')

if exclude.present?
exclude = Node.where(status: 1, type: 'note')
.includes(:revision, :tag)
.references(:node_revisions, :term_data)
.where('term_data.name IN (?)', exclude)
nodes -= exclude
end
output = ''
output += '<p>' if Regexp.last_match(1) == '<p>'
a = ActionController::Base.new
output += a.render_to_string(template: "notes/_note_thumbnails_grid",
layout: false,
locals: {
tagname: tagname,
nodes: nodes,
type: "notes"
})
output
end
end

def self.notes_map_by_tag(body)
body.gsub(/[^\>`](\<p\>)?\[map\:tag\:(\S+)\:(\S+)\:(\S+)\]/) do |_tagname|
tagname = Regexp.last_match(2)
Expand Down
5 changes: 3 additions & 2 deletions app/views/dashboard/_node_default.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<div class="col-md-6 note-container-note" style="overflow: hidden;">
<% width = local_assigns[:notes_thumbnails] ? "col-md-3" : "col-md-6" %>
<div class="<%= width %> note-container-note" style="overflow: hidden;">
<div class="note note-default<% if node.status == 4 || node.status == 3 %> moderated<% end %>">

<%= render partial: 'dashboard/node_moderate', locals: { node: node } %>
Expand All @@ -9,7 +10,7 @@

<h4><a href="<%= node.path %>"><%= node.title %></a> <% if node.status == 3 %><span style="font-size: small;" class="label label-success">Draft</span><% end %></h4>

<p class="meta"><%= render partial: "dashboard/node_meta", locals: { node: node } %></p>
<p class="meta"><%= render partial: "dashboard/node_meta", locals: {node: node, notes_thumbnails: local_assigns[:notes_thumbnails]} %></p>

<hr style="display:none;" class="bottom" />

Expand Down
8 changes: 5 additions & 3 deletions app/views/dashboard/_node_meta.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
<%= distance_of_time_in_words(node.created_at, Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %>
<% node = node.parent if node.is_a?(Revision) %>
<span class="">
<% if params[:controller] == 'questions' %>
| <a href="<%= node.path(:question) %>#answers" title="Answers"><i class="fa fa-comments-o" style="color: #DAA583;"></i> <%= node.answers.length %></a>
<% unless local_assigns[:notes_thumbnails] %>
<% if params[:controller] == 'questions' %>
| <a href="<%= node.path(:question) %>#answers" title="Answers"><i class="fa fa-comments-o" style="color: #DAA583;"></i> <%= node.answers.length %></a>
<% end %>
<% end %>
| <a href="<%= node.path %>#comments"><i class="fa fa-comment-o"></i> <%= node.comment_count %></a>
<span class="hidden-xs hidden-sm">| <i class="fa fa-eye"></i> <%= number_with_delimiter(node.totalviews) %></span>
| <i style="<% if node.likes > 0 %>color:#db4;<% end %>" class="fa fa-star-o"></i> <%= node.likes %>
<% if params[:mod] %>| <a href="#"><i class="fa fa-ban"></i></a><% end %>
<% unless local_assigns[:notes_thumbnails] %><% if params[:mod] %>| <a href="#"><i class="fa fa-ban"></i></a><% end %><% end %>
<a rel="tooltip" title="Flag as spam." class="btn btn-xs btn-default btn-flag-spam-<%= node.id %>" href="mailto:moderators@publiclab.org?subject=Reporting+spam+on+Public+Lab&body=Hi,+I+found+this+item+that+looks+like+spam+or+needs+to+be+moderated:+<%= node.title.gsub(/ /,'+') %>+https://publiclab.org/n/<%= node.id %>+by+https://publiclab.org/profile/<%= node.author.username %>+Thanks!">
<i class="fa fa-flag"></i>
</a>
Expand Down
10 changes: 10 additions & 0 deletions app/views/notes/_note_thumbnails_grid.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<h2 style="margin-top: 60px;margin-bottom: 0;">Related Notes</h2>
<hr style="margin-top:10px;">
<div class="activity">
<div class="row" style="display: flex;flex-wrap: wrap;">
<% nodes.each do |node| %>
<%= render partial: 'dashboard/node_default', locals: {node: node, notes_thumbnails: true} %>
<% end %>
</div>
<br />
</div>