diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 71ee8d34db..9b07fbdea8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -79,6 +79,7 @@ def locale_name_pairs end def insert_extras(body) + body = NodeShared.notes_inline_grid(body) body = NodeShared.notes_grid(body) body = NodeShared.questions_grid(body) body = NodeShared.activities_grid(body) diff --git a/app/models/concerns/node_shared.rb b/app/models/concerns/node_shared.rb index dec87714d1..242b7849b9 100644 --- a/app/models/concerns/node_shared.rb +++ b/app/models/concerns/node_shared.rb @@ -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) diff --git a/app/views/dashboard/_node_default.html.erb b/app/views/dashboard/_node_default.html.erb index ffb5ce981a..281f4e38c9 100644 --- a/app/views/dashboard/_node_default.html.erb +++ b/app/views/dashboard/_node_default.html.erb @@ -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 } %> @@ -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" /> diff --git a/app/views/dashboard/_node_meta.html.erb b/app/views/dashboard/_node_meta.html.erb index 366d4bf627..80303ed7c1 100644 --- a/app/views/dashboard/_node_meta.html.erb +++ b/app/views/dashboard/_node_meta.html.erb @@ -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> diff --git a/app/views/notes/_note_thumbnails_grid.html.erb b/app/views/notes/_note_thumbnails_grid.html.erb new file mode 100644 index 0000000000..5da34b02a3 --- /dev/null +++ b/app/views/notes/_note_thumbnails_grid.html.erb @@ -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> \ No newline at end of file