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

Remove Poll Final Recounts, replace with Total Results #1885

Merged
merged 25 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f27fcc7
Replace FinalResult with TotalResult at admin BoothAssignment show
bertocq Sep 18, 2017
851d397
Replace FinalResult with TotalResult at admin Poll Recounts page
bertocq Sep 18, 2017
1c1bb7b
Remove no longer used functions
bertocq Sep 18, 2017
a3bf69e
Remove final result usage on admin poll officer assignments results
bertocq Sep 18, 2017
2e3b5aa
Totally remove Poll::FinalRecount model, table spec and factory
bertocq Sep 18, 2017
630a325
Fix admin poll officers assignments by officer view
bertocq Sep 18, 2017
6e3f9f9
Remove document cached_attachment value after destroy_upload action.
Senen Sep 11, 2017
6082147
Use snake_case for method names
bertocq Sep 14, 2017
c5671ed
Use correct Predicate name on function
bertocq Sep 14, 2017
d9575ba
Correct end at file ending
bertocq Sep 14, 2017
bf37b8e
Use datetime always with zone
bertocq Sep 14, 2017
adc71fa
moves author actions to sidebar on proposal show
decabeza Sep 18, 2017
b5d0a82
fixes margin of tags on proposal show
decabeza Sep 18, 2017
fc3eac7
refactors proposal helper and use correctly on proposal show view
decabeza Sep 18, 2017
42749b0
avoids use class variables on helper
decabeza Sep 18, 2017
c1543c7
Remove Netbeans folder from .gitignore
bertocq Sep 18, 2017
8db8049
fixes flaky spec
voodoorai2000 Sep 15, 2017
c128a0f
removes obsolete legislations specs
voodoorai2000 Sep 15, 2017
d1aa01b
fixes flaky spec
voodoorai2000 Sep 15, 2017
aee34e6
removes unused expectation
voodoorai2000 Sep 15, 2017
92333e5
fixes flaky spec
voodoorai2000 Sep 15, 2017
6de47e7
fixes flaky spec
voodoorai2000 Sep 15, 2017
882723a
fixes flaky spec
voodoorai2000 Sep 15, 2017
3105bd9
precompile assets in test environment
voodoorai2000 Sep 19, 2017
9c6a974
Fix wrong spectations after final result swap for total result
bertocq Sep 19, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,3 @@

public/sitemap.xml
public/system/

#Netbeans projects files
/nbproject
1 change: 0 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ Lint/ParenthesesAsGroupedExpression:
# Cop supports --auto-correct.
Lint/StringConversionInInterpolation:
Exclude:
- 'app/models/poll/final_recount.rb'
- 'app/models/poll/null_result.rb'
- 'app/models/poll/partial_result.rb'
- 'app/models/poll/white_result.rb'
Expand Down
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ before_script:
- "for i in config/*.example; do cp \"$i\" \"${i/.example}\"; done"
- bundle exec rake db:setup
script:
- "bundle exec rake assets:precompile RAILS_ENV=test"
- "bundle exec rake knapsack:rspec"
env:
global:
Expand Down
13 changes: 11 additions & 2 deletions app/assets/stylesheets/participation.scss
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,8 @@
}
}

