Skip to content

Commit

Permalink
Recently used location in LBL modal . (#5522)
Browse files Browse the repository at this point in the history
* recently used locations in lbl modal added

* function name changed

* code climate issues fixed

* UI changed

* minor CSS change

* Update screenshots_test.rb

* padding tweak

* url in test changed

* Update screenshots_test.rb

* Update screenshots_test.rb

* remove <p>
  • Loading branch information
sagarpreet-chadha authored and jywarren committed Jun 28, 2019
1 parent 61684ae commit 78fffff
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 3 deletions.
12 changes: 11 additions & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,9 @@ def normal_tags
end

def location_tags
if lat && lon
if lat && lon && place
power_tag_objects('lat') + power_tag_objects('lon') + power_tag_objects('place')
elsif lat && lon
power_tag_objects('lat') + power_tag_objects('lon')
else
[]
Expand Down Expand Up @@ -565,6 +567,14 @@ def lon
end
end

def place
if has_power_tag('place')
power_tag('place')
else
false
end
end

def next_by_author
Node.where('uid = ? and nid > ? and type = "note"', author.uid, nid)
.order('nid')
Expand Down
29 changes: 29 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,35 @@ def watching_location(nwlat, selat, nwlng, selng)
end
end

def get_all_used_locations
latest_locations = []
nodes = self.nodes.order('nid DESC').where(status: 1)
nodes.each do |node|
location_tags = node.location_tags
if location_tags.count > 0
latest_locations << location_tags
end
end
latest_locations
end

def get_latest_used_location
latest_location = []
nodes = self.nodes.order('nid DESC').where(status: 1)
nodes.each do |node|
location_tags = node.location_tags
if location_tags.count > 0
latest_location << location_tags
break
end
end
if latest_location.count > 0
latest_location[0][0] = latest_location[0][0].name.split(":")[1].to_f
latest_location[0][1] = latest_location[0][1].name.split(":")[1].to_f
end
latest_location
end

private

def decrease_likes_banned
Expand Down
40 changes: 38 additions & 2 deletions app/views/locations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,32 @@
<input id="placenameInput" type="text" class="form-control" />
</div>

<p><b>By dragging the map</b></p>
<!-- Not part of LBL library -->
<% if current_user %>
<% latest_locations = current_user.get_all_used_locations %>
<% if latest_locations.count > 0 %>
<p><b>Your previous used locations...</b></p>
<div class="row">
<% latest_locations.each_with_index do |location , index| %>
<% if index == 5 %>
<% break %>
<% end %>
<a href="#" onclick="blurredLocation.goTo(<%= location[0].name.split(":")[1] %> , <%= location[1].name.split(":")[1] %> , 6);">
<span class="badge badge-info" style="background-color: #337ab7 ; margin-left: 7px ;margin-top: 2px; ">
<% if location.count == 3 %>
<%= location[2].name.split(":")[1] %>
<%end%>
<span class="badge" style="background-color: white ; color: #337ab7;"><%= location[0].name.split(":")[1] %></span>
<span class="badge" style="background-color: white ; color: #337ab7;"><%= location[1].name.split(":")[1] %></span>
</span>
</a>
<% end %>
</div>
<% end %>
<% end %>

<br>
<p><b>By dragging the map</b></p>
<div id="map" class="leaflet-map" style="width: 100%; height: 300px; margin-bottom:10px;"></div>
<p>
<h3><strong>Scale</strong></h3>
Expand Down Expand Up @@ -54,15 +78,27 @@
InterfaceOptions: {
latId: 'lat',
lngId: 'lng'
},
location: {
lat: 23 ,
lon: 77
}
}
} ;

var blurredLocation;

(function() {

L.Icon.Default.imagePath = '/lib/leaflet/dist/images/';

<% if current_user %>
<% latest_location = current_user.get_latest_used_location %>
<% if !latest_location.empty? %>
options.location.lat = <%= latest_location[0][0] %> ;
options.location.lon = <%= latest_location[0][1] %> ;
<% end %>
<% end %>

blurredLocation = new BlurredLocation(options);

blurredLocation.panMapToGeocodedLocation("placenameInput");
Expand Down
14 changes: 14 additions & 0 deletions test/system/screenshots_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,18 @@ class ScreenshotsTest < ApplicationSystemTestCase
visit node.path
take_screenshot
end

test 'blog page with location modal' do
visit '/'
click_on 'Login'
fill_in("username-login", with: "steff1")
fill_in("password-signup", with: "secretive")
click_on "Log in"
visit nodes(:blog).path
find('a.blurred-location-input').click
# click_on(class: 'blurred-location-input') # alternative
fill_in("placenameInput", with: "Pusan")
take_screenshot
end

end

0 comments on commit 78fffff

Please sign in to comment.