From 9948804e2116e6bb227692d3a563cfdf25e11220 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Thu, 11 Apr 2019 16:41:06 +0200 Subject: [PATCH 01/14] Add selected attribute to proposals --- app/models/proposal.rb | 1 + .../20190410132842_add_selected_to_proposal.rb | 5 +++++ db/schema.rb | 1 + spec/factories/proposals.rb | 4 ++++ spec/models/proposal_spec.rb | 17 +++++++++++++++++ 5 files changed, 28 insertions(+) create mode 100644 db/migrate/20190410132842_add_selected_to_proposal.rb diff --git a/app/models/proposal.rb b/app/models/proposal.rb index dfc81e2ea..c8b7cb0dc 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -74,6 +74,7 @@ class Proposal < ApplicationRecord scope :successful, -> { where("cached_votes_up >= ?", Proposal.votes_needed_for_success) } scope :unsuccessful, -> { where("cached_votes_up < ?", Proposal.votes_needed_for_success) } scope :public_for_api, -> { all } + scope :selected, -> { where(selected: true) } scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal").compact.map(&:id)) } scope :published, -> { where.not(published_at: nil) } scope :draft, -> { where(published_at: nil) } diff --git a/db/migrate/20190410132842_add_selected_to_proposal.rb b/db/migrate/20190410132842_add_selected_to_proposal.rb new file mode 100644 index 000000000..a97d6619c --- /dev/null +++ b/db/migrate/20190410132842_add_selected_to_proposal.rb @@ -0,0 +1,5 @@ +class AddSelectedToProposal < ActiveRecord::Migration + def change + add_column :proposals, :selected, :bool, default: false, index: true + end +end diff --git a/db/schema.rb b/db/schema.rb index b9bfc50a7..9821ab24c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -1194,6 +1194,7 @@ ActiveRecord::Schema.define(version: 20190429125842) do t.text "retired_explanation" t.integer "community_id" t.datetime "published_at" + t.boolean "selected", default: false t.index ["author_id", "hidden_at"], name: "index_proposals_on_author_id_and_hidden_at", using: :btree t.index ["author_id"], name: "index_proposals_on_author_id", using: :btree t.index ["cached_votes_up"], name: "index_proposals_on_cached_votes_up", using: :btree diff --git a/spec/factories/proposals.rb b/spec/factories/proposals.rb index 0821eb168..7cbd44acb 100644 --- a/spec/factories/proposals.rb +++ b/spec/factories/proposals.rb @@ -33,6 +33,10 @@ FactoryBot.define do created_at { 25.months.ago } end + trait :selected do + selected true + end + trait :with_hot_score do before(:save) { |d| d.calculate_hot_score } end diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index e9d316350..51a8128ac 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -866,6 +866,23 @@ describe Proposal do end end + describe "selected" do + let!(:unselected_proposal) { create(:proposal) } + let!(:selected_proposal) { create(:proposal, :selected) } + + it "selected? is true" do + expect(unselected_proposal.selected?).to be false + expect(selected_proposal.selected?).to be true + end + + it "scope selected" do + selected = Proposal.selected + + expect(selected.size).to be 1 + expect(selected.first).to eq selected_proposal + end + end + describe "public_for_api scope" do it "returns proposals" do proposal = create(:proposal) From ad5f7a06e164f27fd05ce7ca21d0e4a29e8b2061 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Tue, 16 Apr 2019 12:39:21 +0200 Subject: [PATCH 02/14] Allow admins to select proposals and users to list them --- app/controllers/admin/proposals_controller.rb | 25 ++++++++- app/controllers/proposals_controller.rb | 5 ++ app/helpers/proposals_helper.rb | 35 +++++++++++++ app/views/admin/proposals/_form.html.erb | 9 ++++ .../admin/proposals/_select_proposal.html.erb | 1 + app/views/admin/proposals/index.html.erb | 2 + app/views/admin/proposals/show.html.erb | 6 +++ .../admin/proposals/toggle_selection.js.erb | 1 + app/views/proposals/_proposal.html.erb | 43 ++++++++-------- app/views/proposals/_selected.html.erb | 8 +++ app/views/proposals/index.html.erb | 16 +++++- config/locales/en/activerecord.yml | 1 + config/locales/en/admin.yml | 6 +++ config/locales/en/general.yml | 1 + config/locales/es/activerecord.yml | 1 + config/locales/es/admin.yml | 6 +++ config/locales/es/general.yml | 1 + config/routes/admin.rb | 3 +- spec/features/admin/proposals_spec.rb | 51 +++++++++++++++++++ spec/features/proposals_spec.rb | 19 +++++++ 20 files changed, 216 insertions(+), 24 deletions(-) create mode 100644 app/views/admin/proposals/_form.html.erb create mode 100644 app/views/admin/proposals/_select_proposal.html.erb create mode 100644 app/views/admin/proposals/toggle_selection.js.erb create mode 100644 app/views/proposals/_selected.html.erb diff --git a/app/controllers/admin/proposals_controller.rb b/app/controllers/admin/proposals_controller.rb index e76efce21..7e53d1a46 100644 --- a/app/controllers/admin/proposals_controller.rb +++ b/app/controllers/admin/proposals_controller.rb @@ -6,8 +6,22 @@ class Admin::ProposalsController < Admin::BaseController has_orders %w[created_at] + before_action :load_proposal, except: :index + def show - @proposal = Proposal.find(params[:id]) + end + + def update + if @proposal.update(proposal_params) + redirect_to admin_proposal_path(@proposal), notice: t("admin.proposals.update.notice") + else + render :show + end + end + + def toggle_selection + @proposal.toggle :selected + @proposal.save! end private @@ -15,4 +29,13 @@ class Admin::ProposalsController < Admin::BaseController def resource_model Proposal end + + def load_proposal + @proposal = Proposal.find(params[:id]) + end + + def proposal_params + params.require(:proposal).permit(:selected) + end + end diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 5cc9b7e10..52c16f0e0 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -51,6 +51,7 @@ class ProposalsController < ApplicationController discard_draft discard_archived load_retired + load_selected load_featured end @@ -139,6 +140,10 @@ class ProposalsController < ApplicationController end end + def load_selected + @resources = @resources.selected if params[:selected].present? + end + def load_featured return unless !@advanced_search_terms && @search_terms.blank? && @tag_filter.blank? && params[:retired].blank? && @current_order != "recommendations" if Setting["feature.featured_proposals"] diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index 633f469a3..3cc0ba03a 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -64,4 +64,39 @@ module ProposalsHelper proposals_current_view == "default" ? "minimal" : "default" end + def link_to_toggle_proposal_selection(proposal) + if proposal.selected? + button_text = t("admin.proposals.index.selected") + html_class = "button expanded" + else + button_text = t("admin.proposals.index.select") + html_class = "button hollow expanded" + end + + link_to button_text, + toggle_selection_admin_proposal_path(proposal), + remote: true, + method: :patch, + class: html_class + end + + def css_for_proposal_info_row + if feature?(:allow_images) + if params[:selected].present? + "small-12 medium-9 column" + else + "small-12 medium-6 large-7 column" + end + else + if params[:selected].present? + "small-12 column" + else + "small-12 medium-9 column" + end + end + end + + def show_proposal_votes? + params[:selected].blank? + end end diff --git a/app/views/admin/proposals/_form.html.erb b/app/views/admin/proposals/_form.html.erb new file mode 100644 index 000000000..b6dc1c442 --- /dev/null +++ b/app/views/admin/proposals/_form.html.erb @@ -0,0 +1,9 @@ +<%= form_for [:admin, @proposal] do |f| %> + + <%= render "shared/errors", resource: @proposal %> + + <%= f.check_box :selected %> + + <%= f.submit t("admin.proposals.form.update"), class: "button success" %> + +<% end %> diff --git a/app/views/admin/proposals/_select_proposal.html.erb b/app/views/admin/proposals/_select_proposal.html.erb new file mode 100644 index 000000000..d5d2069ab --- /dev/null +++ b/app/views/admin/proposals/_select_proposal.html.erb @@ -0,0 +1 @@ +<%= link_to_toggle_proposal_selection(proposal) %> diff --git a/app/views/admin/proposals/index.html.erb b/app/views/admin/proposals/index.html.erb index 8a8372713..bc59de812 100644 --- a/app/views/admin/proposals/index.html.erb +++ b/app/views/admin/proposals/index.html.erb @@ -16,6 +16,7 @@ <%= t("admin.proposals.index.title") %> <%= t("admin.proposals.index.author") %> <%= t("admin.proposals.index.milestones") %> + <%= t("admin.proposals.index.selected") %> @@ -26,6 +27,7 @@ <%= link_to proposal.title, admin_proposal_path(proposal) %> <%= proposal.author.username %> <%= proposal.milestones.count %> + <%= render "select_proposal", proposal: proposal %> <% end %> diff --git a/app/views/admin/proposals/show.html.erb b/app/views/admin/proposals/show.html.erb index 13fbce01e..afb2379e3 100644 --- a/app/views/admin/proposals/show.html.erb +++ b/app/views/admin/proposals/show.html.erb @@ -26,4 +26,10 @@ <%= render "proposals/info", proposal: @proposal %> +
+
+ <%= render "form" %> +
+
+ <%= render "admin/milestones/milestones", milestoneable: @proposal %> diff --git a/app/views/admin/proposals/toggle_selection.js.erb b/app/views/admin/proposals/toggle_selection.js.erb new file mode 100644 index 000000000..4963b7b7c --- /dev/null +++ b/app/views/admin/proposals/toggle_selection.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@proposal) %> .js-select").html('<%= j render("select_proposal", proposal: @proposal) %>'); diff --git a/app/views/proposals/_proposal.html.erb b/app/views/proposals/_proposal.html.erb index 97224172a..bad37f0ee 100644 --- a/app/views/proposals/_proposal.html.erb +++ b/app/views/proposals/_proposal.html.erb @@ -12,10 +12,10 @@ alt: proposal.image.title.unicode_normalize %> -
+
<% else %>
-
+
<% end %>
<% cache [locale_and_user_status(proposal), "index", proposal, proposal.author] do %> @@ -62,24 +62,27 @@
-
- <% if proposal.successful? %> -
-

- <%= t("proposals.proposal.successful") %> -

-
- <% elsif proposal.archived? %> -
- <%= t("proposals.proposal.supports", count: proposal.total_votes) %> -

<%= t("proposals.proposal.archived") %>

-
- <% else %> - <%= render "votes", - { proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %> - <% end %> -
+ <% if show_proposal_votes? %> +
+ <% if proposal.successful? %> +
+

+ <%= t("proposals.proposal.successful") %> +

+
+ <% elsif proposal.archived? %> +
+ <%= t("proposals.proposal.supports", count: proposal.total_votes) %> +

<%= t("proposals.proposal.archived") %>

+
+ <% else %> + <%= render "votes", + { proposal: proposal, vote_url: vote_proposal_path(proposal, value: "yes") } %> + <% end %> +
+ <% end %> +
diff --git a/app/views/proposals/_selected.html.erb b/app/views/proposals/_selected.html.erb new file mode 100644 index 000000000..2d8f272e2 --- /dev/null +++ b/app/views/proposals/_selected.html.erb @@ -0,0 +1,8 @@ +<% if params[:selected].blank? %> + + + +

+ <%= link_to t("proposals.index.selected_proposals"), proposals_path(selected: "all"), class: "small" %> +

+<% end %> diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index fff4a7bed..5729a92c1 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -9,7 +9,13 @@ <% end %>
- <% if @search_terms || @advanced_search_terms || @tag_filter || params[:retired].present? %> + <% if [ + @search_terms, + @advanced_search_terms, + @tag_filter, + params[:retired].present?, + params[:selected].present? + ].any? %>
@@ -29,6 +35,8 @@

<% elsif params[:retired].present? %>

<%= t("proposals.index.retired_proposals") %>

+ <% elsif params[:selected].present? %> +

<%= t("proposals.index.selected_proposals") %>

<% end %>
@@ -69,7 +77,10 @@
- <%= render("shared/advanced_search", search_path: proposals_path(page: 1)) unless params[:retired].present? %> + <% unless params[:retired].present? || params[:selected].present? %> + <%= render "shared/advanced_search", + search_path: proposals_path(page: 1) %> + <% end %> <%= render "shared/order_links", i18n_namespace: "proposals.index" %> @@ -118,6 +129,7 @@ <%= render "popular" %> <% end %> <%= render "retired" %> + <%= render "selected" %> diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index 97c9431ca..142b8ecd4 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -187,6 +187,7 @@ en: title: "Title" question: "Question" description: "Description" + selected: "Mark as selected" terms_of_service: "Terms of service" user: login: "Email or username" diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index c03001722..4376979ba 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -1239,10 +1239,16 @@ en: title: Proposals id: ID author: Author + select: Select + selected: Selected milestones: Milestones no_proposals: There are no proposals. show: create_question: Add this proposal to a poll to be voted + form: + update: Update proposal + update: + notice: Proposal updated successfully hidden_proposals: index: filter: Filter diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 820319ae6..021d120f1 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -376,6 +376,7 @@ en: error: "An error has occured. Please go to 'My account' page to manually disable recommendations for proposals" retired_proposals: Retired proposals retired_proposals_link: "Proposals retired by the author" + selected_proposals: Selected proposals retired_links: all: All duplicated: Duplicated diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 13dd8783c..66a187114 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -187,6 +187,7 @@ es: title: "Título" question: "Pregunta" description: "Descripción" + selected: "Marcar como seleccionada" terms_of_service: "Términos de servicio" user: login: "Email o nombre de usuario" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 0e6a91fc0..7f63504aa 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -1239,9 +1239,15 @@ es: id: ID author: Autor milestones: Hitos + select: Seleccionar + selected: Seleccionada no_proposals: No hay propuestas. show: create_question: Añadir esta propuesta a una votación para ser votada + form: + update: Actualizar propuesta ciudadana + update: + notice: Propuesta actualizada correctamente hidden_proposals: index: filter: Filtro diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index deb858d95..76f88587a 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -376,6 +376,7 @@ es: error: "Ha ocurrido un error. Por favor dirígete al apartado 'Mi cuenta' para desactivar las recomendaciones manualmente" retired_proposals: Propuestas retiradas retired_proposals_link: "Propuestas retiradas por sus autores" + selected_proposals: Propuestas seleccionadas retired_links: all: Todas duplicated: Duplicadas diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 917f1447c..1e67bcc5e 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -29,7 +29,8 @@ namespace :admin do end end - resources :proposals, only: [:index, :show] do + resources :proposals, only: [:index, :show, :update] do + member { patch :toggle_selection } resources :milestones, controller: "proposal_milestones" resources :progress_bars, except: :show, controller: "proposal_progress_bars" end diff --git a/spec/features/admin/proposals_spec.rb b/spec/features/admin/proposals_spec.rb index affc723f7..92685b139 100644 --- a/spec/features/admin/proposals_spec.rb +++ b/spec/features/admin/proposals_spec.rb @@ -10,6 +10,7 @@ feature "Admin proposals" do "admin_proposal_path" context "Index" do + scenario "Search" do create(:proposal, title: "Make Pluto a planet again") create(:proposal, title: "Build a monument to honour CONSUL developers") @@ -26,6 +27,29 @@ feature "Admin proposals" do expect(page).to have_content "Make Pluto a planet again" expect(page).not_to have_content "Build a monument" end + + scenario "Select a proposal", :js do + proposal = create(:proposal) + + visit admin_proposals_path + + within("#proposal_#{proposal.id}") { click_link "Select" } + + within("#proposal_#{proposal.id}") { expect(page).to have_link "Selected" } + expect(proposal.reload.selected?).to be true + end + + scenario "Unselect a proposal", :js do + proposal = create(:proposal, :selected) + + visit admin_proposals_path + + within("#proposal_#{proposal.id}") { click_link "Selected" } + + within("#proposal_#{proposal.id}") { expect(page).to have_link "Select" } + expect(proposal.reload.selected?).to be false + end + end context "Show" do @@ -55,5 +79,32 @@ feature "Admin proposals" do expect(page).to have_link "Add this proposal to a poll to be voted" end end + + scenario "Select a proposal" do + proposal = create(:proposal) + + visit admin_proposal_path(proposal) + + check "Mark as selected" + click_button "Update proposal" + + expect(page).to have_content "Proposal updated successfully" + expect(find_field("Mark as selected")).to be_checked + expect(proposal.reload.selected?).to be true + end + + scenario "Unselect a proposal" do + proposal = create(:proposal, :selected) + + visit admin_proposal_path(proposal) + + uncheck "Mark as selected" + click_button "Update proposal" + + expect(page).to have_content "Proposal updated successfully" + expect(find_field("Mark as selected")).not_to be_checked + expect(proposal.reload.selected?).to be false + end + end end diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 5162dae30..74669a661 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -118,6 +118,25 @@ feature "Proposals" do end end + context "Index" do + scenario "Lists selected proposals" do + selected_proposal = create(:proposal, :selected) + unselected_proposal = create(:proposal) + + visit proposals_path + + expect(page).to have_selector("#proposals .proposal", count: 2) + expect(page).to have_content selected_proposal.title + expect(page).to have_content unselected_proposal.title + + click_link "Selected proposals" + + expect(page).to have_selector("#proposals .proposal", count: 1) + expect(page).to have_content selected_proposal.title + expect(page).not_to have_content unselected_proposal.title + end + end + scenario "Show" do proposal = create(:proposal) From 28835a29efd479a49304586dcbf2cecbe39e1674 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Thu, 23 May 2019 12:22:49 +0200 Subject: [PATCH 03/14] Share helper between class Proposal and Legislation::Proposal --- app/helpers/legislation_helper.rb | 16 ---------------- app/helpers/proposals_helper.rb | 13 ++++++++----- .../legislation/proposals/_proposals.html.erb | 2 +- .../proposals/_select_proposal.html.erb | 2 +- config/locales/en/admin.yml | 2 -- config/locales/es/admin.yml | 2 -- 6 files changed, 10 insertions(+), 27 deletions(-) diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb index 415de8e74..943f1b35d 100644 --- a/app/helpers/legislation_helper.rb +++ b/app/helpers/legislation_helper.rb @@ -11,22 +11,6 @@ module LegislationHelper t("proposals.index.start_proposal") end - def link_to_toggle_legislation_proposal_selection(proposal) - if proposal.selected? - button_text = t("admin.legislation.proposals.index.selected") - html_class = "button expanded" - else - button_text = t("admin.legislation.proposals.index.select") - html_class = "button hollow expanded" - end - - link_to button_text, - toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal), - remote: true, - method: :patch, - class: html_class - end - def legislation_process_tabs(process) { "info" => edit_admin_legislation_process_path(process), diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index 3cc0ba03a..9f0b36815 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -73,11 +73,14 @@ module ProposalsHelper html_class = "button hollow expanded" end - link_to button_text, - toggle_selection_admin_proposal_path(proposal), - remote: true, - method: :patch, - class: html_class + case proposal.class.to_s + when "Proposal" + path = toggle_selection_admin_proposal_path(proposal) + when "Legislation::Proposal" + path = toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal) + end + + link_to button_text, path, remote: true, method: :patch, class: html_class end def css_for_proposal_info_row diff --git a/app/views/admin/legislation/proposals/_proposals.html.erb b/app/views/admin/legislation/proposals/_proposals.html.erb index 8682eeab6..a740cbd38 100644 --- a/app/views/admin/legislation/proposals/_proposals.html.erb +++ b/app/views/admin/legislation/proposals/_proposals.html.erb @@ -9,7 +9,7 @@ <%= t("admin.legislation.proposals.index.id") %> <%= t("admin.legislation.proposals.index.title") %> <%= t("admin.legislation.proposals.index.supports") %> - <%= t("admin.legislation.proposals.index.selected") %> + <%= t("admin.proposals.index.selected") %> diff --git a/app/views/admin/legislation/proposals/_select_proposal.html.erb b/app/views/admin/legislation/proposals/_select_proposal.html.erb index 0d5eb845d..d5d2069ab 100644 --- a/app/views/admin/legislation/proposals/_select_proposal.html.erb +++ b/app/views/admin/legislation/proposals/_select_proposal.html.erb @@ -1 +1 @@ -<%= link_to_toggle_legislation_proposal_selection(proposal) %> +<%= link_to_toggle_proposal_selection(proposal) %> diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 4376979ba..81efc4701 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -556,8 +556,6 @@ en: id: Id title: Title supports: Total supports - select: Select - selected: Selected form: custom_categories: Categories custom_categories_description: Categories that users can select creating the proposal. Max 160 characteres. diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 7f63504aa..30a0512a1 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -555,8 +555,6 @@ es: back: Volver id: Id supports: Apoyos totales - select: Seleccionar - selected: Seleccionada form: custom_categories: Categorías custom_categories_description: Categorías que el usuario puede seleccionar al crear la propuesta. Máximo 160 caracteres. From b68a872298702c0d804a1cb3973ab77803ee4ead Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Tue, 16 Apr 2019 17:55:58 +0200 Subject: [PATCH 04/14] Change links for proposals lists Changed applied: - Remove Archived proposals from tab and add a link under Proposals lists - Remove Popular proposals link from custom section and add it to the Proposals lists - Remove Retired proposals link from custom section and add it to the Proposals lists - Remove Selected proposals link from custom section and add it to the Proposals lists --- app/controllers/proposals_controller.rb | 5 +++++ app/views/proposals/_popular.html.erb | 6 ------ app/views/proposals/_proposals_lists.html.erb | 20 +++++++++++++++++++ app/views/proposals/_retired.html.erb | 8 +++----- app/views/proposals/_selected.html.erb | 8 -------- app/views/proposals/index.html.erb | 3 +-- config/locales/en/general.yml | 2 ++ config/locales/es/general.yml | 2 ++ spec/features/proposals_spec.rb | 8 ++++---- 9 files changed, 37 insertions(+), 25 deletions(-) delete mode 100644 app/views/proposals/_popular.html.erb create mode 100644 app/views/proposals/_proposals_lists.html.erb delete mode 100644 app/views/proposals/_selected.html.erb diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 52c16f0e0..5a19f7907 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -53,6 +53,7 @@ class ProposalsController < ApplicationController load_retired load_selected load_featured + remove_archived_from_order_links end def vote @@ -156,6 +157,10 @@ class ProposalsController < ApplicationController end end + def remove_archived_from_order_links + @valid_orders.delete("archival_date") + end + def set_view @view = (params[:view] == "minimal") ? "minimal" : "default" end diff --git a/app/views/proposals/_popular.html.erb b/app/views/proposals/_popular.html.erb deleted file mode 100644 index 7f46ea802..000000000 --- a/app/views/proposals/_popular.html.erb +++ /dev/null @@ -1,6 +0,0 @@ - - - -

- <%= link_to t("proposals.index.top_link_proposals"), summary_proposals_path, class: "small" %>
-

diff --git a/app/views/proposals/_proposals_lists.html.erb b/app/views/proposals/_proposals_lists.html.erb new file mode 100644 index 000000000..43154aeab --- /dev/null +++ b/app/views/proposals/_proposals_lists.html.erb @@ -0,0 +1,20 @@ + + + +

+ <%= link_to t("proposals.index.top_link_proposals"), + summary_proposals_path, + class: "small" %> +
+ <%= link_to t("proposals.index.archived_proposals"), + proposals_path(order: "archival_date"), + class: "small" %> +
+ <%= link_to t("proposals.index.retired_proposals_link"), + proposals_path(retired: "all"), + class: "small" %> +
+ <%= link_to t("proposals.index.selected_proposals"), + proposals_path(selected: "all"), + class: "small" %> +

diff --git a/app/views/proposals/_retired.html.erb b/app/views/proposals/_retired.html.erb index 78d5c2af0..21b588b0c 100644 --- a/app/views/proposals/_retired.html.erb +++ b/app/views/proposals/_retired.html.erb @@ -1,9 +1,7 @@ - - +<% if params[:retired].present? %> + + -<% if params[:retired].blank? %> -

<%= link_to t("proposals.index.retired_proposals_link"), proposals_path(retired: "all"), class: "small" %>

