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

User page: new following section #1750

Merged
merged 17 commits into from
Jul 24, 2017

Conversation

Senen
Copy link
Member

@Senen Senen commented Jul 13, 2017

What

Show user followable activity on public user page.

Refactor

  • Remove popup on follow and unfollow buttons
  • Add AJAX notice on follows controller actions to keep user better informed

How

Add new tab to show followed objects by user.

Screenshots

captura de pantalla 2017-07-13 a las 18 47 13
captura de pantalla 2017-07-13 a las 18 46 58

Refactor screenshots
captura de pantalla 2017-07-19 a las 19 54 50
captura de pantalla 2017-07-19 a las 19 54 38

Test

Increased test coverage to:

  • Check automatic following tab activation when filter "follows" defined
  • Check "Following" tabs UI behaviour
  • Check following accordion behavior
  • Check followed object presence in correct accordion tab
  • Check action buttons presence, they should be shown when current user has enough rights
  • Check following and unfollowing notices.

Deployment

As usual.

@Senen
Copy link
Member Author

Senen commented Jul 13, 2017

@voodoorai2000, @bertocq, @decabeza ahí va otro pull-request desde la playa! 😄 Esperamos vuestros comentarios.

Falta la verificación de la funcionalidad por parte de Yago Bermejo.

Copy link
Collaborator

@bertocq bertocq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one 😃 👍

Some comments on the side just to improve code readability and a question that might be easy to explain


load_and_authorize_resource
helper_method :author?
helper_method :author_or_admin?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't really understand the reason to remove author_or_admin? method and its usage, can you explain a bit further? :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bertocq The main reason is that apparently it was not being used anywhere in the application.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 you're right, I did a project search and no use, although sometimes looking for the method string is not enough if you do compose de method name with a string interpolation like send("#{this}_or_#{that}") but that's not the case I guess based on the specs passing ^_^

Nice catch & cleanup 👏 😄

end

def entity_icon(entity)
case entity
Copy link
Collaborator

@bertocq bertocq Jul 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered the option to use a hash here instead of a case statement? Something like:

def entity_icon(entity)
  {
    'Proposal' => 'proposals',
    'Budget::Investment' => 'budget'
  }[entity]
end

It could be improved by moving the hash to a constant variable, or even switching keys for values to use new hash syntax:

def entity_icon(entity)
  {
    proposals: 'Proposal',
    budget: 'Budget::Investment'
  }.invert[entity]
end

Last but not least, it seems odd that "proposals" is plural but "budget" is singular 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like very much this option! Less words and same clarity always better!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the plurals question... don't worry @Senen I just realized it was wrong on consul beforehand :) I'll fix it afterwards this PR is merged! 👍

