Merge pull request #3023 from consul/budget-executions

[Backport] Budget executions
This commit is contained in:
Alberto
2018-11-08 13:01:27 +01:00
committed by GitHub
11 changed files with 58 additions and 21 deletions

View File

@@ -760,6 +760,10 @@
&.past-budgets {
min-height: 0;
.button ~ .button {
margin-left: $line-height / 2;
}
}
}
@@ -1691,9 +1695,10 @@
img {
height: $line-height * 9;
min-width: 100%;
max-width: none;
transition-duration: 0.3s;
transition-property: transform;
width: 100%;
}
&:hover {

View File

@@ -13,7 +13,7 @@ module Budgets
.joins(:milestones).includes(:milestones)
.select { |i| i.milestones.published.with_status
.order_by_publication_date.last
.status_id == params[:status].to_i }
.try(:status_id) == params[:status].to_i }
.uniq
.group_by(&:heading)
else

View File

@@ -6,4 +6,9 @@ module BudgetExecutionsHelper
.last.status_id == status rescue false }.count
end
def first_milestone_with_image(investment)
investment.milestones.order_by_publication_date
.select{ |milestone| milestone.image.present? }.last
end
end

View File

@@ -17,7 +17,7 @@ class Budget
validates :publication_date, presence: true
validate :description_or_status_present?
scope :order_by_publication_date, -> { order(publication_date: :asc) }
scope :order_by_publication_date, -> { order(publication_date: :asc, created_at: :asc) }
scope :published, -> { where("publication_date <= ?", Date.current) }
scope :with_status, -> { where("status_id IS NOT NULL") }

View File

@@ -0,0 +1,9 @@
<% milestone = first_milestone_with_image(investment) %>
<% if milestone&.image.present? %>
<%= image_tag milestone.image_url(:large), alt: milestone.image.title %>
<% elsif investment.image.present? %>
<%= image_tag investment.image_url(:large), alt: investment.image.title %>
<% else %>
<%= image_tag "budget_execution_no_image.jpg", alt: investment.title %>
<% end %>

View File

@@ -7,15 +7,7 @@
<div class="small-12 medium-6 large-4 column end margin-bottom">
<div class="budget-execution">
<%= link_to budget_investment_path(@budget, investment, anchor: "tab-milestones"), data: { 'equalizer-watch': true } do %>
<% investment.milestones.order(publication_date: :desc).limit(1).each do |milestone| %>
<% if milestone.image.present? %>
<%= image_tag milestone.image_url(:large), alt: milestone.image.title %>
<% elsif investment.image.present? %>
<%= image_tag investment.image_url(:thumb), alt: investment.image.title %>
<% else %>
<%= image_tag "budget_execution_no_image.jpg", alt: investment.title %>
<% end %>
<% end %>
<%= render 'image', investment: investment %>
<div class="budget-execution-info">
<div class="budget-execution-content">
<h5><%= investment.title %></h5>

View File

@@ -55,7 +55,7 @@
<div class="small-12 medium-9 large-10 column">
<%= form_tag(budget_executions_path(@budget), method: :get) do %>
<div class="small-12 medium-3 column">
<%= label_tag t("budgets.executions.filters.label") %>
<%= label_tag :status, t("budgets.executions.filters.label") %>
<%= select_tag :status,
options_from_collection_for_select(@statuses,
:id, lambda { |s| "#{s.name} (#{filters_select_counts(s.id)})" },

View File

@@ -136,17 +136,20 @@
<div class="budget-investment clear">
<div class="panel past-budgets">
<div class="row" data-equalizer data-equalizer-on="medium">
<div class="small-12 medium-9 column table" data-equalizer-watch>
<div class="small-12 medium-6 column table" data-equalizer-watch>
<div class="table-cell align-middle">
<h3><%= budget.name %></h3>
</div>
</div>
<div class="small-12 medium-3 column table" data-equalizer-watch>
<div class="small-12 medium-6 column table" data-equalizer-watch>
<div id="budget_<%= budget.id %>_results" class="table-cell align-middle">
<%= link_to t("budgets.index.see_results"),
budget_results_path(budget.id),
class: "button expanded" %>
class: "button" %>
<%= link_to t("budgets.index.milestones"),
budget_executions_path(budget.id),
class: "button" %>
</div>
</div>
</div>

View File

@@ -57,6 +57,7 @@ en:
section_footer:
title: Help with participatory budgets
description: With the participatory budgets the citizens decide to which projects is destined a part of the budget.
milestones: Milestones
investments:
form:
tag_category_label: "Categories"

View File

@@ -57,6 +57,7 @@ es:
section_footer:
title: Ayuda sobre presupuestos participativos
description: Con los presupuestos participativos la ciudadanía decide a qué proyectos va destinada una parte del presupuesto.
milestones: Seguimiento de proyectos
investments:
form:
tag_category_label: "Categorías"

View File

@@ -61,6 +61,7 @@ feature 'Executions' do
end
context 'Images' do
scenario 'renders milestone image if available' do
milestone1 = create(:budget_investment_milestone, investment: investment1)
create(:image, imageable: milestone1)
@@ -101,13 +102,19 @@ feature 'Executions' do
scenario "renders last milestone's image if investment has multiple milestones with images associated" do
milestone1 = create(:budget_investment_milestone, investment: investment1,
publication_date: 2.weeks.ago)
publication_date: Date.yesterday)
milestone2 = create(:budget_investment_milestone, investment: investment1,
publication_date: Date.yesterday)
create(:image, imageable: milestone1, title: 'First milestone image')
create(:image, imageable: milestone2, title: 'Second milestone image')
milestone3 = create(:budget_investment_milestone, investment: investment1,
publication_date: Date.yesterday)
milestone4 = create(:budget_investment_milestone, investment: investment1,
publication_date: Date.yesterday)
create(:image, imageable: milestone2, title: 'Image for first milestone with image')
create(:image, imageable: milestone3, title: 'Image for second milestone with image')
visit budget_path(budget)
@@ -115,9 +122,9 @@ feature 'Executions' do
click_link 'Milestones'
expect(page).to have_content(investment1.title)
expect(page).to have_css("img[alt='#{milestone2.image.title}']")
expect(page).not_to have_css("img[alt='#{milestone1.image.title}']")
expect(page).to have_css("img[alt='#{milestone3.image.title}']")
end
end
context 'Filters' do
@@ -249,4 +256,18 @@ feature 'Executions' do
expect(m_heading.name).to appear_before(z_heading.name)
end
end
context 'No milestones' do
scenario 'Milestone not yet published' do
status = create(:budget_investment_status)
unpublished_milestone = create(:budget_investment_milestone, investment: investment1,
status: status, publication_date: Date.tomorrow)
visit budget_executions_path(budget, status: status.id)
expect(page).to have_content('No winner investments in this state')
end
end
end