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

Refactoring profile.html.erb code pt. 3 #4339

Closed
6 tasks
sashadev-sky opened this issue Dec 19, 2018 · 12 comments
Closed
6 tasks

Refactoring profile.html.erb code pt. 3 #4339

sashadev-sky opened this issue Dec 19, 2018 · 12 comments
Assignees

Comments

@sashadev-sky
Copy link
Member

sashadev-sky commented Dec 19, 2018

The problem

Our code in app/views/users/profile.html.erb is very verbose... we could use some refactoring

We can start by refactoring out a reoccuring line from the code. For now, the 1st line of:

<% if @profile_user && current_user && current_user.can_moderate? && @profile_user == current_user %>
<br />
<%= form_tag "/users/test_digest_email", method: :post do %>
<%= submit_tag "Test Digest Email", class: "btn btn-info", style: "width: 100%;" %>
<% end %>
<% end %>

Solution

What to change it to:

Code that we want to refactor and that might be useful to multiple views in the future can go in the app/controllers/application_controller.rb

Try adding a current_profile_user method to the application controller. We can move the conditional to check if there is a current_user and if the current_user is the user who owns the current profile we are viewing with a method like so:

  def current_profile_user
    return @current_user && @profile_user == @current_user
  end

Add your new current_profile_user method to the helper_methods at the top of the page so that it is available to all our views:

helper_method :current_user_session, :current_user, :prompt_login, :sidebar

Refactor the lines in the 3 code blocks found in the "The Problem" section to use your new helper method instead.

Note that the 1st code block has an additional check for current_user.can_moderate? in it which we need to add on.

For ex., that line can be updated to <% if current_profile_user && current_user.can_moderate? %>

Thanks!!

Steps to Fix

  • Claim this issue with a comment here, below, and ask any clarifying questions you need
  • Fork the repository and set it up locally following the main repo README instructions https://github.com/publiclab/plots2
  • Create a new feature branch with a unique name descriptive to the issue
  • Try to fix the issue following the steps above, but even before you're done, you can:
    commit your changes to your branch and start a pull request (see contributing to Public Lab software) but mark it as "in progress" if you have questions or if you haven't finished
  • Reference this issue in your pull request body
  • Once you submit your pull request, an additional checklist will be provided for getting it merged

💬 Get help

If you need any help - here are some options:

Next Steps

When you're done and the code is merged, if you see other places in the code that could use this refactoring, open up another first-timers-only issue and walk a new contributor through it :)

Note related issues #4342 and #4341

@oorjitchowdhary
Copy link
Member

@sashadev-sky I don't think this should be a first-timers-only issue... First timers issues are meant to welcome people and get them familiar with the code base... Sorry if I'm wrong

@sashadev-sky
Copy link
Member Author

@oorjitchowdhary I have been getting mixed reviews so I will wait for @jywarren @gauravano to review. I can rewrite it based on the tags they add!

But I partially agree with you it's on the fence. Maybe I can make it even simpler

@SidharthBansal
Copy link
Member

@sashadev-sky this is properly formatted but I am afraid whether a newcomer can deal with such huge PR or not. We want the first experience with Public Lab will be friendly and very less time-consuming. Collaborators should not be dishearted with any errors or bugs they would get in the PR. I agree with @oorjitchowdhary.
Thanks @sashadev-sky for your hard work. We really appreciate it. Please try to make first timers which have less amount of work.
Let's create this one as help-wanted issue.

@SidharthBansal SidharthBansal added the help wanted requires help by anyone willing to contribute label Dec 19, 2018
@sashadev-sky
Copy link
Member Author

done! @SidharthBansal @oorjitchowdhary
Should we delete our comments so that other users won't assume this issue has been taken?

@grvsachdeva
Copy link
Member

We can also divide this issue in 3 FTO's, corresponding to 3 blocks as explained by @sashadev-sky. What do you think @sashadev-sky, want to open 3 FTO's?

Nice work 🎈 😃 !

@sashadev-sky
Copy link
Member Author

@gauravano Sure! What if I leave the first one that has the extra conditional as a help wanted, and make the two simpler ones FTOs?

@sashadev-sky sashadev-sky changed the title Refactoring profile.html.erb code Refactoring profile.html.erb code pt. 3 Dec 19, 2018
@grvsachdeva
Copy link
Member

Yes, sounds good!

@grvsachdeva
Copy link
Member

Also, both FTO's would depend on 1st block, so I think either we can wait for someone to claim this one or we could add a function ourselves. Thoughs?

@sashadev-sky
Copy link
Member Author

@gauravano you are very right. I can just solve this one myself right now, then rewrite the other two.

@grvsachdeva
Copy link
Member

Looking for your PR 😃

@grvsachdeva grvsachdeva added in-progress and removed help wanted requires help by anyone willing to contribute labels Dec 19, 2018
@ghost ghost added the in progress label Dec 19, 2018
@sashadev-sky
Copy link
Member Author

@gauravano just making sure you saw the PR #4343 I tagged you in

@grvsachdeva
Copy link
Member

grvsachdeva commented Dec 20, 2018 via email

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

No branches or pull requests

4 participants