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

Remove gmaps4rails gem [fixes #134262481] #397

Merged

Conversation

Maroo-b
Copy link
Contributor

@Maroo-b Maroo-b commented Nov 19, 2016

#map_canvas {
height: 400px;
width: 100%;
}

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 {

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() {

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);

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),

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({

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'), {

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;

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';

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".

@Maroo-b Maroo-b added the WIP label Nov 19, 2016
position: absolute;
bottom:0;
left:50%;
transform:translateX(-50%);

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%;

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;

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() {

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);

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'), {

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();

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

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");

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) {

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.

@Maroo-b Maroo-b force-pushed the 134262481_remove_gmaps4rails_gem branch from 391fe49 to 6df044f Compare November 20, 2016 20:03
position: absolute;
bottom:0;
left:50%;
transform:translateX(-50%);

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%;

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%);

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;

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%;

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;
}

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;

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),

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;
}

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

@Maroo-b Maroo-b added RFC and removed WIP labels Nov 28, 2016
@johnnymo87 johnnymo87 changed the title WIP remove gmaps4rails gem [fixes #134262481] Remove gmaps4rails gem [fixes #134262481] Nov 29, 2016
// 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';
Copy link
Member

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++) {
Copy link
Member

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?

Copy link
Contributor Author

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.

@johnnymo87
Copy link
Member

johnnymo87 commented Nov 29, 2016

@Maroo-b Testing this javascript may be difficult due to it's dependence on global variables, e.g. google, document, this.setMap, etc. I see some options:

  1. Refactor to make all dependencies explicitly injected and mocked.
  2. Load the real google map libraries in the test suite.
  3. Load a mock of the google map libraries in the test suite.

I've briefly explored these options, here's what I've seen so far:

  1. I refactored things and then and in the test I initialized things with a mock google object and a real document. This works until InfoBox. That library depends on google and document being globally available. Maybe anInfoBox instance should be mocked and injected as well?
  2. Add - "//maps.google.com/maps/api/js?v=3&amp;libraries=geometry<%= ENV['GMAP_API_KEY'].nil? ? '' : "&key=#{ENV['GMAP_API_KEY']}" %>" to src_files in spec/javascripts/support/jasmine.yml. I think the tests will need to wait for everything to load.
  3. Define google = { ... }; in app/assets/javascripts/fake_google.js and load this in spec/javascripts/support/jasmine.yml. This works until this.setMap. This function and others seem to magically arrive with the real google library. I'm not familiar enough with javascript to understand how they magically get mixed into the CustomMarker class.

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).

@Maroo-b
Copy link
Contributor Author

Maroo-b commented Nov 29, 2016

@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 ?

@johnnymo87
Copy link
Member

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.

@Maroo-b
Copy link
Contributor Author

Maroo-b commented Nov 29, 2016

From the test file (source), it looks like we are testing if function marker_data is able to read data from 'data-markers' attributes.

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.

@johnnymo87
Copy link
Member

johnnymo87 commented Nov 29, 2016

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.

@Maroo-b Maroo-b force-pushed the 134262481_remove_gmaps4rails_gem branch from a31c237 to 5a9fd55 Compare December 3, 2016 06:49
@Maroo-b Maroo-b force-pushed the 134262481_remove_gmaps4rails_gem branch from 5a9fd55 to 118ac7a Compare December 3, 2016 07:08
@Maroo-b
Copy link
Contributor Author

Maroo-b commented Dec 3, 2016

@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.

@tansaku
Copy link
Contributor

tansaku commented Dec 7, 2016

@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 tansaku temporarily deployed to harrowcn-develop-pr-397 December 7, 2016 16:23 Inactive
@Maroo-b
Copy link
Contributor Author

Maroo-b commented Dec 7, 2016

@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.

@tansaku
Copy link
Contributor

tansaku commented Dec 8, 2016

@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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@tansaku this file was extracted from Gmaps4rails gem, the only method I added was generate in class MarkersBuilder source
The MarkerBuilder instance accepts a block that's why it seems that naming the method to call here was chosen to reveal the intention of calling blocks.

@tansaku
Copy link
Contributor

tansaku commented Dec 8, 2016

also, do we need some jasmine tests on custom_marker.js and maps.js ?

@tansaku
Copy link
Contributor

tansaku commented Dec 8, 2016

also, can we find some way to get test coverage information for jasmine?

@Maroo-b
Copy link
Contributor Author

Maroo-b commented Dec 9, 2016

@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 custom_marker.js because when I was working on this PR I used the default google markers to check if the custom markers are correctly positioned.


}

})(marker, item));
Copy link
Member

Choose a reason for hiding this comment

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

Code climate noticed that this function is invoked when passed to the addListener function. It's interesting that this invoked function returns a function. @Maroo-b, does marker and item still work in the inner-most function without being enclosed in this invoked function?

Copy link
Contributor Author

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.

@johnnymo87
Copy link
Member

johnnymo87 commented Dec 10, 2016

@Maroo-b Would you mind tagging all the relevant cucumber tests with an @maps tag?

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. google is a global variable, and CustomMarker inherits from google.maps.OverlayView, introducing a lot of magic functionality. You can't test it without either (1) loading the real google maps libraries in the test suite, or (2) writing an extremely thin wrapper around it, depend on that instead, and test against that.

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 gmaps4rails gem is still maintained, but all we're doing here is taking one file from it and tossing the rest, which probably wouldn't be welcomed upstream.

@Maroo-b
Copy link
Contributor Author

Maroo-b commented Dec 11, 2016

@johnnymo87 I update the PR to add maps tags to cucumber tests.

@tansaku
Copy link
Contributor

tansaku commented Dec 13, 2016

@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

@tansaku
Copy link
Contributor

tansaku commented Dec 13, 2016

I'm just going to run this locally to check for anything we might have missed and then get it merged in

@tansaku tansaku merged commit 9d534c5 into AgileVentures:develop Dec 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants