Remove skip map checkbox

This commit is contained in:
Melvin Lammerts
2020-04-12 21:35:28 +00:00
committed by taitus
parent 414eba83ec
commit c34aa54122
20 changed files with 5 additions and 101 deletions

View File

@@ -6,11 +6,6 @@
$("*[data-map]:visible").each(function() { $("*[data-map]:visible").each(function() {
App.Map.initializeMap(this); App.Map.initializeMap(this);
}); });
$(".js-toggle-map").on({
click: function() {
App.Map.toggleMap();
}
});
}, },
destroy: function() { destroy: function() {
App.Map.maps.forEach(function(map) { App.Map.maps.forEach(function(map) {
@@ -149,10 +144,6 @@
}); });
} }
}, },
toggleMap: function() {
$(".map").toggle();
$(".js-location-map-remove-marker").toggle();
},
cleanInvestmentCoordinates: function(element) { cleanInvestmentCoordinates: function(element) {
var clean_markers, markers; var clean_markers, markers;
markers = $(element).attr("data-marker-investments-coordinates"); markers = $(element).attr("data-marker-investments-coordinates");

View File

@@ -135,7 +135,7 @@ module Budgets
def investment_params def investment_params
attributes = [:heading_id, :tag_list, :organization_name, :location, attributes = [:heading_id, :tag_list, :organization_name, :location,
:terms_of_service, :skip_map, :related_sdg_list, :terms_of_service, :related_sdg_list,
image_attributes: image_attributes, image_attributes: image_attributes,
documents_attributes: document_attributes, documents_attributes: document_attributes,
map_location_attributes: map_location_attributes] map_location_attributes: map_location_attributes]

View File

@@ -60,7 +60,7 @@ class Management::Budgets::InvestmentsController < Management::BaseController
end end
def investment_params 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,
image_attributes: image_attributes, image_attributes: image_attributes,
documents_attributes: document_attributes, documents_attributes: document_attributes,
map_location_attributes: map_location_attributes] map_location_attributes: map_location_attributes]

View File

@@ -57,7 +57,7 @@ class Management::ProposalsController < Management::BaseController
def proposal_params def proposal_params
attributes = [:video_url, :responsible_name, :tag_list, attributes = [:video_url, :responsible_name, :tag_list,
:terms_of_service, :geozone_id, :terms_of_service, :geozone_id,
:skip_map, map_location_attributes: map_location_attributes] map_location_attributes: map_location_attributes]
params.require(:proposal).permit(attributes, translation_params(Proposal)) params.require(:proposal).permit(attributes, translation_params(Proposal))
end end

View File

@@ -101,7 +101,7 @@ class ProposalsController < ApplicationController
def proposal_params def proposal_params
attributes = [:video_url, :responsible_name, :tag_list, :terms_of_service, attributes = [:video_url, :responsible_name, :tag_list, :terms_of_service,
:geozone_id, :skip_map, :related_sdg_list, :geozone_id, :related_sdg_list,
image_attributes: image_attributes, image_attributes: image_attributes,
documents_attributes: document_attributes, documents_attributes: document_attributes,
map_location_attributes: map_location_attributes] map_location_attributes: map_location_attributes]

View File

@@ -2,28 +2,11 @@ module Mappable
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
attr_accessor :skip_map
has_one :map_location, dependent: :destroy has_one :map_location, dependent: :destroy
accepts_nested_attributes_for :map_location, allow_destroy: true, reject_if: :all_blank 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? def feature_maps?
Setting["feature.map"].present? Setting["feature.map"].present?
end end
def skip_map?
skip_map == "1"
end
end end
end end

View File