@@ -50,7 +50,7 @@ def initialize(user)
can :create, Budget::Investment, budget: { phase: "accepting" }
can :suggest, Budget::Investment, budget: { phase: "accepting" }
can :destroy, Budget::Investment, budget: { phase: ["accepting", "reviewing"] }, author_id: user.id
can :vote, Budget::Investment, budget: { phase: "selecting" }
can :vote, Budget::Investment, budget: { phase: "selecting" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^_^ /bertocq likes this

@@ -0,0 +1,28 @@
<tr id="proposal_<%= proposal.id %>">
<td>
<%= link_to proposal.title, proposal, proposal.retired? ? { class: 'retired' } : {} %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that ? { class: 'retired' } : {} :) I think I have added some class="" around :( couldn't figure out this was the way 👏

</td>
<% end %>

<% if author?(proposal) || proposal.retired? %>
Copy link
Collaborator

@bertocq bertocq Jul 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took me a bit to understand all the conditionals around this block and realize there is only 2 scenarios. Maybe this could be easier to read:

<% if proposal.retired? %>
 <td class="text-center">
  <span class="label alert"><%= t('users.proposals.retired') %></span>
 </td>
<% elsif author?(proposal) %>
 <td class="text-center">
   <%= link_to t('users.proposals.retire'),
               retire_form_proposal_path(proposal),
               class: 'button hollow alert' %>
 </td>
<% end %>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree @bertocq! We will make this change too!

@@ -46,7 +46,7 @@
<p><%= t('users.show.private_activity') %></p>
<% end %>

<% if @user.public_interests || @authorized_current_user %>
<% if valid_interests_access? %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@@ -52,6 +52,18 @@ def unfollow_drop_id(followable)
"unfollow-drop-#{entity_full_name(followable)}-#{followable.id}"
end

def entity_title(title)
entity = title.gsub('::', '/').downcase
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you'll love this page http:https://inflector.me/Budget::Investment :)

This two lines could be just one t("activerecord.models.#{title.underscore}.other")

Copy link
Member Author

@Senen Senen Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this resource. 😄 👏. I'll do this change.

<table>
<tbody>
<% @follows.where(followable_type: followable_type).each do |follow| %>
<% if followable_type == "Proposal" %>
Copy link
Collaborator

@bertocq bertocq Jul 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After seeing both entity_title and entity_icon helper methods. I think a third one could be nice to avoid spilling == "Proposal" and == "Budget::Investment" on a view :D, seems tricky to remember if another entity becomes as well "followable"

So the entire if-else could be replace for something like:

<%= render entity_partial(followable_type), entity_partial(followable_type).to_sym => follow.followable %>

Being the helper function at app/helpers/follows_helper.rb:

def entity_partial(title)
  title.parameterize.gsub('-','_')
end

What do you think?

Copy link
Member Author

@Senen Senen Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes @bertocq while we were programming exactly your solution we thought that this abstraction forces the developer to follow entity_partial helper method to understand where to put and how to name new followable object partials. Because of that we decide to let these lines explicitly written, but if you prefer, we can make this change in a second. I think both solutions has some disadvantage and in this case we prefer explicitness over reducing code lines.

Copy link
Collaborator

@bertocq bertocq Jul 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the scenario were another entity becomes followable, for both icon and title translation following the trail to the helper will be needed, so I don't see it as a big downside to the proposed refactor. I just imagine 4-5 entities being followable and the if-elsif-elsif.. being too big when just following a simple convention (that also complains with how rails expects things to be named) could make it easier.

But thats like you say its a subjective matter, I prefer conventions over more lines, maybe @voodoorai2000 can take a look and say if he has a hard opinion about it or not.

Copy link
Collaborator

@bertocq bertocq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems really great to me 👍 😃 & thanks for taking in consideration the suggestions!

@@ -9,23 +9,22 @@ def show_unfollow_action?(followable)
end

def follow_entity_text(followable)
entity = followable.class.name.gsub('::', '/').downcase
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 nice cleaning up on the side! 💪

@Senen
Copy link
Member Author

Senen commented Jul 19, 2017

@bertocq thanks for all your advices! They are allways welcome! 😃.We are still waiting customer validation. We'll let you know when it's done.

@@ -0,0 +1,31 @@
<ul class="accordion" data-accordion data-allow-all-closed="true">

<% @followable_types.each do |followable_type| %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,
I just sent you a small PR regarding this, hope you like it :)

@voodoorai2000
Copy link
Member

Regarding the concept of entity... it's something new that we haven't used yet in Consul... maybe we can postpone the decision of using entity by creating a FollowablesHelper and chaging the following helper methods:

FollowsHelper:
def follow_entity_text
def unfollow_entity_text
def entity_full_name
def entity_title
def entity_icon
def entity_partial

for something like this:

FollowsHelper:
def follow_text
def unfollow_text

FollowablesHelper:
def followable_full_name
def followable_title
def followable_icon
def followable_partial

<table>
<tbody>
<% follows.each do |follow| %>
<%= render_follow(follow) %>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@voodoorai2000 nice refactor! 😍

@Senen
Copy link
Member Author

Senen commented Jul 19, 2017

@voodoorai2000, @bertocq, @decabeza i think we finally have final version. I made all suggested changes by @voodoorai2000 and removed unused translation key, also we removed popup on follow buttons and add a notice message to keep user informed. Off course we increased tests coverage with new notice checks and delete a lot of ugly code needed by popup but useless now.

As always, thanks for your advices. 😃

I add a link to our staging server so you can try look and feel easily.
https://rockandror-consul.herokuapp.com/budgets/1/investments/29
user: [email protected] pass: qwer1234

…owed_by? on followable model concern. Some code improvements.
Copy link
Collaborator

@bertocq bertocq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏 👍

Copy link
Member

@voodoorai2000 voodoorai2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome

@Senen
Copy link
Member Author

Senen commented Jul 24, 2017

@bertocq, @voodoorai2000, @decabeza this feature was approved by Yago. We can merge it! 😃

@bertocq bertocq merged commit 13871b8 into consuldemocracy:master Jul 24, 2017
@voodoorai2000 voodoorai2000 deleted the followable-user-activity branch August 2, 2017 10:08
@voodoorai2000 voodoorai2000 moved this from Doing to Done in Roadmap Aug 2, 2017
@voodoorai2000 voodoorai2000 moved this from Done to Next Release in Roadmap Aug 5, 2017
@voodoorai2000 voodoorai2000 moved this from Next Release to Archive in Roadmap Oct 2, 2017
@voodoorai2000 voodoorai2000 removed this from Archive in Roadmap Oct 6, 2017
javierm pushed a commit to javierm/consul that referenced this pull request Dec 18, 2018
…-processes

Draft phase on legislation processes
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

5 participants