From 1f0ee32998018af7d3870fb6f4ca7c848ca485f4 Mon Sep 17 00:00:00 2001 From: Bertocq Date: Thu, 22 Mar 2018 22:29:39 +0100 Subject: [PATCH 1/3] Add max headings label on Group list --- app/views/admin/budgets/_group.html.erb | 5 +++++ config/locales/en/admin.yml | 1 + config/locales/es/admin.yml | 1 + spec/features/admin/budget_groups_spec.rb | 3 +++ 4 files changed, 10 insertions(+) diff --git a/app/views/admin/budgets/_group.html.erb b/app/views/admin/budgets/_group.html.erb index 360fd75a7..f5922846e 100644 --- a/app/views/admin/budgets/_group.html.erb +++ b/app/views/admin/budgets/_group.html.erb @@ -1,8 +1,13 @@ +<% max_headings_label = t('admin.budgets.form.current_of_max_headings', current: group.max_votable_headings, max: group.headings.count ) %>
<%= content_tag(:span, group.name, class:"group-toggle-#{group.id}", id:"group-name-#{group.id}") %> + + <%= t("admin.budgets.form.max_votable_headings")%> + <%= max_headings_label %> + <%= render 'admin/budgets/group_form', budget: @budget, group: group, id: "group-form-#{group.id}", button_title: t("admin.budgets.form.submit"), css_class: "group-toggle-#{group.id}" %> <%= link_to t("admin.budgets.form.edit_group"), "#", class: "button float-right js-toggle-link hollow", data: { "toggle-selector" => ".group-toggle-#{group.id}" } %> <%= link_to t("admin.budgets.form.add_heading"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => "#group-#{group.id}-new-heading-form" } %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 67273c327..aa2099f3d 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -121,6 +121,7 @@ en: table_population: Population population_info: "Budget Heading population field is used for Statistic purposes at the end of the Budget to show for each Heading that represents an area with population what percentage voted. The field is optional so you can leave it empty if it doesn't apply." max_votable_headings: "Maxium number of headings in which a user can vote" + current_of_max_headings: "%{current} of %{max}" winners: calculate: Calculate Winner Investments calculated: Winners being calculated, it may take a minute. diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 8e3c546f9..12000c207 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -121,6 +121,7 @@ es: table_population: Población population_info: "El campo población de las partidas presupuestarias se usa con fines estadísticos únicamente, con el objetivo de mostrar el porcentaje de votos habidos en cada partida que represente un área con población. Es un campo opcional, así que puedes dejarlo en blanco si no aplica." max_votable_headings: "Máximo número de partidas en que un usuario puede votar" + current_of_max_headings: "%{current} de %{max}" winners: calculate: Calcular propuestas ganadoras calculated: Calculando ganadoras, puede tardar un minuto. diff --git a/spec/features/admin/budget_groups_spec.rb b/spec/features/admin/budget_groups_spec.rb index 3c58a462e..664c4aeda 100644 --- a/spec/features/admin/budget_groups_spec.rb +++ b/spec/features/admin/budget_groups_spec.rb @@ -49,6 +49,8 @@ feature 'Admin can change the groups name' do scenario "Defaults to 1 heading per group", :js do visit admin_budget_path(group.budget) + expect(page).to have_content('Maxium number of headings in which a user can vote 1 of 3') + within("#budget_group_#{group.id}") do click_link 'Edit group' @@ -67,6 +69,7 @@ feature 'Admin can change the groups name' do end visit admin_budget_path(group.budget) + expect(page).to have_content('Maxium number of headings in which a user can vote 2 of 3') within("#budget_group_#{group.id}") do click_link 'Edit group' From f871868a2bf66207f1e8a688b8710c2748cca7da Mon Sep 17 00:00:00 2001 From: iagirre Date: Tue, 3 Apr 2018 08:55:06 +0200 Subject: [PATCH 2/3] Max headings are updated when editing heading The max headings label is updated automatically when updating the heading. It is done via AJAX and a refresh isn't needed. --- app/assets/stylesheets/admin.scss | 11 +++++++++++ app/views/admin/budget_groups/update.js.erb | 1 + app/views/admin/budgets/_group.html.erb | 8 +++----- app/views/admin/budgets/_max_headings_label.html.erb | 5 +++++ config/locales/en/admin.yml | 2 +- 5 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 app/views/admin/budgets/_max_headings_label.html.erb diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index e5070af3b..a8d81a12d 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -1165,6 +1165,17 @@ table { } } +.max-headings-label { + color: $text-medium; + font-size: $small-font-size; + margin-left: $line-height / 2; +} + +.current-of-max-headings { + color: #000; + font-weight: bold; +} + // 11. Newsletters // ----------------- diff --git a/app/views/admin/budget_groups/update.js.erb b/app/views/admin/budget_groups/update.js.erb index 5a5a244df..c4f9774ba 100644 --- a/app/views/admin/budget_groups/update.js.erb +++ b/app/views/admin/budget_groups/update.js.erb @@ -2,5 +2,6 @@ $("#group-form-<%= @group.id %>").html('<%= j render("admin/budgets/group_form", group: @group, budget: @group.budget, button_title: t("admin.budgets.form.submit"), id: "group-form-#{@group.id}", css_class: "group-toggle-#{@group.id}" ) %>'); <% else %> $("#group-name-<%= @group.id %>").html('<%= @group.name %>') + $("#max-heading-label-<%=@group.id%>").html('<%= j render("admin/budgets/max_headings_label", current: @group.max_votable_headings, max: @group.headings.count, group: @group) %>') $(".group-toggle-<%= @group.id %>").toggle() <% end %> diff --git a/app/views/admin/budgets/_group.html.erb b/app/views/admin/budgets/_group.html.erb index f5922846e..f38d34a9d 100644 --- a/app/views/admin/budgets/_group.html.erb +++ b/app/views/admin/budgets/_group.html.erb @@ -1,13 +1,11 @@ -<% max_headings_label = t('admin.budgets.form.current_of_max_headings', current: group.max_votable_headings, max: group.headings.count ) %>
<%= content_tag(:span, group.name, class:"group-toggle-#{group.id}", id:"group-name-#{group.id}") %> - - <%= t("admin.budgets.form.max_votable_headings")%> - <%= max_headings_label %> - + + <%= content_tag(:span, (render 'admin/budgets/max_headings_label', current: group.max_votable_headings, max: group.headings.count, group: group if group.max_votable_headings), class:"max-headings-label group-toggle-#{group.id}", id:"max-heading-label-#{group.id}") %> + <%= render 'admin/budgets/group_form', budget: @budget, group: group, id: "group-form-#{group.id}", button_title: t("admin.budgets.form.submit"), css_class: "group-toggle-#{group.id}" %> <%= link_to t("admin.budgets.form.edit_group"), "#", class: "button float-right js-toggle-link hollow", data: { "toggle-selector" => ".group-toggle-#{group.id}" } %> <%= link_to t("admin.budgets.form.add_heading"), "#", class: "button float-right js-toggle-link", data: { "toggle-selector" => "#group-#{group.id}-new-heading-form" } %> diff --git a/app/views/admin/budgets/_max_headings_label.html.erb b/app/views/admin/budgets/_max_headings_label.html.erb new file mode 100644 index 000000000..61bf98dc7 --- /dev/null +++ b/app/views/admin/budgets/_max_headings_label.html.erb @@ -0,0 +1,5 @@ +<%= t("admin.budgets.form.max_votable_headings")%> +<%= content_tag(:strong, + t('admin.budgets.form.current_of_max_headings', current: current, max: max ), + class:"current-of-max-headings") %> + diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index aa2099f3d..081dea1ce 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -120,7 +120,7 @@ en: table_amount: Amount table_population: Population population_info: "Budget Heading population field is used for Statistic purposes at the end of the Budget to show for each Heading that represents an area with population what percentage voted. The field is optional so you can leave it empty if it doesn't apply." - max_votable_headings: "Maxium number of headings in which a user can vote" + max_votable_headings: "Maximum number of headings in which a user can vote" current_of_max_headings: "%{current} of %{max}" winners: calculate: Calculate Winner Investments From 89a3da1edf97f6b3456e5508f94409247ed0ef62 Mon Sep 17 00:00:00 2001 From: iagirre Date: Tue, 3 Apr 2018 10:03:57 +0200 Subject: [PATCH 3/3] Specs modified to fit the new UI Now, a page refresh isn't needed to see the updated information because it is done via AJAX. The spec has been updated to check that the message is being correctly updated without the refresh. --- spec/features/admin/budget_groups_spec.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/features/admin/budget_groups_spec.rb b/spec/features/admin/budget_groups_spec.rb index 664c4aeda..d69867b8c 100644 --- a/spec/features/admin/budget_groups_spec.rb +++ b/spec/features/admin/budget_groups_spec.rb @@ -49,7 +49,7 @@ feature 'Admin can change the groups name' do scenario "Defaults to 1 heading per group", :js do visit admin_budget_path(group.budget) - expect(page).to have_content('Maxium number of headings in which a user can vote 1 of 3') + expect(page).to have_content('Maximum number of headings in which a user can vote 1 of 3') within("#budget_group_#{group.id}") do click_link 'Edit group' @@ -68,8 +68,7 @@ feature 'Admin can change the groups name' do click_button 'Save group' end - visit admin_budget_path(group.budget) - expect(page).to have_content('Maxium number of headings in which a user can vote 2 of 3') + expect(page).to have_content('Maximum number of headings in which a user can vote 2 of 3') within("#budget_group_#{group.id}") do click_link 'Edit group' @@ -78,13 +77,13 @@ feature 'Admin can change the groups name' do end end - scenario "Do not display maxium votable headings' select in new form", :js do + scenario "Do not display maximum votable headings' select in new form", :js do visit admin_budget_path(group.budget) click_link 'Add new group' expect(page).to have_field('budget_group_name') - expect(page).to_not have_field('budget_group_max_votable_headings') + expect(page).not_to have_field('budget_group_max_votable_headings') end end