@@ -16,10 +16,4 @@
<%= m_l_fields.hidden_field :zoom, <%= m_l_fields.hidden_field :zoom,
value: map_location.zoom, value: map_location.zoom,
id: map_location_input_id(parent_class, "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 %> <% end %>

View File

@@ -536,10 +536,6 @@ en:
attributes: attributes:
segment_recipient: segment_recipient:
invalid: "The user recipients segment is invalid" 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: poll/voter:
attributes: attributes:
document_number: document_number:

View File

@@ -85,7 +85,6 @@ en:
map_location: "Map location" map_location: "Map location"
map_location_instructions: "Navigate the map to the location and place the marker." map_location_instructions: "Navigate the map to the location and place the marker."
map_remove_marker: "Remove map 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: index:
title: Participatory budgeting title: Participatory budgeting
unfeasible: Unfeasible investment projects unfeasible: Unfeasible investment projects

View File

@@ -347,7 +347,6 @@ en:
map_location: "Map location" map_location: "Map location"
map_location_instructions: "Navigate the map to the location and place the marker." map_location_instructions: "Navigate the map to the location and place the marker."
map_remove_marker: "Remove map 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: index:
featured_proposals: Featured featured_proposals: Featured
orders: orders:

View File

@@ -536,10 +536,6 @@ es:
attributes: attributes:
segment_recipient: segment_recipient:
invalid: "El usuario del destinatario es inválido" 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: poll/voter:
attributes: attributes:
document_number: document_number:

View File

@@ -85,7 +85,6 @@ es:
map_location: "Ubicación en el mapa" map_location: "Ubicación en el mapa"
map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador." map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador."
map_remove_marker: "Eliminar el marcador" map_remove_marker: "Eliminar el marcador"
map_skip_checkbox: "Este proyecto no tiene una ubicación concreta o no la conozco."
index: index:
title: Presupuestos participativos title: Presupuestos participativos
unfeasible: Proyectos de gasto no viables unfeasible: Proyectos de gasto no viables

View File

@@ -347,7 +347,6 @@ es:
map_location: "Ubicación en el mapa" map_location: "Ubicación en el mapa"
map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador." map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador."
map_remove_marker: "Eliminar el marcador" map_remove_marker: "Eliminar el marcador"
map_skip_checkbox: "Esta propuesta no tiene una ubicación concreta o no la conozco."
index: index:
featured_proposals: Destacadas featured_proposals: Destacadas
orders: orders:

View File

@@ -140,7 +140,6 @@ section "Creating Investments" do
valuation_finished: [false, true].sample, valuation_finished: [false, true].sample,
tag_list: tags.sample(3).join(","), tag_list: tags.sample(3).join(","),
price: rand(1..100) * 100000, price: rand(1..100) * 100000,
skip_map: "1",
terms_of_service: "1" terms_of_service: "1"
}.merge(translation_attributes)) }.merge(translation_attributes))
@@ -187,7 +186,6 @@ section "Winner Investments" do
valuation_finished: true, valuation_finished: true,
selected: true, selected: true,
price: rand(10000..heading.price), price: rand(10000..heading.price),
skip_map: "1",
terms_of_service: "1" terms_of_service: "1"
) )
add_image_to(investment) if Random.rand > 0.3 add_image_to(investment) if Random.rand > 0.3

View File

@@ -37,7 +37,6 @@ section "Creating Proposals" do
created_at: rand((Time.current - 1.week)..Time.current), created_at: rand((Time.current - 1.week)..Time.current),
tag_list: tags.sample(3).join(","), tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample, geozone: Geozone.all.sample,
skip_map: "1",
terms_of_service: "1", terms_of_service: "1",
published_at: Time.current) published_at: Time.current)
random_locales.map do |locale| random_locales.map do |locale|
@@ -65,7 +64,6 @@ section "Creating Archived Proposals" do
description: description, description: description,
tag_list: tags.sample(3).join(","), tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample, geozone: Geozone.all.sample,
skip_map: "1",
terms_of_service: "1", terms_of_service: "1",
created_at: months_to_archive_proposals.to_i.months.ago, created_at: months_to_archive_proposals.to_i.months.ago,
published_at: months_to_archive_proposals.to_i.months.ago) published_at: months_to_archive_proposals.to_i.months.ago)
@@ -94,7 +92,6 @@ section "Creating Successful Proposals" do
created_at: rand((Time.current - 1.week)..Time.current), created_at: rand((Time.current - 1.week)..Time.current),
tag_list: tags.sample(3).join(","), tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample, geozone: Geozone.all.sample,
skip_map: "1",
terms_of_service: "1", terms_of_service: "1",
cached_votes_up: Setting["votes_for_proposal_success"], cached_votes_up: Setting["votes_for_proposal_success"],
published_at: Time.current) published_at: Time.current)
@@ -121,7 +118,6 @@ section "Creating Successful Proposals" do
created_at: rand((Time.current - 1.week)..Time.current), created_at: rand((Time.current - 1.week)..Time.current),
tag_list: tags.sample(3).join(","), tag_list: tags.sample(3).join(","),
geozone: Geozone.all.sample, geozone: Geozone.all.sample,
skip_map: "1",
terms_of_service: "1", terms_of_service: "1",
published_at: Time.current) published_at: Time.current)
random_locales.map do |locale| random_locales.map do |locale|

View File

@@ -398,7 +398,6 @@ namespace :proposal_actions do
created_at: Time.current - expected_supports.length.days, created_at: Time.current - expected_supports.length.days,
tag_list: "Example", tag_list: "Example",
geozone: Geozone.all.sample, geozone: Geozone.all.sample,
skip_map: "1",
terms_of_service: "1", terms_of_service: "1",
published_at: Time.current - expected_supports.length.days) published_at: Time.current - expected_supports.length.days)

View File

@@ -105,7 +105,6 @@ FactoryBot.define do
description { "Spend money on this" } description { "Spend money on this" }
price { 10 } price { 10 }
unfeasibility_explanation { "" } unfeasibility_explanation { "" }
skip_map { "1" }
terms_of_service { "1" } terms_of_service { "1" }
incompatible { false } incompatible { false }

View File

@@ -6,7 +6,6 @@ FactoryBot.define do
video_url { "https://youtu.be/nhuNb0XtRhQ" } video_url { "https://youtu.be/nhuNb0XtRhQ" }
responsible_name { "John Snow" } responsible_name { "John Snow" }
terms_of_service { "1" } terms_of_service { "1" }
skip_map { "1" }
published_at { Time.current } published_at { Time.current }
association :author, factory: :user association :author, factory: :user

View File

@@ -8,13 +8,11 @@ shared_examples "map validations" do
it "is valid with a map location" do it "is valid with a map location" do
mappable.map_location = build(:map_location) mappable.map_location = build(:map_location)
mappable.skip_map = nil
expect(mappable).to be_valid expect(mappable).to be_valid
end end
it "is valid accepting that the mappable has no map" do it "is valid without a location" do
mappable.skip_map = "1"
mappable.map_location = nil mappable.map_location = nil
expect(mappable).to be_valid expect(mappable).to be_valid
@@ -24,23 +22,9 @@ shared_examples "map validations" do
Setting["feature.map"] = nil Setting["feature.map"] = nil
mappable.map_location = nil mappable.map_location = nil
mappable.skip_map = nil
expect(mappable).to be_valid expect(mappable).to be_valid
end 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 end
describe "cache" do describe "cache" do

View File

@@ -54,7 +54,6 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
send("fill_in_#{mappable_factory_name}_form") send("fill_in_#{mappable_factory_name}_form")
expect(page).to have_css ".map_location" expect(page).to have_css ".map_location"
check "#{mappable_factory_name}_skip_map"
send("submit_#{mappable_factory_name}_form") send("submit_#{mappable_factory_name}_form")
expect(page).not_to have_css(".map_location") expect(page).not_to have_css(".map_location")
@@ -72,15 +71,6 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
expect(page).not_to have_css(".map_location") expect(page).not_to have_css(".map_location")
end 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 describe "When restoring the page from browser history" do
before { Setting["org_name"] = "CONSUL" } before { Setting["org_name"] = "CONSUL" }
@@ -177,26 +167,10 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
visit send(mappable_new_path, arguments) visit send(mappable_new_path, arguments)
send("fill_in_#{mappable_factory_name}_form") send("fill_in_#{mappable_factory_name}_form")
check "#{mappable_factory_name}_skip_map"
send("submit_#{mappable_factory_name}_form") send("submit_#{mappable_factory_name}_form")
expect(page).not_to have_content "Map location can't be blank" expect(page).not_to have_content "Map location can't be blank"
end end
scenario "Toggle map" 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 end
describe "At #{mappable_edit_path}" do describe "At #{mappable_edit_path}" do
@@ -242,7 +216,6 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
visit send(mappable_edit_path, id: mappable.id) visit send(mappable_edit_path, id: mappable.id)
click_link "Remove map marker" click_link "Remove map marker"
check "#{mappable_factory_name}_skip_map"
click_on "Save changes" click_on "Save changes"
expect(page).not_to have_css(".map_location") expect(page).not_to have_css(".map_location")