-<% else %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 021d120f1..09a064b65 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -377,6 +377,8 @@ en: retired_proposals: Retired proposals retired_proposals_link: "Proposals retired by the author" selected_proposals: Selected proposals + archived_proposals: Archived proposals + proposals_lists: Proposals lists retired_links: all: All duplicated: Duplicated diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 76f88587a..e8c555ab7 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -377,6 +377,8 @@ es: retired_proposals: Propuestas retiradas retired_proposals_link: "Propuestas retiradas por sus autores" selected_proposals: Propuestas seleccionadas + archived_proposals: Propuestas archivadas + proposals_lists: Listas de propuestas retired_links: all: Todas duplicated: Duplicadas diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 74669a661..2e58a60c2 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -852,12 +852,12 @@ feature "Proposals" do feature "Archived proposals" do - scenario "show on archived tab" do + scenario "show on proposals list" do create_featured_proposals archived_proposals = create_archived_proposals visit proposals_path - click_link "archived" + click_link "Archived proposals" within("#proposals-list") do archived_proposals.each do |proposal| @@ -925,7 +925,7 @@ feature "Proposals" do expect(page).not_to have_content(archived_proposal.title) end - click_link "archived" + click_link "Archived proposals" within("#featured-proposals") do expect(page).to have_content(featured_proposal.title) @@ -943,7 +943,7 @@ feature "Proposals" do create(:proposal, :archived, title: "Some votes").update_column(:confidence_score, 25) visit proposals_path - click_link "archived" + click_link "Archived proposals" within("#proposals-list") do expect(all(".proposal")[0].text).to match "Most voted" From db774e3fd2b2ab28edcf091e588aa535f3b44219 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 10 May 2019 13:11:58 +0200 Subject: [PATCH 05/14] Extract proposal supports progress bar to a partial --- app/views/proposals/_supports.html.erb | 16 ++++++++++++++++ app/views/proposals/_votes.html.erb | 17 +---------------- config/locales/en/general.yml | 1 + config/locales/es/general.yml | 1 + 4 files changed, 19 insertions(+), 16 deletions(-) create mode 100644 app/views/proposals/_supports.html.erb diff --git a/app/views/proposals/_supports.html.erb b/app/views/proposals/_supports.html.erb new file mode 100644 index 000000000..2ff839593 --- /dev/null +++ b/app/views/proposals/_supports.html.erb @@ -0,0 +1,16 @@ +
+ + + <%= supports_percentage(proposal) %> / <%= t("proposals.proposal.total_percent") %> + +
+ + + <%= t("proposals.proposal.supports", count: proposal.total_votes) %>  + + "> + <%= t("proposals.proposal.supports_necessary", + number: number_with_delimiter(Proposal.votes_needed_for_success)) %> + + + diff --git a/app/views/proposals/_votes.html.erb b/app/views/proposals/_votes.html.erb index 908ebea84..448c9d7a3 100644 --- a/app/views/proposals/_votes.html.erb +++ b/app/views/proposals/_votes.html.erb @@ -1,20 +1,5 @@
-
- - - <%= supports_percentage(proposal) %> / <%= t("proposals.proposal.total_percent") %> - -
- - - <%= t("proposals.proposal.supports", count: proposal.total_votes) %>  - - - <%= t("proposals.proposal.supports_necessary", - number: number_with_delimiter(Proposal.votes_needed_for_success)) %> - - - + <%= render "proposals/supports", proposal: proposal %>
<% if voted_for?(@proposal_votes, proposal) %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 09a064b65..14408f0ca 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -440,6 +440,7 @@ en: other: "%{count} votes" zero: No votes supports_necessary: "%{number} supports needed" + reason_for_supports_necessary: "" total_percent: 100% archived: "This proposal has been archived and can't collect supports." successful: "This proposal has reached the required supports." diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index e8c555ab7..25cc13d62 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -440,6 +440,7 @@ es: one: 1 voto other: "%{count} votos" supports_necessary: "%{number} apoyos necesarios" + reason_for_supports_necessary: "" total_percent: 100% archived: "Esta propuesta ha sido archivada y ya no puede recoger apoyos." successful: "Esta propuesta ha alcanzado los apoyos necesarios." From 6beb11f0a981cc107cb695f593877751530ee263 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 10 May 2019 13:13:11 +0200 Subject: [PATCH 06/14] Show completed progress bar for successful proposals Show a completed progress bar with total supports intead of showing a message telling the proposal has reached the needed supports. --- app/helpers/proposals_helper.rb | 4 ++-- app/views/proposals/_proposal.html.erb | 12 ++++++------ app/views/proposals/show.html.erb | 6 +++--- spec/features/proposal_ballots_spec.rb | 8 ++++---- spec/features/proposals_spec.rb | 8 ++++---- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index 9f0b36815..3ce853dfa 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -83,8 +83,8 @@ module ProposalsHelper link_to button_text, path, remote: true, method: :patch, class: html_class end - def css_for_proposal_info_row - if feature?(:allow_images) + def css_for_proposal_info_row(proposal) + if proposal.image.present? if params[:selected].present? "small-12 medium-9 column" else diff --git a/app/views/proposals/_proposal.html.erb b/app/views/proposals/_proposal.html.erb index bad37f0ee..496f0f4a1 100644 --- a/app/views/proposals/_proposal.html.erb +++ b/app/views/proposals/_proposal.html.erb @@ -12,10 +12,10 @@ alt: proposal.image.title.unicode_normalize %>
-
+
<% else %>
-
+
<% end %>
<% cache [locale_and_user_status(proposal), "index", proposal, proposal.author] do %> @@ -66,10 +66,10 @@
<% if proposal.successful? %> -
-

