From 7d55f64aace3942d08a15bcaae443dc7826197e6 Mon Sep 17 00:00:00 2001 From: decabeza Date: Mon, 10 Sep 2018 17:51:42 +0200 Subject: [PATCH 1/8] Adds link to milestones on budgets index page --- app/assets/stylesheets/participation.scss | 4 ++++ app/views/budgets/index.html.erb | 9 ++++++--- config/locales/en/budgets.yml | 1 + config/locales/es/budgets.yml | 1 + 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 4bc64f9a5..0779a367a 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; + } } } 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 e20c9f09f..db43eca30 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" From 5856af03a5b70831cedec3caaf018aaa5b5b486a Mon Sep 17 00:00:00 2001 From: voodoorai2000 Date: Mon, 10 Sep 2018 18:36:04 +0200 Subject: [PATCH 2/8] Fix exception when no available milestones We were getting an exception when quering[1] for milestones which were not present, due to for example having a publication date later than today Adding a `try` statement and spec to avoid this situation [1] https://github.com/AyuntamientoMadrid/consul/blob/82efc3dd661675dad753eaa0c485fab5d27a7d9f/app/controllers/budgets/executions_controller.rb#L16 --- app/controllers/budgets/executions_controller.rb | 2 +- spec/features/budgets/executions_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index 5449c8c4b..56e030ec7 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -249,4 +249,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 custom_budget_executions_path(budget, status: status.id) + + expect(page).to have_content('No winner investments in this state') + end + + end end From d698a724acfb62b51523a628818cdcd74d52d919 Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 12 Sep 2018 16:23:17 +0200 Subject: [PATCH 3/8] Moves milestone image to a partial --- app/views/budgets/executions/_image.html.erb | 9 +++++++++ app/views/budgets/executions/_investments.html.erb | 10 +--------- 2 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 app/views/budgets/executions/_image.html.erb diff --git a/app/views/budgets/executions/_image.html.erb b/app/views/budgets/executions/_image.html.erb new file mode 100644 index 000000000..e23cd2375 --- /dev/null +++ b/app/views/budgets/executions/_image.html.erb @@ -0,0 +1,9 @@ +<% 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 %> 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 %>
From ba1a6b4cc8d0d4e80841e1bdfbe172b6ab2a224d Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 12 Sep 2018 18:36:17 +0200 Subject: [PATCH 4/8] Display first image available for milestones --- app/helpers/budget_executions_helper.rb | 5 +++++ app/views/budgets/executions/_image.html.erb | 16 ++++++++-------- spec/features/budgets/executions_spec.rb | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/helpers/budget_executions_helper.rb b/app/helpers/budget_executions_helper.rb index fd8376987..d1b6ab15d 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(publication_date: :asc, created_at: :asc) + .select{ |milestone| milestone.image.present? }.first + end + end diff --git a/app/views/budgets/executions/_image.html.erb b/app/views/budgets/executions/_image.html.erb index e23cd2375..639761875 100644 --- a/app/views/budgets/executions/_image.html.erb +++ b/app/views/budgets/executions/_image.html.erb @@ -1,9 +1,9 @@ -<% 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 %> +<% 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/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index 56e030ec7..f3f6a1432 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) @@ -99,15 +100,21 @@ feature 'Executions' do expect(page).to have_css("img[alt='#{investment4.title}']") end - scenario "renders last milestone's image if investment has multiple milestones with images associated" do + scenario "renders first 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) @@ -116,8 +123,8 @@ feature 'Executions' do 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}']") end + end context 'Filters' do From 1d5335c782600569d7c4d8d595cb3c873361c07a Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 7 Nov 2018 18:25:02 +0100 Subject: [PATCH 5/8] Display last milestones image Also adds a second order to ensure the order to display milestones with same publication date is always the same --- app/helpers/budget_executions_helper.rb | 4 ++-- app/models/budget/investment/milestone.rb | 2 +- spec/features/budgets/executions_spec.rb | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/helpers/budget_executions_helper.rb b/app/helpers/budget_executions_helper.rb index d1b6ab15d..d77867052 100644 --- a/app/helpers/budget_executions_helper.rb +++ b/app/helpers/budget_executions_helper.rb @@ -7,8 +7,8 @@ module BudgetExecutionsHelper end def first_milestone_with_image(investment) - investment.milestones.order(publication_date: :asc, created_at: :asc) - .select{ |milestone| milestone.image.present? }.first + 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/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index f3f6a1432..e9b2dbb50 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -100,7 +100,7 @@ feature 'Executions' do expect(page).to have_css("img[alt='#{investment4.title}']") end - scenario "renders first milestone's image if investment has multiple milestones with images associated" 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: Date.yesterday) @@ -122,7 +122,7 @@ 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).to have_css("img[alt='#{milestone3.image.title}']") end end From 7dd530dad7c7ba473d84c7cd59c7007aa3267746 Mon Sep 17 00:00:00 2001 From: decabeza Date: Wed, 7 Nov 2018 18:25:18 +0100 Subject: [PATCH 6/8] Adds missing for to budget exections status label tag --- app/views/budgets/executions/show.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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)})" }, From 3817f59f25c4cde7e91da89336c47e01c78eb082 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 8 Nov 2018 11:57:07 +0100 Subject: [PATCH 7/8] Improves styles to show budgets executions images --- app/assets/stylesheets/participation.scss | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 0779a367a..5469f2658 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1695,9 +1695,10 @@ img { height: $line-height * 9; + min-width: 100%; + max-width: none; transition-duration: 0.3s; transition-property: transform; - width: 100%; } &:hover { From 0c5ac8cba6e43b1d69ef53fe40f816a957844073 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 8 Nov 2018 11:59:29 +0100 Subject: [PATCH 8/8] Removes custom path on budgets executions specs --- spec/features/budgets/executions_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/budgets/executions_spec.rb b/spec/features/budgets/executions_spec.rb index e9b2dbb50..9627cb793 100644 --- a/spec/features/budgets/executions_spec.rb +++ b/spec/features/budgets/executions_spec.rb @@ -264,7 +264,7 @@ feature 'Executions' do unpublished_milestone = create(:budget_investment_milestone, investment: investment1, status: status, publication_date: Date.tomorrow) - visit custom_budget_executions_path(budget, status: status.id) + visit budget_executions_path(budget, status: status.id) expect(page).to have_content('No winner investments in this state') end