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:
@@ -1038,6 +1038,7 @@
|
|||||||
content: none;
|
content: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.progress,
|
||||||
.total-supports {
|
.total-supports {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
@@ -1070,7 +1071,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.supported {
|
.supported {
|
||||||
|
background: none;
|
||||||
|
border: 0;
|
||||||
|
margin-bottom: 0;
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
|
padding: 0;
|
||||||
font-size: $small-font-size;
|
font-size: $small-font-size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
class Proposals::VotesComponent < ApplicationComponent
|
class Proposals::VotesComponent < ApplicationComponent
|
||||||
attr_reader :proposal, :vote_url
|
attr_reader :proposal
|
||||||
delegate :current_user, :link_to_verify_account, :user_signed_in?, to: :helpers
|
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
|
@proposal = proposal
|
||||||
@vote_url = vote_url
|
@vote_url = vote_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def vote_url
|
||||||
|
@vote_url || vote_proposal_path(proposal, value: "yes")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -71,11 +71,6 @@ class ProposalsController < ApplicationController
|
|||||||
def retire_form
|
def retire_form
|
||||||
end
|
end
|
||||||
|
|
||||||
def vote_featured
|
|
||||||
@follow = Follow.find_or_create_by!(user: current_user, followable: @proposal)
|
|
||||||
@proposal.register_vote(current_user, "yes")
|
|
||||||
end
|
|
||||||
|
|
||||||
def summary
|
def summary
|
||||||
@proposals = Proposal.for_summary
|
@proposals = Proposal.for_summary
|
||||||
@tag_cloud = tag_cloud
|
@tag_cloud = tag_cloud
|
||||||
|
|||||||
@@ -85,7 +85,6 @@ module Abilities
|
|||||||
|
|
||||||
if user.level_two_or_three_verified?
|
if user.level_two_or_three_verified?
|
||||||
can :vote, Proposal, &:published?
|
can :vote, Proposal, &:published?
|
||||||
can :vote_featured, Proposal
|
|
||||||
|
|
||||||
can :vote, Legislation::Proposal
|
can :vote, Legislation::Proposal
|
||||||
can :create, Legislation::Answer
|
can :create, Legislation::Answer
|
||||||
|
|||||||
@@ -22,6 +22,6 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="<%= dom_id(proposal) %>_votes" class="small-12 medium-3 column">
|
<div id="<%= dom_id(proposal) %>_votes" class="small-12 medium-3 column">
|
||||||
<%= render "featured_votes", proposal: proposal %>
|
<%= render Proposals::VotesComponent.new(proposal) %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -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>
|
|
||||||
@@ -77,8 +77,7 @@
|
|||||||
<p><%= t("proposals.proposal.archived") %></p>
|
<p><%= t("proposals.proposal.archived") %></p>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= render "votes",
|
<%= render "votes", proposal: proposal %>
|
||||||
{ proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|||||||
@@ -32,7 +32,7 @@
|
|||||||
<p><%= t("proposals.proposal.archived") %></p>
|
<p><%= t("proposals.proposal.archived") %></p>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= render "votes", { proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %>
|
<%= render "votes", proposal: proposal %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<%= render Proposals::VotesComponent.new(proposal, vote_url: vote_url) %>
|
<%= render Proposals::VotesComponent.new(proposal, vote_url: local_assigns[:vote_url]) %>
|
||||||
|
|||||||
@@ -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) %>",
|
App.Followable.update("<%= dom_id(@follow.followable) %>",
|
||||||
"<%= j render("follows/follow_button", follow: @follow) %>",
|
"<%= j render("follows/follow_button", follow: @follow) %>",
|
||||||
"<%= j render("layouts/flash") %>")
|
"<%= j render("layouts/flash") %>")
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
$("#<%= dom_id(@proposal) %>_votes").html("<%= j render("proposals/featured_votes", proposal: @proposal) %>");
|
|
||||||
@@ -1,2 +1 @@
|
|||||||
<%= render "proposals/votes",
|
<%= render "proposals/votes", proposal: proposal %>
|
||||||
{ proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %>
|
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ resources :proposals do
|
|||||||
|
|
||||||
member do
|
member do
|
||||||
post :vote
|
post :vote
|
||||||
post :vote_featured
|
|
||||||
put :flag
|
put :flag
|
||||||
put :unflag
|
put :unflag
|
||||||
get :retire_form
|
get :retire_form
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ describe Abilities::Common do
|
|||||||
it { should be_able_to(:index, Proposal) }
|
it { should be_able_to(:index, Proposal) }
|
||||||
it { should be_able_to(:show, proposal) }
|
it { should be_able_to(:show, proposal) }
|
||||||
it { should_not be_able_to(:vote, 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_administrator, debate) }
|
||||||
it { should_not be_able_to(:comment_as_moderator, debate) }
|
it { should_not be_able_to(:comment_as_moderator, debate) }
|
||||||
@@ -212,7 +211,6 @@ describe Abilities::Common do
|
|||||||
|
|
||||||
describe "Proposal" do
|
describe "Proposal" do
|
||||||
it { should be_able_to(:vote, Proposal) }
|
it { should be_able_to(:vote, Proposal) }
|
||||||
it { should be_able_to(:vote_featured, Proposal) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Direct Message" do
|
describe "Direct Message" do
|
||||||
@@ -292,7 +290,6 @@ describe Abilities::Common do
|
|||||||
before { user.update(verified_at: Time.current) }
|
before { user.update(verified_at: Time.current) }
|
||||||
|
|
||||||
it { should be_able_to(:vote, Proposal) }
|
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(:new, DirectMessage) }
|
||||||
it { should be_able_to(:create, DirectMessage) }
|
it { should be_able_to(:create, DirectMessage) }
|
||||||
|
|||||||
Reference in New Issue
Block a user