- <%= t("proposals.proposal.successful") %> -

+
+
+ <%= render "proposals/supports", proposal: proposal %> +
<% elsif proposal.archived? %>
diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index e3b25a52d..c662740b9 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -80,9 +80,9 @@

<%= t('.draft') %>

<% elsif @proposal.successful? %> -

- <%= t("proposals.proposal.successful") %> -

+
+ <%= render "supports", proposal: @proposal %> +
<% elsif @proposal.archived? %>

diff --git a/spec/features/proposal_ballots_spec.rb b/spec/features/proposal_ballots_spec.rb index d67585a7c..5a8f12db6 100644 --- a/spec/features/proposal_ballots_spec.rb +++ b/spec/features/proposal_ballots_spec.rb @@ -9,8 +9,8 @@ feature "Proposal ballots" do visit proposals_path successful_proposals.each do |proposal| - within("#proposal_#{proposal.id}_votes") do - expect(page).to have_content "This proposal has reached the required supports" + within("#proposal_#{proposal.id}_votes .supports .progress") do + expect(page).to have_content "100% / 100%" end end end @@ -20,8 +20,8 @@ feature "Proposal ballots" do successful_proposals.each do |proposal| visit proposal_path(proposal) - within("#proposal_#{proposal.id}_votes") do - expect(page).to have_content "This proposal has reached the required supports" + within("#proposal_#{proposal.id}_votes .supports .progress") do + expect(page).to have_content "100% / 100%" end end end diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 2e58a60c2..3861680a4 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -1773,8 +1773,8 @@ feature "Successful proposals" do successful_proposals.each do |proposal| within("#proposal_#{proposal.id}_votes") do - expect(page).not_to have_css(".supports") - expect(page).to have_content "This proposal has reached the required supports" + expect(page).not_to have_link "Support" + expect(page).to have_content "100% / 100%" end end end @@ -1785,8 +1785,8 @@ feature "Successful proposals" do successful_proposals.each do |proposal| visit proposal_path(proposal) within("#proposal_#{proposal.id}_votes") do - expect(page).not_to have_css(".supports") - expect(page).to have_content "This proposal has reached the required supports" + expect(page).not_to have_link "Support" + expect(page).to have_content "100% / 100%" end end end From a852696eebcf0633b67a326da92269e464ee0be6 Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 24 May 2019 12:38:31 +0200 Subject: [PATCH 07/14] Remove not selected proposals from other lists --- app/controllers/proposals_controller.rb | 6 +++- app/models/proposal.rb | 1 + spec/features/proposals_spec.rb | 41 +++++++++++++------------ spec/models/proposal_spec.rb | 11 +++++-- 4 files changed, 37 insertions(+), 22 deletions(-) diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index 5a19f7907..a7d171d9a 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -142,7 +142,11 @@ class ProposalsController < ApplicationController end def load_selected - @resources = @resources.selected if params[:selected].present? + if params[:selected].present? + @resources = @resources.selected + else + @resources = @resources.not_selected + end end def load_featured diff --git a/app/models/proposal.rb b/app/models/proposal.rb index c8b7cb0dc..deb829058 100644 --- a/app/models/proposal.rb +++ b/app/models/proposal.rb @@ -75,6 +75,7 @@ class Proposal < ApplicationRecord scope :unsuccessful, -> { where("cached_votes_up < ?", Proposal.votes_needed_for_success) } scope :public_for_api, -> { all } scope :selected, -> { where(selected: true) } + scope :not_selected, -> { where(selected: false) } scope :not_supported_by_user, ->(user) { where.not(id: user.find_voted_items(votable_type: "Proposal").compact.map(&:id)) } scope :published, -> { where.not(published_at: nil) } scope :draft, -> { where(published_at: nil) } diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 3861680a4..a3eee84a6 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -118,25 +118,6 @@ feature "Proposals" do end end - context "Index" do - scenario "Lists selected proposals" do - selected_proposal = create(:proposal, :selected) - unselected_proposal = create(:proposal) - - visit proposals_path - - expect(page).to have_selector("#proposals .proposal", count: 2) - expect(page).to have_content selected_proposal.title - expect(page).to have_content unselected_proposal.title - - click_link "Selected proposals" - - expect(page).to have_selector("#proposals .proposal", count: 1) - expect(page).to have_content selected_proposal.title - expect(page).not_to have_content unselected_proposal.title - end - end - scenario "Show" do proposal = create(:proposal) @@ -954,6 +935,28 @@ feature "Proposals" do end + context "Selected Proposals" do + let!(:selected_proposal) { create(:proposal, :selected) } + let!(:not_selected_proposal) { create(:proposal) } + + scenario "do not show in index by default" do + visit proposals_path + + expect(page).to have_selector("#proposals .proposal", count: 1) + expect(page).to have_content not_selected_proposal.title + expect(page).not_to have_content selected_proposal.title + end + + scenario "show in selected proposals list" do + visit proposals_path + click_link "Selected proposals" + + expect(page).to have_selector("#proposals .proposal", count: 1) + expect(page).to have_content selected_proposal.title + expect(page).not_to have_content not_selected_proposal.title + end + end + context "Search" do context "Basic search" do diff --git a/spec/models/proposal_spec.rb b/spec/models/proposal_spec.rb index 51a8128ac..b55cbba9f 100644 --- a/spec/models/proposal_spec.rb +++ b/spec/models/proposal_spec.rb @@ -867,11 +867,11 @@ describe Proposal do end describe "selected" do - let!(:unselected_proposal) { create(:proposal) } + let!(:not_selected_proposal) { create(:proposal) } let!(:selected_proposal) { create(:proposal, :selected) } it "selected? is true" do - expect(unselected_proposal.selected?).to be false + expect(not_selected_proposal.selected?).to be false expect(selected_proposal.selected?).to be true end @@ -881,6 +881,13 @@ describe Proposal do expect(selected.size).to be 1 expect(selected.first).to eq selected_proposal end + + it "scope not_selected" do + not_selected = Proposal.not_selected + + expect(not_selected.size).to be 1 + expect(not_selected.first).to eq not_selected_proposal + end end describe "public_for_api scope" do From 5952c2664d74290098f48b7a06651c4240e77faa Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 24 May 2019 15:45:07 +0200 Subject: [PATCH 08/14] Show a 'Selected proposal' message in the show view --- app/views/proposals/show.html.erb | 72 +++++++++++++++++-------------- config/locales/en/general.yml | 1 + config/locales/es/general.yml | 1 + spec/features/proposals_spec.rb | 7 +++ 4 files changed, 48 insertions(+), 33 deletions(-) diff --git a/app/views/proposals/show.html.erb b/app/views/proposals/show.html.erb index c662740b9..f405f15af 100644 --- a/app/views/proposals/show.html.erb +++ b/app/views/proposals/show.html.erb @@ -62,44 +62,50 @@

