From 05340e423c93e2ad3b1c984bf60b11e87dbe5525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Fuentes?= Date: Wed, 8 Aug 2018 10:57:42 +0200 Subject: [PATCH 01/23] Add select to Legislation::Proposals Add admin interface for mark any proposal as selected Add filter to public interface for selected proposals --- .../admin/legislation/proposals_controller.rb | 18 ++++++++- .../legislation/processes_controller.rb | 6 ++- app/models/legislation/proposal.rb | 4 ++ .../legislation/proposals/index.html.erb | 40 +++++++++++++++++++ .../processes/_proposals_content.html.erb | 1 + .../shared/_wide_order_selector.html.erb | 1 + config/locales/en/activerecord.yml | 3 ++ config/locales/en/admin.yml | 14 +++++++ config/locales/en/legislation.yml | 3 ++ config/locales/es/activerecord.yml | 3 ++ config/locales/es/admin.yml | 14 +++++++ config/locales/es/legislation.yml | 3 ++ ...1_add_selected_to_legislation_proposals.rb | 5 +++ db/schema.rb | 1 + 14 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 db/migrate/20180807104331_add_selected_to_legislation_proposals.rb diff --git a/app/controllers/admin/legislation/proposals_controller.rb b/app/controllers/admin/legislation/proposals_controller.rb index 7f4441bce..bd46d28fe 100644 --- a/app/controllers/admin/legislation/proposals_controller.rb +++ b/app/controllers/admin/legislation/proposals_controller.rb @@ -1,7 +1,23 @@ class Admin::Legislation::ProposalsController < Admin::Legislation::BaseController + + has_orders %w{id title supports}, only: :index + load_and_authorize_resource :process, class: "Legislation::Process" load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process def index + @proposals = @proposals.send("sort_by_#{@current_order}").page(params[:page]) end -end + + def update + @proposal.selected = !@proposal.selected + + if @proposal.save + notice = t('admin.legislation.proposals.update.notice') + else + notice = t('admin.legislation.proposals.update.error') + end + redirect_to admin_legislation_process_proposals_path, notice: notice + end + +end \ No newline at end of file diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index f30b9d894..11b1be0d6 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -1,5 +1,7 @@ class Legislation::ProcessesController < Legislation::BaseController has_filters %w{open next past}, only: :index + has_filters %w{all selected}, only: :proposals + load_and_authorize_resource before_action :set_random_seed, only: :proposals @@ -91,7 +93,9 @@ class Legislation::ProcessesController < Legislation::BaseController @proposals = ::Legislation::Proposal.where(process: @process) @proposals = @proposals.search(params[:search]) if params[:search].present? - @proposals = @proposals.order('random()').page(params[:page]) + @proposals = @proposals.send(@current_filter).order('random()').page(params[:page]) + + @valid_filters = [] unless @proposals.map(&:selected).include? true if @process.proposals_phase.started? || (current_user && current_user.administrator?) legislation_proposal_votes(@proposals) diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index a345a5904..ad6691578 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -45,9 +45,13 @@ class Legislation::Proposal < ActiveRecord::Base scope :sort_by_confidence_score, -> { reorder(confidence_score: :desc) } scope :sort_by_created_at, -> { reorder(created_at: :desc) } scope :sort_by_most_commented, -> { reorder(comments_count: :desc) } + scope :sort_by_title, -> { reorder(title: :asc) } + scope :sort_by_id, -> { reorder(id: :asc) } + scope :sort_by_supports, -> { reorder(cached_votes_up: :asc) } scope :sort_by_random, -> { reorder("RANDOM()") } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} + scope :selected, -> { where(selected: true) } def to_param "#{id}-#{title}".parameterize diff --git a/app/views/admin/legislation/proposals/index.html.erb b/app/views/admin/legislation/proposals/index.html.erb index aae66e008..d5f4c39fe 100644 --- a/app/views/admin/legislation/proposals/index.html.erb +++ b/app/views/admin/legislation/proposals/index.html.erb @@ -11,4 +11,44 @@ <%= render 'admin/legislation/processes/subnav', process: @process, active: 'proposals' %> <%= render 'form' %> + +<% if @proposals.any? %> +

<%= page_entries_info @proposals %>

+ + <%= render 'shared/wide_order_selector', i18n_namespace: "admin.legislation.processes.proposals" %> + + + + + + + + + + + + + <% @proposals.each do |proposal| %> + + + + + + + <% end %> + +
<%= t("admin.legislation.proposals.index.id") %><%= t("admin.legislation.proposals.index.title") %><%= t("admin.legislation.proposals.index.supports") %><%= t("admin.legislation.proposals.index.selected") %>
<%= proposal.id %><%= proposal.title %><%= proposal.cached_votes_up %> + <% if proposal.selected? + button_text = t("admin.legislation.proposals.index.selected") + clas = 'button expanded' + else + button_text = t("admin.legislation.proposals.index.select") + clas = 'button hollow expanded' + end %> + <%= link_to button_text, admin_legislation_process_proposal_path(@process, proposal), method: 'PUT', class: clas %> +
+ + <%= paginate @proposals %> +<% end %> + diff --git a/app/views/legislation/processes/_proposals_content.html.erb b/app/views/legislation/processes/_proposals_content.html.erb index 63a7ac926..cd36125d0 100644 --- a/app/views/legislation/processes/_proposals_content.html.erb +++ b/app/views/legislation/processes/_proposals_content.html.erb @@ -8,6 +8,7 @@

<%= t("legislation.processes.proposals.empty_proposals") %>

