Compare commits

..

6 commits

Author SHA1 Message Date
0b59a74cf6 Update PO files and Catalan translation 2025-10-13 20:21:08 +02:00
507a8dfaea Fix translations 2025-10-13 20:20:46 +02:00
8d8bce3207 Translate value labels 2025-10-13 20:10:15 +02:00
b07b0da672 Force ratings on all candidates before saving 2025-10-13 20:07:34 +02:00
fa57d465be Limit width of text 2025-10-07 11:02:22 +02:00
0dd3d03b67 Read RACK_ENV but apply RAILS_ENV
Ruby whenever uses RAILS_ENV in crontab.
2025-10-07 11:01:30 +02:00
7 changed files with 86 additions and 42 deletions

View file

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-06-08 20:44-0600\n" "POT-Creation-Date: 2025-10-13 20:19+0200\n"
"PO-Revision-Date: 2025-03-29 20:41-0600\n" "PO-Revision-Date: 2025-03-29 20:41-0600\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -41,11 +41,11 @@ msgstr "Bé"
msgid "Very good" msgid "Very good"
msgstr "Molt bé" msgstr "Molt bé"
#: ../vedia.rb:119 #: ../vedia.rb:127
msgid "Incorrect email or password." msgid "Incorrect email or password."
msgstr "Correu o contrasenya incorrecte." msgstr "Correu o contrasenya incorrecte."
#: ../vedia.rb:141 #: ../vedia.rb:149
msgid "Reset your password" msgid "Reset your password"
msgstr "Reiniciar contrasenya" msgstr "Reiniciar contrasenya"
@ -133,7 +133,7 @@ msgid "Description: %{description}"
msgstr "Descripció: %{description}" msgstr "Descripció: %{description}"
#: ../views/admin_votes.erb:15 ../views/votes_open.erb:3 #: ../views/admin_votes.erb:15 ../views/votes_open.erb:3
#: ../views/votes_show_closed.erb:4 ../views/votes_show_open.erb:4 #: ../views/votes_show_closed.erb:4 ../views/votes_show_open.erb:12
msgid "Closing date: %{date}" msgid "Closing date: %{date}"
msgstr "Data de tancament: %{date}" msgstr "Data de tancament: %{date}"
@ -147,7 +147,7 @@ msgstr "Estat: %{state}"
#: ../views/admin_votes.erb:19 ../views/votes_edit.erb:39 #: ../views/admin_votes.erb:19 ../views/votes_edit.erb:39
#: ../views/votes_show_closed.erb:79 ../views/votes_show_draft.erb:5 #: ../views/votes_show_closed.erb:79 ../views/votes_show_draft.erb:5
#: ../views/votes_show_open.erb:40 #: ../views/votes_show_open.erb:54
msgid "Organizers" msgid "Organizers"
msgstr "Organitzadores" msgstr "Organitzadores"
@ -193,7 +193,7 @@ msgstr "Connexió"
#: ../views/login.erb:9 ../views/reset.erb:5 ../views/reset_change.erb:13 #: ../views/login.erb:9 ../views/reset.erb:5 ../views/reset_change.erb:13
#: ../views/signup.erb:24 ../views/votes_edit.erb:51 #: ../views/signup.erb:24 ../views/votes_edit.erb:51
#: ../views/votes_show_closed.erb:99 ../views/votes_show_open.erb:66 #: ../views/votes_show_closed.erb:99 ../views/votes_show_open.erb:80
msgid "Email" msgid "Email"
msgstr "Correu" msgstr "Correu"
@ -268,7 +268,7 @@ msgstr "Títol"
msgid "Description" msgid "Description"
msgstr "Descripció" msgstr "Descripció"
#: ../views/votes_edit.erb:12 ../views/votes_show_open.erb:27 #: ../views/votes_edit.erb:12 ../views/votes_show_open.erb:41
msgid "Save" msgid "Save"
msgstr "Guardar" msgstr "Guardar"
@ -287,12 +287,12 @@ msgstr "Nom"
#: ../views/votes_edit.erb:47 ../views/votes_edit.erb:54 #: ../views/votes_edit.erb:47 ../views/votes_edit.erb:54
#: ../views/votes_show_closed.erb:95 ../views/votes_show_closed.erb:102 #: ../views/votes_show_closed.erb:95 ../views/votes_show_closed.erb:102
#: ../views/votes_show_open.erb:62 ../views/votes_show_open.erb:69 #: ../views/votes_show_open.erb:76 ../views/votes_show_open.erb:83
msgid "Add organizer" msgid "Add organizer"
msgstr "Afegeix organitzadora" msgstr "Afegeix organitzadora"
#: ../views/votes_edit.erb:57 ../views/votes_show_closed.erb:89 #: ../views/votes_edit.erb:57 ../views/votes_show_closed.erb:89
#: ../views/votes_show_open.erb:52 #: ../views/votes_show_open.erb:66
msgid "Actions for organizers" msgid "Actions for organizers"
msgstr "Accions per les organitzadores" msgstr "Accions per les organitzadores"
@ -371,18 +371,22 @@ msgstr "No hi ha cap resultat perquè ningú va votar en aquesta votació."
msgid "Reopen voting period" msgid "Reopen voting period"
msgstr "Reobrir el període de votació" msgstr "Reobrir el període de votació"
#: ../views/votes_show_open.erb:9 #: ../views/votes_show_open.erb:6
msgid "Missing rating for candidate <i>%{name}</i>."
msgstr "Falta una valoració per l'opció <i>%{name}</i>."
#: ../views/votes_show_open.erb:17
msgid "Your ratings" msgid "Your ratings"
msgstr "Les teves valoracions" msgstr "Les teves valoracions"
#: ../views/votes_show_open.erb:30 #: ../views/votes_show_open.erb:44
msgid "Participants" msgid "Participants"
msgstr "Votants" msgstr "Votants"
#: ../views/votes_show_open.erb:55 #: ../views/votes_show_open.erb:69
msgid "Change back to draft vote" msgid "Change back to draft vote"
msgstr "Tornar a l'esborrany de votació" msgstr "Tornar a l'esborrany de votació"
#: ../views/votes_show_open.erb:59 #: ../views/votes_show_open.erb:73
msgid "Close votes and show results" msgid "Close votes and show results"
msgstr "Tancar la votació i veure els resultats" msgstr "Tancar la votació i veure els resultats"

