Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several minor corrections #89

Merged
merged 11 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test-rails.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ jobs:
with:
token: ${{ env.CODECOV_TOKEN }}

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
if: always()
with:
name: screenshots
path: ./spec/decidim_dummy_app/tmp/screenshots
if-no-files-found: ignore

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
if: always()
with:
name: Test logs
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ GEM
activesupport (>= 5.2)
sprockets (>= 3.0.0)
ssrf_filter (1.1.2)
stringio (3.1.0)
stringio (3.1.1)
temple (0.10.3)
terminal-table (3.0.2)
unicode-display_width (>= 1.1.1, < 3)
Expand Down
6 changes: 5 additions & 1 deletion app/cells/decidim/vocdoni/election_results/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@
<%= translated_attribute(answer.title) %>
</p>

<%= render view: :progress_bar, locals: { id: answer.id, votes_percentage: answer.votes_percentage, votes: answer.votes } %>
<% if answer.votes_percentage.nil? %>
<p class="text-alert text-center"><%= t("decidim.vocdoni.elections.results.results_error") %></p>
<% else %>
<%= render view: :progress_bar, locals: { id: answer.id, votes_percentage: answer.votes_percentage, votes: answer.votes } %>
<% end %>
</div>
<% end %>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def update_election!
def election_type_attributes
{
election_type: {
auto_start: !form.manual_start,
secret_until_the_end: form.result_type == "after_voting",
interruptible: Decidim::Vocdoni.interruptible_elections,
dynamic_census: election.internal_census?,
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/decidim/vocdoni/admin/questions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def create
@form = form(QuestionForm).from_params(params, election:)

CreateQuestion.call(@form) do
on(:ok) do
on(:ok) do |question|
flash[:notice] = I18n.t("questions.create.success", scope: "decidim.vocdoni.admin")
redirect_to election_questions_path(election)
redirect_to election_question_answers_path(election, question)
end

on(:invalid) do
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/decidim/vocdoni/admin/steps_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ def current_step_form_class
"created" => ElectionStatusForm, # This allows for resending data to vocdoni if there's been a problem
"paused" => ElectionStatusForm,
"vote" => ElectionStatusForm,
"vote_ended" => ResultsForm
"vote_ended" => ResultsForm,
"results_published" => election.answers_have_results? ? nil : ResultsForm
}[current_step]
end

Expand All @@ -102,7 +103,8 @@ def current_step_command_class
"created" => UpdateElectionStatus,
"paused" => UpdateElectionStatus,
"vote" => UpdateElectionStatus,
"vote_ended" => SaveResults
"vote_ended" => SaveResults,
"results_published" => SaveResults
}[current_step]
end

