-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
"Browse other activities" next to "replicate this" prompt, fixes #754 #1090
Conversation
<p id="<%= response_type %>s"><a class='btn btn-primary btn-lg' href="/post?tags=<%= response_type %>:<%= @node.id %><% if response_type == 'response' %>,hidden:response<% end %><%= ',' + (@tagnames.uniq.delete_if{|x| x.match(":") }).join(',') if @tagnames && @tagnames.length > 0 %>"><%= t('notes._responses.post_' + response_type) %></a> | ||
<% if @node.power_tag('activity') %> | ||
<% if DrupalTag.where(name: @node.power_tag('activity')) %> | ||
<% @responses = DrupalTag.where(name: @node.power_tag('activity')).tag.nodes.first %><% end %><% end %></p> |
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.
OK, - closer, great -- here, I don't think we need an instance variable for @responses
-- but we could say:
<% if @node.power_tag('activity') %>
<% if DrupalTag.where(name: @node.power_tag('activity')).first.nodes %>
<%= DrupalTag.where(name: @node.power_tag('activity')).first.nodes.first.path %>
<% end %>
<% end %>
Please also put end
statements and close </p>
tags on their own line, with clean indentations (two spaces per indent) -- that makes it a lot easier to read!
See how this is a lot of logic to put into a template? If we imagined we'd use this logic more than just once, we might want to move some of it into the DrupalTag
model, to simplify the code here. Then we could also unit test the code to ensure it doesn't break in the future. But it's your choice -- if it's just going to be used here, we're OK just doing a little bit of logic in the templates, as long as its readable and efficient.
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.
And see how we ask @node.power_tag('activity')
three times? We could make that a bit more efficient too -- although it will probably cache the database call that fetches that info, so it's not too bad.
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.
Okay it isnt used that much so we will see about adding it to the DrupalTag model. I will make these changes. And don't we need all this in 'Browse other activities' link and '' tags?
OK - great - see how the tests ran, and some failed? This highlights exactly the IF checks we need -- i guess we forgot at least one. So the first test failure is:
And note that these failed on the following line: So, we're calling DrupalTag.where(name: @node.power_tag('activity')).first So i guess we have to add another check that the above call doesn't return You can also write shorter checks by using this neat Thanks!!! |
This is a great example of how testing can help catch problems before we merge code! |
don't we need all this in 'Browse other activities' link and '' tags? |
<% if @node.power_tag('activity') %> | ||
<% if DrupalTag.where(name: @node.power_tag('activity')).first %> | ||
<% if DrupalTag.where(name: @node.power_tag('activity')).first.nodes %> | ||
<%= DrupalTag.where(name: @node.power_tag('activity')).first.nodes.first.path %> |
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.
Not sure if this answers your question, but here, we now can make this appear in a link, like:
<a href="<%= DrupalTag.where(name: @node.power_tag('activity')).first.nodes.first.path %>">Browse other activities for "<%= @node.power_tag('activity') %>"</a>
Make sense?
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.
Got it! Yes it clears it up. Thanks!
Now do we need to add a test for this link in **** ? |
I think we could... You could add an extra assert_select to an existing
test on a node tagged with "activity:...." -- there should be one in
/test/functional/notes_controller_test.rb, though you might have to add an
id= property to the <a> tag so you can correctly select it.
I can help with this tomorrow!
…On Dec 12, 2016 6:27 PM, "500swapnil" ***@***.***> wrote:
Now do we need to add a test for this link in **** ?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1090 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJxw_UPXH7S5vfatg_UzdRvkmS-02ks5rHdhmgaJpZM4LK8Ot>
.
|
So I guess it would be |
Yes, but # instead of . for ids -- periods are for class=
I can provide more input tomorrow!
…On Dec 12, 2016 6:44 PM, "500swapnil" ***@***.***> wrote:
So I guess it would be
assert_select "a.other-activites" , true
where the id of '' is 'other-activites'. Ok let me know where I can add
this tomorrow. Thanks!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1090 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AABfJ31JaN3xVyArmiTQkq73uknOxTqYks5rHdxJgaJpZM4LK8Ot>
.
|
So, if it's an id, you do https://github.com/publiclab/plots2/blob/master/test/integration/node_insert_extras_test.rb#L47 |
Is this ok? |
Hi -- this looks perfect; merging now. If you're looking for a new challenge, please take a look at our Thanks! |
Thanks! |
Thanks so much @500swapnil !!!!! This is a really useful addition to helping everyone find the projects they are interested in. |
Happy to help! @ebarry |
Make sure these boxes are checked before your pull request is ready to be reviewed and merged. Thanks!
rake test:all
schema.rb.example
has been updated if any database migrations were addedPlease be sure you've reviewed our contribution guidelines at https://publiclab.org/wiki/contributing-to-public-lab-software
We have a loose schedule of reviewing and pulling in changes every Tuesday and Friday, and publishing changes on Fridays. Please alert developers on plots-dev@googlegroups.com when your request is ready or if you need assistance.
Thanks!