Skip to content

Commit

Permalink
rename voting_cards manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
microstudi committed Nov 2, 2023
1 parent 5768ddd commit 4439849
Show file tree
Hide file tree
Showing 26 changed files with 78 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Decidim
module DecidimAwesome
module Voting
class ThreeFlagsBaseCell < Decidim::ViewModel
class VotingCardsBaseCell < Decidim::ViewModel
include Decidim::IconHelper
include Decidim::ComponentPathHelper
include Decidim::Proposals::ProposalVotesHelper
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<% unless proposal.rejected? || proposal.withdrawn? %>
<% unless current_settings.votes_hidden? %>
<span class="votes_counter">
<span data-weight="3" title="<%= proposal.manifest.label_for(3) %>" class="text-success"><%= t("decidim.decidim_awesome.voting.three_flags.weights.g") %>: <%= model.weight_count(3) %></span> |
<span data-weight="2" title="<%= proposal.manifest.label_for(2) %>" class="text-warning"><%= t("decidim.decidim_awesome.voting.three_flags.weights.y") %>: <%= model.weight_count(2) %></span> |
<span data-weight="1" title="<%= proposal.manifest.label_for(1) %>" class="text-alert"><%= t("decidim.decidim_awesome.voting.three_flags.weights.r") %>: <%= model.weight_count(1) %></span>
<% if current_component.settings.three_flags_show_abstain %>
| <span title="<%= proposal.manifest.label_for(0) %>" data-weight="0"><%= t("decidim.decidim_awesome.voting.three_flags.weights.a") %>: <%= model.weight_count(0) %></span>
<span data-weight="3" title="<%= proposal.manifest.label_for(3) %>" class="text-success"><%= t("decidim.decidim_awesome.voting.voting_cards.weights.g") %>: <%= model.weight_count(3) %></span> |
<span data-weight="2" title="<%= proposal.manifest.label_for(2) %>" class="text-warning"><%= t("decidim.decidim_awesome.voting.voting_cards.weights.y") %>: <%= model.weight_count(2) %></span> |
<span data-weight="1" title="<%= proposal.manifest.label_for(1) %>" class="text-alert"><%= t("decidim.decidim_awesome.voting.voting_cards.weights.r") %>: <%= model.weight_count(1) %></span>
<% if current_component.settings.voting_cards_show_abstain %>
| <span title="<%= proposal.manifest.label_for(0) %>" data-weight="0"><%= t("decidim.decidim_awesome.voting.voting_cards.weights.a") %>: <%= model.weight_count(0) %></span>
<% end %>
</span>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<%= link_to resource_path,
class: "button #{vote_btn_class} small button--sc#{" disabled" if current_settings.votes_blocked?}",
title: t("decidim.decidim_awesome.voting.three_flags.vote_button") do %>
title: t("decidim.decidim_awesome.voting.voting_cards.vote_button") do %>
<% if user_voted_weight %>
<%= icon "actions", class: "icon" %> <%= t("decidim.decidim_awesome.voting.three_flags.voted") %>
<%= icon "actions", class: "icon" %> <%= t("decidim.decidim_awesome.voting.voting_cards.voted") %>
<% elsif proposal.maximum_votes_reached? && !proposal.can_accumulate_supports_beyond_threshold && current_component.participatory_space.can_participate?(current_user) %>
<%= t("decidim.proposals.proposals.vote_button.maximum_votes_reached") %>
<% elsif vote_limit_enabled? && remaining_votes_count_for(current_user) <= 0 %>
<%= t("decidim.proposals.proposals.vote_button.no_votes_remaining") %>
<% elsif current_settings.votes_blocked? || !current_component.participatory_space.can_participate?(current_user) %>
<%= t("decidim.proposals.proposals.vote_button.votes_blocked") %>
<% else %>
<%= t("decidim.decidim_awesome.voting.three_flags.vote_button") %>
<%= t("decidim.decidim_awesome.voting.voting_cards.vote_button") %>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Decidim
module DecidimAwesome
module Voting
class ThreeFlagsCounterCell < ThreeFlagsBaseCell
class VotingCardsCounterCell < VotingCardsBaseCell
COLORS = { 1 => "alert", 2 => "warning", 3 => "success" }.freeze
BUTTON_CLASSES = { 0 => "hollow", 1 => "danger", 2 => "warning", 3 => "success" }.freeze

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
<%= vote_block_for(proposal, 1) %>
</div>

