-
-
Notifications
You must be signed in to change notification settings - Fork 408
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve experience, usability giving proposals minimum votes number (#…
…13349) Co-authored-by: Alexandru Emil Lupu <contact@alecslupu.ro>
- Loading branch information
Showing
21 changed files
with
534 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
decidim-core/app/views/layouts/decidim/shared/_layout_item.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
decidim-proposals/app/packs/src/decidim/proposals/exit_handler.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const allowExitFrom = (el) => { | ||
if (el.id === "exit-proposal-notification-link" || el.classList.contains("no-modal")) { | ||
return true; | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
const exitNotification = document.getElementById("exit-proposal-notification"); | ||
const exitLink = document.getElementById("exit-proposal-notification-link"); | ||
if (!exitLink) { | ||
return; | ||
} | ||
const defaultExitUrl = exitLink.href; | ||
const defaultExitLinkText = exitLink.textContent; | ||
const signOutPath = window.Decidim.config.get("sign_out_path"); | ||
let exitLinkText = defaultExitLinkText; | ||
|
||
if (!exitNotification) { | ||
// Do not apply when not inside the voting pipeline | ||
return; | ||
} | ||
|
||
const openExitNotification = (url, method = null) => { | ||
if (method && method !== "get") { | ||
exitLink.setAttribute("data-method", method); | ||
} else { | ||
exitLink.removeAttribute("data-method"); | ||
} | ||
|
||
exitLink.setAttribute("href", url); | ||
exitLink.textContent = exitLinkText; | ||
window.Decidim.currentDialogs["exit-proposal-notification"].open(); | ||
}; | ||
|
||
const handleClicks = (link) => { | ||
link.addEventListener("click", (event) => { | ||
exitLinkText = defaultExitLinkText; | ||
|
||
if ( | ||
!allowExitFrom(link) && | ||
((window.Decidim.currentDialogs["exit-proposal-notification"].dialog.querySelector("[data-dialog-container]")).dataset.minimumVotesReached !== "true") && | ||
((window.Decidim.currentDialogs["exit-proposal-notification"].dialog.querySelector("[data-dialog-container]")).dataset.minimumVotesCount > 0) | ||
) { | ||
event.preventDefault(); | ||
openExitNotification(link.getAttribute("href"), link.dataset.method); | ||
} | ||
}); | ||
}; | ||
|
||
document.querySelectorAll("a").forEach(handleClicks); | ||
// Custom handling for the header sign-out link | ||
const signOutLink = document.querySelector(`[href='${signOutPath}']`); | ||
if (signOutLink) { | ||
signOutLink.addEventListener("click", (event) => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
|
||
exitLinkText = signOutLink.textContent; | ||
openExitNotification(signOutLink.getAttribute("href"), signOutLink.dataset.method); | ||
}); | ||
} | ||
|
||
// Custom handling for links that open the exit notification dialog | ||
const dialogOpenLinks = document.querySelectorAll("a[data-dialog-open='exit-proposal-notification']"); | ||
dialogOpenLinks.forEach((link) => { | ||
link.addEventListener("click", () => { | ||
exitLinkText = defaultExitLinkText; | ||
openExitNotification(defaultExitUrl); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
decidim-proposals/app/views/decidim/proposals/proposals/_exit_modal.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<%= decidim_modal id: "exit-proposal-notification" do %> | ||
<div data-dialog-container data-minimum-votes-reached="<%= remaining_minimum_votes_count_for(current_user).zero? %>" data-minimum-votes-count="<%= minimum_votes_per_user - remaining_minimum_votes_count_for(current_user) %>"> | ||
<%= icon "information-line" %> | ||
<h3 class="h3 text-base" id="dialog-title-exit-proposal-notification" tabindex="-1" data-dialog-title> | ||
<%= t("title", scope: "decidim.proposals.exit_modal", number: remaining_minimum_votes_count_for(current_user)) %> | ||
</h3> | ||
<p id="dialog-desc-budget-modal"> | ||
<%= t("message", scope: "decidim.proposals.exit_modal", number: remaining_minimum_votes_count_for(current_user)) %> | ||
</p> | ||
</div> | ||
<div data-dialog-actions> | ||
<button data-dialog-close="exit-proposal-notification" class="button button__sm md:button__lg button__secondary"> | ||
<%= t("cancel", scope: "decidim.proposals.exit_modal") %> | ||
</button> | ||
<%= link_to t("exit", scope: "decidim.proposals.exit_modal"), proposals_path, id: "exit-proposal-notification-link", class: "button button__sm md:button__lg button__secondary" %> | ||
</div> | ||
<% end %> |
1 change: 1 addition & 0 deletions
1
decidim-proposals/app/views/decidim/proposals/proposals/_notification_alert_box.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= alert_box(t("success", scope: "decidim.proposals.proposals.voting_rules"), :success, true, { id: "success-proposal-vote" }) %> |
33 changes: 33 additions & 0 deletions
33
decidim-proposals/app/views/decidim/proposals/proposals/_proposal_voting_rules.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<div id="proposal-voting-rules" class="flash flex-col p-0 gap-0"> | ||
<button id="dropdown-trigger-proposal-voting-rules" data-component="dropdown" data-target="dropdown-menu-proposal-voting-rules" class="flash__title"> | ||
<%= t("title", scope: "decidim.proposals.proposals.voting_rules") %> | ||
<%= icon "arrow-down-s-line" %> | ||
<%= icon "arrow-up-s-line" %> | ||
</button> | ||
|
||
<div class="flash__message"> | ||
<div class="text-base editor-content"> | ||
<ul id="dropdown-menu-proposal-voting-rules" class="mt-0 mb-2"> | ||
<% if vote_limit_enabled? %> | ||
<li><%= t("vote_limit.description", scope: "decidim.proposals.proposals.voting_rules", limit: component_settings.vote_limit) %></li> | ||
<% end %> | ||
|
||
<% if proposal_limit_enabled? %> | ||
<li><%= t("proposal_limit.description", scope: "decidim.proposals.proposals.voting_rules", limit: proposal_limit) %></li> | ||
<% end %> | ||
|
||
<% if threshold_per_proposal_enabled? %> | ||
<li><%= t("threshold_per_proposal.description", scope: "decidim.proposals.proposals.voting_rules", limit: threshold_per_proposal) %></li> | ||
<% end %> | ||
|
||
<% if can_accumulate_votes_beyond_threshold? %> | ||
<li><%= t("can_accumulate_votes_beyond_threshold.description", scope: "decidim.proposals.proposals.voting_rules", limit: threshold_per_proposal) %></li> | ||
<% end %> | ||
|
||
<% if minimum_votes_per_user_enabled? %> | ||
<li><%= t("minimum_votes_per_user.description", scope: "decidim.proposals.proposals.voting_rules", votes: minimum_votes_per_user) %></li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> |
2 changes: 1 addition & 1 deletion
2
decidim-proposals/app/views/decidim/proposals/proposals/_remaining_votes_count.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<div id="remaining-votes-count"> | ||
<%= t("votes", scope: "decidim.proposals.proposals.voting_rules.vote_limit", number: remaining_votes_count_for(current_user)) %> | ||
<%= t("votes", scope: "decidim.proposals.proposals.voting_rules.vote_limit", number: remaining_minimum_votes_count_for(current_user)) %> | ||
</div> |
12 changes: 12 additions & 0 deletions
12
...im-proposals/app/views/decidim/proposals/proposals/_remaining_votes_notification.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<%= alert_box( | ||
message( | ||
content_tag(:div, class: "") do | ||
concat content_tag(:strong, t("already_vote.title", scope: "decidim.proposals.proposals.voting_rules", number: remaining_minimum_votes_count_for(current_user))) | ||
concat content_tag(:p, t("already_vote.description", scope: "decidim.proposals.proposals.voting_rules", number: remaining_minimum_votes_count_for(current_user))) | ||
concat link_to(t("already_vote.see_other_proposals", scope: "decidim.proposals.proposals.voting_rules"), proposals_path, class: "no-modal") | ||
end | ||
), | ||
:secondary, | ||
true, | ||
{ id: "remaining-votes-notification", class: "flash secondary #{"hidden" unless remaining_minimum_votes_count_for(current_user).positive?}" } | ||
) %> |
6 changes: 6 additions & 0 deletions
6
...im-proposals/app/views/decidim/proposals/proposals/_update_proposal_voting_rules.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<% if show_voting_rules? %> | ||
<div class="item_voting_rules"> | ||
<%= render partial: "remaining_votes_notification" %> | ||
<%= render partial: "proposal_voting_rules" %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.