Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update proposals advanced search #2133

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,9 @@ GEM
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2020.0512)
mimemagic (0.3.5)
mimemagic (0.3.10)
nokogiri (~> 1)
rake
mini_mime (1.0.2)
mini_portile2 (2.4.0)
minitest (5.14.1)
Expand Down
13 changes: 13 additions & 0 deletions app/assets/stylesheets/custom/_proposals.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.proposal {
ul.geozone, ul.tags {
display: inline-block;

li {
display: inline-block;
}
}

ul.geozone a {
font-size: 0.75rem;
}
}
4 changes: 4 additions & 0 deletions app/helpers/proposals_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,8 @@ def show_featured_proposals?
def show_recommended_proposals?
params[:selected].blank? && feature?("user.recommendations") && @recommended_proposals.present?
end

def advanced_search_geozone_options
options_for_select(geozone_select_options, params[:advanced_search]&.dig(:geozone_id))
end
end
6 changes: 0 additions & 6 deletions app/helpers/search_helper.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
module SearchHelper

def official_level_search_options
options_for_select((1..5).map{ |i| [setting["official_level_#{i}_name"], i] },
params[:advanced_search].try(:[], :official_level))
end

def date_range_options
options_for_select([
[t("shared.advanced_search.date_1"), 1],
Expand Down
3 changes: 1 addition & 2 deletions app/models/concerns/filterable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Filterable
extend ActiveSupport::Concern

included do
scope :by_official_level, ->(official_level) { where(users: { official_level: official_level }).joins(:author) }
scope :by_date_range, ->(date_range) { where(created_at: date_range) }
end

Expand All @@ -20,7 +19,7 @@ def filter_by(params)

def allowed_filter?(filter, value)
return if value.blank?
["official_level", "date_range"].include?(filter)
["date_range"].include?(filter)
end

end
Expand Down
19 changes: 19 additions & 0 deletions app/models/custom/proposal.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require_dependency Rails.root.join("app", "models", "proposal").to_s

Proposal.class_eval do
scope :by_geozone_id, ->(geozone_id) { where(geozone_id: geozone_id) }
scope :sort_by_oldest, -> { reorder(:created_at) }

class << self
alias_method :consul_proposals_orders, :proposals_orders

def allowed_filter?(filter, value)
return if value.blank?
%w[date_range geozone_id].include?(filter)
end

def proposals_orders(user)
consul_proposals_orders(user) << "oldest"
end
end
end
5 changes: 3 additions & 2 deletions app/views/custom/proposals/_proposal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
<p><%= proposal.summary %></p>
<div class="truncate"></div>
</div>
<%= render "shared/tags", taggable: proposal, limit: 5 %>
<%= render "shared/geozone", geozonable: proposal %>
<%= render "shared/tags", taggable: proposal, limit: 4 %>
<% end %>
</div>
</div>
Expand Down Expand Up @@ -97,4 +98,4 @@
</div>
</div>
</div>
<%end%>
<%end%>
5 changes: 5 additions & 0 deletions app/views/custom/shared/_geozone.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<ul class="no-bullet geozone">
<li>
<%= link_to geozone_name(geozonable), proposals_path("advanced_search[geozone_id]": geozonable.geozone_id) %>
</li>
</ul>
13 changes: 7 additions & 6 deletions app/views/shared/_advanced_search.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
placeholder: t("shared.advanced_search.general_placeholder") %>
</div>

<div class="small-12 large-3 column">
<label for="advanced_search_official_level"><%= t("shared.advanced_search.author_type") %></label>
<%= select_tag("advanced_search[official_level]", official_level_search_options,
include_blank: t("shared.advanced_search.author_type_blank")) %>
</div>

<div class="small-12 large-9">
<div class="small-12 large-4 column">
<label for="js-advanced-search-date-min"><%= t("shared.advanced_search.date") %></label>
Expand Down Expand Up @@ -54,6 +48,13 @@
</div>
</div>

<% if controller_name == "proposals" %>
<div class="small-12 large-3 column">
<label for="advanced_search_geozone_id"><%= t("proposals.form.geozone") %></label>
<%= select_tag("advanced_search[geozone_id]", advanced_search_geozone_options, include_blank: t("geozones.none")) %>
</div>
<% end %>

<div class="small-12 medium-3 column end clear">
<%= submit_tag t("shared.advanced_search.search"), class: "button expanded" %>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/views/shared/_map.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<% @geozones.each do |geozone| %>
<%unless geozone.name == "Toda la ciudad"%>
<%if params[:type].blank? %>
<li><%= link_to geozone.name, proposals_path(geozone: geozone.id) %></li>
<li><%= link_to geozone.name, proposals_path("advanced_search[geozone_id]": geozone.id) %></li>
<% else %>
<li><%= link_to geozone.name, "#{legislation_process_proposals_path(process_id: params[:process_id],search: geozone.name, type: params[:type], map: true)}#filter-subnav" %></li>
<%end%>
Expand All @@ -28,7 +28,7 @@
<% @geozones.each do |geozone| %>
<area shape="poly"
coords="<%= geozone.html_map_coordinates %>"
href="<%= params[:type].blank? ? proposals_path(geozone: geozone.id) : "#{legislation_process_proposals_path(process_id: params[:process_id],search: geozone.name, type: params[:type], map: true)}#filter-subnav" %>"
href="<%= params[:type].blank? ? proposals_path("advanced_search[geozone_id]": geozone.id) : "#{legislation_process_proposals_path(process_id: params[:process_id],search: geozone.name, type: params[:type], map: true)}#filter-subnav" %>"
title="<%= geozone.name %>"
alt="<%= geozone.name %>">
<% end %>
Expand Down
2 changes: 2 additions & 0 deletions config/locales/custom/en/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ en:
help_text_2: "To create a proposal, you must sign up on %{org}. The proposals that get the support of 1% of the users (persons over 16 years of age registered in Madrid; 27,064 people) in the web, goes to voting phase. To support proposals it is necessary to have a verified account."
help_text_3: "The City Council of Madrid celebrates a citizen vote when the proposals get the necessary supports. Once celebrated, if there are more people in favor than against, the City Council assumes the proposal and carries it out."
help_text_4: 'In February 2017 occurred the first citizen vote in which were approved the proposals "Madrid 100% sostenible" and "Billete único para el transporte público".'
orders:
oldest: Oldest first
form:
sub_proceeding: Human right
proposal_type: Proposal type
Expand Down
2 changes: 2 additions & 0 deletions config/locales/custom/es/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ es:
help_text_2: "Para crear una propuesta hay que registrarse en %{org}. Las propuestas que consigan el apoyo del 1% de la gente (personas mayores de 16 años empadronadas en Madrid; %{supports} apoyos) en la web, pasan a votación. Para apoyar propuestas es necesario tener una cuenta verificada."
help_text_3: "El Ayuntamiento de Madrid convoca una votación ciudadana cuando las propuestas consiguen los apoyos necesarios. Una vez celebrada, si hay más gente a favor que en contra, el Consistorio asume la propuesta y la lleva a cabo."
help_text_4: 'En febrero de 2017 tuvo lugar la primera votación ciudadana en la que se aprobaron las propuestas "Madrid 100% sostenible" y "Billete único para el transporte público".'
orders:
oldest: Más antiguas
form:
sub_proceeding: "Derecho"
proposal_type: Tipo de propuesta
Expand Down
2 changes: 0 additions & 2 deletions config/locales/en/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,6 @@ en:
"no": "No"
search_results: "Search results"
advanced_search:
author_type: 'By author category'
author_type_blank: 'Select a category'
date: 'By date'
date_placeholder: 'DD/MM/YYYY'
date_range_blank: 'Choose a date'
Expand Down
2 changes: 0 additions & 2 deletions config/locales/es/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,6 @@ es:
"no": "No"
search_results: "Resultados de la búsqueda"
advanced_search:
author_type: 'Por categoría de autor'
author_type_blank: 'Elige una categoría'
date: 'Por fecha'
date_placeholder: 'DD/MM/AAAA'
date_range_blank: 'Elige una fecha'
Expand Down
162 changes: 0 additions & 162 deletions spec/features/budgets/investments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -220,125 +220,6 @@
end
end

context "Search by author type" do

scenario "Public employee", :js do
ana = create :user, official_level: 1
john = create :user, official_level: 2

bdgt_invest1 = create(:budget_investment, heading: heading, author: ana)
bdgt_invest2 = create(:budget_investment, heading: heading, author: ana)
bdgt_invest3 = create(:budget_investment, heading: heading, author: john)

visit budget_investments_path(budget)

click_link "Advanced search"
select Setting["official_level_1_name"], from: "advanced_search_official_level"
click_button "Filter"

expect(page).to have_content("There are 2 investments")

within("#budget-investments") do
expect(page).to have_content(bdgt_invest1.title)
expect(page).to have_content(bdgt_invest2.title)
expect(page).not_to have_content(bdgt_invest3.title)
end
end

scenario "Municipal Organization", :js do
ana = create :user, official_level: 2
john = create :user, official_level: 3

bdgt_invest1 = create(:budget_investment, heading: heading, author: ana)
bdgt_invest2 = create(:budget_investment, heading: heading, author: ana)
bdgt_invest3 = create(:budget_investment, heading: heading, author: john)

visit budget_investments_path(budget)

click_link "Advanced search"
select Setting["official_level_2_name"], from: "advanced_search_official_level"
click_button "Filter"

expect(page).to have_content("There are 2 investments")

within("#budget-investments") do
expect(page).to have_content(bdgt_invest1.title)
expect(page).to have_content(bdgt_invest2.title)
expect(page).not_to have_content(bdgt_invest3.title)
end
end

scenario "General director", :js do
ana = create :user, official_level: 3
john = create :user, official_level: 4

bdgt_invest1 = create(:budget_investment, heading: heading, author: ana)
bdgt_invest2 = create(:budget_investment, heading: heading, author: ana)
bdgt_invest3 = create(:budget_investment, heading: heading, author: john)

visit budget_investments_path(budget)

click_link "Advanced search"
select Setting["official_level_3_name"], from: "advanced_search_official_level"
click_button "Filter"

expect(page).to have_content("There are 2 investments")

within("#budget-investments") do
expect(page).to have_content(bdgt_invest1.title)
expect(page).to have_content(bdgt_invest2.title)
expect(page).not_to have_content(bdgt_invest3.title)
end
end

scenario "City councillor", :js do
ana = create :user, official_level: 4
john = create :user, official_level: 5

bdgt_invest1 = create(:budget_investment, heading: heading, author: ana)
bdgt_invest2 = create(:budget_investment, heading: heading, author: ana)
bdgt_invest3 = create(:budget_investment, heading: heading, author: john)

visit budget_investments_path(budget)

click_link "Advanced search"
select Setting["official_level_4_name"], from: "advanced_search_official_level"
click_button "Filter"

expect(page).to have_content("There are 2 investments")

within("#budget-investments") do
expect(page).to have_content(bdgt_invest1.title)
expect(page).to have_content(bdgt_invest2.title)
expect(page).not_to have_content(bdgt_invest3.title)
end
end

scenario "Mayoress", :js do
ana = create :user, official_level: 5
john = create :user, official_level: 4

bdgt_invest1 = create(:budget_investment, heading: heading, author: ana)
bdgt_invest2 = create(:budget_investment, heading: heading, author: ana)
bdgt_invest3 = create(:budget_investment, heading: heading, author: john)

visit budget_investments_path(budget)

click_link "Advanced search"
select Setting["official_level_5_name"], from: "advanced_search_official_level"
click_button "Filter"

expect(page).to have_content("There are 2 investments")

within("#budget-investments") do
expect(page).to have_content(bdgt_invest1.title)
expect(page).to have_content(bdgt_invest2.title)
expect(page).not_to have_content(bdgt_invest3.title)
end
end

end

context "Search by date" do

context "Predefined date ranges" do
Expand Down Expand Up @@ -469,49 +350,6 @@
end
end

scenario "Search by multiple filters", :js do
ana = create :user, official_level: 1
john = create :user, official_level: 1

bdgt_invest1 = create(:budget_investment, heading: heading,title: "Get Schwifty", author: ana, created_at: 1.minute.ago)
bdgt_invest2 = create(:budget_investment, heading: heading,title: "Hello Schwifty", author: john, created_at: 2.days.ago)
bdgt_invest3 = create(:budget_investment, heading: heading,title: "Save the forest")

visit budget_investments_path(budget)

click_link "Advanced search"
fill_in "Write the text", with: "Schwifty"
select Setting["official_level_1_name"], from: "advanced_search_official_level"
select "Last 24 hours", from: "js-advanced-search-date-min"

click_button "Filter"

expect(page).to have_content("There is 1 investment")

within("#budget-investments") do
expect(page).to have_content(bdgt_invest1.title)
end
end

scenario "Maintain advanced search criteria", :js do
visit budget_investments_path(budget)
click_link "Advanced search"

fill_in "Write the text", with: "Schwifty"
select Setting["official_level_1_name"], from: "advanced_search_official_level"
select "Last 24 hours", from: "js-advanced-search-date-min"

click_button "Filter"

expect(page).to have_content("investments cannot be found")

within "#js-advanced-search" do
expect(page).to have_selector("input[name='search'][value='Schwifty']")
expect(page).to have_select("advanced_search[official_level]", selected: Setting["official_level_1_name"])
expect(page).to have_select("advanced_search[date_min]", selected: "Last 24 hours")
end
end

scenario "Maintain custom date search criteria", :js do
visit budget_investments_path(budget)
click_link "Advanced search"
Expand Down
Loading