diff --git a/app/controllers/proposals_controller.rb b/app/controllers/proposals_controller.rb index ff200fe9a..7e679a05d 100644 --- a/app/controllers/proposals_controller.rb +++ b/app/controllers/proposals_controller.rb @@ -8,6 +8,7 @@ class ProposalsController < ApplicationController before_action :load_geozones, only: [:edit, :map, :summary] before_action :authenticate_user!, except: [:index, :show, :map, :summary] before_action :destroy_map_location_association, only: :update + before_action :set_view, only: :index feature_flag :proposals @@ -127,6 +128,10 @@ class ProposalsController < ApplicationController end end + def set_view + @view = (params[:view] == "minimal") ? "minimal" : "default" + end + def load_successful_proposals @proposal_successful_exists = Proposal.successful.exists? end diff --git a/app/helpers/proposals_helper.rb b/app/helpers/proposals_helper.rb index 9d5ac40cc..84407f840 100644 --- a/app/helpers/proposals_helper.rb +++ b/app/helpers/proposals_helper.rb @@ -48,4 +48,20 @@ module ProposalsHelper current_user && proposal.editable_by?(current_user) end + def proposals_minimal_view_path + proposals_path(view: proposals_secondary_view) + end + + def proposals_default_view? + @view == "default" + end + + def proposals_current_view + @view + end + + def proposals_secondary_view + proposals_current_view == "default" ? "minimal" : "default" + end + end diff --git a/app/views/proposals/_proposal_minimal.html.erb b/app/views/proposals/_proposal_minimal.html.erb new file mode 100644 index 000000000..f99b01c2c --- /dev/null +++ b/app/views/proposals/_proposal_minimal.html.erb @@ -0,0 +1,14 @@ +
+
+
+
+
+ <% cache [locale_and_user_status(proposal), + 'index_minimal', proposal, proposal.author] do %> +

<%= link_to proposal.title, namespaced_proposal_path(proposal) %>

+ <% end %> +
+
+
+
+
diff --git a/app/views/proposals/_view_mode.html.erb b/app/views/proposals/_view_mode.html.erb new file mode 100644 index 000000000..7b0952401 --- /dev/null +++ b/app/views/proposals/_view_mode.html.erb @@ -0,0 +1,30 @@ +
+ + + +
diff --git a/spec/features/proposals_spec.rb b/spec/features/proposals_spec.rb index 7c27220f8..2fcb6a17e 100644 --- a/spec/features/proposals_spec.rb +++ b/spec/features/proposals_spec.rb @@ -48,6 +48,35 @@ feature 'Proposals' do end end + scenario 'Index view mode' do + featured_proposals = create_featured_proposals + proposals = [create(:proposal), create(:proposal), create(:proposal)] + + visit proposals_path + + click_button 'View mode' + + click_link 'List' + + proposals.each do |proposal| + within('#proposals') do + expect(page).to have_link proposal.title + expect(page).to_not have_content proposal.summary + end + end + + click_button 'View mode' + + click_link 'Cards' + + proposals.each do |proposal| + within('#proposals') do + expect(page).to have_link proposal.title + expect(page).to have_content proposal.summary + end + end + end + scenario 'Pagination' do per_page = Kaminari.config.default_per_page (per_page + 5).times { create(:proposal) }