Skip to content

Commit

Permalink
Remove skip map checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
melvinsh authored and taitus committed Dec 2, 2020
1 parent 05620c3 commit f4c9fa6
Show file tree
Hide file tree
Showing 20 changed files with 6 additions and 101 deletions.
9 changes: 0 additions & 9 deletions app/assets/javascripts/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
$("*[data-map]:visible").each(function() {
App.Map.initializeMap(this);
});
$(".js-toggle-map").on({
click: function() {
App.Map.toggleMap();
}
});
},
destroy: function() {
App.Map.maps.forEach(function(map) {
Expand Down Expand Up @@ -149,10 +144,6 @@
});
}
},
toggleMap: function() {
$(".map").toggle();
$(".js-location-map-remove-marker").toggle();
},
cleanInvestmentCoordinates: function(element) {
var clean_markers, markers;
markers = $(element).attr("data-marker-investments-coordinates");
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/budgets/investments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def load_investment_votes(investments)

def investment_params
attributes = [:heading_id, :tag_list,
:organization_name, :location, :terms_of_service, :skip_map,
:organization_name, :location, :terms_of_service,
image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
map_location_attributes: [:latitude, :longitude, :zoom]]
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/management/budgets/investments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def load_investment_votes(investments)
end

def investment_params
attributes = [:external_url, :heading_id, :tag_list, :organization_name, :location, :skip_map]
attributes = [:external_url, :heading_id, :tag_list, :organization_name, :location,
map_location_attributes: [:latitude, :longitude, :zoom]]
params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment))
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/management/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def set_proposal
def proposal_params
attributes = [:video_url, :responsible_name, :tag_list,
:terms_of_service, :geozone_id,
:skip_map, map_location_attributes: [:latitude, :longitude, :zoom]]
map_location_attributes: [:latitude, :longitude, :zoom]]
params.require(:proposal).permit(attributes, translation_params(Proposal))
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/proposals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def publish

def proposal_params
attributes = [:video_url, :responsible_name, :tag_list,
:terms_of_service, :geozone_id, :skip_map,
:terms_of_service, :geozone_id,
image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, :cached_attachment,
:user_id, :_destroy],
Expand Down
17 changes: 0 additions & 17 deletions app/models/concerns/mappable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,11 @@ module Mappable
extend ActiveSupport::Concern

included do
attr_accessor :skip_map

has_one :map_location, dependent: :destroy
accepts_nested_attributes_for :map_location, allow_destroy: true, reject_if: :all_blank

validate :map_must_be_valid, on: :create, if: :feature_maps?

def map_must_be_valid
return true if skip_map?

unless map_location&.available?
skip_map_error = I18n.t("activerecord.errors.models.map_location.attributes.map.invalid")
errors.add(:skip_map, skip_map_error)
end
end

def feature_maps?
Setting["feature.map"].present?
end

def skip_map?
skip_map == "1"
end
end
end
6 changes: 0 additions & 6 deletions app/views/map_locations/_form_fields.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,4 @@
<%= m_l_fields.hidden_field :zoom,
value: map_location.zoom,
id: map_location_input_id(parent_class, "zoom") %>

<div>
<%= form.check_box :skip_map,
label: t("#{i18n_namespace}.form.map_skip_checkbox"),
class: "js-toggle-map" %>
</div>
<% end %>
4 changes: 0 additions & 4 deletions config/locales/en/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,6 @@ en:
attributes:
segment_recipient:
invalid: "The user recipients segment is invalid"
map_location:
attributes:
map:
invalid: Map location can't be blank. Place a marker or select the checkbox if geolocalization is not needed
poll/voter:
attributes:
document_number:
Expand Down
1 change: 0 additions & 1 deletion config/locales/en/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ en:
map_location: "Map location"
map_location_instructions: "Navigate the map to the location and place the marker."
map_remove_marker: "Remove map marker"
map_skip_checkbox: "This investment doesn't have a concrete location or I'm not aware of it."
index:
title: Participatory budgeting
unfeasible: Unfeasible investment projects
Expand Down
1 change: 0 additions & 1 deletion config/locales/en/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ en:
map_location: "Map location"
map_location_instructions: "Navigate the map to the location and place the marker."
map_remove_marker: "Remove map marker"
map_skip_checkbox: "This proposal doesn't have a concrete location or I'm not aware of it."
index:
featured_proposals: Featured
orders:
Expand Down
4 changes: 0 additions & 4 deletions config/locales/es/activerecord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -507,10 +507,6 @@ es:
attributes:
segment_recipient:
invalid: "El usuario del destinatario es inválido"
map_location:
attributes:
map:
invalid: El mapa no puede estar en blanco. Añade un punto al mapa o marca la casilla si no hace falta un mapa.
poll/voter:
attributes:
document_number:
Expand Down
1 change: 0 additions & 1 deletion config/locales/es/budgets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ es:
map_location: "Ubicación en el mapa"
map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador."
map_remove_marker: "Eliminar el marcador"
map_skip_checkbox: "Este proyecto no tiene una ubicación concreta o no la conozco."
index:
title: Presupuestos participativos
unfeasible: Proyectos de gasto no viables
Expand Down
1 change: 0 additions & 1 deletion config/locales/es/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ es:
map_location: "Ubicación en el mapa"
map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador."
map_remove_marker: "Eliminar el marcador"
map_skip_checkbox: "Esta propuesta no tiene una ubicación concreta o no la conozco."
index:
featured_proposals: Destacadas
orders:
Expand Down
2 changes: 0 additions & 2 deletions db/dev_seeds/budgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ def add_image_to(imageable)
valuation_finished: [false, true].sample,
tag_list: tags.sample(3).join(","),
price: rand(1..100) * 100000,
skip_map: "1",
terms_of_service: "1"
}.merge(translation_attributes))

