Skip to content

Commit

Permalink
Fix policy viev statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
beastie87 committed Nov 27, 2019
1 parent 2732d5d commit bdffbae
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public/image/*
config/settings.local.yml
config/settings/*.local.yml
config/environments/*.local.yml
config/settings.yml
config/settings.yml
.vscode
2 changes: 1 addition & 1 deletion app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def get_mp
return get_divisions(@mp.id, @mp.faction)
end
else
#redirect_to people_path, :notice => "Не занйдено #{params[:mp]}"
redirect_to people_path, :notice => "Не занйдено #{mp_find.join(" ")}"
end
end

Expand Down
13 changes: 12 additions & 1 deletion app/controllers/policies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def show
if params[:history] == '1'
history()
end

end
def detal

Expand Down Expand Up @@ -88,8 +89,18 @@ def provisional?
end
# Use callbacks to share common setup or constraints between actions.
def set_policy

@policy = Policy.includes(:policy_divisions).find(params[:id])
@polisy_mp = @policy.policy_person_distances.includes(:mp).filter_polices(params[:policy])
@policy_level_up = []
(1..8).each do |l|
if @policy.policy_person_distances.filter_polices(l.to_s).count > 0
@policy_level_up << l
end
end
if params[:policy].nil?
params[:policy] = @policy_level_up.first.to_s
end
@polisy_mp = @policy.policy_person_distances.includes(:mp).filter_polices(params[:policy]).where(mps: {end_date: "9999-12-31"})
end

# Never trust parameters from the scary internet, only allow the white list through.
Expand Down
2 changes: 1 addition & 1 deletion app/models/policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Policy < ApplicationRecord
scope :never_voted, -> { where("same = 0 and same_strong = 0 and diff = 0 and diff_strong = 0") }

def self.filter_polices(param)
if param.nil?
if param =="1"
very_strongly_for
elsif param =="2"
strongly_for
Expand Down
2 changes: 1 addition & 1 deletion app/models/policy_person_distance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def voted
end
end
def self.filter_polices(param)
if param.nil?
if param=="1"
very_strongly_for
elsif param =="2"
strongly_for
Expand Down
25 changes: 23 additions & 2 deletions app/views/policies/_show.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="container">
<div class="col-12 list-filters clearfix">
<ul class="sort-first text-uppercase">
<li <%= params[:vote].blank? ? "class=disabled": "" %>><%= link_to "Підтримка політики", policy_path(@policy.id, vote: nil ), remote: true %></li>
<li <%= params[:vote].blank? ? "class=disabled": "" %>><%= link_to "Підтримка політики", policy_path(@policy.id, vote: nil, policy: @policy_level_up.first ), remote: true %></li>
<li <%= params[:vote] == "true" ? "class=disabled": "" %>><%= link_to "Пов’язані голосування (" + @policy.policy_divisions.size.to_s + ")", policy_path(vote: true), remote: true %></li>

</ul>
Expand All @@ -15,16 +15,37 @@
<div class="col-11 list-filters">
<ul class="sort-fraction text-uppercase">
<div style="display: flex; justify-content: space-between">
<li <%= params[:policy].blank? ? "class=active-fon-fraction col col-4": "col col-4" %>><%= link_to "Максимально голосує за", policy_path(@policy.id), remote: true, "data-toggle": "tooltip", "data-placement": "top", title: "між 95% та 100%" %></li>

<% if @policy_level_up.include?(1) %>
<li <%= params[:policy] == "1" ? "class=active-fon-fraction col col-4": "col col-4" %>><%= link_to "Максимально голосує за", policy_path(@policy.id, policy: 1), remote: true, "data-toggle": "tooltip", "data-placement": "top", title: "між 95% та 100%" %></li>
<% end %>
<% if @policy_level_up.include?(2) %>
<li <%= params[:policy] == "2" ? "class=active-fon-fraction col col-4": "col col-4" %>><%= link_to "Послідовно голосує за", policy_path(@policy.id, policy: 2), remote: true, "data-toggle": "tooltip", "data-placement": "top", title: "між 85% та 95%" %></li>
<% end %>
<% if @policy_level_up.include?(3) %>
<li <%= params[:policy] == "3" ? "class=active-fon-fraction col col-4": "col col-4" %>><%= link_to "Переважно голосує за", policy_path(@policy.id, policy: 3 ), remote: true, "data-toggle": "tooltip", "data-placement": "top", title: "між 60% та 85%" %></li>
<% end %>
<% if @policy_level_up.include?(4) %>
<li <%= params[:policy] == "4" ? "class=active-fon-fraction col col-4": "col col-4" %>><%= link_to "Суміш за та проти", policy_path(@policy.id, policy:4 ), remote: true, "data-toggle": "tooltip", "data-placement": "top", title: "між 40% та 60%%" %></li>
<% end %>

</div>

<div style="display: flex; justify-content: space-between">
<% if @policy_level_up.include?(5) %>
<li <%= params[:policy] == "5" ? "class=active-fon-fraction col col-4": "col col-4" %>><%= link_to "Переважно голосує проти", policy_path(@policy.id, policy:5 ), remote: true, "data-toggle": "tooltip", "data-placement": "top", title: "між 15% та 40%" %></li>
<% end %>
<% if @policy_level_up.include?(6) %>
<li <%= params[:policy] == "6" ? "class=active-fon-fraction col col-4": "col col-4" %>><%= link_to "Послідовно голосує проти", policy_path(@policy.id, policy:6 ), remote: true, "data-toggle": "tooltip", "data-placement": "top", title: "між 5,0% та 15%" %></li>
<% end %>
<% if @policy_level_up.include?(7) %>
<li <%= params[:policy] == "7" ? "class=active-fon-fraction col col-4": "col col-4" %>><%= link_to "Максимально голосує проти", policy_path(@policy.id, policy:7 ), remote: true, "data-toggle": "tooltip", "data-placement": "top", title: "між 0,0% та 5,0%" %></li>
<% end %>
<% if @policy_level_up.include?(8) %>
<li <%= params[:policy] == "8" ? "class=active-fon-fraction col col-4": "col col-4" %>><%= link_to "Ніколи не голосує", policy_path(@policy.id, policy:8 ), remote: true, "data-toggle": "tooltip", "data-placement": "top", title: "У разі відсутності депутата та/або його неголосування" %></li>

<% end %>

</div>
</ul>
</div>
Expand Down

0 comments on commit bdffbae

Please sign in to comment.