Expand Down
2 changes: 2 additions & 0 deletions app/jobs/decidim/vocdoni/admin/create_vocdoni_election_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def perform(election_id)
election.build_answer_values!
result = sdk.createElection(election.to_vocdoni, election.questions_to_vocdoni, election.census_status.all_wallets)
@vocdoni_id = result["electionId"]
@census_id = result["censusId"]
@census_identifier = result["censusIdentifier"]
@census_address = result["censusAddress"]
@census_private_key = result["censusPrivateKey"]
Expand All @@ -33,6 +34,7 @@ def perform(election_id)
def update_election
election.vocdoni_election_id = vocdoni_id
election.census_attributes = {
id: @census_id,
identifier: @census_identifier,
address: @census_address,
private_key: @census_private_key,
Expand Down
2 changes: 2 additions & 0 deletions app/models/decidim/vocdoni/answer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Answer < ApplicationRecord
# A votes percentage relative to the question
# Returns a Float.
def votes_percentage
return unless question.total_votes.positive? && !votes.nil?

@votes_percentage ||= (votes.to_f / question.total_votes * 100.0).round(2)
end

Expand Down
15 changes: 10 additions & 5 deletions app/models/decidim/vocdoni/election.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ def blocked?
end

def auto_start?
election_type&.fetch("auto_start", true)
start_time.present?
end

def manual_start?
auto_start? == false
!auto_start?
end

def interruptible?
Expand Down Expand Up @@ -176,6 +176,11 @@ def answers_have_votes?
questions.map(&:answers).flatten.pluck(:votes).any? Integer
end

# Public: Checks if the election has all results correctly defined
def answers_have_results?
questions.map(&:answers).flatten.pluck(:votes).none? nil
end

# Public: Gets the voting period status of the election
#
# Returns one of these symbols: upcoming, ongoing or finished
Expand Down Expand Up @@ -205,7 +210,7 @@ def build_answer_values!
end

# Public: the Vocdoni's format to create a new election
# @see https://developer.vocdoni.io/sdk#creating-a-voting-process
# @see https://developer.vocdoni.io/sdk/tutorial
# The process to create an election still needs to add the keys "census" and "questions"
# This is done using the Vocdoni SDK
def to_vocdoni
Expand All @@ -217,12 +222,12 @@ def to_vocdoni
"startDate" => start_time&.iso8601,
"endDate" => end_time.iso8601,
"electionType" => {
"autoStart" => auto_start?,
# For the moment, we consider all censuses dynamic so admins can update them
"dynamicCensus" => true,
"interruptible" => interruptible?,
"secretUntilTheEnd" => secret_until_the_end?,
"anonymous" => anonymous?
"anonymous" => anonymous?,
"metadata" => { "encrypted" => false, "password" => nil }
},
"voteType" => {
# uniqueChoices: false, # if the choices are unique when voting
Expand Down
2 changes: 1 addition & 1 deletion app/models/decidim/vocdoni/question.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Question < ApplicationRecord
delegate :organization, to: :election

def total_votes
answers.sum(:votes)
answers.sum { |a| a.votes.to_i }
end

def slug
Expand Down
3 changes: 3 additions & 0 deletions app/packs/entrypoints/decidim_vocdoni_elections.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
// JS
import "src/decidim/vocdoni/global-polyfills";

// CSS
import "entrypoints/decidim_vocdoni_elections.scss";
7 changes: 7 additions & 0 deletions app/packs/src/decidim/vocdoni/global-polyfills.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Adding this polyfill for `process` because `util.js` relies on `process.env.NODE_DEBUG`.
// This ensures compatibility in environments where `process` is not defined (e.g., browsers).
window.process = window.process || {
env: {
NODE_DEBUG: ""
}
};
8 changes: 4 additions & 4 deletions app/packs/src/decidim/vocdoni/voter/new-vote.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* eslint-disable no-console */
import { ElectionStatus, VocdoniSDKClient } from "@vocdoni/sdk";

import VoteQuestionsComponent from "./vote_questions.component";
import VoteComponent from "./setup-vote";
import PreviewVoteComponent from "./setup-preview";
import { walletFromLoginForm } from "./census-utils";
import VoteQuestionsComponent from "src/decidim/vocdoni/voter/vote_questions.component";
import VoteComponent from "src/decidim/vocdoni/voter/setup-vote";
import PreviewVoteComponent from "src/decidim/vocdoni/voter/setup-preview";
import { walletFromLoginForm } from "src/decidim/vocdoni/voter/census-utils";

/*
* Mount the VoteComponent object and bind the events to the UI
Expand Down
14 changes: 7 additions & 7 deletions app/packs/stylesheets/decidim/vocdoni/admin/elections_tabs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}

.tabs-title.is-active {
background: #ffffff;
background: #fff;
}

.progress-indicator {
Expand Down Expand Up @@ -44,8 +44,8 @@
content: attr(data-step);
display: block;
background: #ccc;
width: .5em;
height: .5em;
width: 0.5em;
height: 0.5em;
text-align: center;
margin: 0 auto 0.25em;
line-height: 1.5em;
Expand All @@ -55,11 +55,11 @@
}

.progress-indicator > li.text-warning::before {
background: #ffae00;;
background: #ffae00;
}

.progress-indicator > li::after {
content: '';
content: "";
position: absolute;
display: block;
background: #ccc;
Expand All @@ -70,11 +70,11 @@
-ms-transform: translateY(-100%);
transform: translateY(-100%);
left: 50%;
margin-left: 1.5em\9;
margin-left: 1.5em;
z-index: 0;
}

.progress-indicator > li:last-child:after {
.progress-indicator > li:last-child::after {
display: none;
}

Expand Down
62 changes: 22 additions & 40 deletions app/packs/stylesheets/decidim/vocdoni/admin/vocdoni.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,10 @@ $white: #fff;
}
}

.spinner-container {
position: relative;
cursor: wait;

&::before{
content: " ";
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
@apply bg-white bg-opacity-80;
z-index: 1;
}

&::after{
-webkit-animation: animation-spin 800ms infinite linear;
animation: animation-spin 800ms infinite linear;
width: 25px;
height: 25px;
box-sizing: border-box;
border-radius: 50%;
border: 3px solid #e8e8e8;
border-right-color: var(--primary);
display: inline-block;
position: absolute;
content: "";
vertical-align: middle;
z-index: 1;
top: 47%;
left: 47%;
.evote__preview.spinner-container {
&::before {
margin-left: calc(50% - 1rem);
top: 10vh;
}
}

Expand All @@ -49,7 +22,8 @@ $white: #fff;
&:hover {
@apply text-white #{!important};

background: linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), rgb(var(--alert-rgb) / var(--tw-bg-opacity)) !important;
background: linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)),
rgb(var(--alert-rgb) / var(--tw-bg-opacity)) !important;
}
}

Expand All @@ -59,7 +33,8 @@ $white: #fff;
&:hover {
@apply text-white #{!important};

background: linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), rgb(var(--warning-rgb) / var(--tw-bg-opacity)) !important;
background: linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)),
rgb(var(--warning-rgb) / var(--tw-bg-opacity)) !important;
}
}

Expand All @@ -69,7 +44,8 @@ $white: #fff;
&:hover {
@apply text-white #{!important};

background: linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)), rgb(var(--success-rgb) / var(--tw-bg-opacity)) !important;
background: linear-gradient(0deg, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.3)),
rgb(var(--success-rgb) / var(--tw-bg-opacity)) !important;
}
}

Expand All @@ -95,12 +71,13 @@ a.button__alert {
}

.publish-text p {
@apply mb-2
@apply mb-2;
}

.wallet-container {
@apply w-full mx-auto py-2;
}

.wallet-input {
@apply rounded-none rounded-s-md block flex-1 min-w-0 w-full text-sm p-2 border-2 text-gray-2 cursor-not-allowed;
}
Expand All @@ -110,14 +87,19 @@ button.copy-button {
}

.vocdoni__accordion-trigger {
@apply flex w-full items-center justify-between font-semibold text-secondary ;
@apply flex w-full items-center justify-between font-semibold text-secondary;

&:hover {
@apply underline;
}

svg {
@apply w-8 h-8;
fill: currentColor;
}
svg {
@apply w-8 h-8;

fill: currentColor;
}
}

.evote__preview-question {
@apply border-0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@

th {
@apply bg-gray-3 px-6 py-3 text-left text-xs font-medium uppercase tracking-wider;

&.w-3\/4 {
width: 75%;
}

&.w-1\/4 {
width: 25%;
}
Expand All @@ -136,6 +138,7 @@
&:nth-child(odd) {
@apply bg-white;
}

&:nth-child(even) {
@apply bg-gray-5;
}
Expand All @@ -155,7 +158,9 @@
line-height: 18px;
font-weight: 600;
text-transform: uppercase;

--tw-text-opacity: 1;

color: rgb(62 76 92 / 1);
}

Expand All @@ -164,5 +169,5 @@
width: 1rem;
flex: none;
fill: currentColor;
color: #6B7280CC;
color: #6b7280cc;
}
Loading
Loading