&.tags,
&.geozone {
.tags,
.geozone {

li {
margin-bottom: 0;
Expand Down Expand Up @@ -478,6 +478,7 @@

.tags {
display: block;
margin-bottom: 0;

a {
margin-right: rem-calc(6);
Expand Down Expand Up @@ -610,6 +611,14 @@
}
}

.show-actions-menu {

[class^="icon-"] {
display: inline-block;
vertical-align: middle;
}
}

// 04. List participation
// ----------------------

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/poll/booth_assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def search_booths
end

def show
@booth_assignment = @poll.booth_assignments.includes(:final_recounts, :voters,
@booth_assignment = @poll.booth_assignments.includes(:total_results, :voters,
officer_assignments: [officer: [:user]]).find(params[:id])
@voters_by_date = @booth_assignment.voters.group_by {|v| v.created_at.to_date}
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def by_officer
@officer = ::Poll::Officer.includes(:user).find(officer_assignment_params[:officer_id])
@officer_assignments = ::Poll::OfficerAssignment.
joins(:booth_assignment).
includes(:final_recounts, booth_assignment: :booth).
includes(:total_results, booth_assignment: :booth).
where("officer_id = ? AND poll_booth_assignments.poll_id = ?", @officer.id, @poll.id).
order(:date)
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/admin/poll/recounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Admin::Poll::RecountsController < Admin::BaseController

def index
@booth_assignments = @poll.booth_assignments.
includes(:booth, :final_recounts, :voters).
includes(:booth, :total_results, :voters).
order("poll_booths.name").
page(params[:page]).per(50)
end
Expand Down
1 change: 1 addition & 0 deletions app/controllers/documents_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def destroy
def destroy_upload
@document = Document.new(cached_attachment: params[:path])
@document.set_attachment_from_cached_attachment
@document.cached_attachment = nil
@document.documentable = @documentable

if @document.attachment.destroy
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/communities_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def community_description(community)
community.from_proposal? ? t("community.show.description.proposal") : t("community.show.description.investment")
end

def is_author?(community, participant)
def author?(community, participant)
if community.from_proposal?
community.proposal.author_id == participant.id
else
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/documentables_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def max_documents_allowed(documentable)
end

def max_file_size(documentable)
bytesToMeg(documentable.class.max_file_size)
bytes_to_mega(documentable.class.max_file_size)
end

def accepted_content_types(documentable)
Expand Down Expand Up @@ -38,4 +38,4 @@ def max_documents_allowed?(documentable)
documentable.documents.count >= documentable.class.max_documents_allowed
end

end
end
2 changes: 1 addition & 1 deletion app/helpers/documents_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def errors_on_attachment(document)
document.errors[:attachment].join(', ') if document.errors.key?(:attachment)
end

def bytesToMeg(bytes)
def bytes_to_mega(bytes)
bytes / Numeric::MEGABYTE
end

Expand Down
12 changes: 0 additions & 12 deletions app/helpers/officing_helper.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
module OfficingHelper

def officer_assignments_select_options(officer_assignments)
options = []
officer_assignments.each do |oa|
options << ["#{oa.booth_assignment.booth.name}: #{l(oa.date.to_date, format: :long)}", oa.id]
end
options_for_select(options)
end

def booths_for_officer_select_options(officer_assignments)
options = []
officer_assignments.each do |oa|
Expand All @@ -17,10 +9,6 @@ def booths_for_officer_select_options(officer_assignments)
options_for_select(options, params[:oa])
end

def system_recount_to_compare_with_final_recount(final_recount)
final_recount.booth_assignment.voters.select {|v| v.created_at.to_date == final_recount.date}.size
end

def answer_result_value(question_id, answer_index)
return nil if params.blank?
return nil if params[:questions].blank?
Expand Down
7 changes: 0 additions & 7 deletions app/helpers/poll_final_recounts_helper.rb

This file was deleted.

4 changes: 2 additions & 2 deletions app/helpers/poll_recounts_helper.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module PollRecountsHelper

def booth_assignment_sum_final_recounts(ba)
ba.final_recounts.any? ? ba.final_recounts.to_a.sum(&:count) : nil
def total_recounts_by_booth(booth_assignment)
booth_assignment.total_results.any? ? booth_assignment.total_results.to_a.sum(&:amount) : nil
end

end
7 changes: 1 addition & 6 deletions app/helpers/polls_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ def poll_dates_select_options(poll)
options_for_select(options, params[:d])
end

def poll_final_recount_option(poll)
final_date = poll.ends_at.to_date + 1.day
options_for_select([[I18n.t("polls.final_date"), l(final_date)]])
end

def poll_booths_select_options(poll)
options = []
poll.booths.each do |booth|
Expand All @@ -46,4 +41,4 @@ def booth_name_with_location(booth)
booth.name + location
end

end
end
12 changes: 12 additions & 0 deletions app/helpers/proposals_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,16 @@ def retire_proposals_options
Proposal::RETIRE_OPTIONS.collect { |option| [ t("proposals.retire_options.#{option}"), option ] }
end

def can_create_document?(document, proposal)
can?(:create, document) && proposal.documents.size < Proposal.max_documents_allowed
end

def author_of_proposal?(proposal)
author_of?(proposal, current_user)
end

def current_editable?(proposal)
current_user && proposal.editable_by?(current_user)
end

end
1 change: 0 additions & 1 deletion app/models/poll/booth_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class BoothAssignment < ActiveRecord::Base
belongs_to :poll

has_many :officer_assignments, class_name: "Poll::OfficerAssignment", dependent: :destroy
has_many :final_recounts, class_name: "Poll::FinalRecount", dependent: :destroy
has_many :officers, through: :officer_assignments
has_many :voters
has_many :partial_results
Expand Down
19 changes: 0 additions & 19 deletions app/models/poll/final_recount.rb

This file was deleted.

4 changes: 3 additions & 1 deletion app/models/poll/officer_assignment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ class Poll
class OfficerAssignment < ActiveRecord::Base
belongs_to :officer
belongs_to :booth_assignment
has_many :final_recounts
has_many :partial_results
has_many :white_results
has_many :null_results
has_many :total_results
has_many :voters

validates :officer_id, presence: true
Expand Down
2 changes: 1 addition & 1 deletion app/models/poll/shift.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ def persist_data
end

end
end
end
8 changes: 4 additions & 4 deletions app/views/admin/poll/booth_assignments/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@
<thead>
<tr>
<th><%= t("admin.poll_booth_assignments.show.date") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_final") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.total_recount") %></th>
<th class="text-center"><%= t("admin.poll_booth_assignments.show.count_by_system") %></th>
</tr>
</thead>
<tbody>
<% (@poll.starts_at.to_date..@poll.ends_at.to_date).each do |voting_date| %>
<% final_recount = final_recount_for_date(@booth_assignment.final_recounts, voting_date) %>
<% total_recount = @booth_assignment.total_results.where(date: voting_date).first %>
<% system_count = @voters_by_date[voting_date].present? ? @voters_by_date[voting_date].size : 0 %>
<tr id="recounting_<%= voting_date.strftime('%Y%m%d') %>">
<td><%= l voting_date %></td>
<% if final_recount.present? %>
<td class="text-center <%= 'count-error' if final_recount.count != system_count %>" title="<%= final_recount.officer_assignment.officer.name %>"><%= final_recount.count %></td>
<% if total_recount.present? %>
<td class="text-center <%= 'count-error' if total_recount.amount != system_count %>" title="<%= total_recount.officer_assignment.officer.name %>"><%= total_recount.amount %></td>
<% else %>
<td class="text-center" title=""> - </td>
<% end %>
Expand Down
17 changes: 7 additions & 10 deletions app/views/admin/poll/officer_assignments/by_officer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,24 @@
<% end %>
</tbody>
</table>
<% end %>

<% final_officer_assignments = @officer_assignments.select{|oa| oa.final == true} %>
<% if final_officer_assignments.any? %>
<h3><%= t("admin.poll_officer_assignments.by_officer.final_recounts") %></h3>
<table id="final_recount_list" class="fixed">
<h3><%= t("admin.poll_officer_assignments.by_officer.total_recounts") %></h3>
<table id="total_recount_list" class="fixed">
<thead>
<tr>
<th><%= t("admin.poll_officer_assignments.by_officer.date") %></th>
<th><%= t("admin.poll_officer_assignments.by_officer.booth") %></th>
<th class="text-right"><%= t("admin.poll_officer_assignments.by_officer.final_recount") %></th>
<th class="text-right"><%= t("admin.poll_officer_assignments.by_officer.total_recount") %></th>
</tr>
</thead>
<tbody>
<% final_officer_assignments.each do |officer_assignment| %>
<tr id="final_recount_<%= officer_assignment.date.to_date.strftime('%Y%m%d') %>">
<% @officer_assignments.each do |officer_assignment| %>
<tr id="total_recount_<%= officer_assignment.date.to_date.strftime('%Y%m%d') %>">
<td><%= l(officer_assignment.date.to_date) %></td>
<td><%= booth_name_with_location(officer_assignment.booth_assignment.booth) %></td>
<td class="text-right">
<% if officer_assignment.final_recounts.any? %>
<%= officer_assignment.final_recounts.to_a.sum(&:count) %>
<% if officer_assignment.total_results.any? %>
<%= officer_assignment.total_results.to_a.sum(&:amount) %>
<% else %>
<span>-</span>
<% end %>
Expand Down
10 changes: 5 additions & 5 deletions app/views/admin/poll/recounts/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
<table class="fixed margin">
<thead>
<th><%= t("admin.recounts.index.table_booth_name") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_final_recount") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_total_recount") %></th>
<th class="text-center"><%= t("admin.recounts.index.table_system_count") %></th>
</thead>
<tbody>
<% @booth_assignments.each do |booth_assignment| %>
<% final_recount = booth_assignment_sum_final_recounts(booth_assignment) %>
<% total_recounts = total_recounts_by_booth(booth_assignment) %>
<% system_count = booth_assignment.voters.size %>
<tr id="<%= dom_id(booth_assignment) %>_recounts" class="booth_recounts">
<td>
<strong>
<%= link_to booth_assignment.booth.name, admin_poll_booth_assignment_path(@poll, booth_assignment, anchor: 'tab-recounts') %>
</strong>
</td>
<td class="text-center <%= 'count-error' if final_recount.to_i != system_count %>">
<% if final_recount.present? %>
<strong><%= final_recount %></strong>
<td class="text-center <%= 'count-error' if total_recounts.to_i != system_count %>">
<% if total_recounts.present? %>
<strong><%= total_recounts %></strong>
<% else %>
<span>-</span>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/communities/_participant.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<%= link_to participant.name, user_path(participant)%>
</span>

<% if is_author?(@community, participant) %>
<% if author?(@community, participant) %>
&nbsp;&bull;&nbsp;
<span class="label round is-author">
<%= t("comments.comment.author") %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/officing/_menu.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<% end %>
</li>

<li <%= "class=active" if ["final_recounts", "results"].include?(controller_name) || (controller_name == "polls" && action_name == "final") %>>
<li <%= "class=active" if ["results"].include?(controller_name) || (controller_name == "polls" && action_name == "final") %>>
<%= link_to final_officing_polls_path do %>
<span class="icon-user"></span>
<%= t("officing.menu.final_recounts") %>
<%= t("officing.menu.total_recounts") %>
<% end %>
</li>
</ul>
Expand Down