<% end %> -
-
-
- -

<%= t("votes.supports") %>

+ <% if @proposal.selected? %> +
+ <%= t("proposals.proposal.selected") %> +
+ <% else %> +
+
+
+ +

<%= t("votes.supports") %>

-
- <% if @proposal.draft? %> -
-

<%= t('.draft') %>

-
- <% elsif @proposal.successful? %> -
- <%= render "supports", proposal: @proposal %> -
- <% elsif @proposal.archived? %> -
-

- <%= t("proposals.proposal.supports", count: @proposal.total_votes) %> -

-

<%= t("proposals.proposal.archived") %>

-
- <% else %> - <%= render "votes", - { proposal: @proposal, vote_url: vote_proposal_path(@proposal, value: "yes") } %> - <% end %> +
+ <% if @proposal.draft? %> +
+

<%= t(".draft") %>

+
+ <% elsif @proposal.successful? %> +
+ <%= render "supports", proposal: @proposal %> +
+ <% elsif @proposal.archived? %> +
+

+ <%= t("proposals.proposal.supports", count: @proposal.total_votes) %> +

+

<%= t("proposals.proposal.archived") %>

+
+ <% else %> + <%= render "votes", + { proposal: @proposal, vote_url: vote_proposal_path(@proposal, value: "yes") } %> + <% end %> +
-
-
+
+ <% end %> <%= render "proposals/social_share", proposal: @proposal, share_title: t("proposals.show.share") %> diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml index 14408f0ca..66c04b8cc 100644 --- a/config/locales/en/general.yml +++ b/config/locales/en/general.yml @@ -444,6 +444,7 @@ en: total_percent: 100% archived: "This proposal has been archived and can't collect supports." successful: "This proposal has reached the required supports." + selected: "Selected proposal" show: author_deleted: User deleted code: "Proposal code:" diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml index 25cc13d62..a91d6ea0b 100644 --- a/config/locales/es/general.yml +++ b/config/locales/es/general.yml @@ -444,6 +444,7 @@ es: total_percent: 100% archived: "Esta propuesta ha sido archivada y ya no puede recoger apoyos." successful: "Esta propuesta ha alcanzado los apoyos necesarios." + selected: "Propuesta seleccionada" show: author_deleted: Usuario eliminado code: "Código de la propuesta:" diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index a3eee84a6..744d4bf76 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -955,6 +955,13 @@ feature "Proposals" do expect(page).to have_content selected_proposal.title expect(page).not_to have_content not_selected_proposal.title end + + scenario "show a selected proposal message in show view" do + visit proposal_path(selected_proposal) + + within("aside") { expect(page).not_to have_content "SUPPORTS" } + within("aside") { expect(page).to have_content "Selected proposal" } + end end context "Search" do From dfe3764616df286e01e14260b77de338f8471b8e Mon Sep 17 00:00:00 2001 From: Julian Herrero Date: Fri, 24 May 2019 16:10:41 +0200 Subject: [PATCH 09/14] Don't show featured proposals in selected proposals list --- app/helpers/proposals_helper.rb | 4 ++++ app/views/proposals/index.html.erb | 2 +- spec/features/proposals_spec.rb | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index 3ce853dfa..9abbb198c 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -102,4 +102,8 @@ module ProposalsHelper def show_proposal_votes? params[:selected].blank? end + + def show_featured_proposals? + params[:selected].blank? && @featured_proposals.present? + end end diff --git a/app/views/proposals/index.html.erb b/app/views/proposals/index.html.erb index ababd571f..33be571fd 100644 --- a/app/views/proposals/index.html.erb +++ b/app/views/proposals/index.html.erb @@ -58,7 +58,7 @@ <%= render "shared/banner" %> <% end %> - <% if @featured_proposals.present? %> + <% if show_featured_proposals? %>