Skip to content

Commit

Permalink
Add voting status for participants (#176)
Browse files Browse the repository at this point in the history
* prepare modal

* fix lint

* add override view

* add consultations callout override

* customize callout

* add total of questions to consultation_callout

* add total of questions answered to consultation_callout

* add count of consultations questions

* add conditional classes to callout

* remove lint whitespaces detected

* refactor callout code

* add modal questions table

* add modal table content

* display current_user summary responses

* add link styles on table

* add link path

* add translations

* run bundle exec i18n-tasks normalize --locales en

* add styles to delegations-button

* refactor delegations button

* fix delegations_spec

* fix delegations_multiple_spec

* add utf char to delegations button

* add consultation_question_vote_callout_spec

* add callout and modal test

* test callout links

* resolve review comments

* add translation

* test callout performance with multiple answers

* fix copies

* fix html questions

* fix tests

* fix unregistered

* fix style

* fix tests

* add sumary to consultations too

* Update app/views/decidim/consultations/question_votes/_callout.html.erb

---------

Co-authored-by: Ivan Vergés <ivan@pokecode.net>
  • Loading branch information
ElviaBth and microstudi committed Apr 29, 2024
1 parent b481bde commit 9654679
Show file tree
Hide file tree
Showing 19 changed files with 450 additions and 111 deletions.
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Decidim
module ActionDelegator
# This controller handles user profile actions for this module
class QuestionsSummaryController < ActionDelegator::ApplicationController
include Decidim::Consultations::NeedsConsultation

def show
render partial: "decidim/consultations/question_votes/callout", locals: { consultation: current_consultation }
end
end
end
end
@@ -1,3 +1,3 @@
<!-- insert_before '.table-list' -->

<%= render "decidim/action_delegator/admin/consultations/ongoing_consultation_warning", consultation: current_consultation %>
<%= render "decidim/action_delegator/admin/consultations/ongoing_consultation_warning", consultation: current_consultation %>
@@ -1,4 +1,3 @@
<!-- insert_before "erb[loud]:contains('javascript_pack_tag')" -->

<%= javascript_pack_tag "decidim_action_delegator_questions" %>

@@ -0,0 +1,9 @@
<!-- insert_after '.consultations-home-banner' -->

<% if user_signed_in? %>
<div id="user-answers-summary" class="row" style="padding:0 1rem;margint-top:-1rem" data-summary-path="<%= decidim_action_delegator.questions_summary_path(current_consultation) %>">
<%= render "decidim/consultations/question_votes/callout", consultation: current_consultation %>
<%= javascript_pack_tag "decidim_action_delegator_questions_summary" %>
</div>
<% end %>
@@ -0,0 +1,9 @@
<!-- insert_before 'h2' -->

<% if user_signed_in? %>
<div id="user-answers-summary" data-summary-path="<%= decidim_action_delegator.questions_summary_path(current_question.consultation) %>">
<%= render "decidim/consultations/question_votes/callout", consultation: current_question.consultation %>
<%= javascript_pack_tag "decidim_action_delegator_questions_summary" %>
</div>
<% end %>
@@ -0,0 +1 @@
import "src/decidim/action_delegator/summary.js";
24 changes: 24 additions & 0 deletions app/packs/src/decidim/action_delegator/summary.js
@@ -0,0 +1,24 @@
$(() => {
const $usersAnswers = $("#user-answers-summary");
const path = $usersAnswers.data("summaryPath");
let $button = $("#consultations-questions-summary-button");
let $modal = $("#consultations-questions-summary-modal");
const $div = $(".question-vote-cabin").parent();
const openModal = (evt) => {
evt.preventDefault();
$modal.foundation("open");
};

$button.on("click", openModal);

$div.bind("DOMSubtreeModified", function() {
// console.log("tree changed", path);
$usersAnswers.load(path, () => {
$button = $usersAnswers.find("#consultations-questions-summary-button");
$modal = $usersAnswers.find("#consultations-questions-summary-modal");
// console.log("usersanswer loaded")
$usersAnswers.foundation();
$button.on("click", openModal);
});
});
});
Expand Up @@ -11,7 +11,7 @@

.question-vote-cabin {
.delegations-notice {
a {
button {
color: var(--secondary);
font-weight: 600;
background: transparent;
Expand Down
@@ -1,11 +1,15 @@
<% if Decidim::ActionDelegator::Delegation.granted_to?(current_user, question.consultation) %>
<% if has_any_delegate_vote?(question) %>
<div class="delegations-notice flex--cc">
<%= link_to t("action_delegator.delegations.has_delegations", scope: "decidim"), "#", id: "delegations-button" %>
<div class="delegations-notice flex--cc" style="margin-top:1rem;">
<button id="delegations-button" class="card__button hollow button small expanded text-white">
<%= t("action_delegator.delegations.has_delegations", scope: "decidim") %>
</button>
</div>
<% else %>
<div class="delegations-notice flex--cc">
<%= link_to t("action_delegator.delegations.link", scope: "decidim"), "#", id: "delegations-button" %>
</div>
<div class="delegations-notice flex--cc" style="margin-top:1rem; width: 100%;">
<button id="delegations-button" class="card__button button small expanded secondary hollow">
<%= t("action_delegator.delegations.link", scope: "decidim") %>
</button>
</div>
<% end %>
<% end %>
47 changes: 47 additions & 0 deletions app/views/decidim/consultations/question_votes/_callout.html.erb
@@ -0,0 +1,47 @@
<% total_published_questions = consultation.questions.published.count %>
<% voted_questions = consultation.questions.published.joins(:votes).where(votes: { author: current_user }).distinct.count(:id) %>
<% alert_class = total_published_questions != voted_questions ? "warning" : "success" %>

<div class="callout <%= alert_class %>">
<p>
<%= t("action_delegator.questions.callout_text", scope: "decidim", voted: voted_questions, total: total_published_questions) %>
<a href="#" class="text-primary" id="consultations-questions-summary-button"><%= t("action_delegator.questions.callout_link_text", scope: "decidim") %></a>
</p>
</div>

<div class="reveal" id="consultations-questions-summary-modal" data-reveal>
<h4><%= t("action_delegator.questions.modal.modal_votes_title", scope: "decidim", title: translated_attribute(consultation.title)) %></h4>
<p class="lead">
<table class="table-list">
<thead>
<tr>
<th width="200"><%= t("action_delegator.questions.modal.modal_table_header_question", scope: "decidim") %></th>
<th width="150"><%= t("action_delegator.questions.modal.modal_table_header_answer", scope: "decidim") %></th>
</tr>
</thead>
<tbody>
<% consultation.questions.each do |question| %>
<tr>
<td><%= strip_tags(translated_attribute(question.title)).truncate(200, separator: /\s/) %></td>
<td>
<% if question.votes.where(author: current_user).any? %>
<% user_response = question.responses.joins(:votes).find_by(votes: { author: current_user }) %>
<% if user_response %>
<p title="<%= translated_attribute(user_response.title) %>"><%= t("booleans.true") %></p>
<% else %>
<%= link_to t("action_delegator.questions.question_not_answered", scope: "decidim"), decidim_consultations.question_path(question), class: "text-primary" %>
<% end %>
<% else %>
<%= link_to t("action_delegator.questions.question_not_answered", scope: "decidim"), decidim_consultations.question_path(question), class: "text-primary" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</p>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">&times;</span>
</button>
</div>
3 changes: 2 additions & 1 deletion config/assets.rb
Expand Up @@ -19,7 +19,8 @@
# SCSS files within the entrypoints, they become available for inclusion using
# `stylesheet_pack_tag`.
Decidim::Webpacker.register_entrypoints(
decidim_action_delegator_questions: "#{base_path}/app/packs/entrypoints/decidim_action_delegator_questions.js"
decidim_action_delegator_questions: "#{base_path}/app/packs/entrypoints/decidim_action_delegator_questions.js",
decidim_action_delegator_questions_summary: "#{base_path}/app/packs/entrypoints/decidim_action_delegator_questions_summary.js"
)

# If you want to import some extra SCSS files in the Decidim main SCSS file
Expand Down

0 comments on commit 9654679

Please sign in to comment.