<% else %> + <%= render 'shared/filter_subnav', i18n_namespace: "legislation.processes.proposals" %> <%= render proposals %> <%= paginate proposals %> <% end %> diff --git a/app/views/shared/_wide_order_selector.html.erb b/app/views/shared/_wide_order_selector.html.erb index d5b1405eb..0594f4301 100644 --- a/app/views/shared/_wide_order_selector.html.erb +++ b/app/views/shared/_wide_order_selector.html.erb @@ -2,6 +2,7 @@ # # i18n_namespace: for example "moderation.debates.index" %> + <% if @valid_orders.present? && @valid_orders.count > 1 %>
diff --git a/config/locales/en/activerecord.yml b/config/locales/en/activerecord.yml index d3d19f1ed..84dee7a77 100644 --- a/config/locales/en/activerecord.yml +++ b/config/locales/en/activerecord.yml @@ -76,6 +76,9 @@ en: legislation/process: one: "Process" other: "Processes" + legislation/proposal: + one: "Proposal" + other: "Proposals" legislation/draft_versions: one: "Draft version" other: "Draft versions" diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 261aca613..fa4e84b62 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -394,6 +394,12 @@ en: back: Back title: Create new collaborative legislation process submit_button: Create process + proposals: + select_order: Sort by + orders: + id: Id + title: Title + supports: Supports process: title: Process comments: Comments @@ -411,6 +417,14 @@ en: index: title: Proposals back: Back + id: Id + title: Title + supports: Supports + select: Select + selected: Selected + update: + notice: 'Proposal updated successfully' + error: Proposal couldn't be updated form: custom_categories: Categories custom_categories_description: Categories that users can select creating the proposal. diff --git a/config/locales/en/legislation.yml b/config/locales/en/legislation.yml index 479517a9d..212e3b9ca 100644 --- a/config/locales/en/legislation.yml +++ b/config/locales/en/legislation.yml @@ -52,6 +52,9 @@ en: more_info: More information and context proposals: empty_proposals: There are no proposals + filters: + all: All + selected: Selected debate: empty_questions: There aren't any questions participate: Participate in the debate diff --git a/config/locales/es/activerecord.yml b/config/locales/es/activerecord.yml index 52bb51e9f..2af5c034f 100644 --- a/config/locales/es/activerecord.yml +++ b/config/locales/es/activerecord.yml @@ -76,6 +76,9 @@ es: legislation/process: one: "Proceso" other: "Procesos" + legislation/proposal: + one: "Propuesta" + other: "Propuestas" legislation/draft_versions: one: "Versión borrador" other: "Versiones borrador" diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 58ea76f13..e6fce5ceb 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -395,6 +395,12 @@ es: back: Volver title: Crear nuevo proceso de legislación colaborativa submit_button: Crear proceso + proposals: + select_order: Ordenar por + orders: + id: Id + title: Título + supports: Apoyos process: title: Proceso comments: Comentarios @@ -412,6 +418,14 @@ es: index: title: Propuestas back: Volver + id: Id + title: Título + supports: Apoyos + select: Seleccionar + selected: Seleccionado + update: + notice: Propuesta actualizada correctamente. + error: No se ha podido actualizar la propuesta form: custom_categories: Categorías custom_categories_description: Categorías que el usuario puede seleccionar al crear la propuesta. diff --git a/config/locales/es/legislation.yml b/config/locales/es/legislation.yml index cb7d9785d..db250f604 100644 --- a/config/locales/es/legislation.yml +++ b/config/locales/es/legislation.yml @@ -52,6 +52,9 @@ es: more_info: Más información y contexto proposals: empty_proposals: No hay propuestas + filters: + all: Todos + selected: Seleccionados debate: empty_questions: No hay preguntas participate: Realiza tus aportaciones al debate previo participando en los siguientes temas. diff --git a/db/migrate/20180807104331_add_selected_to_legislation_proposals.rb b/db/migrate/20180807104331_add_selected_to_legislation_proposals.rb new file mode 100644 index 000000000..6696c2796 --- /dev/null +++ b/db/migrate/20180807104331_add_selected_to_legislation_proposals.rb @@ -0,0 +1,5 @@ +class AddSelectedToLegislationProposals < ActiveRecord::Migration + def change + add_column :legislation_proposals, :selected, :boolean + end +end diff --git a/db/schema.rb b/db/schema.rb index b4e58d0e7..ea0b1bbbd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -687,6 +687,7 @@ ActiveRecord::Schema.define(version: 20180924071722) do t.datetime "updated_at", null: false t.integer "cached_votes_total", default: 0 t.integer "cached_votes_down", default: 0 + t.boolean "selected" end add_index "legislation_proposals", ["legislation_process_id"], name: "index_legislation_proposals_on_legislation_process_id", using: :btree From a859de5d1655938989bb0c8913e836b5938770b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Fuentes?= Date: Thu, 9 Aug 2018 14:11:28 +0200 Subject: [PATCH 02/23] Test the selectable proposals --- .../admin/legislation/proposals_spec.rb | 100 ++++++++++++++++++ spec/features/legislation/proposals_spec.rb | 27 +++++ 2 files changed, 127 insertions(+) create mode 100644 spec/features/admin/legislation/proposals_spec.rb diff --git a/spec/features/admin/legislation/proposals_spec.rb b/spec/features/admin/legislation/proposals_spec.rb new file mode 100644 index 000000000..f6e15a548 --- /dev/null +++ b/spec/features/admin/legislation/proposals_spec.rb @@ -0,0 +1,100 @@ +require 'rails_helper' + +feature 'Admin legislation processes' do + + background do + admin = create(:administrator) + login_as(admin.user) + end + + context "Index" do + + scenario 'Displaying legislation proposals' do + proposal = create(:legislation_proposal, cached_votes_up: 10) + visit admin_legislation_process_proposals_path(proposal.legislation_process_id) + within "#legislation_proposal_#{proposal.id}" do + expect(page).to have_content(proposal.title) + expect(page).to have_content(proposal.id) + expect(page).to have_content(proposal.cached_votes_up) + expect(page).to have_content('Select') + end + end + + scenario 'Selecting legislation proposals' do + proposal = create(:legislation_proposal, cached_votes_up: 10) + visit admin_legislation_process_proposals_path(proposal.legislation_process_id) + + click_link 'Select' + within "#legislation_proposal_#{proposal.id}" do + expect(page).to have_content('Selected') + end + end + + scenario 'Sorting legislation proposals by title', js: true do + legislation_process = create(:legislation_process) + create(:legislation_proposal, title: 'bbbb', cached_votes_up: 10, legislation_process_id: legislation_process.id) + create(:legislation_proposal, title: 'aaaa', cached_votes_up: 20, legislation_process_id: legislation_process.id) + create(:legislation_proposal, title: 'cccc', cached_votes_up: 30, legislation_process_id: legislation_process.id) + visit admin_legislation_process_proposals_path(legislation_process.id) + + select "Title", from: "order-selector-participation" + + within('#proposals_table') do + within(:xpath, "//tbody/tr[1]") do + expect(page).to have_content('aaaa') + end + within(:xpath, "//tbody/tr[2]") do + expect(page).to have_content('bbbb') + end + within(:xpath, "//tbody/tr[3]") do + expect(page).to have_content('cccc') + end + end + end + + scenario 'Sorting legislation proposals by supports', js: true do + legislation_process = create(:legislation_process) + create(:legislation_proposal, title: 'bbbb', cached_votes_up: 10, legislation_process_id: legislation_process.id) + create(:legislation_proposal, title: 'aaaa', cached_votes_up: 20, legislation_process_id: legislation_process.id) + create(:legislation_proposal, title: 'cccc', cached_votes_up: 30, legislation_process_id: legislation_process.id) + visit admin_legislation_process_proposals_path(legislation_process.id) + + select "Supports", from: "order-selector-participation" + + within('#proposals_table') do + within(:xpath, "//tbody/tr[1]") do + expect(page).to have_content('10') + end + within(:xpath, "//tbody/tr[2]") do + expect(page).to have_content('20') + end + within(:xpath, "//tbody/tr[3]") do + expect(page).to have_content('30') + end + end + end + + scenario 'Sorting legislation proposals by Id', js: true do + legislation_process = create(:legislation_process) + proposal1 = create(:legislation_proposal, title: 'bbbb', cached_votes_up: 10, legislation_process_id: legislation_process.id) + proposal2 = create(:legislation_proposal, title: 'aaaa', cached_votes_up: 20, legislation_process_id: legislation_process.id) + proposal3 = create(:legislation_proposal, title: 'cccc', cached_votes_up: 30, legislation_process_id: legislation_process.id) + visit admin_legislation_process_proposals_path(legislation_process.id) + + select "Id", from: "order-selector-participation" + + within('#proposals_table') do + within(:xpath, "//tbody/tr[1]") do + expect(page).to have_content(proposal1.id) + end + within(:xpath, "//tbody/tr[2]") do + expect(page).to have_content(proposal2.id) + end + within(:xpath, "//tbody/tr[3]") do + expect(page).to have_content(proposal3.id) + end + end + end + end + +end \ No newline at end of file diff --git a/spec/features/legislation/proposals_spec.rb b/spec/features/legislation/proposals_spec.rb index 0d6784a2f..7413dcec3 100644 --- a/spec/features/legislation/proposals_spec.rb +++ b/spec/features/legislation/proposals_spec.rb @@ -64,6 +64,33 @@ feature 'Legislation Proposals' do expect(legislation_proposals_order).to eq(first_page_proposals_order) end + scenario 'Selected filter apperars only if exists any eslecte poposal' do + legislation_process = create(:legislation_process) + create(:legislation_proposal, legislation_process_id: legislation_process.id) + + visit legislation_process_proposals_path(legislation_process.id) + + expect(page).not_to have_content('Selected') + + create(:legislation_proposal, legislation_process_id: legislation_process.id, selected: true) + + visit legislation_process_proposals_path(legislation_process.id) + + expect(page).to have_content('Selected') + end + + scenario 'Selected filter works correctly' do + legislation_process = create(:legislation_process) + proposal1 = create(:legislation_proposal, legislation_process_id: legislation_process.id) + proposal2 = create(:legislation_proposal, legislation_process_id: legislation_process.id, selected: true) + visit legislation_process_proposals_path(legislation_process.id) + + click_link 'Selected' + + expect(page).to have_css("div#legislation_proposal_#{proposal2.id}") + expect(page).not_to have_css("div#legislation_proposal_#{proposal1.id}") + end + def legislation_proposals_order all("[id^='legislation_proposal_']").collect { |e| e[:id] } end From 9df201780d5f4ff021e5e34e4d08a3ece4231f9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 17 Sep 2018 17:23:11 +0200 Subject: [PATCH 03/23] Extract proposals table into a partial --- .../legislation/proposals/_proposals.html.erb | 38 +++++++++++++++++ .../legislation/proposals/index.html.erb | 41 +------------------ 2 files changed, 39 insertions(+), 40 deletions(-) create mode 100644 app/views/admin/legislation/proposals/_proposals.html.erb diff --git a/app/views/admin/legislation/proposals/_proposals.html.erb b/app/views/admin/legislation/proposals/_proposals.html.erb new file mode 100644 index 000000000..cc2de04ce --- /dev/null +++ b/app/views/admin/legislation/proposals/_proposals.html.erb @@ -0,0 +1,38 @@ +<% if proposals.any? %> +