<% if component_settings.three_flags_show_abstain? %>
<% if component_settings.voting_cards_show_abstain? %>
<%= action_authorized_link_to :vote,
voted_for?(0) ? t("decidim.decidim_awesome.voting.three_flags.abstained") : proposal.manifest.label_for(0),
voted_for?(0) ? t("decidim.decidim_awesome.voting.voting_cards.abstained") : proposal.manifest.label_for(0),
proposal_vote_path(0),
link_options(0).merge({
title: t("decidim.decidim_awesome.voting.three_flags.voting_for", type: proposal.manifest.label_for(0)),
title: t("decidim.decidim_awesome.voting.voting_cards.voting_for", type: proposal.manifest.label_for(0)),
class: "button secondary hollow expanded vote-action abstain-button small #{classes_for(0)}"
}) %>
<% end %>

<% if voted_for_any? && !current_settings.votes_blocked? %>
<p class="text-center">
<%= action_authorized_link_to :unvote,
t("decidim.decidim_awesome.voting.three_flags.change_vote"),
t("decidim.decidim_awesome.voting.voting_cards.change_vote"),
proposal_vote_path(current_vote&.weight),
remote: true,
method: :delete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
**link_options(weight) do %>
<span class="vote-label"><%= proposal.manifest.label_for(weight) %></span>
<%= content_tag :svg, role: "img" do
content_tag(:title, t("decidim.decidim_awesome.voting.three_flags.voting_for", type: proposal.manifest.label_for(weight))) +
content_tag(:title, t("decidim.decidim_awesome.voting.voting_cards.voting_for", type: proposal.manifest.label_for(weight))) +
content_tag(:use, "", "href" => svg_path(weight))
end %>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Decidim
module DecidimAwesome
module Voting
class ThreeFlagsProposalCell < ThreeFlagsBaseCell
class VotingCardsProposalCell < VotingCardsBaseCell
VOTE_WEIGHTS = [0, 1, 2, 3].freeze

def show
Expand Down Expand Up @@ -76,10 +76,10 @@ def voted_for_any?
end

def title
txt ||= translated_attribute(current_component.settings.three_flags_box_title)
txt ||= translated_attribute(current_component.settings.voting_cards_box_title)
return "" if txt == "-"

txt.presence || t("decidim.decidim_awesome.voting.three_flags.default_box_title")
txt.presence || t("decidim.decidim_awesome.voting.voting_cards.default_box_title")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<!--the modal window will be used in another pr-->
<div class="reveal vote_proposal_modal voting-three-flag" id="threeFlagsModalHelp" data-reveal role="dialog" aria-modal="true" aria-labelledby="threeFlagsModalHelp-label">
<div class="reveal vote_proposal_modal voting-three-flag" id="VotingCardsModalHelp" data-reveal role="dialog" aria-modal="true" aria-labelledby="VotingCardsModalHelp-label">
<div class="reveal__content">
<div class="instructions"><%= vote_instructions %></div>
<div class="current-choice voting-three-flags"><div class="vote-card"></div></div>
<div class="current-choice voting-voting_cards"><div class="vote-card"></div></div>
<div class="future-dismiss">
<%= check_box_tag "three_flag-skip_help", current_component.id, false %>
<%= label_tag "three_flag-skip_help", t("decidim.decidim_awesome.voting.three_flags.modal.skip") %>
<%= label_tag "three_flag-skip_help", t("decidim.decidim_awesome.voting.voting_cards.modal.skip") %>
</div>

<div class="text-center">
<button class="button vote-action"><%= t("decidim.decidim_awesome.voting.three_flags.modal.proceed") %></button>
<button class="button cancel-action hollow secondary" data-close><%= t("decidim.decidim_awesome.voting.three_flags.modal.cancel") %></button>
<button class="button vote-action"><%= t("decidim.decidim_awesome.voting.voting_cards.modal.proceed") %></button>
<button class="button cancel-action hollow secondary" data-close><%= t("decidim.decidim_awesome.voting.voting_cards.modal.cancel") %></button>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
module Decidim
module DecidimAwesome
module Voting
class ThreeFlagsProposalModalCell < ThreeFlagsBaseCell
class VotingCardsProposalModalCell < VotingCardsBaseCell
include Decidim::Proposals::Engine.routes.url_helpers

def show
render :show
end