Expand Down Expand Up @@ -185,7 +184,6 @@ def add_image_to(imageable)
valuation_finished: true,
selected: true,
price: rand(10000..heading.price),
skip_map: "1",
terms_of_service: "1"
)
add_image_to(investment) if Random.rand > 0.3
Expand Down
4 changes: 0 additions & 4 deletions db/dev_seeds/proposals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def add_image_to(imageable)
created_at: rand((Time.current - 1.week)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
skip_map: "1",
terms_of_service: "1",
published_at: Time.current)
random_locales.map do |locale|
Expand Down Expand Up @@ -65,7 +64,6 @@ def add_image_to(imageable)
description: description,
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
skip_map: "1",
terms_of_service: "1",
created_at: months_to_archive_proposals.to_i.months.ago,
published_at: months_to_archive_proposals.to_i.months.ago)
Expand Down Expand Up @@ -94,7 +92,6 @@ def add_image_to(imageable)
created_at: rand((Time.current - 1.week)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
skip_map: "1",
terms_of_service: "1",
cached_votes_up: Setting["votes_for_proposal_success"],
published_at: Time.current)
Expand All @@ -121,7 +118,6 @@ def add_image_to(imageable)
created_at: rand((Time.current - 1.week)..Time.current),
tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample,
skip_map: "1",
terms_of_service: "1",
published_at: Time.current)
random_locales.map do |locale|
Expand Down
1 change: 0 additions & 1 deletion lib/tasks/proposal_actions.rake
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ namespace :proposal_actions do
created_at: Time.current - expected_supports.length.days,
tag_list: "Example",
geozone: Geozone.all.sample,
skip_map: "1",
terms_of_service: "1",
published_at: Time.current - expected_supports.length.days)

Expand Down
1 change: 0 additions & 1 deletion spec/factories/budgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
description { "Spend money on this" }
price { 10 }
unfeasibility_explanation { "" }
skip_map { "1" }
terms_of_service { "1" }
incompatible { false }

Expand Down
1 change: 0 additions & 1 deletion spec/factories/proposals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
video_url { "https://youtu.be/nhuNb0XtRhQ" }
responsible_name { "John Snow" }
terms_of_service { "1" }
skip_map { "1" }
published_at { Time.current }

association :author, factory: :user
Expand Down
18 changes: 1 addition & 17 deletions spec/shared/models/map_validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@

it "is valid with a map location" do
mappable.map_location = build(:map_location)
mappable.skip_map = nil

expect(mappable).to be_valid
end

it "is valid accepting that the mappable has no map" do
mappable.skip_map = "1"
it "is valid without a location" do
mappable.map_location = nil

expect(mappable).to be_valid
Expand All @@ -24,23 +22,9 @@
Setting["feature.map"] = nil

mappable.map_location = nil
mappable.skip_map = nil

expect(mappable).to be_valid
end

it "is not valid without a map location" do
mappable.map_location = nil
mappable.skip_map = nil

expect(mappable).not_to be_valid
end

it "is not valid without accepting that the mappable has no map" do
mappable.skip_map = nil

expect(mappable).not_to be_valid
end
end

describe "cache" do
Expand Down
27 changes: 0 additions & 27 deletions spec/shared/system/mappable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@

send("fill_in_#{mappable_factory_name}_form")
expect(page).to have_css ".map_location"
check "#{mappable_factory_name}_skip_map"
send("submit_#{mappable_factory_name}_form")

expect(page).not_to have_css(".map_location")
Expand All @@ -70,15 +69,6 @@
expect(page).not_to have_css(".map_location")
end

scenario "Errors on create" do
do_login_for user
visit send(mappable_new_path, arguments)

send("submit_#{mappable_factory_name}_form")

expect(page).to have_content "Map location can't be blank"
end

describe "When restoring the page from browser history" do
scenario "map should not be duplicated", :js do
do_login_for user
Expand Down Expand Up @@ -173,26 +163,10 @@
visit send(mappable_new_path, arguments)

send("fill_in_#{mappable_factory_name}_form")
check "#{mappable_factory_name}_skip_map"
send("submit_#{mappable_factory_name}_form")

expect(page).not_to have_content "Map location can't be blank"
end

scenario "Toggle map", :js do
do_login_for user
visit send(mappable_new_path, arguments)

check "#{mappable_factory_name}_skip_map"

expect(page).not_to have_css(".map")
expect(page).not_to have_content("Remove map marker")

uncheck "#{mappable_factory_name}_skip_map"

expect(page).to have_css(".map")
expect(page).to have_content("Remove map marker")
end
end

describe "At #{mappable_edit_path}" do
Expand Down Expand Up @@ -238,7 +212,6 @@

visit send(mappable_edit_path, id: mappable.id)
click_link "Remove map marker"
check "#{mappable_factory_name}_skip_map"
click_on "Save changes"

expect(page).not_to have_css(".map_location")
Expand Down

0 comments on commit f4c9fa6

Please sign in to comment.