diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 4bc64f9a5..5469f2658 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -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 { diff --git a/app/controllers/budgets/executions_controller.rb b/app/controllers/budgets/executions_controller.rb index e33f43dcd..b321c4377 100644 --- a/app/controllers/budgets/executions_controller.rb +++ b/app/controllers/budgets/executions_controller.rb @@ -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 diff --git a/app/helpers/budget_executions_helper.rb b/app/helpers/budget_executions_helper.rb index fd8376987..d77867052 100644 --- a/app/helpers/budget_executions_helper.rb +++ b/app/helpers/budget_executions_helper.rb @@ -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 diff --git a/app/models/budget/investment/milestone.rb b/app/models/budget/investment/milestone.rb index 562be54b8..f59705ede 100644 --- a/app/models/budget/investment/milestone.rb +++ b/app/models/budget/investment/milestone.rb @@ -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") } diff --git a/app/views/budgets/executions/_image.html.erb b/app/views/budgets/executions/_image.html.erb new file mode 100644 index 000000000..639761875 --- /dev/null +++ b/app/views/budgets/executions/_image.html.erb @@ -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 %> diff --git a/app/views/budgets/executions/_investments.html.erb b/app/views/budgets/executions/_investments.html.erb index b329e1a7b..e9ddd48fb 100644 --- a/app/views/budgets/executions/_investments.html.erb +++ b/app/views/budgets/executions/_investments.html.erb @@ -7,15 +7,7 @@
<%= 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 %>
<%= investment.title %>
diff --git a/app/views/budgets/executions/show.html.erb b/app/views/budgets/executions/show.html.erb index c6844c955..91f50684a 100644 --- a/app/views/budgets/executions/show.html.erb +++ b/app/views/budgets/executions/show.html.erb @@ -55,7 +55,7 @@
<%= form_tag(budget_executions_path(@budget), method: :get) do %>
- <%= 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)})" }, diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index 4f9184477..bc236377f 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -136,17 +136,20 @@
-
+

<%= budget.name %>

-
+
<%= 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" %>
diff --git a/config/locales/en/budgets.yml b/config/locales/en/budgets.yml index 7aae18bfd..ec1887f37 100644 --- a/config/locales/en/budgets.yml +++ b/config/locales/en/budgets.yml @@ -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" diff --git a/config/locales/es/budgets.yml b/config/locales/es/budgets.yml index 531960330..9b477a586 100644 --- a/config/locales/es/budgets.yml +++ b/config/locales/es/budgets.yml @@ -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" diff --git a/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index 5449c8c4b..9627cb793 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -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