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

Add default location to /post #6957

Merged
merged 9 commits into from
Jan 6, 2020
Merged
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
11 changes: 11 additions & 0 deletions app/controllers/editor_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,17 @@ def rich
x.include? "zoom:" and (@zoom = x.split(':')[1])
end
end

# if user has a location, set the @lat and @lon
if @lat.nil? && @lon.nil? && current_user&.has_power_tag("lat") && current_user&.has_power_tag("lon")
@lat = current_user.get_value_of_power_tag("lat").to_f
@lon = current_user.get_value_of_power_tag("lon").to_f
@map_blurred = current_user.has_tag('location:blurred')
if @zoom.nil? && current_user&.has_power_tag("zoom")
@zoom = current_user.get_value_of_power_tag("zoom")
end
end

template if params[:n] && !params[:body] # use another node body as a template
image if params[:i]
end
Expand Down
43 changes: 42 additions & 1 deletion app/views/editor/rich.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@
#coord_button {
text-decoration: underline;
}

button i.fa-map-marker {
color: #c40;
}
button:hover i.fa-map-marker {
color: inherit;
}
</style>

<div class="pl-editor">
Expand Down Expand Up @@ -136,6 +143,8 @@
class="leaflet-map"
style="width: 100% ; height: 300px; margin-bottom:8px;">
</div>


</div>

<div class="col-lg-6">
Expand Down Expand Up @@ -208,7 +217,6 @@
</div>
<!-- Map Module end -->


<!-- body module -->
<div class="ple-module-body ple-module row">

Expand Down Expand Up @@ -420,12 +428,44 @@
new L.LatLng(-90, 180)
);
editor.mapModule.blurredLocation.map.setMaxBounds(bounds);

<% if @lat and @lon %>
<% if @zoom %>
editor.mapModule.blurredLocation.setZoom(<%= @zoom %>);
<% else %>
let zoom = editor.mapModule.blurredLocation.getZoomFromCoordinates(<%= @lat %>, <%= @lon %>);
addTag('zoom:'+zoom, '/profile/tags/create/<%= current_user.uid %>');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we are explicitly adding tag here?
Pl.editor will automatically add zoom tag, right?
Moreover if user changes zoom level, we will have 2 zoom tags? One from here and other from PL.editor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only calculates zoom in the instances that the user has a lat and lon in their profile but no zoom level saved. So it calculates a zoom and saves it to their profile using the addTag javascript function (I worked on that a few weeks ago). It does not add the tag into the map, just to their profile. :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh i see, the name is misleading. Very cool place to put this though :)

editor.mapModule.blurredLocation.setZoom(zoom);
<% end %>
<% end %>

$('#coord_button').click((event) => {
event.preventDefault();
$('#coord_input').toggle();
});
$("#coord_input").hide();

$(function() {
var target = document.querySelector('#map_content');
var observer = new MutationObserver(function(mutations) {
setLocationButtonText();
});
observer.observe(target, {
attributes: true
});
});

function setLocationButtonText() {
if ($('#map_content').is(':hidden')) {
$('#location_button').html('<i class="fa fa-map-marker" aria-hidden="true"></i> Add a location');
} else {
$('#location_button').html('<i class="fa fa-trash"></i> Remove location');
}
}
setLocationButtonText();

$("#obscureLocation").prop('checked', <%= @map_blurred %>);
editor.mapModule.blurredLocation.setBlurred(<%= @map_blurred %>);

// upload via posting "posted_main_image"
function dataURItoBlob(dataURI) {
Expand Down Expand Up @@ -472,3 +512,4 @@
}

</script>

21 changes: 13 additions & 8 deletions app/views/locations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,19 @@

blurredLocation.map.setMaxBounds(bounds);

var changeZoom = function() {
var zoom = slider.getValue();
blurredLocation.map.setZoom(zoom);
}

var slider = $('#ex1').slider()
.on('slide', changeZoom)
.data('slider');
var changeZoom = function() {
var zoom = slider.getValue();
blurredLocation.map.setZoom(zoom);
}

var slider = $('#ex1').slider()
.on('slide', changeZoom)
.data('slider');

blurredLocation.map.on('zoomend', function() {
let zoom = blurredLocation.map.getZoom();
$('#ex1').slider('setValue', zoom);
})

})();

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@
"jquery-validation": "^1.19.1",
"jsdiff": "components/jsdiff#~3.4.0",
"junction": "theleagueof/junction#*",
"urlhash": "^0.1.3",
"leaflet": "^1.6.0",
"leaflet-environmental-layers": "^2.0.6",
"leaflet-blurred-location": "^1.5.1",
"leaflet-environmental-layers": "^2.0.6",
"leaflet-hash": "^0.2.1",
"leaflet-spin": "1.1.0",
"leaflet.fullscreen": "1.6.0",
Expand All @@ -58,6 +57,7 @@
"simple-data-grapher": "^2.0.0",
"typeahead.js": "^0.11.1",
"typeahead.js-browserify": "Javier-Rotelli/typeahead.js-browserify#~1.0.7",
"urlhash": "^0.1.3",
"woofmark": "~4.2.0"
},
"devDependencies": {},
Expand Down
Loading