From 86b7045b3a1adfbfaba864b2f2a3321bcec2c8e1 Mon Sep 17 00:00:00 2001 From: viditchitkara Date: Sun, 5 Aug 2018 22:26:10 +0530 Subject: [PATCH] feature-power tag for notes grid with specific tagname --- app/helpers/application_helper.rb | 1 + app/models/concerns/node_shared.rb | 36 +++++++++++++++++++ app/views/dashboard/_node_default.html.erb | 5 +-- app/views/dashboard/_node_meta.html.erb | 8 +++-- .../notes/_note_thumbnails_grid.html.erb | 10 ++++++ 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 app/views/notes/_note_thumbnails_grid.html.erb 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(/[^\>`](\)?\[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 += '

' if Regexp.last_match(1) == '

' + 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(/[^\>`](\)?\[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 @@ -

+<% width = local_assigns[:notes_thumbnails] ? "col-md-3" : "col-md-6" %> +
<%= render partial: 'dashboard/node_moderate', locals: { node: node } %> @@ -9,7 +10,7 @@

<%= node.title %> <% if node.status == 3 %>Draft<% end %>

-

<%= render partial: "dashboard/node_meta", locals: { node: node } %>

+

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

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) %> - <% if params[:controller] == 'questions' %> - | <%= node.answers.length %> + <% unless local_assigns[:notes_thumbnails] %> + <% if params[:controller] == 'questions' %> + | <%= node.answers.length %> + <% end %> <% end %> | <%= node.comment_count %> | <%= node.likes %> - <% if params[:mod] %>| <% end %> + <% unless local_assigns[:notes_thumbnails] %><% if params[:mod] %>| <% end %><% end %> 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 @@ +

Related Notes

+
+
+
+ <% nodes.each do |node| %> + <%= render partial: 'dashboard/node_default', locals: {node: node, notes_thumbnails: true} %> + <% end %> +
+
+
\ No newline at end of file