-
Notifications
You must be signed in to change notification settings - Fork 214
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
Remove gmaps4rails gem [fixes #134262481] #397
Remove gmaps4rails gem [fixes #134262481] #397
Conversation
#map_canvas { | ||
height: 400px; | ||
width: 100%; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule declaration should be followed by an empty line
@@ -1,5 +1,9 @@ | |||
@import "utils/colors"; | |||
|
|||
#map_canvas { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using id selectors
Selector map_canvas
should be written in lowercase with hyphens
@@ -0,0 +1,17 @@ | |||
'use strict'; | |||
var map; | |||
function initMap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'initMap' is defined but never used.
zoom: 12 | ||
}); | ||
var markerData = $("#marker_data").data().markers; | ||
console.log(markerData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'console' is not defined.
var marker, i; | ||
for (i = 0; i < markerData.length; i++) { | ||
marker = new google.maps.Marker({ | ||
position: new google.maps.LatLng(markerData[i].lat, markerData[i].lng), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'google' is not defined.
console.log(markerData); | ||
var marker, i; | ||
for (i = 0; i < markerData.length; i++) { | ||
marker = new google.maps.Marker({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'google' is not defined.
'use strict'; | ||
var map; | ||
function initMap() { | ||
map = new google.maps.Map(document.getElementById('map_canvas'), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'google' is not defined.
center: {lat: 51.5978, lng: -0.3370}, | ||
zoom: 12 | ||
}); | ||
var markerData = $("#marker_data").data().markers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed double and single quotes.
@@ -0,0 +1,17 @@ | |||
'use strict'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the function form of "use strict".
position: absolute; | ||
bottom:0; | ||
left:50%; | ||
transform:translateX(-50%); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon after property should be followed by one space
display: block; | ||
position: absolute; | ||
bottom:0; | ||
left:50%; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon after property should be followed by one space
@@ -30,6 +34,11 @@ | |||
.measle { | |||
height: 6px; | |||
width: 6px; | |||
display: block; | |||
position: absolute; | |||
bottom:0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon after property should be followed by one space
@@ -0,0 +1,73 @@ | |||
var map; | |||
function initMap() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'initMap' is defined but never used.
var markerData = $("#marker_data").data().markers; | ||
var marker, i; | ||
for (i = 0; i < markerData.length; i++) { | ||
var latLng = new google.maps.LatLng(markerData[i].lat, markerData[i].lng); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'google' is not defined.
CustomMarker.prototype.getPosition = function() { | ||
return this.latlng; | ||
}; | ||
map = new google.maps.Map(document.getElementById('map_canvas'), { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'google' is not defined.
this.setMap(map); | ||
} | ||
|
||
CustomMarker.prototype = new google.maps.OverlayView(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'google' is not defined.
latLng, | ||
map, | ||
{ | ||
content: markerData[i].custom_marker |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifier 'custom_marker' is not in camel case.
|
||
|
||
google.maps.event.addDomListener(div, "click", function(event) { | ||
google.maps.event.trigger(self, "click"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed double and single quotes.
'google' is not defined.
div.innerHTML = self.args.content; | ||
|
||
|
||
google.maps.event.addDomListener(div, "click", function(event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed double and single quotes.
'event' is defined but never used.
'google' is not defined.
391fe49
to
6df044f
Compare
position: absolute; | ||
bottom:0; | ||
left:50%; | ||
transform:translateX(-50%); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon after property should be followed by one space
.measle { | ||
height: 6px; | ||
width: 6px; | ||
position: absolute; | ||
bottom:0; | ||
left:50%; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon after property should be followed by one space
position: absolute; | ||
bottom:0; | ||
left:50%; | ||
transform:translateX(-50%); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon after property should be followed by one space
.measle { | ||
height: 6px; | ||
width: 6px; | ||
position: absolute; | ||
bottom:0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon after property should be followed by one space
.measle { | ||
height: 6px; | ||
width: 6px; | ||
position: absolute; | ||
bottom:0; | ||
left:50%; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon after property should be followed by one space
.custom-marker { | ||
height: 22px; | ||
width: 22px; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule declaration should be followed by an empty line
.measle { | ||
height: 6px; | ||
width: 6px; | ||
position: absolute; | ||
bottom:0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colon after property should be followed by one space
var latLng = new google.maps.LatLng(markerData[i].lat, markerData[i].lng); | ||
|
||
marker = new google.maps.Marker({ | ||
position: new google.maps.LatLng(markerData[i].lat, markerData[i].lng), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'google' is not defined.
.custom-marker { | ||
height: 22px; | ||
width: 22px; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule declaration should be followed by an empty line
// check the explancation from: http://humaan.com/custom-html-markers-google-maps/ | ||
if (point) { | ||
div.style.left = (point.x - ($('.custom-marker').width() / 2)) + 'px'; | ||
div.style.top = (point.y - $('.custom-marker').height()) + 'px'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do these markers have a consistent height and width? If so, I wonder if we could avoid doing this calculation for each marker?
boxText.setAttribute("class", "arrow_box") | ||
ibOptions.content = boxText; | ||
|
||
for (i = 0; i < markerData.length; i++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you feel about using forEach
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thx for the note I'll make an update.
@Maroo-b Testing this javascript may be difficult due to it's dependence on global variables, e.g.
I've briefly explored these options, here's what I've seen so far:
I feel like option 1 is our safest bet. I would separate the initialization from the implementation, so that the tests can load just the implementation, and initialize it with mocks. We can test the real initialization via selenium (cucumber). |
@johnnymo87 thanks for your feedback, I think the easiest solution is to extract marker_reader to a separate function but is it really worth it to be tested ? It seems it's an implementation test not behavior one no ? |
Yeah, I agree it's an implementation test, but if I am not sure if there is any other way to assert that markers are drawn on the provided coordinates. |
From the test file (source), it looks like we are testing if function Regarding to check if markers are drawn I checked that the functionality is verified by those cucumber tests ( maps, volunteer ops) for the moment I'll delete that file to make the test suite pass. |
Yeah, we probably have a good deal of coverage via selenium. I'm not sure if it's 100%, though. For instance, what if we swapped the latitude and longitude of the coordinates when passing them to the google libraries ... would any cukes fail? If not, we probably need lower-level javascript tests. |
a31c237
to
5a9fd55
Compare
5a9fd55
to
118ac7a
Compare
@johnnymo87 good point, When I was working on this PR I used the default google markers to check if the custom markers are correctly positioned, maybe we can think how to implement this test with jasmine. Regarding swapping lat and lng inputs to google library, technically it will draws the marker to another position that why I suggested to compare default markers with custom ones. |
@Maroo-b many thanks for working on this - great to see that old coffee script thrown out - I'm much more comfortable with pure JS. I notice that we now have a custom markers_builder.rb class - is that not what the gem was providing for us before? If memory serves we are removing the gem to make tighter list/map integration possible is that right? We're making some custom ruby code here to give us more flexibility about how we use the map, is that right? |
@tansaku thank you for checking the PR. I extracted the markers_builder.rb from gmaps4rails gem with it's spec file it's used to create the options for the markers. The main change as you noted is in the javascript part, know we are using the native google js library so it's more easier to customize and check google maps docs for reference. For example I added the option to center a maker on click source which is now so easy and straightforward. |
@Maroo-b great! so we are good to go? What do you think of these two code climate issues? do you think we can safely ignore them? @johnnymo87 ? Could we ultimately be extracting our js code into an npm module that we could share with others? Is the gmap4rails gem not being maintained? Should we be doing PRs against that? |
@hash = {} | ||
end | ||
|
||
def call(&block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe prefer run
here? http://blog.silvabox.com/musings-on-service-objects/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also, do we need some jasmine tests on custom_marker.js and maps.js ? |
also, can we find some way to get test coverage information for jasmine? |
@tansaku for a custom google maps integration, it seems easier to use the native google maps js library. And now with pure js it's simple to check customization of event handling and managing opening infobox based on list items. So for jasmine tests, I find that maps integration is well covered with integration tests but it will be amazing if we could add tests for |
|
||
} | ||
|
||
})(marker, item)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@johnnymo87 I had to use this
keyword to refer the object to which the event handler is attached. It seems this solution fixed the warning from code climate.
@Maroo-b Would you mind tagging all the relevant cucumber tests with an I agree, the native google maps library is too easy to integrate with to merit making this a public library. I think that javascript could use some testing. It will be challenging, though. The downside of the easy integration is that it's too easy. That said, this otherwise looks like a very nice implementation, so if the cucumber tests are sufficient, I say we ship it and open a separate ticket for the javascript testing. @tansaku I believe the |
@johnnymo87 I update the PR to add |
@Maroo-b @johnnymo87 that's great - thanks for the explanation, I'll make a ticket for the javascript unit testing ... https://www.pivotaltracker.com/story/show/136036569 |
I'm just going to run this locally to check for anything we might have missed and then get it merged in |
Addresses: https://www.pivotaltracker.com/story/show/134262481