<%= page_entries_info proposals %>

+ + <%= render 'shared/wide_order_selector', i18n_namespace: "admin.legislation.processes.proposals" %> + + + + + + + + + + + + + <% proposals.each do |proposal| %> + + + + + + + <% end %> + +
<%= t("admin.legislation.proposals.index.id") %><%= t("admin.legislation.proposals.index.title") %><%= t("admin.legislation.proposals.index.supports") %><%= t("admin.legislation.proposals.index.selected") %>
<%= proposal.id %><%= proposal.title %><%= proposal.cached_votes_up %> + <% if proposal.selected? + button_text = t("admin.legislation.proposals.index.selected") + clas = 'button expanded' + else + button_text = t("admin.legislation.proposals.index.select") + clas = 'button hollow expanded' + end %> + <%= link_to button_text, admin_legislation_process_proposal_path(@process, proposal), method: 'PUT', class: clas %> +
+ + <%= paginate proposals %> +<% end %> diff --git a/app/views/admin/legislation/proposals/index.html.erb b/app/views/admin/legislation/proposals/index.html.erb index d5f4c39fe..d8dd407a5 100644 --- a/app/views/admin/legislation/proposals/index.html.erb +++ b/app/views/admin/legislation/proposals/index.html.erb @@ -11,44 +11,5 @@ <%= render 'admin/legislation/processes/subnav', process: @process, active: 'proposals' %> <%= render 'form' %> - -<% if @proposals.any? %> -

<%= page_entries_info @proposals %>

- - <%= render 'shared/wide_order_selector', i18n_namespace: "admin.legislation.processes.proposals" %> - - - - - - - - - - - - - <% @proposals.each do |proposal| %> - - - - - - - <% end %> - -
<%= t("admin.legislation.proposals.index.id") %><%= t("admin.legislation.proposals.index.title") %><%= t("admin.legislation.proposals.index.supports") %><%= t("admin.legislation.proposals.index.selected") %>
<%= proposal.id %><%= proposal.title %><%= proposal.cached_votes_up %> - <% if proposal.selected? - button_text = t("admin.legislation.proposals.index.selected") - clas = 'button expanded' - else - button_text = t("admin.legislation.proposals.index.select") - clas = 'button hollow expanded' - end %> - <%= link_to button_text, admin_legislation_process_proposal_path(@process, proposal), method: 'PUT', class: clas %> -
- - <%= paginate @proposals %> -<% end %> - + <%= render 'proposals', proposals: @proposals %>
From 806b1fb3ca2dfd1e9e0219c6a0f3402136dd38c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 17 Sep 2018 17:23:31 +0200 Subject: [PATCH 04/23] Extract select proposal button into a partial --- .../admin/legislation/proposals/_proposals.html.erb | 11 +---------- .../legislation/proposals/_select_proposal.html.erb | 8 ++++++++ 2 files changed, 9 insertions(+), 10 deletions(-) create mode 100644 app/views/admin/legislation/proposals/_select_proposal.html.erb diff --git a/app/views/admin/legislation/proposals/_proposals.html.erb b/app/views/admin/legislation/proposals/_proposals.html.erb index cc2de04ce..cbdfa1dd7 100644 --- a/app/views/admin/legislation/proposals/_proposals.html.erb +++ b/app/views/admin/legislation/proposals/_proposals.html.erb @@ -19,16 +19,7 @@ <%= proposal.id %> <%= proposal.title %> <%= proposal.cached_votes_up %> - - <% if proposal.selected? - button_text = t("admin.legislation.proposals.index.selected") - clas = 'button expanded' - else - button_text = t("admin.legislation.proposals.index.select") - clas = 'button hollow expanded' - end %> - <%= link_to button_text, admin_legislation_process_proposal_path(@process, proposal), method: 'PUT', class: clas %> - + <%= render "select_proposal", proposal: proposal %> <% end %> diff --git a/app/views/admin/legislation/proposals/_select_proposal.html.erb b/app/views/admin/legislation/proposals/_select_proposal.html.erb new file mode 100644 index 000000000..9a40b2c2f --- /dev/null +++ b/app/views/admin/legislation/proposals/_select_proposal.html.erb @@ -0,0 +1,8 @@ +<% if proposal.selected? + button_text = t("admin.legislation.proposals.index.selected") + clas = 'button expanded' + else + button_text = t("admin.legislation.proposals.index.select") + clas = 'button hollow expanded' + end %> +<%= link_to button_text, admin_legislation_process_proposal_path(proposal.process, proposal), method: 'PUT', class: clas %> From 667c2c82b505682e478ce52d2b60335b1f30fb5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 17 Sep 2018 17:36:41 +0200 Subject: [PATCH 05/23] Use toggle_select action for legislation proposals The `update` action is usually expected to behave the same way it does everywhere else, which is updating a record using the `params` hash. The name `toggle_select` comes from the name we use in a similar situation for budget investments. --- .../admin/legislation/proposals_controller.rb | 15 +++++---------- .../proposals/_select_proposal.html.erb | 6 +++++- config/routes/admin.rb | 4 +++- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/controllers/admin/legislation/proposals_controller.rb b/app/controllers/admin/legislation/proposals_controller.rb index bd46d28fe..0c3116cd7 100644 --- a/app/controllers/admin/legislation/proposals_controller.rb +++ b/app/controllers/admin/legislation/proposals_controller.rb @@ -9,15 +9,10 @@ class Admin::Legislation::ProposalsController < Admin::Legislation::BaseControll @proposals = @proposals.send("sort_by_#{@current_order}").page(params[:page]) end - def update - @proposal.selected = !@proposal.selected - - if @proposal.save - notice = t('admin.legislation.proposals.update.notice') - else - notice = t('admin.legislation.proposals.update.error') - end - redirect_to admin_legislation_process_proposals_path, notice: notice + def toggle_selection + @proposal.toggle :selected + @proposal.save! + redirect_to admin_legislation_process_proposals_path, + notice: t('admin.legislation.proposals.update.notice') end - end \ No newline at end of file diff --git a/app/views/admin/legislation/proposals/_select_proposal.html.erb b/app/views/admin/legislation/proposals/_select_proposal.html.erb index 9a40b2c2f..6749c5904 100644 --- a/app/views/admin/legislation/proposals/_select_proposal.html.erb +++ b/app/views/admin/legislation/proposals/_select_proposal.html.erb @@ -5,4 +5,8 @@ button_text = t("admin.legislation.proposals.index.select") clas = 'button hollow expanded' end %> -<%= link_to button_text, admin_legislation_process_proposal_path(proposal.process, proposal), method: 'PUT', class: clas %> + +<%= link_to button_text, + toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal), + method: :patch, + class: clas %> diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 335d389d0..bd296658d 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -194,7 +194,9 @@ namespace :admin do namespace :legislation do resources :processes do resources :questions - resources :proposals + resources :proposals do + member { patch :toggle_selection } + end resources :draft_versions end end From 75d1ab1e520d5b07634ca204e9aed39f2f539c6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 17 Sep 2018 17:38:00 +0200 Subject: [PATCH 06/23] Use AJAX requests to select legislation proposals Now the interface is more similar to the one in budget investments. --- app/controllers/admin/legislation/proposals_controller.rb | 2 -- app/views/admin/legislation/proposals/_proposals.html.erb | 2 +- .../admin/legislation/proposals/_select_proposal.html.erb | 1 + app/views/admin/legislation/proposals/toggle_selection.js.erb | 1 + config/locales/en/admin.yml | 3 --- config/locales/es/admin.yml | 3 --- spec/features/admin/legislation/proposals_spec.rb | 2 +- 7 files changed, 4 insertions(+), 10 deletions(-) create mode 100644 app/views/admin/legislation/proposals/toggle_selection.js.erb diff --git a/app/controllers/admin/legislation/proposals_controller.rb b/app/controllers/admin/legislation/proposals_controller.rb index 0c3116cd7..05313ef7b 100644 --- a/app/controllers/admin/legislation/proposals_controller.rb +++ b/app/controllers/admin/legislation/proposals_controller.rb @@ -12,7 +12,5 @@ class Admin::Legislation::ProposalsController < Admin::Legislation::BaseControll def toggle_selection @proposal.toggle :selected @proposal.save! - redirect_to admin_legislation_process_proposals_path, - notice: t('admin.legislation.proposals.update.notice') end end \ No newline at end of file diff --git a/app/views/admin/legislation/proposals/_proposals.html.erb b/app/views/admin/legislation/proposals/_proposals.html.erb index cbdfa1dd7..a18d0b623 100644 --- a/app/views/admin/legislation/proposals/_proposals.html.erb +++ b/app/views/admin/legislation/proposals/_proposals.html.erb @@ -19,7 +19,7 @@ <%= proposal.id %> <%= proposal.title %> <%= proposal.cached_votes_up %> - <%= render "select_proposal", proposal: proposal %> + <%= render "select_proposal", proposal: proposal %> <% end %> diff --git a/app/views/admin/legislation/proposals/_select_proposal.html.erb b/app/views/admin/legislation/proposals/_select_proposal.html.erb index 6749c5904..6b8f40b6d 100644 --- a/app/views/admin/legislation/proposals/_select_proposal.html.erb +++ b/app/views/admin/legislation/proposals/_select_proposal.html.erb @@ -8,5 +8,6 @@ <%= link_to button_text, toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal), + remote: true, method: :patch, class: clas %> diff --git a/app/views/admin/legislation/proposals/toggle_selection.js.erb b/app/views/admin/legislation/proposals/toggle_selection.js.erb new file mode 100644 index 000000000..093afa904 --- /dev/null +++ b/app/views/admin/legislation/proposals/toggle_selection.js.erb @@ -0,0 +1 @@ +$("#<%= dom_id(@proposal) %> .select").html('<%= j render("select_proposal", proposal: @proposal) %>'); diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index fa4e84b62..c119b2cff 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -422,9 +422,6 @@ en: supports: Supports select: Select selected: Selected - update: - notice: 'Proposal updated successfully' - error: Proposal couldn't be updated form: custom_categories: Categories custom_categories_description: Categories that users can select creating the proposal. diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index e6fce5ceb..eabea7211 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -423,9 +423,6 @@ es: supports: Apoyos select: Seleccionar selected: Seleccionado - update: - notice: Propuesta actualizada correctamente. - error: No se ha podido actualizar la propuesta form: custom_categories: Categorías custom_categories_description: Categorías que el usuario puede seleccionar al crear la propuesta. diff --git a/spec/features/admin/legislation/proposals_spec.rb b/spec/features/admin/legislation/proposals_spec.rb index f6e15a548..2ea10786e 100644 --- a/spec/features/admin/legislation/proposals_spec.rb +++ b/spec/features/admin/legislation/proposals_spec.rb @@ -20,7 +20,7 @@ feature 'Admin legislation processes' do end end - scenario 'Selecting legislation proposals' do + scenario 'Selecting legislation proposals', :js do proposal = create(:legislation_proposal, cached_votes_up: 10) visit admin_legislation_process_proposals_path(proposal.legislation_process_id) From f1745f804041ec080cca7fa6d2924d39647fb612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 17 Sep 2018 17:41:05 +0200 Subject: [PATCH 07/23] Fix typo --- spec/features/legislation/proposals_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/legislation/proposals_spec.rb b/spec/features/legislation/proposals_spec.rb index 7413dcec3..d624bdd74 100644 --- a/spec/features/legislation/proposals_spec.rb +++ b/spec/features/legislation/proposals_spec.rb @@ -64,7 +64,7 @@ feature 'Legislation Proposals' do expect(legislation_proposals_order).to eq(first_page_proposals_order) end - scenario 'Selected filter apperars only if exists any eslecte poposal' do + scenario 'Selected filter apperars only if exists any selected poposal' do legislation_process = create(:legislation_process) create(:legislation_proposal, legislation_process_id: legislation_process.id) From dc9cf5da55e0eb360791c2186193d16e811b7ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 21 Sep 2018 13:43:07 +0200 Subject: [PATCH 08/23] Order by supports in descending order Just as we do with confidence score, and as admins expect when they order by received supports: the ones with more supports appear first. --- app/models/legislation/proposal.rb | 2 +- spec/features/admin/legislation/proposals_spec.rb | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index ad6691578..61398f178 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -47,7 +47,7 @@ class Legislation::Proposal < ActiveRecord::Base scope :sort_by_most_commented, -> { reorder(comments_count: :desc) } scope :sort_by_title, -> { reorder(title: :asc) } scope :sort_by_id, -> { reorder(id: :asc) } - scope :sort_by_supports, -> { reorder(cached_votes_up: :asc) } + scope :sort_by_supports, -> { reorder(cached_votes_up: :desc) } scope :sort_by_random, -> { reorder("RANDOM()") } scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} diff --git a/spec/features/admin/legislation/proposals_spec.rb b/spec/features/admin/legislation/proposals_spec.rb index 2ea10786e..394a32ad7 100644 --- a/spec/features/admin/legislation/proposals_spec.rb +++ b/spec/features/admin/legislation/proposals_spec.rb @@ -62,15 +62,9 @@ feature 'Admin legislation processes' do select "Supports", from: "order-selector-participation" within('#proposals_table') do - within(:xpath, "//tbody/tr[1]") do - expect(page).to have_content('10') - end - within(:xpath, "//tbody/tr[2]") do - expect(page).to have_content('20') - end - within(:xpath, "//tbody/tr[3]") do - expect(page).to have_content('30') - end + within(:xpath, "//tbody/tr[1]") { expect(page).to have_content('30') } + within(:xpath, "//tbody/tr[2]") { expect(page).to have_content('20') } + within(:xpath, "//tbody/tr[3]") { expect(page).to have_content('10') } end end From 7d69f2aaabaf0339cd39ee4cbea3c5dafb2f5a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 21 Sep 2018 13:48:29 +0200 Subject: [PATCH 09/23] Properly test order by ID By default records are already ordered by ID, so we weren't checking the ordering by ID functionality was working properly. Making the records be ordered by title first makes the test a bit more reliable. --- spec/features/admin/legislation/proposals_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/features/admin/legislation/proposals_spec.rb b/spec/features/admin/legislation/proposals_spec.rb index 394a32ad7..efd754b8a 100644 --- a/spec/features/admin/legislation/proposals_spec.rb +++ b/spec/features/admin/legislation/proposals_spec.rb @@ -73,7 +73,7 @@ feature 'Admin legislation processes' do proposal1 = create(:legislation_proposal, title: 'bbbb', cached_votes_up: 10, legislation_process_id: legislation_process.id) proposal2 = create(:legislation_proposal, title: 'aaaa', cached_votes_up: 20, legislation_process_id: legislation_process.id) proposal3 = create(:legislation_proposal, title: 'cccc', cached_votes_up: 30, legislation_process_id: legislation_process.id) - visit admin_legislation_process_proposals_path(legislation_process.id) + visit admin_legislation_process_proposals_path(legislation_process.id, order: :title) select "Id", from: "order-selector-participation" From d6ff7e0f3fdabb9ee43c082437a1a353ac0dada6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Fri, 21 Sep 2018 18:30:41 +0200 Subject: [PATCH 10/23] Simplify code --- app/controllers/legislation/processes_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 11b1be0d6..970e44a75 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -95,7 +95,7 @@ class Legislation::ProcessesController < Legislation::BaseController @proposals = @proposals.search(params[:search]) if params[:search].present? @proposals = @proposals.send(@current_filter).order('random()').page(params[:page]) - @valid_filters = [] unless @proposals.map(&:selected).include? true + @valid_filters = [] unless @proposals.selected.any? if @process.proposals_phase.started? || (current_user && current_user.administrator?) legislation_proposal_votes(@proposals) From 659a45af0adb6a47d4a23dbbdab5c5e081e6b5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 24 Sep 2018 19:02:32 +0200 Subject: [PATCH 11/23] Seed some selected legislation proposals --- db/dev_seeds/legislation_proposals.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/dev_seeds/legislation_proposals.rb b/db/dev_seeds/legislation_proposals.rb index ec6427395..e309dd28c 100644 --- a/db/dev_seeds/legislation_proposals.rb +++ b/db/dev_seeds/legislation_proposals.rb @@ -6,6 +6,7 @@ section "Creating legislation proposals" do summary: Faker::Lorem.paragraph, author: User.all.sample, process: Legislation::Process.all.sample, - terms_of_service: '1') + terms_of_service: '1', + selected: rand <= 1.0 / 3) end end From 66fc49f9ed55a8efa534f54cc60b14817dccef3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 24 Sep 2018 19:30:01 +0200 Subject: [PATCH 12/23] Ignore dynamically used I18n keys --- config/i18n-tasks.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index b673c2110..ba9a522b8 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -139,6 +139,8 @@ ignore_unused: - 'admin.activity.show.filter*' - 'admin.legislation.processes.index.filter*' - 'admin.legislation.processes.*.submit_button' + - 'admin.legislation.processes.proposals.orders.*' + - 'admin.legislation.processes.proposals.select_order' - 'admin.legislation.draft_versions.*.submit_button' - 'admin.legislation.questions.*.submit_button' - 'admin.comments.index.hidden_*' @@ -176,6 +178,7 @@ ignore_unused: - 'notifications.notification.action.*' - 'legislation.processes.index.filter*' - 'legislation.processes.index.section_header.*' + - 'legislation.processes.proposals.filters.*' - 'helpers.page_entries_info.*' # kaminari - 'views.pagination.*' # kaminari - 'shared.suggest.*' From 81871a56f8438e259568bcb6018ec15b5ef4ce0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 24 Sep 2018 19:53:04 +0200 Subject: [PATCH 13/23] Simplify legislation process specs We kill two birds with one stone and also make each line less than 100 characters long. --- .../admin/legislation/proposals_spec.rb | 30 +++++++++---------- spec/features/legislation/proposals_spec.rb | 16 +++++----- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/spec/features/admin/legislation/proposals_spec.rb b/spec/features/admin/legislation/proposals_spec.rb index efd754b8a..9684c69ee 100644 --- a/spec/features/admin/legislation/proposals_spec.rb +++ b/spec/features/admin/legislation/proposals_spec.rb @@ -31,12 +31,12 @@ feature 'Admin legislation processes' do end scenario 'Sorting legislation proposals by title', js: true do - legislation_process = create(:legislation_process) - create(:legislation_proposal, title: 'bbbb', cached_votes_up: 10, legislation_process_id: legislation_process.id) - create(:legislation_proposal, title: 'aaaa', cached_votes_up: 20, legislation_process_id: legislation_process.id) - create(:legislation_proposal, title: 'cccc', cached_votes_up: 30, legislation_process_id: legislation_process.id) - visit admin_legislation_process_proposals_path(legislation_process.id) + process = create(:legislation_process) + create(:legislation_proposal, title: 'bbbb', legislation_process_id: process.id) + create(:legislation_proposal, title: 'aaaa', legislation_process_id: process.id) + create(:legislation_proposal, title: 'cccc', legislation_process_id: process.id) + visit admin_legislation_process_proposals_path(process.id) select "Title", from: "order-selector-participation" within('#proposals_table') do @@ -53,12 +53,12 @@ feature 'Admin legislation processes' do end scenario 'Sorting legislation proposals by supports', js: true do - legislation_process = create(:legislation_process) - create(:legislation_proposal, title: 'bbbb', cached_votes_up: 10, legislation_process_id: legislation_process.id) - create(:legislation_proposal, title: 'aaaa', cached_votes_up: 20, legislation_process_id: legislation_process.id) - create(:legislation_proposal, title: 'cccc', cached_votes_up: 30, legislation_process_id: legislation_process.id) - visit admin_legislation_process_proposals_path(legislation_process.id) + process = create(:legislation_process) + create(:legislation_proposal, cached_votes_up: 10, legislation_process_id: process.id) + create(:legislation_proposal, cached_votes_up: 30, legislation_process_id: process.id) + create(:legislation_proposal, cached_votes_up: 20, legislation_process_id: process.id) + visit admin_legislation_process_proposals_path(process.id) select "Supports", from: "order-selector-participation" within('#proposals_table') do @@ -69,12 +69,12 @@ feature 'Admin legislation processes' do end scenario 'Sorting legislation proposals by Id', js: true do - legislation_process = create(:legislation_process) - proposal1 = create(:legislation_proposal, title: 'bbbb', cached_votes_up: 10, legislation_process_id: legislation_process.id) - proposal2 = create(:legislation_proposal, title: 'aaaa', cached_votes_up: 20, legislation_process_id: legislation_process.id) - proposal3 = create(:legislation_proposal, title: 'cccc', cached_votes_up: 30, legislation_process_id: legislation_process.id) - visit admin_legislation_process_proposals_path(legislation_process.id, order: :title) + process = create(:legislation_process) + proposal1 = create(:legislation_proposal, title: 'bbbb', legislation_process_id: process.id) + proposal2 = create(:legislation_proposal, title: 'aaaa', legislation_process_id: process.id) + proposal3 = create(:legislation_proposal, title: 'cccc', legislation_process_id: process.id) + visit admin_legislation_process_proposals_path(process.id, order: :title) select "Id", from: "order-selector-participation" within('#proposals_table') do diff --git a/spec/features/legislation/proposals_spec.rb b/spec/features/legislation/proposals_spec.rb index d624bdd74..b4800528f 100644 --- a/spec/features/legislation/proposals_spec.rb +++ b/spec/features/legislation/proposals_spec.rb @@ -65,25 +65,23 @@ feature 'Legislation Proposals' do end scenario 'Selected filter apperars only if exists any selected poposal' do - legislation_process = create(:legislation_process) - create(:legislation_proposal, legislation_process_id: legislation_process.id) + create(:legislation_proposal, legislation_process_id: process.id) - visit legislation_process_proposals_path(legislation_process.id) + visit legislation_process_proposals_path(process) expect(page).not_to have_content('Selected') - create(:legislation_proposal, legislation_process_id: legislation_process.id, selected: true) + create(:legislation_proposal, legislation_process_id: process.id, selected: true) - visit legislation_process_proposals_path(legislation_process.id) + visit legislation_process_proposals_path(process) expect(page).to have_content('Selected') end scenario 'Selected filter works correctly' do - legislation_process = create(:legislation_process) - proposal1 = create(:legislation_proposal, legislation_process_id: legislation_process.id) - proposal2 = create(:legislation_proposal, legislation_process_id: legislation_process.id, selected: true) - visit legislation_process_proposals_path(legislation_process.id) + proposal1 = create(:legislation_proposal, legislation_process_id: process.id) + proposal2 = create(:legislation_proposal, legislation_process_id: process.id, selected: true) + visit legislation_process_proposals_path(process) click_link 'Selected' From ec2b4fe7ff3d6b03e0c914018740e934a74b4325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Mon, 24 Sep 2018 19:56:00 +0200 Subject: [PATCH 14/23] Use %w[] instead of %w{} As agreed when discussing our rubocop rules. --- app/controllers/admin/legislation/proposals_controller.rb | 2 +- app/controllers/legislation/processes_controller.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/legislation/proposals_controller.rb b/app/controllers/admin/legislation/proposals_controller.rb index 05313ef7b..dd92d1492 100644 --- a/app/controllers/admin/legislation/proposals_controller.rb +++ b/app/controllers/admin/legislation/proposals_controller.rb @@ -1,6 +1,6 @@ class Admin::Legislation::ProposalsController < Admin::Legislation::BaseController - has_orders %w{id title supports}, only: :index + has_orders %w[id title supports], only: :index load_and_authorize_resource :process, class: "Legislation::Process" load_and_authorize_resource :proposal, class: "Legislation::Proposal", through: :process diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 970e44a75..83976db8c 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -1,6 +1,6 @@ class Legislation::ProcessesController < Legislation::BaseController - has_filters %w{open next past}, only: :index - has_filters %w{all selected}, only: :proposals + has_filters %w[open next past], only: :index + has_filters %w[all selected], only: :proposals load_and_authorize_resource From 2fb5fb5fb29d5757e1ac9c53c926d1823bb718a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 26 Sep 2018 14:02:13 +0200 Subject: [PATCH 15/23] Add missing newline characters --- app/controllers/admin/legislation/proposals_controller.rb | 2 +- spec/features/admin/legislation/proposals_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/legislation/proposals_controller.rb b/app/controllers/admin/legislation/proposals_controller.rb index dd92d1492..44a1dd192 100644 --- a/app/controllers/admin/legislation/proposals_controller.rb +++ b/app/controllers/admin/legislation/proposals_controller.rb @@ -13,4 +13,4 @@ class Admin::Legislation::ProposalsController < Admin::Legislation::BaseControll @proposal.toggle :selected @proposal.save! end -end \ No newline at end of file +end diff --git a/spec/features/admin/legislation/proposals_spec.rb b/spec/features/admin/legislation/proposals_spec.rb index 9684c69ee..7a6d03c59 100644 --- a/spec/features/admin/legislation/proposals_spec.rb +++ b/spec/features/admin/legislation/proposals_spec.rb @@ -91,4 +91,4 @@ feature 'Admin legislation processes' do end end -end \ No newline at end of file +end From d9410a132a901570e6de58467693633f9e656d5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 26 Sep 2018 11:28:22 +0200 Subject: [PATCH 16/23] Always show filters for legislation proposals As done in the rest of the application: we show the filters even if there isn't any data to display. --- app/controllers/legislation/processes_controller.rb | 2 -- .../legislation/processes/_proposals_content.html.erb | 2 +- spec/features/legislation/proposals_spec.rb | 8 +------- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index 83976db8c..abe814574 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -95,8 +95,6 @@ class Legislation::ProcessesController < Legislation::BaseController @proposals = @proposals.search(params[:search]) if params[:search].present? @proposals = @proposals.send(@current_filter).order('random()').page(params[:page]) - @valid_filters = [] unless @proposals.selected.any? - if @process.proposals_phase.started? || (current_user && current_user.administrator?) legislation_proposal_votes(@proposals) render :proposals diff --git a/app/views/legislation/processes/_proposals_content.html.erb b/app/views/legislation/processes/_proposals_content.html.erb index cd36125d0..714ed4305 100644 --- a/app/views/legislation/processes/_proposals_content.html.erb +++ b/app/views/legislation/processes/_proposals_content.html.erb @@ -3,12 +3,12 @@
+ <%= render 'shared/filter_subnav', i18n_namespace: "legislation.processes.proposals" %> <% if proposals.empty? %>