View file

@ -8,8 +8,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2025-06-08 20:44-0600\n" "POT-Creation-Date: 2025-10-13 20:19+0200\n"
"PO-Revision-Date: 2025-06-08 20:44-0600\n" "PO-Revision-Date: 2025-10-13 20:19+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n" "Language: \n"
@ -42,11 +42,11 @@ msgstr ""
msgid "Very good" msgid "Very good"
msgstr "" msgstr ""
#: ../vedia.rb:119 #: ../vedia.rb:127
msgid "Incorrect email or password." msgid "Incorrect email or password."
msgstr "" msgstr ""
#: ../vedia.rb:141 #: ../vedia.rb:149
msgid "Reset your password" msgid "Reset your password"
msgstr "" msgstr ""
@ -134,7 +134,7 @@ msgid "Description: %{description}"
msgstr "" msgstr ""
#: ../views/admin_votes.erb:15 ../views/votes_open.erb:3 #: ../views/admin_votes.erb:15 ../views/votes_open.erb:3
#: ../views/votes_show_closed.erb:4 ../views/votes_show_open.erb:4 #: ../views/votes_show_closed.erb:4 ../views/votes_show_open.erb:12
msgid "Closing date: %{date}" msgid "Closing date: %{date}"
msgstr "" msgstr ""
@ -148,7 +148,7 @@ msgstr ""
#: ../views/admin_votes.erb:19 ../views/votes_edit.erb:39 #: ../views/admin_votes.erb:19 ../views/votes_edit.erb:39
#: ../views/votes_show_closed.erb:79 ../views/votes_show_draft.erb:5 #: ../views/votes_show_closed.erb:79 ../views/votes_show_draft.erb:5
#: ../views/votes_show_open.erb:40 #: ../views/votes_show_open.erb:54
msgid "Organizers" msgid "Organizers"
msgstr "" msgstr ""
@ -194,7 +194,7 @@ msgstr ""
#: ../views/login.erb:9 ../views/reset.erb:5 ../views/reset_change.erb:13 #: ../views/login.erb:9 ../views/reset.erb:5 ../views/reset_change.erb:13
#: ../views/signup.erb:24 ../views/votes_edit.erb:51 #: ../views/signup.erb:24 ../views/votes_edit.erb:51
#: ../views/votes_show_closed.erb:99 ../views/votes_show_open.erb:66 #: ../views/votes_show_closed.erb:99 ../views/votes_show_open.erb:80
msgid "Email" msgid "Email"
msgstr "" msgstr ""
@ -267,7 +267,7 @@ msgstr ""
msgid "Description" msgid "Description"
msgstr "" msgstr ""
#: ../views/votes_edit.erb:12 ../views/votes_show_open.erb:27 #: ../views/votes_edit.erb:12 ../views/votes_show_open.erb:41
msgid "Save" msgid "Save"
msgstr "" msgstr ""
@ -286,12 +286,12 @@ msgstr ""
#: ../views/votes_edit.erb:47 ../views/votes_edit.erb:54 #: ../views/votes_edit.erb:47 ../views/votes_edit.erb:54
#: ../views/votes_show_closed.erb:95 ../views/votes_show_closed.erb:102 #: ../views/votes_show_closed.erb:95 ../views/votes_show_closed.erb:102
#: ../views/votes_show_open.erb:62 ../views/votes_show_open.erb:69 #: ../views/votes_show_open.erb:76 ../views/votes_show_open.erb:83
msgid "Add organizer" msgid "Add organizer"
msgstr "" msgstr ""
#: ../views/votes_edit.erb:57 ../views/votes_show_closed.erb:89 #: ../views/votes_edit.erb:57 ../views/votes_show_closed.erb:89
#: ../views/votes_show_open.erb:52 #: ../views/votes_show_open.erb:66
msgid "Actions for organizers" msgid "Actions for organizers"
msgstr "" msgstr ""
@ -368,18 +368,22 @@ msgstr ""
msgid "Reopen voting period" msgid "Reopen voting period"
msgstr "" msgstr ""
#: ../views/votes_show_open.erb:9 #: ../views/votes_show_open.erb:6
msgid "Missing rating for candidate <i>%{name}</i>."
msgstr ""
#: ../views/votes_show_open.erb:17
msgid "Your ratings" msgid "Your ratings"
msgstr "" msgstr ""
#: ../views/votes_show_open.erb:30 #: ../views/votes_show_open.erb:44
msgid "Participants" msgid "Participants"
msgstr "" msgstr ""
#: ../views/votes_show_open.erb:55 #: ../views/votes_show_open.erb:69
msgid "Change back to draft vote" msgid "Change back to draft vote"
msgstr "" msgstr ""
#: ../views/votes_show_open.erb:59 #: ../views/votes_show_open.erb:73
msgid "Close votes and show results" msgid "Close votes and show results"
msgstr "" msgstr ""

