From aaccf87ec5f2050dd1d36e54e1c90decbd0097d9 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 18 Jan 2018 16:51:02 +0100 Subject: [PATCH 1/9] adds new partial for phases info on budget homepage --- app/views/budgets/_phases.html.erb | 17 +++++++++++++++++ app/views/budgets/index.html.erb | 9 ++++----- 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 app/views/budgets/_phases.html.erb diff --git a/app/views/budgets/_phases.html.erb b/app/views/budgets/_phases.html.erb new file mode 100644 index 000000000..a50f48503 --- /dev/null +++ b/app/views/budgets/_phases.html.erb @@ -0,0 +1,17 @@ + diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index bf0bbe7ab..b8e057a2f 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -10,7 +10,9 @@

<%= @budget.name %>

<%= safe_html_with_links(@budget.description) %> - <%= link_to t("budgets.index.section_header.help"), "#section_help" %> +

+ <%= link_to t("budgets.index.section_header.help"), "#section_help" %> +

@@ -94,10 +96,7 @@

<%= t("budgets.index.all_phases") %>

- + <%= render "phases" %>
From c9994da33975e0f988d0222ff0a30fad39b96727 Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 18 Jan 2018 16:51:16 +0100 Subject: [PATCH 2/9] adds css styles --- app/assets/stylesheets/participation.scss | 57 +++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index a8a593dab..0c4aee9fa 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -1472,6 +1472,63 @@ } } +.budget-timeline { + border-left: 3px solid $budget; + margin-left: $line-height / 2; + padding: $line-height $line-height / 2; + + h3, + span, + p { + padding: 0 $line-height / 4; + } + + h3 { + margin-bottom: 0; + } + + span { + color: $text-medium; + display: block; + font-size: $small-font-size; + margin-bottom: $line-height / 2; + } + + .phase { + position: relative; + + &:not(:first-child) { + margin-top: $line-height * 1.5; + } + + &::before { + background-color: #fff; + border: 4px solid $budget; + border-radius: 100%; + content: ''; + height: 16px; + left: -22px; + position: absolute; + top: 6px; + width: 16px; + z-index: 99; + } + + &.active { + + h3 { + background: $budget; + color: white; + display: inline-block; + } + + &::before { + background-color: $budget; + } + } + } +} + // 07. Proposals successful // ------------------------- From b48fb7a41e9864f53a375b965bb287770dd029af Mon Sep 17 00:00:00 2001 From: decabeza Date: Thu, 18 Jan 2018 16:51:30 +0100 Subject: [PATCH 3/9] adds specs --- spec/features/budgets/budgets_spec.rb | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/spec/features/budgets/budgets_spec.rb b/spec/features/budgets/budgets_spec.rb index bb7ab2e91..4756be10f 100644 --- a/spec/features/budgets/budgets_spec.rb +++ b/spec/features/budgets/budgets_spec.rb @@ -45,6 +45,71 @@ feature 'Budgets' do end end + scenario 'Index shows only published phases' do + + budget.update(phase: :finished) + + budget.phases.drafting.update(starts_at: '30-12-2017', ends_at: '31-12-2017', enabled: true, + description: 'Description of drafting phase', + summary: 'This is the summary for drafting phase') + + budget.phases.accepting.update(starts_at: '01-01-2018', ends_at: '10-01-2018', enabled: true, + description: 'Description of accepting phase', + summary: 'This is the summary for accepting phase') + + budget.phases.reviewing.update(starts_at: '11-01-2018', ends_at: '20-01-2018', enabled: false, + description: 'Description of reviewing phase', + summary: 'This is the summary for reviewing phase') + + budget.phases.selecting.update(starts_at: '21-01-2018', ends_at: '01-02-2018', enabled: true, + description: 'Description of selecting phase', + summary: 'This is the summary for selecting phase') + + budget.phases.valuating.update(starts_at: '10-02-2018', ends_at: '20-02-2018', enabled: false, + description: 'Description of valuating phase', + summary: 'This is the summary for valuating phase') + + budget.phases.publishing_prices.update(starts_at: '21-02-2018', ends_at: '01-03-2018', enabled: false, + description: 'Description of publishing prices phase', + summary: 'This is the summary for publishing_prices phase') + + budget.phases.balloting.update(starts_at: '02-03-2018', ends_at: '10-03-2018', enabled: true, + description: 'Description of balloting phase', + summary: 'This is the summary for balloting phase') + + budget.phases.reviewing_ballots.update(starts_at: '11-03-2018', ends_at: '20-03-2018', enabled: false, + description: 'Description of reviewing ballots phase', + summary: 'This is the summary for reviewing_ballots phase') + + budget.phases.finished.update(starts_at: '21-03-2018', ends_at: '30-03-2018', enabled: true, + description: 'Description of finished phase', + summary: 'This is the summary for finished phase') + + visit budgets_path + + expect(page).not_to have_content "This is the summary for drafting phase" + expect(page).not_to have_content "30 Dec 2017 - 31 Dec 2017" + expect(page).not_to have_content "This is the summary for reviewing phase" + expect(page).not_to have_content "11 Jan 2018 - 20 Jan 2018" + expect(page).not_to have_content "This is the summary for valuating phase" + expect(page).not_to have_content "10 Feb 2018 - 20 Feb 2018" + expect(page).not_to have_content "This is the summary for publishing_prices phase" + expect(page).not_to have_content "21 Feb 2018 - 01 Mar 2018" + expect(page).not_to have_content "This is the summary for reviewing_ballots phase" + expect(page).not_to have_content "11 Mar 2018 - 20 Mar 2018'" + + expect(page).to have_content "This is the summary for accepting phase" + expect(page).to have_content "01 Jan 2018 - 21 Jan 2018" + expect(page).to have_content "This is the summary for selecting phase" + expect(page).to have_content "21 Jan 2018 - 02 Mar 2018" + expect(page).to have_content "This is the summary for balloting phase" + expect(page).to have_content "02 Mar 2018 - 21 Mar 2018" + expect(page).to have_content "This is the summary for finished phase" + expect(page).to have_content "21 Mar 2018 - 30 Mar 2018" + + expect(page).to have_css(".phase.active", count: 1) + end + context 'Show' do scenario "List all groups" do From 7599eb4c352615b4430771d71726a6674ef0d93e Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 18 Jan 2018 17:14:58 +0100 Subject: [PATCH 4/9] Refactor budget phases step progress functions and usage --- app/models/budget.rb | 2 +- app/models/budget/phase.rb | 2 +- app/views/budgets/index.html.erb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/budget.rb b/app/models/budget.rb index 5d24e2437..8457ba1ac 100644 --- a/app/models/budget.rb +++ b/app/models/budget.rb @@ -41,7 +41,7 @@ class Budget < ActiveRecord::Base end def published_phases - phases.published + phases.published.order(:id) end def description diff --git a/app/models/budget/phase.rb b/app/models/budget/phase.rb index 87a3909a0..61f778678 100644 --- a/app/models/budget/phase.rb +++ b/app/models/budget/phase.rb @@ -56,7 +56,7 @@ class Budget end def step_number - budget.published_phases.order(:id).index(self) + 1 || 0 + budget.published_phases.index(self) + 1 || 0 end private diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index b8e057a2f..ef94c423d 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -16,8 +16,8 @@

- <% steps_progress = "(#{current_phase.step_number}/#{@budget.published_phases.count})" %> - <%= t('budgets.show.phase') %> <%= steps_progress %> + <% steps = "(#{@budget.current_phase.step_number}/#{@budget.published_phases.count})" %> + <%= t('budgets.show.phase') %> <%= steps %>

<%= t("budgets.phase.#{@budget.phase}") %>

From 872e7ceb02678ced470bd2707d68ef5996fa22cc Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 18 Jan 2018 17:15:21 +0100 Subject: [PATCH 5/9] Use budget published_phases's method to get them ordered, and decrease final date --- app/views/budgets/_phases.html.erb | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/app/views/budgets/_phases.html.erb b/app/views/budgets/_phases.html.erb index a50f48503..fbf65ab22 100644 --- a/app/views/budgets/_phases.html.erb +++ b/app/views/budgets/_phases.html.erb @@ -1,15 +1,11 @@
    - <% @budget.phases.published.each do |phase| %> + <% @budget.published_phases.each do |phase| %>
  • <%= t("budgets.phase.#{phase.kind}") %>

    - <% if phase.starts_at.to_date.present? %> - <%= format_date(phase.starts_at) %> - <% end %> + <%= format_date(phase.starts_at) if phase.starts_at.present? %> - - <% if phase.ends_at.to_date.present? %> - <%= format_date(phase.ends_at) %> - <% end %> + <%= format_date(phase.ends_at - 1.day) if phase.ends_at.present? %>

    <%= phase.summary %>

  • From e4e9a149b0c0b5cca0c8ba1d1376b64d76c07f6d Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 18 Jan 2018 17:17:13 +0100 Subject: [PATCH 6/9] Update expectations after decreasing end date of budget phase --- spec/features/budgets/budgets_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/features/budgets/budgets_spec.rb b/spec/features/budgets/budgets_spec.rb index 4756be10f..ced6a2328 100644 --- a/spec/features/budgets/budgets_spec.rb +++ b/spec/features/budgets/budgets_spec.rb @@ -99,13 +99,13 @@ feature 'Budgets' do expect(page).not_to have_content "11 Mar 2018 - 20 Mar 2018'" expect(page).to have_content "This is the summary for accepting phase" - expect(page).to have_content "01 Jan 2018 - 21 Jan 2018" + expect(page).to have_content "01 Jan 2018 - 20 Jan 2018" expect(page).to have_content "This is the summary for selecting phase" - expect(page).to have_content "21 Jan 2018 - 02 Mar 2018" + expect(page).to have_content "21 Jan 2018 - 01 Mar 2018" expect(page).to have_content "This is the summary for balloting phase" - expect(page).to have_content "02 Mar 2018 - 21 Mar 2018" + expect(page).to have_content "02 Mar 2018 - 20 Mar 2018" expect(page).to have_content "This is the summary for finished phase" - expect(page).to have_content "21 Mar 2018 - 30 Mar 2018" + expect(page).to have_content "21 Mar 2018 - 29 Mar 2018" expect(page).to have_css(".phase.active", count: 1) end From 95a794237280342e9e535c93318ec51b88fbd685 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 18 Jan 2018 17:37:08 +0100 Subject: [PATCH 7/9] Some css class improvements at budget list on /budget --- app/views/budgets/index.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index ef94c423d..465b50cf3 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -119,11 +119,11 @@
    -
    +

    <%= budget.name %>

    <%= budget.description %>
    -
    +
    <%= link_to t("budgets.index.see_results"), budget_results_path(budget.id), From e6e9e2db055a00dce01900ad7beeb06cbf09dcfe Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 18 Jan 2018 17:40:37 +0100 Subject: [PATCH 8/9] Render budget description html with links on budget index --- app/views/budgets/index.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/budgets/index.html.erb b/app/views/budgets/index.html.erb index 465b50cf3..2b1905e29 100644 --- a/app/views/budgets/index.html.erb +++ b/app/views/budgets/index.html.erb @@ -121,7 +121,7 @@

    <%= budget.name %>

    - <%= budget.description %> + <%= safe_html_with_links(budget.description) %>
    From 06a178544514cf283880330af1684f2100a05eda Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 18 Jan 2018 17:55:21 +0100 Subject: [PATCH 9/9] Prevent empty html to be safe rendered to html with links --- app/helpers/text_with_links_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/helpers/text_with_links_helper.rb b/app/helpers/text_with_links_helper.rb index baff460a1..9144bdd6b 100644 --- a/app/helpers/text_with_links_helper.rb +++ b/app/helpers/text_with_links_helper.rb @@ -7,6 +7,7 @@ module TextWithLinksHelper end def safe_html_with_links(html) + return if html.nil? return html.html_safe unless html.html_safe? Rinku.auto_link(html, :all, 'target="_blank" rel="nofollow"').html_safe end