<%= t("legislation.processes.proposals.empty_proposals") %>

<% else %> - <%= render 'shared/filter_subnav', i18n_namespace: "legislation.processes.proposals" %> <%= render proposals %> <%= paginate proposals %> <% end %> diff --git a/spec/features/legislation/proposals_spec.rb b/spec/features/legislation/proposals_spec.rb index b4800528f..d89a381f1 100644 --- a/spec/features/legislation/proposals_spec.rb +++ b/spec/features/legislation/proposals_spec.rb @@ -64,17 +64,11 @@ feature 'Legislation Proposals' do expect(legislation_proposals_order).to eq(first_page_proposals_order) end - scenario 'Selected filter apperars only if exists any selected poposal' do + scenario 'Selected filter apperars even if there are not any selected poposals' do create(:legislation_proposal, legislation_process_id: process.id) visit legislation_process_proposals_path(process) - expect(page).not_to have_content('Selected') - - create(:legislation_proposal, legislation_process_id: process.id, selected: true) - - visit legislation_process_proposals_path(process) - expect(page).to have_content('Selected') end From 89762804939262dbf25b22cf4ebc107a7d03c217 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 26 Sep 2018 12:50:48 +0200 Subject: [PATCH 17/23] Order selected proposals by confidence score The same way we order budget results. --- app/controllers/legislation/processes_controller.rb | 4 ++-- app/models/legislation/proposal.rb | 2 ++ config/locales/en/legislation.yml | 4 ++-- config/locales/es/legislation.yml | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index abe814574..bde762666 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -1,6 +1,6 @@ class Legislation::ProcessesController < Legislation::BaseController has_filters %w[open next past], only: :index - has_filters %w[all selected], only: :proposals + has_filters %w[random winners], only: :proposals load_and_authorize_resource @@ -93,7 +93,7 @@ class Legislation::ProcessesController < Legislation::BaseController @proposals = ::Legislation::Proposal.where(process: @process) @proposals = @proposals.search(params[:search]) if params[:search].present? - @proposals = @proposals.send(@current_filter).order('random()').page(params[:page]) + @proposals = @proposals.send(@current_filter).page(params[:page]) if @process.proposals_phase.started? || (current_user && current_user.administrator?) legislation_proposal_votes(@proposals) diff --git a/app/models/legislation/proposal.rb b/app/models/legislation/proposal.rb index 61398f178..43a5cf1e8 100644 --- a/app/models/legislation/proposal.rb +++ b/app/models/legislation/proposal.rb @@ -52,6 +52,8 @@ class Legislation::Proposal < ActiveRecord::Base scope :sort_by_flags, -> { order(flags_count: :desc, updated_at: :desc) } scope :last_week, -> { where("proposals.created_at >= ?", 7.days.ago)} scope :selected, -> { where(selected: true) } + scope :random, -> { sort_by_random } + scope :winners, -> { selected.sort_by_confidence_score } def to_param "#{id}-#{title}".parameterize diff --git a/config/locales/en/legislation.yml b/config/locales/en/legislation.yml index 212e3b9ca..ae04ad606 100644 --- a/config/locales/en/legislation.yml +++ b/config/locales/en/legislation.yml @@ -53,8 +53,8 @@ en: proposals: empty_proposals: There are no proposals filters: - all: All - selected: Selected + random: All + winners: Selected debate: empty_questions: There aren't any questions participate: Participate in the debate diff --git a/config/locales/es/legislation.yml b/config/locales/es/legislation.yml index db250f604..d6cb1670c 100644 --- a/config/locales/es/legislation.yml +++ b/config/locales/es/legislation.yml @@ -53,8 +53,8 @@ es: proposals: empty_proposals: No hay propuestas filters: - all: Todos - selected: Seleccionados + random: Todas + winners: Seleccionadas debate: empty_questions: No hay preguntas participate: Realiza tus aportaciones al debate previo participando en los siguientes temas. From 2a5a2e0fcb89aa52c08688b98700042a61c4b612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 26 Sep 2018 12:52:47 +0200 Subject: [PATCH 18/23] Use "Random" instead of "All" in proposals filters That way users might be less surprised when they see proposals are different each time they access the page. --- config/locales/en/legislation.yml | 2 +- config/locales/es/legislation.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/en/legislation.yml b/config/locales/en/legislation.yml index ae04ad606..f6b4b1491 100644 --- a/config/locales/en/legislation.yml +++ b/config/locales/en/legislation.yml @@ -53,7 +53,7 @@ en: proposals: empty_proposals: There are no proposals filters: - random: All + random: Random winners: Selected debate: empty_questions: There aren't any questions diff --git a/config/locales/es/legislation.yml b/config/locales/es/legislation.yml index d6cb1670c..d98ff37a9 100644 --- a/config/locales/es/legislation.yml +++ b/config/locales/es/legislation.yml @@ -53,7 +53,7 @@ es: proposals: empty_proposals: No hay propuestas filters: - random: Todas + random: Aleatorias winners: Seleccionadas debate: empty_questions: No hay preguntas From 9c13f08c8e3602e0702eeec02b6d8d3b39e55f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 26 Sep 2018 13:48:34 +0200 Subject: [PATCH 19/23] Show selected legislation proposals by default --- .../legislation/processes_controller.rb | 2 + spec/features/legislation/proposals_spec.rb | 48 ++++++++++++++----- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app/controllers/legislation/processes_controller.rb b/app/controllers/legislation/processes_controller.rb index bde762666..f05d2fdda 100644 --- a/app/controllers/legislation/processes_controller.rb +++ b/app/controllers/legislation/processes_controller.rb @@ -93,6 +93,8 @@ class Legislation::ProcessesController < Legislation::BaseController @proposals = ::Legislation::Proposal.where(process: @process) @proposals = @proposals.search(params[:search]) if params[:search].present? + + @current_filter = "winners" if params[:filter].blank? && @proposals.winners.any? @proposals = @proposals.send(@current_filter).page(params[:page]) if @process.proposals_phase.started? || (current_user && current_user.administrator?) diff --git a/spec/features/legislation/proposals_spec.rb b/spec/features/legislation/proposals_spec.rb index d89a381f1..a153bea1d 100644 --- a/spec/features/legislation/proposals_spec.rb +++ b/spec/features/legislation/proposals_spec.rb @@ -64,23 +64,47 @@ feature 'Legislation Proposals' do expect(legislation_proposals_order).to eq(first_page_proposals_order) end - scenario 'Selected filter apperars even if there are not any selected poposals' do - create(:legislation_proposal, legislation_process_id: process.id) + context 'Selected filter' do + scenario 'apperars even if there are not any selected poposals' do + create(:legislation_proposal, legislation_process_id: process.id) - visit legislation_process_proposals_path(process) + visit legislation_process_proposals_path(process) - expect(page).to have_content('Selected') - end + expect(page).to have_content('Selected') + end - scenario 'Selected filter works correctly' do - proposal1 = create(:legislation_proposal, legislation_process_id: process.id) - proposal2 = create(:legislation_proposal, legislation_process_id: process.id, selected: true) - visit legislation_process_proposals_path(process) + scenario 'defaults to winners if there are selected proposals' do + create(:legislation_proposal, legislation_process_id: process.id) + create(:legislation_proposal, legislation_process_id: process.id, selected: true) - click_link 'Selected' + visit legislation_process_proposals_path(process) - expect(page).to have_css("div#legislation_proposal_#{proposal2.id}") - expect(page).not_to have_css("div#legislation_proposal_#{proposal1.id}") + expect(page).to have_link('Random') + expect(page).not_to have_link('Selected') + expect(page).to have_content('Selected') + end + + scenario 'defaults to random if the current process does not have selected proposals' do + create(:legislation_proposal, legislation_process_id: process.id) + create(:legislation_proposal, selected: true) + + visit legislation_process_proposals_path(process) + + expect(page).to have_link('Selected') + expect(page).not_to have_link('Random') + expect(page).to have_content('Random') + end + + scenario 'filters correctly' do + proposal1 = create(:legislation_proposal, legislation_process_id: process.id) + proposal2 = create(:legislation_proposal, legislation_process_id: process.id, selected: true) + visit legislation_process_proposals_path(process, filter: "random") + + click_link 'Selected' + + expect(page).to have_css("div#legislation_proposal_#{proposal2.id}") + expect(page).not_to have_css("div#legislation_proposal_#{proposal1.id}") + end end def legislation_proposals_order From 4c84a3a854f5792963123f2c82292009a3571ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 26 Sep 2018 14:19:17 +0200 Subject: [PATCH 20/23] Move logic from view to helper --- app/helpers/legislation_helper.rb | 16 ++++++++++++++++ .../proposals/_select_proposal.html.erb | 14 +------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/app/helpers/legislation_helper.rb b/app/helpers/legislation_helper.rb index d8dc77f87..a737824ab 100644 --- a/app/helpers/legislation_helper.rb +++ b/app/helpers/legislation_helper.rb @@ -10,4 +10,20 @@ module LegislationHelper def new_legislation_proposal_link_text(process) 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 end diff --git a/app/views/admin/legislation/proposals/_select_proposal.html.erb b/app/views/admin/legislation/proposals/_select_proposal.html.erb index 6b8f40b6d..0d5eb845d 100644 --- a/app/views/admin/legislation/proposals/_select_proposal.html.erb +++ b/app/views/admin/legislation/proposals/_select_proposal.html.erb @@ -1,13 +1 @@ -<% if proposal.selected? - button_text = t("admin.legislation.proposals.index.selected") - clas = 'button expanded' - else - button_text = t("admin.legislation.proposals.index.select") - clas = 'button hollow expanded' - end %> - -<%= link_to button_text, - toggle_selection_admin_legislation_process_proposal_path(proposal.process, proposal), - remote: true, - method: :patch, - class: clas %> +<%= link_to_toggle_legislation_proposal_selection(proposal) %> From 959270b0bb290fadb74be843408310068b225f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 27 Sep 2018 17:20:44 +0200 Subject: [PATCH 21/23] Separate setup, actions and expections in specs --- spec/features/admin/legislation/proposals_spec.rb | 5 ++++- spec/features/legislation/proposals_spec.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/features/admin/legislation/proposals_spec.rb b/spec/features/admin/legislation/proposals_spec.rb index 7a6d03c59..5be2bf08b 100644 --- a/spec/features/admin/legislation/proposals_spec.rb +++ b/spec/features/admin/legislation/proposals_spec.rb @@ -11,7 +11,9 @@ feature 'Admin legislation processes' do scenario 'Displaying legislation proposals' do proposal = create(:legislation_proposal, cached_votes_up: 10) + visit admin_legislation_process_proposals_path(proposal.legislation_process_id) + within "#legislation_proposal_#{proposal.id}" do expect(page).to have_content(proposal.title) expect(page).to have_content(proposal.id) @@ -22,9 +24,10 @@ feature 'Admin legislation processes' do scenario 'Selecting legislation proposals', :js do proposal = create(:legislation_proposal, cached_votes_up: 10) - visit admin_legislation_process_proposals_path(proposal.legislation_process_id) + visit admin_legislation_process_proposals_path(proposal.legislation_process_id) click_link 'Select' + within "#legislation_proposal_#{proposal.id}" do expect(page).to have_content('Selected') end diff --git a/spec/features/legislation/proposals_spec.rb b/spec/features/legislation/proposals_spec.rb index a153bea1d..17a7c607e 100644 --- a/spec/features/legislation/proposals_spec.rb +++ b/spec/features/legislation/proposals_spec.rb @@ -98,8 +98,8 @@ feature 'Legislation Proposals' do scenario 'filters correctly' do proposal1 = create(:legislation_proposal, legislation_process_id: process.id) proposal2 = create(:legislation_proposal, legislation_process_id: process.id, selected: true) - visit legislation_process_proposals_path(process, filter: "random") + visit legislation_process_proposals_path(process, filter: "random") click_link 'Selected' expect(page).to have_css("div#legislation_proposal_#{proposal2.id}") From 0945f046a33175743a224ddeeeabe40118a152a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Thu, 27 Sep 2018 17:44:03 +0200 Subject: [PATCH 22/23] Avoid using xpath in specs Using xpath is usually harder to read and more fragile. --- .../legislation/proposals/_proposals.html.erb | 4 +-- .../admin/legislation/proposals_spec.rb | 36 +++++++------------ 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/app/views/admin/legislation/proposals/_proposals.html.erb b/app/views/admin/legislation/proposals/_proposals.html.erb index a18d0b623..2f75b4223 100644 --- a/app/views/admin/legislation/proposals/_proposals.html.erb +++ b/app/views/admin/legislation/proposals/_proposals.html.erb @@ -3,7 +3,7 @@ <%= render 'shared/wide_order_selector', i18n_namespace: "admin.legislation.processes.proposals" %> - +
@@ -15,7 +15,7 @@ <% proposals.each do |proposal| %> - + diff --git a/spec/features/admin/legislation/proposals_spec.rb b/spec/features/admin/legislation/proposals_spec.rb index 5be2bf08b..bd8caf0a3 100644 --- a/spec/features/admin/legislation/proposals_spec.rb +++ b/spec/features/admin/legislation/proposals_spec.rb @@ -42,16 +42,10 @@ feature 'Admin legislation processes' do visit admin_legislation_process_proposals_path(process.id) select "Title", from: "order-selector-participation" - within('#proposals_table') do - within(:xpath, "//tbody/tr[1]") do - expect(page).to have_content('aaaa') - end - within(:xpath, "//tbody/tr[2]") do - expect(page).to have_content('bbbb') - end - within(:xpath, "//tbody/tr[3]") do - expect(page).to have_content('cccc') - end + within('#legislation_proposals_list') do + within all('.legislation_proposal')[0] { expect(page).to have_content('aaaa') } + within all('.legislation_proposal')[1] { expect(page).to have_content('bbbb') } + within all('.legislation_proposal')[2] { expect(page).to have_content('cccc') } end end @@ -64,10 +58,10 @@ feature 'Admin legislation processes' do visit admin_legislation_process_proposals_path(process.id) select "Supports", from: "order-selector-participation" - within('#proposals_table') do - within(:xpath, "//tbody/tr[1]") { expect(page).to have_content('30') } - within(:xpath, "//tbody/tr[2]") { expect(page).to have_content('20') } - within(:xpath, "//tbody/tr[3]") { expect(page).to have_content('10') } + within('#legislation_proposals_list') do + within all('.legislation_proposal')[0] { expect(page).to have_content('30') } + within all('.legislation_proposal')[1] { expect(page).to have_content('20') } + within all('.legislation_proposal')[2] { expect(page).to have_content('10') } end end @@ -80,16 +74,10 @@ feature 'Admin legislation processes' do visit admin_legislation_process_proposals_path(process.id, order: :title) select "Id", from: "order-selector-participation" - within('#proposals_table') do - within(:xpath, "//tbody/tr[1]") do - expect(page).to have_content(proposal1.id) - end - within(:xpath, "//tbody/tr[2]") do - expect(page).to have_content(proposal2.id) - end - within(:xpath, "//tbody/tr[3]") do - expect(page).to have_content(proposal3.id) - end + within('#legislation_proposals_list') do + within all('.legislation_proposal')[0] { expect(page).to have_content(proposal1.id) } + within all('.legislation_proposal')[1] { expect(page).to have_content(proposal2.id) } + within all('.legislation_proposal')[2] { expect(page).to have_content(proposal3.id) } end end end From 0d8c9c289a2cb9d47f48f267cd989d4399b83a34 Mon Sep 17 00:00:00 2001 From: decabeza Date: Sat, 29 Sep 2018 12:54:59 +0200 Subject: [PATCH 23/23] Removes closed message on legislation proposals votes --- app/assets/stylesheets/participation.scss | 7 +++++++ app/views/legislation/proposals/_votes.html.erb | 2 -- config/locales/en/legislation.yml | 1 - config/locales/es/legislation.yml | 1 - 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/assets/stylesheets/participation.scss b/app/assets/stylesheets/participation.scss index 1cc6e87c9..cafbb52be 100644 --- a/app/assets/stylesheets/participation.scss +++ b/app/assets/stylesheets/participation.scss @@ -887,6 +887,13 @@ } } +.legislation-proposals { + + .votes { + min-height: $line-height * 8; + } +} + .proposal-show .votes, .debate-show .votes { border: 0; diff --git a/app/views/legislation/proposals/_votes.html.erb b/app/views/legislation/proposals/_votes.html.erb index 8452bed9f..d88cf96d2 100644 --- a/app/views/legislation/proposals/_votes.html.erb +++ b/app/views/legislation/proposals/_votes.html.erb @@ -39,8 +39,6 @@ <% end %> - <% else %> -

<%= t("legislation.proposals.closed") %>

<% end %> diff --git a/config/locales/en/legislation.yml b/config/locales/en/legislation.yml index f6b4b1491..bd3ed87c1 100644 --- a/config/locales/en/legislation.yml +++ b/config/locales/en/legislation.yml @@ -123,4 +123,3 @@ en: form: tags_label: "Categories" not_verified: "For vote proposals %{verify_account}." - closed: "This process has been closed and can not receive votes." \ No newline at end of file diff --git a/config/locales/es/legislation.yml b/config/locales/es/legislation.yml index d98ff37a9..03f4724fd 100644 --- a/config/locales/es/legislation.yml +++ b/config/locales/es/legislation.yml @@ -123,4 +123,3 @@ es: form: tags_label: "Categorías" not_verified: "Para votar propuestas %{verify_account}." - closed: "Este proceso se ha cerrado y ya no puede recoger votos."
<%= t("admin.legislation.proposals.index.id") %>
<%= proposal.id %> <%= proposal.title %> <%= proposal.cached_votes_up %>