View file

@ -1,19 +1,22 @@
require 'sinatra' require 'sinatra'
# Set environment before requiring 'sinatra/activerecord' to make `whenever` uses the database.
if ENV['RAILS_ENV']
set :environment, ENV['RAILS_ENV']
end
require 'sinatra/activerecord' require 'sinatra/activerecord'
require 'bcrypt' require 'bcrypt'
require 'gettext' require 'gettext'
require 'securerandom' require 'securerandom'
require 'chartkick' require 'chartkick'
require 'mail' require 'mail'
require 'ostruct'
require 'tzinfo' require 'tzinfo'
require 'redcarpet' require 'redcarpet'
include GetText include GetText
if ENV['RAILS_ENV']
set :environment, ENV['RAILS_ENV']
end
require_relative 'mj' require_relative 'mj'
require_relative 'config/environments/defaults.rb' require_relative 'config/environments/defaults.rb'
require_relative "config/environments/#{settings.environment}" require_relative "config/environments/#{settings.environment}"
@ -384,16 +387,31 @@ post '/votes/:id/reopen' do
redirect '/votes/' + @vote.secure_id redirect '/votes/' + @vote.secure_id
end end
get '/votes/:id/ratings' do
redirect '/votes/' + params[:id]
end
post '/votes/:id/ratings' do post '/votes/:id/ratings' do
require_login require_login
find_vote find_vote
require_open_vote require_open_vote
@errors = []
@vote.candidates.each do |candidate| @vote.candidates.each do |candidate|
rating = Rating.find_or_initialize_by(vote: @vote, user: current_user, candidate: candidate) if not params[candidate.id.to_s]
rating.value = params[candidate.id.to_s] @errors << OpenStruct.new(:attribute => :rating, :type => :blank, :candidate => candidate)
rating.save end
end
if not @errors.empty?
@params = params
erb :votes_show_open
else
@vote.candidates.each do |candidate|
rating = Rating.find_or_initialize_by(vote: @vote, user: current_user, candidate: candidate)
rating.value = params[candidate.id.to_s]
rating.save
end
redirect '/votes/' + @vote.secure_id
end end
redirect '/votes/' + @vote.secure_id
end end
post '/votes/:id/organizers' do post '/votes/:id/organizers' do

View file

