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

Place tag detection and replacing "-" with "" #2734

Merged
merged 19 commits into from
Jun 5, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ GEM
debug_inspector (>= 0.0.1)
builder (3.2.3)
byebug (10.0.2)
chronic (0.10.2)
Copy link
Member

Choose a reason for hiding this comment

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

Hi, @mridulnagpal -- are these gems used in your code, or was this added by mistake? I guess we can upgrade the versions without a problem, though!

Copy link
Member Author

@mridulnagpal mridulnagpal May 19, 2018

Choose a reason for hiding this comment

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

No, I am not using these gems, must be by mistake

Copy link
Member

Choose a reason for hiding this comment

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

Just remember to remove this!

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

ci_reporter (2.0.0)
builder (>= 2.1.2)
ci_reporter_test_unit (1.0.1)
Expand Down Expand Up @@ -408,6 +409,8 @@ GEM
binding_of_caller (>= 0.7.2)
railties (>= 4.0)
sprockets-rails (>= 2.0, < 4.0)
whenever (0.10.0)
chronic (>= 0.6.3)
will_paginate (3.1.6)
will_paginate-bootstrap (1.0.1)
will_paginate (>= 3.0.3)
Expand Down Expand Up @@ -490,6 +493,7 @@ DEPENDENCIES
uglifier (>= 1.0.3)
unicode-emoji
web-console (~> 2.0)
whenever
will_paginate (>= 3.0.6)
will_paginate-bootstrap (>= 1.0.1)

Expand Down
23 changes: 23 additions & 0 deletions app/assets/javascripts/tagging.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ function addTag(tagname, selector) {

selector = selector || '#tagform';

if (tagname.indexOf("place") != -1) {
place = tagname.split(":")[1];
place.replace("-", " ");
geocodeStringAndPan(place);
Copy link
Member

Choose a reason for hiding this comment

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

do we need to put the prompt code into a callback so it executes /after/ the geocode is complete? Or does this just work?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, perhaps in the onComplete parameter!

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied this code from blurred-location library, how do I test all of it?

var choice = prompt("This looks like a location: A) Geocode B) Leave");
while(choice == NULL)
}
Copy link
Member

Choose a reason for hiding this comment

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

I think the while may not be needed? the prompt() should hang up the process until it's submitted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Awesome


var el = $(selector);

el.find('.tag-input').val(tagname);
Expand Down Expand Up @@ -80,3 +88,18 @@ function initTagForm(deletion_path, selector) {
return el;

}

function geocodeStringAndPan(string, onComplete) {
var url = "https://maps.googleapis.com/maps/api/geocode/json?address=" + string.split(" ").join("+");
var Blurred = $.ajax({
async: false,
url: url
});
onComplete = onComplete || function onComplete(geometry) {
Copy link
Member

Choose a reason for hiding this comment

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

Plus, I believe you'll have to assign the onComplete function to run once this Ajax call is complete. See jQuery docs to see how to attach this so it's run on the response only. Make sense?

lat = geometry.lat;
lng = geometry.lng;

return [lat, lng];
}
onComplete(Blurred.responseJSON.results[0].geometry.location);
Copy link
Member

Choose a reason for hiding this comment

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

Great but let's attach this to the Ajax call so it runs when they call completes; you'll have to look up how this is done in the jQuery Ajax docs!

}
2 changes: 0 additions & 2 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ def create
uid: current_user.uid,
body: " @#{current_user.username} has marked #{tagname.split(':')[1]} as a co-author. ")

end
Copy link
Member

Choose a reason for hiding this comment

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

Is this a stray deletion? Maybe re-adding the end will fix some of the tests?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, on it!!


if saved
@tags << tag
@output[:saved] << [tag.name, tag.id]
Expand Down