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

Start to pinning in notes grids (work in progress) #5681

Merged
merged 7 commits into from
May 20, 2019
Merged
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
9 changes: 8 additions & 1 deletion app/models/concerns/node_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,17 @@ def self.nodes_grid(body, _page = 1)
tagname = tagname.split('!').first
end

nodes = Node.where(status: 1).where("node.type = 'page' OR node.type = 'note'")
pinned = Node.where(status: 1)
.where("node.type = 'page' OR node.type = 'note'")
.includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name = ?', "pin:#{tagname}")
nodes = pinned + Node.where(status: 1)
.where("node.type = 'page' OR node.type = 'note'")
.includes(:revision, :tag)
.references(:term_data, :node_revisions)
.where('term_data.name = ?', tagname)
.where.not(nid: pinned.collect(&:nid)) # don't include pinned items twice
.order('node_revisions.timestamp DESC')

if exclude.present?
Expand Down
5 changes: 4 additions & 1 deletion app/views/grids/_nodes.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
</tr>
<% nodes.each do |node| %>
<tr>
<td style="width:40%"><a href="<%= node.path %>"><%= node.latest.title %></a></td>
<td style="width:40%">
<% if node.has_tag("pinned:#{tagname}") %><i class="fa fa-thumb-tack"></i> <% end %>
<a href="<%= node.path %>"><%= node.latest.title %></a>
</td>
<td class="author"><a href="/profile/<%= node.author.username %>">@<%= node.author.username %> <%=node.author.new_contributor %></a></td>
<td class="updated" data-timestamp="<%= node.latest.timestamp.to_s %>"><%= distance_of_time_in_words(Time.at(node.latest.updated_at), Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %></td>
<td class="likes"><%= node.cached_likes.to_s %></td>
Expand Down
9 changes: 3 additions & 6 deletions test/system/post_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
# https://guides.rubyonrails.org/testing.html#implementing-a-system-test

class PostTest < ApplicationSystemTestCase

def setup
activate_authlogic
end
Capybara.default_max_wait_time = 60

test 'posting from the editor' do
visit '/'
Expand All @@ -17,15 +14,15 @@ def setup

visit '/post'

fill_in("Title", with: "My new post", wait: 4)
fill_in("Title", with: "My new post")

el = find(".wk-wysiwyg") # rich text input
el.set("All about this interesting stuff")

assert_page_reloads do

find('.ple-publish').click
assert_selector('h1', text: "My new post", wait: 4)
assert_selector('h1', text: "My new post")
assert_selector('#content', text: "All about this interesting stuff")
assert_selector('.alert-success', text: "×\nSuccess! Thank you for contributing open research, and thanks for your patience while your post is approved by community moderators and we'll email you when it is published. In the meantime, if you have more to contribute, feel free to do so.")

Expand Down
13 changes: 13 additions & 0 deletions test/unit/node_shared_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,19 @@ class NodeSharedTest < ActiveSupport::TestCase
assert html.scan('<td class="author">').length > 1
end

test 'that pinned notes with "pinned:foo" tags appear at the top of [nodes:foo] inline tables' do
before = "Here are some nodes in a table: \n\n[nodes:test] \n\nThis is how you make it work:\n\n`[nodes:tagname]`\n\n `[nodes:tagname]`\n\nMake sense?"
nodes(:one).add_tag('pinned:test', User.first)
nodes(:one).add_tag('test', User.first) # ensure it would appear anyways (although we aren't yet asserting order below, we should)
html = NodeShared.nodes_grid(before)
assert html
assert_equal 1, html.scan('<table class="table inline-grid nodes-grid nodes-grid-test nodes-grid-test-').length
assert_equal 1, html.scan('<table').length
assert_equal 5, html.scan('nodes-grid-test').length
assert_equal 2, html.scan('<td class="author">').length # but not 3 because it shouldn't appear twice
assert_equal 1, html.scan(nodes(:one).title).length
end

test 'that NodeShared can be used to convert short codes like [notes:foo] into tables which list notes' do
before = "Here are some notes in a table: \n\n[notes:test] \n\nThis is how you make it work:\n\n`[notes:tagname]`\n\n `[notes:tagname]`\n\nMake sense?"
html = NodeShared.notes_grid(before)
Expand Down