@ -2,6 +2,10 @@
color: red; color: red;
} }
p, li {
max-width: 50em;
}
textarea { textarea {
width: 80em; width: 80em;
height: 20em; height: 20em;

View file

@ -1,6 +1,6 @@
<h1><%= _("Open vote") %></h1> <h1><%= _("Open vote") %></h1>
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@expire_on) }) %></p> <p><%= _("Closing date: %{date}") % { date: format_date_and_time(@expire_on) } %></p>
<p><%= _("The vote will automatically close on that date and the results will <p><%= _("The vote will automatically close on that date and the results will
be sent to all users by email.") %></p> be sent to all users by email.") %></p>

View file

@ -1,7 +1,7 @@
<h1><%= @vote.title %></h1> <h1><%= @vote.title %></h1>
<% if @vote.expire_on %> <% if @vote.expire_on %>
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p> <p><%= _("Closing date: %{date}") % { date: format_date_and_time(@vote.expire_on) } %></p>
<% end %> <% end %>
<%= markdown(@vote.description) %> <%= markdown(@vote.description) %>
@ -23,7 +23,7 @@
<% @vote.candidates.each do |candidate| %> <% @vote.candidates.each do |candidate| %>
<% if rating = @vote.ratings.find { |rating| rating.user == user and rating.candidate == candidate } %> <% if rating = @vote.ratings.find { |rating| rating.user == user and rating.candidate == candidate } %>
<% value = settings.values.select { |e| e[:id] == rating.value }.first %> <% value = settings.values.select { |e| e[:id] == rating.value }.first %>
<td class="value-<%= value[:id] %>"><%= value[:label] %></td> <td class="value-<%= value[:id] %>"><%= _(value[:label]) %></td>
<% end %> <% end %>
<% end %> <% end %>
</tr> </tr>
@ -47,7 +47,7 @@
<td><%= i %></td> <td><%= i %></td>
<td><%= candidate.name %></td> <td><%= candidate.name %></td>
<% value = settings.values.select { |e| e[:id] == candidate.mj.mj }.first %> <% value = settings.values.select { |e| e[:id] == candidate.mj.mj }.first %>
<td class="value-<%= value[:id] %>"><%= value[:label] %></td> <td class="value-<%= value[:id] %>"><%= _(value[:label]) %></td>
<td><%= candidate.mj.proponents %></td> <td><%= candidate.mj.proponents %></td>
<td><%= candidate.mj.opponents %></td> <td><%= candidate.mj.opponents %></td>
</tr> </tr>

View file

@ -1,7 +1,15 @@
<h1><%= @vote.title %></h1> <h1><%= @vote.title %></h1>
<% if @errors %>
<% @errors.each do |error| %>
<% if error.attribute == :rating and error.type == :blank %>
<p class="error"><%= _("Missing rating for candidate <i>%{name}</i>.") % { name: error.candidate.name } %></p>
<% end %>
<% end %>
<% end %>
<% if @vote.expire_on %> <% if @vote.expire_on %>
<p><%= _("Closing date: %{date}" % { date: format_date_and_time(@vote.expire_on) }) %></p> <p><%= _("Closing date: %{date}") % { date: format_date_and_time(@vote.expire_on) } %></p>
<% end %> <% end %>
<%= markdown(@vote.description) %> <%= markdown(@vote.description) %>
@ -12,13 +20,19 @@
<ul> <ul>
<% @vote.candidates.each do |candidate| %> <% @vote.candidates.each do |candidate| %>
<% rating = @vote.ratings.find { |rating| rating.user == current_user and rating.candidate == candidate } %> <% rating = @vote.ratings.find { |rating| rating.user == current_user and rating.candidate == candidate } %>
<% value = rating ? rating.value : 0 %> <% if rating
value = rating.value
elsif @params[candidate.id.to_s]
value = params[candidate.id.to_s].to_i
else
value = 0
end %>
<li> <li>
<p><b><%= candidate.name %></b></p> <p><b><%= candidate.name %></b></p>
<%= markdown(candidate.description) %> <%= markdown(candidate.description) %>
<ul> <ul>
<% settings.values.reverse.each do |v| %> <% settings.values.reverse.each do |v| %>
<li><input type="radio" name="<%= candidate.id %>" id="<%= candidate.id %>-<%= v[:id] %>" value="<%= v[:id] %>" <% if value == v[:id] %>checked<% end %>><label for="<%= candidate.id %>-<%= v[:id] %>" class="value-<%= v[:id] %>"><%= v[:label] %></label></li> <li><input type="radio" name="<%= candidate.id %>" id="<%= candidate.id %>-<%= v[:id] %>" value="<%= v[:id] %>" <% if value == v[:id] %>checked<% end %>><label for="<%= candidate.id %>-<%= v[:id] %>" class="value-<%= v[:id] %>"><%= _(v[:label]) %></label></li>
<% end %> <% end %>
</ul> </ul>
</li> </li>