diff --git a/app/assets/stylesheets/admin/poll/questions/filter.scss b/app/assets/stylesheets/admin/poll/questions/filter.scss deleted file mode 100644 index 498872d2b..000000000 --- a/app/assets/stylesheets/admin/poll/questions/filter.scss +++ /dev/null @@ -1,11 +0,0 @@ -.admin .poll-questions-filter { - $gap: 0.5em; - @include flex-with-gap($gap); - align-items: flex-end; - flex-wrap: wrap; - - [type="submit"] { - @include regular-button; - margin-left: $gap; - } -} diff --git a/app/components/admin/poll/questions/filter_component.html.erb b/app/components/admin/poll/questions/filter_component.html.erb deleted file mode 100644 index ee1f443ff..000000000 --- a/app/components/admin/poll/questions/filter_component.html.erb +++ /dev/null @@ -1,7 +0,0 @@ -<%= form_tag "", method: :get, class: "poll-questions-filter" do %> -
<%= proposal.title %>
diff --git a/app/components/admin/proposals/successful_component.rb b/app/components/admin/proposals/successful_component.rb
new file mode 100644
index 000000000..553485665
--- /dev/null
+++ b/app/components/admin/proposals/successful_component.rb
@@ -0,0 +1,12 @@
+class Admin::Proposals::SuccessfulComponent < ApplicationComponent
+ include Header
+ attr_reader :proposals
+
+ def initialize(proposals)
+ @proposals = proposals
+ end
+
+ def title
+ t("admin.questions.index.successful_proposals_tab")
+ end
+end
diff --git a/app/controllers/admin/poll/questions_controller.rb b/app/controllers/admin/poll/questions_controller.rb
index 3981f652b..19b659158 100644
--- a/app/controllers/admin/poll/questions_controller.rb
+++ b/app/controllers/admin/poll/questions_controller.rb
@@ -4,14 +4,7 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
load_and_authorize_resource :poll
load_resource class: "Poll::Question"
- authorize_resource except: [:new, :index]
-
- def index
- @polls = Poll.not_budget
- @questions = @questions.search(search_params).page(params[:page]).order("created_at DESC")
-
- @proposals = Proposal.successful.sort_by_confidence_score
- end
+ authorize_resource except: :new
def new
proposal = Proposal.find(params[:proposal_id]) if params[:proposal_id].present?
@@ -61,8 +54,4 @@ class Admin::Poll::QuestionsController < Admin::Poll::BaseController
attributes = [:poll_id, :question, :proposal_id, votation_type_attributes: [:vote_type, :max_votes]]
[*attributes, translation_params(Poll::Question)]
end
-
- def search_params
- params.permit(:poll_id, :search)
- end
end
diff --git a/app/controllers/admin/proposals_controller.rb b/app/controllers/admin/proposals_controller.rb
index 5e9e52b49..a0c2770d1 100644
--- a/app/controllers/admin/proposals_controller.rb
+++ b/app/controllers/admin/proposals_controller.rb
@@ -6,7 +6,11 @@ class Admin::ProposalsController < Admin::BaseController
has_orders %w[created_at]
- before_action :load_proposal, except: :index
+ before_action :load_proposal, except: [:index, :successful]
+
+ def successful
+ @proposals = Proposal.successful.sort_by_confidence_score
+ end
def show
end
diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb
index c55320560..f1015bba7 100644
--- a/app/models/poll/question.rb
+++ b/app/models/poll/question.rb
@@ -1,6 +1,5 @@
class Poll::Question < ApplicationRecord
include Measurable
- include Searchable
acts_as_paranoid column: :hidden_at
include ActsAsParanoidAliases
@@ -30,25 +29,9 @@ class Poll::Question < ApplicationRecord
delegate :multiple?, :vote_type, to: :votation_type, allow_nil: true
- scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) }
-
scope :sort_for_list, -> { order(Arel.sql("poll_questions.proposal_id IS NULL"), :created_at) }
scope :for_render, -> { includes(:author, :proposal) }
- def self.search(params)
- results = all
- results = results.by_poll_id(params[:poll_id]) if params[:poll_id].present?
- results = results.pg_search(params[:search]) if params[:search].present?
- results
- end
-
- def searchable_values
- { title => "A",
- proposal&.title => "A",
- author.username => "C",
- author_visible_name => "C" }
- end
-
def copy_attributes_from_proposal(proposal)
if proposal.present?
self.author = proposal.author
diff --git a/app/views/admin/poll/questions/_filter_subnav.html.erb b/app/views/admin/poll/questions/_filter_subnav.html.erb
deleted file mode 100644
index 7f641d390..000000000
--- a/app/views/admin/poll/questions/_filter_subnav.html.erb
+++ /dev/null
@@ -1,12 +0,0 @@
-
- <%= t("admin.questions.index.no_questions") %>
-
-<% else %>
-
<%= t("admin.questions.index.title") %>- -<%= link_to t("admin.questions.index.create"), new_admin_question_path, - class: "button float-right" %> - -<%= render "search" %> - -
- <%= render "filter_subnav" %>
-
-
diff --git a/app/views/admin/proposals/successful.html.erb b/app/views/admin/proposals/successful.html.erb
new file mode 100644
index 000000000..d3c3c9c62
--- /dev/null
+++ b/app/views/admin/proposals/successful.html.erb
@@ -0,0 +1 @@
+<%= render Admin::Proposals::SuccessfulComponent.new(@proposals) %>
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 0f4ae62ee..d842a34fa 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -1134,18 +1134,11 @@ en:
multiple_description: "Allows to choose multiple answers. It's possible to set the maximum number of answers."
questions:
index:
- title: "Questions"
create: "Create question"
- no_questions: "There are no questions."
- filter_poll: Filter by Poll
select_poll: Select Poll
- questions_tab: "Questions"
successful_proposals_tab: "Successful proposals"
create_question: "Create question"
table_proposal: "Proposal"
- table_question: "Question"
- table_poll: "Poll"
- poll_not_assigned: "Poll not assigned"
edit:
title: "Edit Question"
form:
diff --git a/config/locales/en/general.yml b/config/locales/en/general.yml
index d62b8a1f5..4ee75c137 100644
--- a/config/locales/en/general.yml
+++ b/config/locales/en/general.yml
@@ -569,7 +569,6 @@ en:
support: "You just have to click on the button that you will see below 'Support this proposal' and you can inform yourself about before promoting it. Only the proposals that achieve the maximum support will be carried out by the City Council, and I thought that you, I'm sure you help me achieve it!"
share: "And if you also do me the great favor of sharing my proposal with your friends, family and contacts, it would be perfect!"
polls:
- all: "All"
dates: "From %{open_at} to %{closed_at}"
final_date: "Final recounts/Results"
index:
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index 41848b570..ffa0f58f4 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -1134,18 +1134,11 @@ es:
multiple_description: "Permite elegir más de una respuesta. Se puede elegir el número máximo de respuestas."
questions:
index:
- title: "Preguntas de votaciones"
create: "Crear pregunta ciudadana"
- no_questions: "No hay ninguna pregunta ciudadana."
- filter_poll: Filtrar por votación
select_poll: Seleccionar votación
- questions_tab: "Preguntas"
successful_proposals_tab: "Propuestas que han superado el umbral"
create_question: "Crear pregunta para votación"
table_proposal: "Propuesta"
- table_question: "Pregunta"
- table_poll: "Votación"
- poll_not_assigned: "Votación no asignada"
edit:
title: "Editar pregunta ciudadana"
form:
diff --git a/config/locales/es/general.yml b/config/locales/es/general.yml
index ff88aca9c..458f437a8 100644
--- a/config/locales/es/general.yml
+++ b/config/locales/es/general.yml
@@ -569,7 +569,6 @@ es:
support: "Tan sólo tienes que hacer clic en el botón que verás a continuación 'Apoyar esta propuesta' y directamente podrás informarte acerca de ella antes de impulsarla. Sólo las propuestas que consigan el máximo apoyo se llevarán a cabo por parte del Ayuntamiento, y he pensado que tú ¡seguro que me ayudas a lograrlo!"
share: "Y si además, me haces el gran favor de compartir mi propuesta con tus amigos, familiares y contactos ¡sería perfecto!"
polls:
- all: "Todas"
dates: "Desde el %{open_at} hasta el %{closed_at}"
final_date: "Recuento final/Resultados"
index:
diff --git a/config/routes/admin.rb b/config/routes/admin.rb
index e0eec7867..7407e6736 100644
--- a/config/routes/admin.rb
+++ b/config/routes/admin.rb
@@ -45,6 +45,10 @@ namespace :admin do
resources :debates, only: [:index, :show]
resources :proposals, only: [:index, :show, :update] do
+ collection do
+ get :successful
+ end
+
member do
patch :select
patch :deselect
@@ -192,7 +196,7 @@ namespace :admin do
end
end
- resources :questions, shallow: true do
+ resources :questions, except: :index, shallow: true do
resources :options, except: [:index, :show], controller: "questions/options", shallow: false
resources :options, only: [], controller: "questions/options" do
resources :images, controller: "questions/options/images"
diff --git a/spec/components/admin/poll/questions/filter_component_spec.rb b/spec/components/admin/poll/questions/filter_component_spec.rb
deleted file mode 100644
index 3da7270ad..000000000
--- a/spec/components/admin/poll/questions/filter_component_spec.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-require "rails_helper"
-
-describe Admin::Poll::Questions::FilterComponent do
- it "renders a button to submit the form" do
- render_inline Admin::Poll::Questions::FilterComponent.new([])
-
- expect(page).to have_button "Filter"
- end
-end
diff --git a/spec/components/admin/proposals/index_component_spec.rb b/spec/components/admin/proposals/index_component_spec.rb
new file mode 100644
index 000000000..e1620e76c
--- /dev/null
+++ b/spec/components/admin/proposals/index_component_spec.rb
@@ -0,0 +1,35 @@
+require "rails_helper"
+
+describe Admin::Proposals::IndexComponent, controller: Admin::ProposalsController do
+ around do |example|
+ with_request_url(Rails.application.routes.url_helpers.admin_proposals_path) { example.run }
+ end
+
+ describe "#successful_proposals_link" do
+ it "is shown when there are successful proposals" do
+ create(:proposal, :successful)
+
+ render_inline Admin::Proposals::IndexComponent.new(Proposal.page(1))
+
+ expect(page).to have_link "Successful proposals"
+ end
+
+ it "is not shown when there aren't any successful proposals" do
+ create(:proposal)
+
+ render_inline Admin::Proposals::IndexComponent.new(Proposal.page(1))
+
+ expect(page).not_to have_link "Successful proposals"
+ end
+
+ it "is shown when there are successful proposals on a previous page" do
+ allow(Proposal).to receive(:default_per_page).and_return(1)
+ create(:proposal, :successful)
+ create(:proposal)
+
+ render_inline Admin::Proposals::IndexComponent.new(Proposal.order(:id).page(2))
+
+ expect(page).to have_link "Successful proposals"
+ end
+ end
+end
diff --git a/spec/system/admin/poll/questions_spec.rb b/spec/system/admin/poll/questions_spec.rb
index b71f92db5..127dca219 100644
--- a/spec/system/admin/poll/questions_spec.rb
+++ b/spec/system/admin/poll/questions_spec.rb
@@ -118,10 +118,9 @@ describe "Admin poll questions", :admin do
create(:poll, :future, name: "Proposals")
proposal = create(:proposal, :successful)
- visit admin_proposal_path(proposal)
-
- expect(page).to have_content("This proposal has reached the required supports")
- click_link "Add this proposal to a poll to be voted"
+ visit admin_proposals_path
+ click_link "Successful proposals"
+ click_link "Create question"
expect(page).to have_current_path(new_admin_question_path, ignore_query: true)
expect(page).to have_field("Question", with: proposal.title)
@@ -130,11 +129,7 @@ describe "Admin poll questions", :admin do
click_button "Save"
- expect(page).to have_content(proposal.title)
-
- visit admin_questions_path
-
- expect(page).to have_content(proposal.title)
+ expect(page).to have_content proposal.title
end
scenario "Update" do
diff --git a/spec/system/budget_polls/questions_spec.rb b/spec/system/budget_polls/questions_spec.rb
deleted file mode 100644
index bc96e8e0c..000000000
--- a/spec/system/budget_polls/questions_spec.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require "rails_helper"
-
-describe "Poll Questions", :admin do
- scenario "Do not display polls associated to a budget" do
- create(:poll, name: "Citizen Proposal Poll")
- create(:poll, :for_budget, name: "Participatory Budget Poll")
-
- visit admin_questions_path
-
- expect(page).to have_select("poll_id", text: "Citizen Proposal Poll")
- expect(page).not_to have_select("poll_id", text: "Participatory Budget Poll")
- end
-end
- <%= render "questions" %>
-
-
-
- <%= render "successful_proposals" %>
-
- |