def vote_instructions
translated_attribute(current_component.settings.three_flags_instructions).presence || t("decidim.decidim_awesome.voting.three_flags.default_instructions_html",
organization: current_organization.name)
translated_attribute(current_component.settings.voting_cards_instructions).presence || t("decidim.decidim_awesome.voting.voting_cards.default_instructions_html",
organization: current_organization.name)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "src/decidim/decidim_awesome/proposals/images"
import "src/decidim/decidim_awesome/forms/autosave"
import "src/decidim/decidim_awesome/voting/three_flags"
import "src/decidim/decidim_awesome/voting/voting_cards"
import {destroyQuillEditor, createQuillEditor, createMarkdownEditor} from "src/decidim/decidim_awesome/editors/editor"

$(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
$(() => {
if ($(".voting-three-flags").length === 0 || $("#threeFlagsModalHelp").length === 0 || $(".sign-out-link").length === 0) {
if ($(".voting-voting_cards").length === 0 || $("#VotingCardsModalHelp").length === 0 || $(".sign-out-link").length === 0) {
return;
}

const $modal = $("#threeFlagsModalHelp");
const $modal = $("#VotingCardsModalHelp");
const $card = $modal.find(".current-choice .vote-card");
const $check = $("#three_flag-skip_help");

Expand Down Expand Up @@ -40,7 +40,7 @@ $(() => {
$modal.foundation("close");
});

$(".button--vote-button .voting-three-flags").on("click", ".vote-action", (evt) => {
$(".button--vote-button .voting-voting_cards").on("click", ".vote-action", (evt) => {
if (showModal()) {
evt.stopPropagation();
evt.preventDefault();
Expand All @@ -57,7 +57,7 @@ $(() => {
}
$modal.foundation("open");
} else {
$(evt.currentTarget).closest(".voting-three-flags").addClass("loading");
$(evt.currentTarget).closest(".voting-voting_cards").addClass("loading");
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@import "stylesheets/decidim/decidim_awesome/editors/markdown_editor";
@import "stylesheets/decidim/decidim_awesome/editors/quill_editor";
@import "stylesheets/decidim/decidim_awesome/forms/autosave";
@import "stylesheets/decidim/decidim_awesome/voting/three_flags";
@import "stylesheets/decidim/decidim_awesome/voting/voting_cards";

.decidim_awesome-custom_fields {
dd {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.voting-three-flags {
.voting-voting_cards {
$rectangle-width: 3rem;
$green-color: #4caf50;
$yellow-color: #ffc107;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="card__footer">
<div class="card__support" style="display: block">
<% if has_actions? %>
<div class="flex--sbc voting-three-flags-card" id="proposal-<%= model.id %>-votes-count"><%= cell("decidim/decidim_awesome/voting/three_flags_counter", model) %></div>
<div class="flex--sbc voting-voting_cards-card" id="proposal-<%= model.id %>-votes-count"><%= cell("decidim/decidim_awesome/voting/voting_cards_counter", model) %></div>
<% elsif has_footer? %>
<div class="card__support__data"></div>
<%= link_to resource_path, class: "card__button button--sc light button small" do %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="voting-three-flags">
<%= cell("decidim/decidim_awesome/voting/three_flags_proposal", proposal, from_proposals_list: true) %>
<% if current_component.settings.three_flags_show_modal_help %>
<%= cell("decidim/decidim_awesome/voting/three_flags_proposal_modal", proposal) %>
<div class="voting-voting_cards">
<%= cell("decidim/decidim_awesome/voting/voting_cards_proposal", proposal, from_proposals_list: true) %>
<% if current_component.settings.voting_cards_show_modal_help %>
<%= cell("decidim/decidim_awesome/voting/voting_cards_proposal_modal", proposal) %>
<% end %>
</div>
16 changes: 8 additions & 8 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,21 +128,21 @@ en:
setting can only be edited if the component has no supports yet.
awesome_voting_manifest_options:
default: Simple vote (default)
three_flags: Voting using coloured cards
voting_cards: Voting using coloured cards
default_sort_order_options:
az: A-Z (Alphabetical)
supported_first: Supported first
supported_last: Supported last
za: Z-A (Reverse alphabetical)
three_flags_box_title: Title for the voting box
three_flags_box_title_help: Default is "Vote on this proposal". Use "-"
voting_cards_box_title: Title for the voting box
voting_cards_box_title_help: Default is "Vote on this proposal". Use "-"
to hide it.
three_flags_instructions: Support instructions/help (dissmissable modal
voting_cards_instructions: Support instructions/help (dissmissable modal
window)
three_flags_instructions_help: Default is "Please read the election rules
voting_cards_instructions_help: Default is "Please read the election rules
carefully to understand how your vote will be used by %{organization}""
three_flags_show_abstain: Add an abstention option
three_flags_show_modal_help: Show instructions/help modal when support
voting_cards_show_abstain: Add an abstention option
voting_cards_show_modal_help: Show instructions/help modal when support
is clicked
step:
default_sort_order_options:
Expand Down Expand Up @@ -513,7 +513,7 @@ en:
too_much_caps: Is using too many capital letters (over %{percent}% of the
text)
voting:
three_flags:
voting_cards:
abstained: "✔ Abstained"
change_vote: Change my vote
default_box_title: Vote on this proposal
Expand Down
18 changes: 9 additions & 9 deletions lib/decidim/decidim_awesome/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ class Engine < ::Rails::Engine
initializer "decidim_decidim_awesome.weighted_proposal_voting" do |_app|
if DecidimAwesome.enabled?(:weighted_proposal_voting)
# register available processors
Decidim::DecidimAwesome.voting_registry.register(:three_flags) do |voting|
voting.show_vote_button_view = "decidim/decidim_awesome/voting/three_flags/show_vote_button"
voting.show_votes_count_view = "decidim/decidim_awesome/voting/three_flags/show_votes_count"
Decidim::DecidimAwesome.voting_registry.register(:voting_cards) do |voting|
voting.show_vote_button_view = "decidim/decidim_awesome/voting/voting_cards/show_vote_button"
voting.show_votes_count_view = "decidim/decidim_awesome/voting/voting_cards/show_votes_count"
voting.show_votes_count_view = "" # hide votes count if needed
voting.proposal_m_cell_footer = "decidim/decidim_awesome/voting/three_flags/proposal_m_cell_footer"
voting.proposal_m_cell_footer = "decidim/decidim_awesome/voting/voting_cards/proposal_m_cell_footer"
voting.weight_validator do |weight, context|
allowed = [1, 2, 3]
allowed << 0 if context[:proposal]&.component&.settings&.three_flags_show_abstain
allowed << 0 if context[:proposal]&.component&.settings&.voting_cards_show_abstain
weight.in? allowed
end
end
Expand All @@ -138,16 +138,16 @@ class Engine < ::Rails::Engine
readonly: lambda { |context|
Decidim::Proposals::Proposal.where(component: context[:component]).where.not(proposal_votes_count: 0).any?
}
settings.attribute :three_flags_box_title,
settings.attribute :voting_cards_box_title,
type: :string,
translated: true
settings.attribute :three_flags_show_modal_help,
settings.attribute :voting_cards_show_modal_help,
type: :boolean,
default: true
settings.attribute :three_flags_show_abstain,
settings.attribute :voting_cards_show_abstain,
type: :boolean,
default: false
settings.attribute :three_flags_instructions,
settings.attribute :voting_cards_instructions,
type: :text,
translated: true,
editor: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
module Decidim
module DecidimAwesome
module Voting
describe ThreeFlagsBaseCell, type: :cell do
subject { cell("decidim/decidim_awesome/voting/three_flags_base", proposal, context: { current_user: user }) }
describe VotingCardsBaseCell, type: :cell do
subject { cell("decidim/decidim_awesome/voting/voting_cards_base", proposal, context: { current_user: user }) }

let(:manifest) { :three_flags }
let(:manifest) { :voting_cards }
let!(:organization) { create :organization }
let(:user) { create(:user, :confirmed, organization: organization) }
let!(:component) { create :proposal_component, :with_votes_enabled, organization: organization, settings: { awesome_voting_manifest: manifest } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
module Decidim
module DecidimAwesome
module Voting
describe ThreeFlagsCounterCell, type: :cell do
subject { cell("decidim/decidim_awesome/voting/three_flags_counter", proposal, context: { current_user: user }) }
describe VotingCardsCounterCell, type: :cell do
subject { cell("decidim/decidim_awesome/voting/voting_cards_counter", proposal, context: { current_user: user }) }

let(:manifest) { :three_flags }
let(:manifest) { :voting_cards }
let!(:organization) { create :organization }
let(:user) { create(:user, :confirmed, organization: organization) }
let!(:component) { create :proposal_component, :with_votes_enabled, organization: organization, settings: { awesome_voting_manifest: manifest } }
Expand Down
Loading

0 comments on commit 4439849

Please sign in to comment.