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

"Browse other activities" next to "replicate this" prompt, fixes #754 #1090

Merged
merged 6 commits into from
Dec 13, 2016
Merged

"Browse other activities" next to "replicate this" prompt, fixes #754 #1090

merged 6 commits into from
Dec 13, 2016

Conversation

500swapnil
Copy link
Collaborator

@500swapnil 500swapnil commented Dec 12, 2016

Make sure these boxes are checked before your pull request is ready to be reviewed and merged. Thanks!

  • all tests pass -- rake test:all
  • code is in uniquely-named feature branch, and has been rebased on top of latest master (especially if you've been asked to make additional changes)
  • pull request is descriptively named with #number reference back to original issue
  • if possible, multiple commits squashed if they're smaller changes
  • reviewed/confirmed/tested by another contributor or maintainer
  • schema.rb.example has been updated if any database migrations were added

Please 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!

<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>&nbsp;
<% 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>
Copy link
Member

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.

Copy link
Member

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.

Copy link
Collaborator Author

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?

@jywarren
Copy link
Member

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:

Error: test_users_are_logged_out_and_alerted_when_banned,_and_notes_are_not_accessible(ModerateAndBanTest): ActionView::Template::Error: undefined method `nodes' for nil:NilClass

And note that these failed on the following line: app/views/notes/_responses.html.erb:10

So, we're calling .nodes on a nil -- that nil was the result of:

DrupalTag.where(name: @node.power_tag('activity')).first

So i guess we have to add another check that the above call doesn't return nil.

You can also write shorter checks by using this neat .try() method in ActiveSupport. That can perhaps keep your code a bit more compact, if it's helpful.

Thanks!!!

@jywarren
Copy link
Member

This is a great example of how testing can help catch problems before we merge code!

@500swapnil
Copy link
Collaborator Author

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 %>
Copy link
Member

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?

Copy link
Collaborator Author

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!

@500swapnil
Copy link
Collaborator Author

Now do we need to add a test for this link in **** ?

@jywarren
Copy link
Member

jywarren commented Dec 12, 2016 via email

@500swapnil
Copy link
Collaborator Author

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!

@jywarren
Copy link
Member

jywarren commented Dec 13, 2016 via email

@jywarren
Copy link
Member

So, if it's an id, you do assert_select "a#other-activities" (true is implied with only one param), and the test could go among these similar ones:

https://github.com/publiclab/plots2/blob/master/test/integration/node_insert_extras_test.rb#L47

@500swapnil
Copy link
Collaborator Author

Is this ok?

@jywarren jywarren merged commit 3cbe709 into publiclab:master Dec 13, 2016
@jywarren
Copy link
Member

Hi -- this looks perfect; merging now. If you're looking for a new challenge, please take a look at our help-wanted list: https://github.com/publiclab/plots2/labels/help-wanted

Thanks!

@500swapnil
Copy link
Collaborator Author

Thanks!

@ebarry
Copy link
Member

ebarry commented Dec 21, 2016

Thanks so much @500swapnil !!!!! This is a really useful addition to helping everyone find the projects they are interested in.

@500swapnil
Copy link
Collaborator Author

Happy to help! @ebarry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants