Merge branch 'master' into 1647-locale_site_customization
This commit is contained in:
@@ -15,6 +15,11 @@ App.Forms =
|
||||
toggleLink: ->
|
||||
$('.js-toggle-link').unbind('click').on('click', ->
|
||||
$($(this).data('toggle-selector')).toggle("down")
|
||||
if $(this).data('toggle-text') isnt undefined
|
||||
toggle_txt = $(this).text()
|
||||
$(this).text( $(this).data('toggle-text') )
|
||||
$(this).data('toggle-text', toggle_txt)
|
||||
|
||||
false
|
||||
)
|
||||
|
||||
@@ -22,4 +27,4 @@ App.Forms =
|
||||
App.Forms.disableEnter()
|
||||
App.Forms.submitOnChange()
|
||||
App.Forms.toggleLink()
|
||||
false
|
||||
false
|
||||
|
||||
@@ -51,7 +51,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
|
||||
|
||||
def budget_investment_params
|
||||
params.require(:budget_investment)
|
||||
.permit(:title, :description, :external_url, :heading_id, :administrator_id, :valuation_tag_list, valuator_ids: [])
|
||||
.permit(:title, :description, :external_url, :heading_id, :administrator_id, :valuation_tag_list, :incompatible, valuator_ids: [])
|
||||
end
|
||||
|
||||
def load_budget
|
||||
|
||||
@@ -5,7 +5,8 @@ module Budgets
|
||||
|
||||
def show
|
||||
authorize! :read_results, @budget
|
||||
@result = load_result
|
||||
@investments = load_result.investments
|
||||
@heading = heading
|
||||
end
|
||||
|
||||
private
|
||||
@@ -19,4 +20,4 @@ module Budgets
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -83,7 +83,12 @@ class Legislation::ProcessesController < Legislation::BaseController
|
||||
|
||||
private
|
||||
|
||||
def member_method?
|
||||
params[:id].present?
|
||||
end
|
||||
|
||||
def set_process
|
||||
return if member_method?
|
||||
@process = ::Legislation::Process.find(params[:process_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,7 +50,9 @@ class Budget
|
||||
scope :undecided, -> { where(feasibility: "undecided") }
|
||||
scope :with_supports, -> { where('cached_votes_up > 0') }
|
||||
scope :selected, -> { feasible.where(selected: true) }
|
||||
scope :winners, -> { selected.where(winner: true) }
|
||||
scope :compatible, -> { where(incompatible: false) }
|
||||
scope :incompatible, -> { where(incompatible: true) }
|
||||
scope :winners, -> { selected.compatible.where(winner: true) }
|
||||
scope :unselected, -> { not_unfeasible.where(selected: false) }
|
||||
scope :last_week, -> { where("created_at >= ?", 7.days.ago)}
|
||||
|
||||
@@ -63,6 +65,7 @@ class Budget
|
||||
scope :for_render, -> { includes(:heading) }
|
||||
|
||||
before_save :calculate_confidence_score
|
||||
after_save :recalculate_heading_winners if :incompatible_changed?
|
||||
before_validation :set_responsible_name
|
||||
before_validation :set_denormalized_ids
|
||||
|
||||
@@ -200,6 +203,10 @@ class Budget
|
||||
self.confidence_score = ScoreCalculator.confidence_score(total_votes, total_votes)
|
||||
end
|
||||
|
||||
def recalculate_heading_winners
|
||||
Budget::Result.new(budget, heading).calculate_winners if incompatible_changed? && winner? && incompatible?
|
||||
end
|
||||
|
||||
def set_responsible_name
|
||||
self.responsible_name = author.try(:document_number) if author.try(:document_number).present?
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ class Budget
|
||||
|
||||
def calculate_winners
|
||||
reset_winners
|
||||
investments.each do |investment|
|
||||
investments.compatible.each do |investment|
|
||||
@current_investment = investment
|
||||
set_winner if inside_budget?
|
||||
end
|
||||
|
||||
@@ -12,7 +12,9 @@
|
||||
<th><%= t("admin.budget_investments.index.table_feasibility") %></th>
|
||||
<th class="text-center"><%= t("admin.budget_investments.index.table_valuation_finished") %></th>
|
||||
<th class="text-center"><%= t("admin.budget_investments.index.table_selection") %></th>
|
||||
<th class="text-center"><%= t("admin.budget_investments.index.table_winner") %></th>
|
||||
<% if params[:filter] == 'selected' %>
|
||||
<th class="text-center"><%= t("admin.budget_investments.index.table_incompatible") %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@@ -75,9 +77,11 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="small text-center">
|
||||
<%= investment.winner? ? t('shared.yes'): t('shared.no') %>
|
||||
</td>
|
||||
<% if params[:filter] == 'selected' %>
|
||||
<td class="small text-center">
|
||||
<%= investment.incompatible? ? t('shared.yes'): t('shared.no') %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</table>
|
||||
|
||||
@@ -61,9 +61,20 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="clear">
|
||||
<h2 id="incompatible"><%= t("admin.budget_investments.edit.compatibility") %></h2>
|
||||
|
||||
<div class="row">
|
||||
<div class="small-12 medium-8 column">
|
||||
<%= f.label :incompatible do %>
|
||||
<%= f.check_box :incompatible, title: t('admin.budget_investments.edit.compatibility'), label: false %>
|
||||
<span class="checkbox"><%= t("admin.budget_investments.edit.mark_as_incompatible") %></span>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="margin-top">
|
||||
<%= f.submit(class: "button", value: t("admin.budget_investments.edit.submit_button")) %>
|
||||
</p>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<hr>
|
||||
|
||||
@@ -56,3 +56,8 @@
|
||||
<p>
|
||||
<%= link_to t("admin.budget_investments.show.new_milestone"), new_admin_budget_budget_investment_budget_investment_milestone_path(@budget, @investment) %>
|
||||
</p>
|
||||
|
||||
<h2 id="incompatible"><%= t("admin.budget_investments.show.compatibility.title") %></h2>
|
||||
<p id="incompatible">
|
||||
<%= t("admin.budget_investments.show.compatibility.#{@investment.incompatible?}") %>
|
||||
</p>
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
<div class="small-12 medium-9 column" id="results-container">
|
||||
<div class="small-12 medium-9 column <%= results_type == :compatible ? 'success' : 'js-discarded' %>" id="<%= results_type %>-container">
|
||||
|
||||
<h3 class="inline-block">
|
||||
<%= heading.name %>
|
||||
<%= title %>
|
||||
</h3>
|
||||
|
||||
<%= link_to t("budgets.results.show_all_link"), "#",
|
||||
class: "js-toggle-link button hollow margin-bottom float-right",
|
||||
data: {'toggle-selector' => '.js-discarded',
|
||||
'toggle-text' => t("budgets.results.hide_discarded_link")} %>
|
||||
|
||||
<table id="budget-investments-results" class="table-for-mobile">
|
||||
<table id="budget-investments-<%= results_type %>" class="table-for-mobile">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">
|
||||
@@ -20,23 +16,19 @@
|
||||
<th scope="col" class="text-center">
|
||||
<%= t("budgets.results.price") %>
|
||||
</th>
|
||||
<th scope="col" class="text-right">
|
||||
<%= format_price(heading.price) %><br>
|
||||
<small><%= t("budgets.results.amount_available") %></small>
|
||||
</th>
|
||||
<% if results_type == :compatible %>
|
||||
<th scope="col" class="text-right">
|
||||
<%= format_price(heading_price) %><br>
|
||||
<small><%= t("budgets.results.amount_available") %></small>
|
||||
</th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% amount_available = heading.price %>
|
||||
<% @result.investments.each do |investment| %>
|
||||
<% if investment.winner? %>
|
||||
<tr id="<%= dom_id(investment) %>"
|
||||
class="spending_proposal success">
|
||||
<% else %>
|
||||
<tr id="<%= dom_id(investment) %>"
|
||||
class="spending_proposal js-discarded" style="display:none">
|
||||
<% end %>
|
||||
<% amount_available = heading_price %>
|
||||
<% investments.each do |investment| %>
|
||||
<tr id="<%= dom_id(investment) %>" class="budget-investments <%= investment.winner? ? 'success' : 'js-discarded' %>">
|
||||
<td>
|
||||
<% if investment.winner? %>
|
||||
<span class="icon-check">
|
||||
@@ -51,8 +43,7 @@
|
||||
</span>
|
||||
</span>
|
||||
<% end %>
|
||||
<%= link_to investment.title,
|
||||
budget_investment_path(@budget, investment) %>
|
||||
<%= link_to investment.title, budget_investment_path(@budget, investment) %>
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<%= investment.ballot_lines_count %>
|
||||
@@ -60,11 +51,13 @@
|
||||
<td class="text-center">
|
||||
<%= format_price investment.price %>
|
||||
</td>
|
||||
<td class="small text-right"
|
||||
title="<%= format_price(amount_available) %> - <%= format_price(investment.price) %>">
|
||||
<%= format_price amount_available - investment.price %>
|
||||
<% amount_available -= investment.price if investment.winner? %>
|
||||
</td>
|
||||
<% if results_type == :compatible %>
|
||||
<td class="small text-right"
|
||||
title="<%= format_price(amount_available) %> - <%= format_price(investment.price) %>">
|
||||
<%= format_price amount_available - investment.price %>
|
||||
<% amount_available -= investment.price if investment.winner? %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<% provide :title, t("budgets.results.page_title", budget: @budget.name) %>
|
||||
<% content_for :canonical do %>
|
||||
<%= render "shared/canonical", href: budget_results_url(@budget, heading_id: @result.heading) %>
|
||||
<%= render "shared/canonical", href: budget_results_url(@budget, heading_id: @heading) %>
|
||||
<% end %>
|
||||
|
||||
<div class="expanded budget no-margin-top">
|
||||
@@ -34,5 +34,16 @@
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<%= render 'results_table', heading: @result.heading %>
|
||||
<span class="float-right"><%= link_to t("budgets.results.hide_discarded_link"), "#", class: "js-toggle-link button hollow margin-bottom", data: {'toggle-selector' => '.js-discarded', 'toggle-text' => t("budgets.results.show_all_link")} %></span>
|
||||
|
||||
|
||||
<%= render 'results_table', results_type: :compatible,
|
||||
title: @heading.name,
|
||||
heading_price: @heading.price,
|
||||
investments: @investments.compatible %>
|
||||
|
||||
<%= render 'results_table', results_type: :incompatible,
|
||||
title: t("budgets.results.incompatibles"),
|
||||
heading_price: @heading.price,
|
||||
investments: @investments.incompatible %>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user