Use the vote action to vote featured proposals

The action and the views were almost identical, with the supports
progress and the HTML classes of the success message element being the
only exceptions; we can use CSS for the styles instead.
This commit is contained in:
Javi Martín
2021-09-28 20:02:41 +02:00
parent b98244afd9
commit 4b42a68b6a
14 changed files with 17 additions and 64 deletions

View File

@@ -1038,6 +1038,7 @@
content: none;
}
.progress,
.total-supports {
display: none;
}
@@ -1070,7 +1071,11 @@
}
.supported {
background: none;
border: 0;
margin-bottom: 0;
margin-top: 0;
padding: 0;
font-size: $small-font-size;
}
}

View File

@@ -1,9 +1,13 @@
class Proposals::VotesComponent < ApplicationComponent
attr_reader :proposal, :vote_url
attr_reader :proposal
delegate :current_user, :link_to_verify_account, :user_signed_in?, to: :helpers
def initialize(proposal, vote_url:)
def initialize(proposal, vote_url: nil)
@proposal = proposal
@vote_url = vote_url
end
def vote_url
@vote_url || vote_proposal_path(proposal, value: "yes")
end
end

View File

@@ -71,11 +71,6 @@ class ProposalsController < ApplicationController
def retire_form
end
def vote_featured
@follow = Follow.find_or_create_by!(user: current_user, followable: @proposal)
@proposal.register_vote(current_user, "yes")
end
def summary
@proposals = Proposal.for_summary
@tag_cloud = tag_cloud

View File

@@ -85,7 +85,6 @@ module Abilities
if user.level_two_or_three_verified?
can :vote, Proposal, &:published?
can :vote_featured, Proposal
can :vote, Legislation::Proposal
can :create, Legislation::Answer

View File

@@ -22,6 +22,6 @@
</div>
<div id="<%= dom_id(proposal) %>_votes" class="small-12 medium-3 column">
<%= render "featured_votes", proposal: proposal %>
<%= render Proposals::VotesComponent.new(proposal) %>
</div>
</div>

View File

@@ -1,43 +0,0 @@
<div class="supports text-center">
<div class="in-favor">
<% if current_user&.voted_for?(proposal) %>
<div class="supported">
<%= t("proposals.proposal.already_supported") %>
</div>
<% else %>
<%= link_to vote_featured_proposal_path(proposal, value: "yes"),
class: "button button-support small expanded",
title: t("proposals.proposal.support_title"), method: "post", remote: true do %>
<%= t("proposals.proposal.support") %>
<% end %>
<% end %>
</div>
<% if user_signed_in? && current_user.organization? %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= t("votes.organizations") %>
</p>
</div>
<% elsif user_signed_in? && !proposal.votable_by?(current_user) %>
<div class="participation-not-allowed" style="display:none" aria-hidden="false">
<p>
<%= sanitize(t("votes.verified_only", verify_account: link_to_verify_account)) %>
</p>
</div>
<% elsif !user_signed_in? %>
<%= render "shared/login_to_vote" %>
<% end %>
<% if current_user&.voted_for?(proposal) %>
<% if setting["twitter_handle"] %>
<div class="share-supported">
<%= render "shared/social_share",
title: proposal.title,
url: proposal_url(proposal),
description: proposal.summary,
mobile: proposal.title %>
</div>
<% end %>
<% end %>
</div>

View File

@@ -77,8 +77,7 @@
<p><%= t("proposals.proposal.archived") %></p>
</div>
<% else %>
<%= render "votes",
{ proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %>
<%= render "votes", proposal: proposal %>
<% end %>
</div>
<% end %>

View File

@@ -32,7 +32,7 @@
<p><%= t("proposals.proposal.archived") %></p>
</div>
<% else %>
<%= render "votes", { proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %>
<%= render "votes", proposal: proposal %>
<% end %>
</div>
</div>

View File

@@ -1 +1 @@
<%= render Proposals::VotesComponent.new(proposal, vote_url: vote_url) %>
<%= render Proposals::VotesComponent.new(proposal, vote_url: local_assigns[:vote_url]) %>

View File

@@ -1,4 +1,4 @@
$("#<%= dom_id(@proposal) %>_votes").html("<%= j render("proposals/votes", proposal: @proposal, vote_url: nil) %>");
$("#<%= dom_id(@proposal) %>_votes").html("<%= j render("proposals/votes", proposal: @proposal) %>");
App.Followable.update("<%= dom_id(@follow.followable) %>",
"<%= j render("follows/follow_button", follow: @follow) %>",
"<%= j render("layouts/flash") %>")

View File

@@ -1 +0,0 @@
$("#<%= dom_id(@proposal) %>_votes").html("<%= j render("proposals/featured_votes", proposal: @proposal) %>");

View File

@@ -1,2 +1 @@
<%= render "proposals/votes",
{ proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %>
<%= render "proposals/votes", proposal: proposal %>

View File

@@ -34,7 +34,6 @@ resources :proposals do
member do
post :vote
post :vote_featured
put :flag
put :unflag
get :retire_form

View File

@@ -69,7 +69,6 @@ describe Abilities::Common do
it { should be_able_to(:index, Proposal) }
it { should be_able_to(:show, proposal) }
it { should_not be_able_to(:vote, Proposal) }
it { should_not be_able_to(:vote_featured, Proposal) }
it { should_not be_able_to(:comment_as_administrator, debate) }
it { should_not be_able_to(:comment_as_moderator, debate) }
@@ -212,7 +211,6 @@ describe Abilities::Common do
describe "Proposal" do
it { should be_able_to(:vote, Proposal) }
it { should be_able_to(:vote_featured, Proposal) }
end
describe "Direct Message" do
@@ -292,7 +290,6 @@ describe Abilities::Common do
before { user.update(verified_at: Time.current) }
it { should be_able_to(:vote, Proposal) }
it { should be_able_to(:vote_featured, Proposal) }
it { should be_able_to(:new, DirectMessage) }
it { should be_able_to(:create, DirectMessage) }