From 52e195d83756230d4172ed00be11e4d27c840de6 Mon Sep 17 00:00:00 2001 From: Alessandro Cuoghi Date: Tue, 27 Jun 2017 12:05:56 +0200 Subject: [PATCH 01/16] Add tab. Add accordion. Add style. Pass test scss-lint. --- app/assets/stylesheets/layout.scss | 30 ++++++++++++++++++++++ app/views/users/_activity_page.html.erb | 1 + app/views/users/_following.html.erb | 34 +++++++++++++++++++++++++ app/views/users/show.html.erb | 4 +++ 4 files changed, 69 insertions(+) create mode 100644 app/views/users/_following.html.erb diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index b4ea0cca3..5bd9aedfd 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -1932,6 +1932,36 @@ table { .activity { margin-bottom: $line-height * 2; + .accordion li { + margin-bottom: $line-height / 2; + + .accordion-title { + border-bottom: 1px solid $border; + background: #f8f9fb; + font-size: $small-font-size; + padding: $line-height / 2; + } + + .accordion-content { + padding: 0; + } + } + + .accordion .title { + display: block; + line-height: $line-height; + } + + .accordion .icon { + font-size: rem-calc(20); + float: left; + margin-right: $line-height / 3; + + &.icon-debates { + margin-top: rem-calc(3); + } + } + table { border: 0; } diff --git a/app/views/users/_activity_page.html.erb b/app/views/users/_activity_page.html.erb index df46df76d..455d30f50 100644 --- a/app/views/users/_activity_page.html.erb +++ b/app/views/users/_activity_page.html.erb @@ -1,3 +1,4 @@ +<%= render "following" %> <%= render "proposals" if @proposals.present? %> <%= render "debates" if @debates.present? && feature?(:debates) %> <%= render "budget_investments" if @budget_investments.present? && feature?(:budgets) %> diff --git a/app/views/users/_following.html.erb b/app/views/users/_following.html.erb new file mode 100644 index 000000000..217312177 --- /dev/null +++ b/app/views/users/_following.html.erb @@ -0,0 +1,34 @@ + diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index fb4a3d1f9..86d37f104 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -38,6 +38,10 @@ <% end %> <% end %> <% end %> + +
  • + Add translate +
  • <%= t("users.show.no_activity") if @activity_counts.values.inject(&:+) == 0 %> From 7e2e94d7091d8f8c7d24a172eab4811383016146 Mon Sep 17 00:00:00 2001 From: taitus Date: Fri, 30 Jun 2017 18:26:46 +0200 Subject: [PATCH 02/16] Add following tab to user public page. --- app/controllers/users_controller.rb | 16 +++++++--- app/helpers/follows_helper.rb | 12 ++++++++ app/helpers/users_helper.rb | 2 +- app/views/users/_activity_page.html.erb | 2 +- app/views/users/_budget_investment.html.erb | 11 +++++++ app/views/users/_budget_investments.html.erb | 12 +------- app/views/users/_following.html.erb | 32 ++++++++++---------- app/views/users/_proposal.html.erb | 25 +++++++++++++++ app/views/users/_proposals.html.erb | 26 +--------------- app/views/users/show.html.erb | 4 --- 10 files changed, 79 insertions(+), 63 deletions(-) create mode 100644 app/views/users/_budget_investment.html.erb create mode 100644 app/views/users/_proposal.html.erb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6ef59fb60..2346a2017 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,5 +1,5 @@ class UsersController < ApplicationController - has_filters %w{proposals debates budget_investments comments}, only: :show + has_filters %w{proposals debates budget_investments comments follows}, only: :show load_and_authorize_resource helper_method :author? @@ -17,7 +17,8 @@ class UsersController < ApplicationController proposals: Proposal.where(author_id: @user.id).count, debates: (Setting['feature.debates'] ? Debate.where(author_id: @user.id).count : 0), budget_investments: (Setting['feature.budgets'] ? Budget::Investment.where(author_id: @user.id).count : 0), - comments: only_active_commentables.count) + comments: only_active_commentables.count, + follows: @user.follows.count) end def load_filtered_activity @@ -26,7 +27,8 @@ class UsersController < ApplicationController when "proposals" then load_proposals when "debates" then load_debates when "budget_investments" then load_budget_investments - when "comments" then load_comments + when "comments" then load_comments + when "follows" then load_follows else load_available_activity end end @@ -44,6 +46,9 @@ class UsersController < ApplicationController elsif @activity_counts[:comments] > 0 load_comments @current_filter = "comments" + elsif @activity_counts[:follows] > 0 + load_follows + @current_filter = "follows" end end @@ -63,8 +68,9 @@ class UsersController < ApplicationController @budget_investments = Budget::Investment.where(author_id: @user.id).order(created_at: :desc).page(params[:page]) end - def load_interests - @user.interests + def load_follows + @followable_types = @user.follows.pluck(:followable_type).uniq + @follows = @user.follows end def valid_access? diff --git a/app/helpers/follows_helper.rb b/app/helpers/follows_helper.rb index 63f50f7be..60ee0141f 100644 --- a/app/helpers/follows_helper.rb +++ b/app/helpers/follows_helper.rb @@ -52,6 +52,18 @@ module FollowsHelper "unfollow-drop-#{entity_full_name(followable)}-#{followable.id}" end + def entity_title(title) + entity = title.gsub('::', '/').downcase + t("activerecord.models.#{entity}.other") + end + + def entity_icon(entity) + case entity + when "Proposal" then "proposals" + when "Budget::Investment" then "budget" + end + end + private def followed?(followable) diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index 9c13e8ef8..968fa6e66 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -41,4 +41,4 @@ module UsersHelper current_user && current_user.administrator? end -end \ No newline at end of file +end diff --git a/app/views/users/_activity_page.html.erb b/app/views/users/_activity_page.html.erb index 455d30f50..bbea17ae6 100644 --- a/app/views/users/_activity_page.html.erb +++ b/app/views/users/_activity_page.html.erb @@ -1,4 +1,4 @@ -<%= render "following" %> +<%= render "following" if @follows.present? %> <%= render "proposals" if @proposals.present? %> <%= render "debates" if @debates.present? && feature?(:debates) %> <%= render "budget_investments" if @budget_investments.present? && feature?(:budgets) %> diff --git a/app/views/users/_budget_investment.html.erb b/app/views/users/_budget_investment.html.erb new file mode 100644 index 000000000..774fae777 --- /dev/null +++ b/app/views/users/_budget_investment.html.erb @@ -0,0 +1,11 @@ + + + <%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %> + + + <% if can? :destroy, budget_investment %> + <%= link_to t('shared.delete'), budget_investment_path(budget_investment.budget, budget_investment), + method: :delete, class: "button hollow alert" %> + <% end %> + + diff --git a/app/views/users/_budget_investments.html.erb b/app/views/users/_budget_investments.html.erb index 64cad676d..fb782f97c 100644 --- a/app/views/users/_budget_investments.html.erb +++ b/app/views/users/_budget_investments.html.erb @@ -1,16 +1,6 @@ <% @budget_investments.each do |budget_investment| %> - - - - + <%= render "budget_investment", budget_investment: budget_investment %> <% end %>
    - <%= link_to budget_investment.title, budget_investment_path(budget_investment.budget, budget_investment) %> - - <% if can? :destroy, budget_investment %> - <%= link_to t('shared.delete'), budget_investment_path(budget_investment.budget, budget_investment), - method: :delete, class: "button hollow alert" %> - <% end %> -
    diff --git a/app/views/users/_following.html.erb b/app/views/users/_following.html.erb index 217312177..defac258a 100644 --- a/app/views/users/_following.html.erb +++ b/app/views/users/_following.html.erb @@ -1,34 +1,34 @@
      - <% (1..2).each do |i| %> + + <% @followable_types.each do |followable_type| %> +
    • + - - + - Debate.title + <%= entity_title(followable_type) %> +
      - <% (1..3).each do |i| %> - - - + <% @follows.where(followable_type: followable_type).each do |follow| %> + <% if followable_type == "Proposal" %> + <%= render "proposal", proposal: follow.followable %> + <% elsif followable_type == "Budget::Investment" %> + <%= render "budget_investment", budget_investment: follow.followable %> + <% end %> <% end %>
      - <%= link_to "add translation", nil %> -
      - This is longer content Donec id elit non mi porta gravida at eget metus. -
      +
    • + <% end %> +
    diff --git a/app/views/users/_proposal.html.erb b/app/views/users/_proposal.html.erb new file mode 100644 index 000000000..2a94bf021 --- /dev/null +++ b/app/views/users/_proposal.html.erb @@ -0,0 +1,25 @@ + + + <%= link_to proposal.title, proposal, proposal.retired? ? {class: 'retired'} : {} %> +
    + <%= proposal.summary %> + + + <% if author? %> + + <%= link_to t("users.proposals.send_notification"), new_proposal_notification_path(proposal_id: proposal.id), + class: 'button hollow' %> + + + + <% if proposal.retired? %> + <%= t('users.proposals.retired') %> + <% else %> + <%= link_to t('users.proposals.retire'), + retire_form_proposal_path(proposal), + class: 'button hollow alert' %> + <% end %> + + <% end %> + + diff --git a/app/views/users/_proposals.html.erb b/app/views/users/_proposals.html.erb index 3112dd572..87cc6ee2f 100644 --- a/app/views/users/_proposals.html.erb +++ b/app/views/users/_proposals.html.erb @@ -1,30 +1,6 @@ <% @proposals.each do |proposal| %> - - - - <% if author? %> - - - - <% end %> - - + <%= render "proposal", proposal: proposal %> <% end %>
    - <%= link_to proposal.title, proposal, proposal.retired? ? {class: 'retired'} : {} %> -
    - <%= proposal.summary %> -
    - <%= link_to t("users.proposals.send_notification"), new_proposal_notification_path(proposal_id: proposal.id), - class: 'button hollow' %> - - <% if proposal.retired? %> - <%= t('users.proposals.retired') %> - <% else %> - <%= link_to t('users.proposals.retire'), - retire_form_proposal_path(proposal), - class: 'button hollow alert' %> - <% end %> -
    diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 86d37f104..fb4a3d1f9 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -38,10 +38,6 @@ <% end %> <% end %> <% end %> - -
  • - Add translate -
  • <%= t("users.show.no_activity") if @activity_counts.values.inject(&:+) == 0 %> From 556e2598c3735d89dc0e993942c729c5fa7cee08 Mon Sep 17 00:00:00 2001 From: Alessandro Cuoghi Date: Mon, 3 Jul 2017 12:14:00 +0200 Subject: [PATCH 03/16] Remove margin bottom in the table inside accordion. Divided into groups of 10 interests. Inserted interests in columns. --- app/assets/stylesheets/layout.scss | 1 + app/controllers/users_controller.rb | 2 +- app/views/users/_proposal.html.erb | 11 +++++++---- app/views/users/show.html.erb | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss index 5bd9aedfd..25d569ff7 100644 --- a/app/assets/stylesheets/layout.scss +++ b/app/assets/stylesheets/layout.scss @@ -1964,6 +1964,7 @@ table { table { border: 0; + margin-bottom: 0; } td { diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2346a2017..1392472c8 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,11 +3,11 @@ class UsersController < ApplicationController load_and_authorize_resource helper_method :author? + helper_method :valid_interests_access? helper_method :author_or_admin? def show load_filtered_activity if valid_access? - load_interests if valid_interests_access? end private diff --git a/app/views/users/_proposal.html.erb b/app/views/users/_proposal.html.erb index 2a94bf021..4d8e5451b 100644 --- a/app/views/users/_proposal.html.erb +++ b/app/views/users/_proposal.html.erb @@ -1,16 +1,19 @@ - <%= link_to proposal.title, proposal, proposal.retired? ? {class: 'retired'} : {} %> + <%= link_to proposal.title, proposal, proposal.retired? ? { class: 'retired' } : {} %>
    <%= proposal.summary %> - <% if author? %> + <% if can? :retire_form, proposal %> - <%= link_to t("users.proposals.send_notification"), new_proposal_notification_path(proposal_id: proposal.id), - class: 'button hollow' %> + <%= link_to t("users.proposals.send_notification"), + new_proposal_notification_path(proposal_id: proposal.id), + class: 'button hollow' %> + <% end %> + <% if can? :new, ProposalNotification, author_id: proposal.author_id %> <% if proposal.retired? %> <%= t('users.proposals.retired') %> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index fb4a3d1f9..989e90aac 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -46,7 +46,7 @@

    <%= t('users.show.private_activity') %>

    <% end %> - <% if @user.public_interests || @authorized_current_user %> + <% if valid_interests_access? %>

    <%= t('account.show.public_interests_title_list') %>

    <% @user.interests.in_groups_of(10, false) do |interests_group| %> From b0c571e658e6e4c293e6a58e57ae0af1bb2d9062 Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 13 Jul 2017 18:39:17 +0200 Subject: [PATCH 04/16] Do not display send notification button when proposal is from another author. --- app/controllers/users_controller.rb | 9 ++------- app/models/abilities/common.rb | 2 +- app/views/users/_proposal.html.erb | 4 ++-- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1392472c8..1c425e4ac 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,7 +4,6 @@ class UsersController < ApplicationController load_and_authorize_resource helper_method :author? helper_method :valid_interests_access? - helper_method :author_or_admin? def show load_filtered_activity if valid_access? @@ -81,12 +80,8 @@ class UsersController < ApplicationController @user.public_interests || authorized_current_user? end - def author? - @author ||= current_user && (current_user == @user) - end - - def author_or_admin? - @author_or_admin ||= current_user && (author? || current_user.administrator?) + def author?(proposal) + proposal.author_id == current_user.id end def authorized_current_user? diff --git a/app/models/abilities/common.rb b/app/models/abilities/common.rb index cf183ec53..33a9d50f6 100644 --- a/app/models/abilities/common.rb +++ b/app/models/abilities/common.rb @@ -50,7 +50,7 @@ module Abilities 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" } can [:show, :create], Budget::Ballot, budget: { phase: "balloting" } can [:create, :destroy], Budget::Ballot::Line, budget: { phase: "balloting" } diff --git a/app/views/users/_proposal.html.erb b/app/views/users/_proposal.html.erb index 4d8e5451b..f5a361c19 100644 --- a/app/views/users/_proposal.html.erb +++ b/app/views/users/_proposal.html.erb @@ -5,7 +5,7 @@ <%= proposal.summary %> - <% if can? :retire_form, proposal %> + <% if author?(proposal) %> <%= link_to t("users.proposals.send_notification"), new_proposal_notification_path(proposal_id: proposal.id), @@ -13,7 +13,7 @@ <% end %> - <% if can? :new, ProposalNotification, author_id: proposal.author_id %> + <% if author?(proposal) || proposal.retired? %> <% if proposal.retired? %> <%= t('users.proposals.retired') %> From cef67c50a842550914bc1c035479e4e2782a5847 Mon Sep 17 00:00:00 2001 From: taitus Date: Thu, 13 Jul 2017 19:56:31 +0200 Subject: [PATCH 05/16] Increased test coverage to Following user public page. --- app/controllers/users_controller.rb | 2 +- spec/features/users_spec.rb | 155 ++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+), 1 deletion(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 1c425e4ac..152d41599 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -81,7 +81,7 @@ class UsersController < ApplicationController end def author?(proposal) - proposal.author_id == current_user.id + proposal.author_id == current_user.id if current_user end def authorized_current_user? diff --git a/spec/features/users_spec.rb b/spec/features/users_spec.rb index a6e9e2941..3eba5a1f6 100644 --- a/spec/features/users_spec.rb +++ b/spec/features/users_spec.rb @@ -357,4 +357,159 @@ feature 'Users' do end end + feature 'Following (public page)' do + + before do + @user = create(:user) + end + + scenario 'Not display following tab when user is not following any followable' do + visit user_path(@user) + + expect(page).not_to have_content('0 Following') + end + + scenario 'Active following tab by default when follows filters selected', :js do + proposal = create(:proposal, author: @user) + create(:follow, followable: proposal, user: @user) + + visit user_path(@user, filter: "follows") + + expect(page).to have_selector(".activity li.active", text: "1 Following" ) + end + + describe 'Proposals' do + + scenario 'Display following tab when user is following one proposal at least' do + proposal = create(:proposal) + create(:follow, followable: proposal, user: @user) + + visit user_path(@user) + + expect(page).to have_content('1 Following') + end + + scenario 'Display accordion proposal tab when user is following one proposal at least' do + proposal = create(:proposal) + create(:follow, followable: proposal, user: @user) + + visit user_path(@user, filter: "follows") + + expect(page).to have_link('Citizen proposals', href: "#") + end + + scenario 'Not display accordion proposal tab when user is not following any proposal' do + visit user_path(@user, filter: "follows") + + expect(page).not_to have_link('Citizen proposals', href: "#") + end + + scenario 'Display proposal with action buttons inside accordion proposal tab when current user is proposal author', :js do + proposal = create(:proposal, author: @user) + create(:follow, followable: proposal, user: @user) + login_as @user + + visit user_path(@user, filter: "follows") + click_link 'Citizen proposals' + + expect(page).to have_content proposal.title + expect(page).to have_link "Send notification" + expect(page).to have_link "Retire" + end + + scenario 'Display proposal with action buttons inside accordion proposal tab when there is no logged user', :js do + proposal = create(:proposal, author: @user) + create(:follow, followable: proposal, user: @user) + + visit user_path(@user, filter: "follows") + click_link 'Citizen proposals' + + expect(page).to have_content proposal.title + expect(page).not_to have_link "Send notification" + expect(page).not_to have_link "Retire" + end + + scenario 'Display proposal without action buttons inside accordion proposal tab when current user is not proposal author', :js do + proposal = create(:proposal) + create(:follow, followable: proposal, user: @user) + login_as @user + + visit user_path(@user, filter: "follows") + click_link 'Citizen proposals' + + expect(page).to have_content proposal.title + expect(page).not_to have_link "Send notification" + expect(page).not_to have_link "Retire" + end + + end + + describe 'Budget Investments' do + + scenario 'Display following tab when user is following one budget investment at least' do + budget_investment = create(:budget_investment) + create(:follow, followable: budget_investment, user: @user) + + visit user_path(@user) + + expect(page).to have_content('1 Following') + end + + scenario 'Display accordion budget investment tab when user is following one budget investment at least' do + budget_investment = create(:budget_investment) + create(:follow, followable: budget_investment, user: @user) + + visit user_path(@user, filter: "follow") + + expect(page).to have_link('Investments', href: "#") + end + + scenario 'Not display accordion budget investment tab when user is not following any budget investment' do + visit user_path(@user, filter: "follow") + + expect(page).not_to have_link('Investments', href: "#") + end + + scenario 'Display budget investment with action buttons inside accordion budget investment tab when current user is a verified user and author', :js do + user = create(:user, :level_two) + budget_investment = create(:budget_investment, author: user) + create(:follow, followable: budget_investment, user: user) + login_as user + + visit user_path(user, filter: "follows") + click_link 'Investments' + + expect(page).to have_link budget_investment.title + expect(page).to have_link "Delete" + end + + scenario 'Display budget investment with action buttons inside accordion budget investment tab when there is no logged user', :js do + user = create(:user, :level_two) + budget_investment = create(:budget_investment, author: user) + create(:follow, followable: budget_investment, user: user) + + visit user_path(user, filter: "follows") + click_link 'Investments' + + expect(page).to have_link budget_investment.title + expect(page).not_to have_link "Delete" + end + + scenario 'Display budget investment without action buttons inside accordion budget investment tab when current user is not budget investment author', :js do + user = create(:user, :level_two) + budget_investment = create(:budget_investment) + create(:follow, followable: budget_investment, user: user) + login_as user + + visit user_path(user, filter: "follows") + click_link 'Investments' + + expect(page).to have_link budget_investment.title + expect(page).not_to have_link "Delete" + end + + end + + end + end From 36f9836e680d1a656ce439a1cb1fb2ee6225739e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Tue, 18 Jul 2017 19:12:24 +0200 Subject: [PATCH 06/16] Use inflector methods instead of manual replacements. --- app/helpers/follows_helper.rb | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/helpers/follows_helper.rb b/app/helpers/follows_helper.rb index 60ee0141f..cab18bbeb 100644 --- a/app/helpers/follows_helper.rb +++ b/app/helpers/follows_helper.rb @@ -9,23 +9,22 @@ module FollowsHelper end def follow_entity_text(followable) - entity = followable.class.name.gsub('::', '/').downcase + entity = followable.class.name.underscore t('shared.follow_entity', entity: t("activerecord.models.#{entity}.one").downcase) end def follow_entity_title(followable) - entity = followable.class.name.gsub('::', '/').downcase + entity = followable.class.name.underscore t('shared.follow_entity_title', entity: t("activerecord.models.#{entity}.one").downcase) end def unfollow_entity_text(followable) - entity = followable.class.name.gsub('::', '/').downcase + entity = followable.class.name.underscore t('shared.unfollow_entity', entity: t("activerecord.models.#{entity}.one").downcase) end def entity_full_name(followable) - name = followable.class.name - name.downcase.gsub("::", "-") + followable.class.name.parameterize end def follow_link_wrapper_id(followable) @@ -53,8 +52,7 @@ module FollowsHelper end def entity_title(title) - entity = title.gsub('::', '/').downcase - t("activerecord.models.#{entity}.other") + t("activerecord.models.#{title.underscore}.other") end def entity_icon(entity) From 249641fe2318dd48a2cc0aa0414cc7ff3bdbd3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Tue, 18 Jul 2017 19:16:48 +0200 Subject: [PATCH 07/16] Simpler code to get followable object icon. --- app/helpers/follows_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/follows_helper.rb b/app/helpers/follows_helper.rb index cab18bbeb..e4923f2b9 100644 --- a/app/helpers/follows_helper.rb +++ b/app/helpers/follows_helper.rb @@ -56,10 +56,10 @@ module FollowsHelper end def entity_icon(entity) - case entity - when "Proposal" then "proposals" - when "Budget::Investment" then "budget" - end + { + proposals: 'Proposal', + budget: 'Budget::Investment' + }.invert[entity] end private From 16987e7eb8bc6cb4c95255b9cb3e666adfe7c9d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Tue, 18 Jul 2017 19:21:17 +0200 Subject: [PATCH 08/16] Easier conditional usage. --- app/views/users/_proposal.html.erb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/views/users/_proposal.html.erb b/app/views/users/_proposal.html.erb index f5a361c19..cd41de6f8 100644 --- a/app/views/users/_proposal.html.erb +++ b/app/views/users/_proposal.html.erb @@ -5,15 +5,16 @@ <%= proposal.summary %> - <% if author?(proposal) %> + <% if proposal.retired? %> + <%= link_to t("users.proposals.send_notification"), new_proposal_notification_path(proposal_id: proposal.id), class: 'button hollow' %> - <% end %> - <% if author?(proposal) || proposal.retired? %> + <% elsif author?(proposal) %> + <% if proposal.retired? %> <%= t('users.proposals.retired') %> @@ -23,6 +24,7 @@ class: 'button hollow alert' %> <% end %> + <% end %> From 57c8887077164f4a2cabc919be33e15654261708 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sen=C3=A9n=20Rodero=20Rodr=C3=ADguez?= Date: Tue, 18 Jul 2017 19:30:14 +0200 Subject: [PATCH 09/16] Add method to follows helper to get followable partial name and arguments automatically. --- app/helpers/follows_helper.rb | 4 ++++ app/views/users/_following.html.erb | 7 ++----- app/views/users/_proposal.html.erb | 8 ++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/helpers/follows_helper.rb b/app/helpers/follows_helper.rb index e4923f2b9..b04835b95 100644 --- a/app/helpers/follows_helper.rb +++ b/app/helpers/follows_helper.rb @@ -62,6 +62,10 @@ module FollowsHelper }.invert[entity] end + def entity_partial(class_name) + class_name.parameterize.gsub('-','_') + end + private def followed?(followable) diff --git a/app/views/users/_following.html.erb b/app/views/users/_following.html.erb index defac258a..110d012aa 100644 --- a/app/views/users/_following.html.erb +++ b/app/views/users/_following.html.erb @@ -17,11 +17,8 @@ <% @follows.where(followable_type: followable_type).each do |follow| %> - <% if followable_type == "Proposal" %> - <%= render "proposal", proposal: follow.followable %> - <% elsif followable_type == "Budget::Investment" %> - <%= render "budget_investment", budget_investment: follow.followable %> - <% end %> + <%= render entity_partial(followable_type), + entity_partial(followable_type).to_sym => follow.followable %> <% end %>
    diff --git a/app/views/users/_proposal.html.erb b/app/views/users/_proposal.html.erb index cd41de6f8..9144de099 100644 --- a/app/views/users/_proposal.html.erb +++ b/app/views/users/_proposal.html.erb @@ -7,14 +7,18 @@ <% if proposal.retired? %> + + <%= t('users.proposals.retired') %> + + + <% elsif author?(proposal) %> + <%= link_to t("users.proposals.send_notification"), new_proposal_notification_path(proposal_id: proposal.id), class: 'button hollow' %> - <% elsif author?(proposal) %> - <% if proposal.retired? %> <%= t('users.proposals.retired') %> From b7ef755b16689d59171ea31135c9802e219c06c7 Mon Sep 17 00:00:00 2001 From: rgarcia Date: Wed, 19 Jul 2017 13:52:38 +0200 Subject: [PATCH 10/16] minor refactoring for follows --- app/controllers/users_controller.rb | 3 +-- app/helpers/follows_helper.rb | 12 ++++++++++-- app/views/users/_following.html.erb | 7 +++---- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 152d41599..ae3ce3692 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -68,8 +68,7 @@ class UsersController < ApplicationController end def load_follows - @followable_types = @user.follows.pluck(:followable_type).uniq - @follows = @user.follows + @follows = @user.follows.group_by(&:followable_type) end def valid_access? diff --git a/app/helpers/follows_helper.rb b/app/helpers/follows_helper.rb index b04835b95..2b09ccb67 100644 --- a/app/helpers/follows_helper.rb +++ b/app/helpers/follows_helper.rb @@ -62,8 +62,16 @@ module FollowsHelper }.invert[entity] end - def entity_partial(class_name) - class_name.parameterize.gsub('-','_') + def entity_class_name(followable) + followable.class.to_s.parameterize.gsub('-','_') + end + + def render_follow(follow) + followable = follow.followable + partial = entity_class_name(followable) + locals = {entity_class_name(followable).to_sym => followable} + + render partial, locals end private diff --git a/app/views/users/_following.html.erb b/app/views/users/_following.html.erb index 110d012aa..83729c2f4 100644 --- a/app/views/users/_following.html.erb +++ b/app/views/users/_following.html.erb @@ -1,6 +1,6 @@