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

[Outreachy]Add Nearby Activity #9202

Merged
merged 9 commits into from
Feb 19, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/assets/javascripts/leafletHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
options.setHash = params.setHash || false;
options.mainContent = params.mainContent || ""; // "content" to show site content, default "" shows no site content
options.displayAllLayers = params.displayAllLayers || false; // turn on display for all maps available in menu
options.imageLoadingUrl = "/lib/leaflet-environmental-layers/example/images/owmloading.gif";

if (typeof options.layers === "string") {
options.layers = options.layers.split(',');
Expand All @@ -135,7 +136,6 @@
optionsLEL.addLayersToMap = options.displayAllLayers;
optionsLEL.display = options.layers;
optionsLEL.include = options.limitMenuTo;
optionsLEL.imageLoadingUrl = "/lib/leaflet-environmental-layers/example/images/owmloading.gif";
optionsLEL.hash = options.setHash;
}
optionsLEL.imageLoadingUrl = "/lib/leaflet-environmental-layers/example/images/owmloading.gif";
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def lon
get_value_of_power_tag('lon')
end

def zoom
get_value_of_power_tag('zoom')
end

# we can revise/improve this for m2m later...
def has_role(some_role)
role == some_role
Expand Down
19 changes: 19 additions & 0 deletions app/views/dashboard_v2/_location.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<% if current_user.has_power_tag("lat") && current_user.has_power_tag("lon") %>
<% lon = current_user.lon %>
<% lat = current_user.lat%>
<% zoom = current_user.zoom ? current_user.zoom: '' %>
<%# Display Map %>
<%= render_map(lat, lon, zoom) %>
<%# Link to view Nearby Activity %>
<% url = "/map#" + zoom.to_s + "/" + lat.to_s + lon.to_s %>
<a href="<%= url %>" class="btn btn-outline-secondary btn-location mt-2 mb-5"><i class="fa fa-map-marker" aria-hidden="true"></i> <%= translation('dashboard_v2.sidebar.nearby_activity') %> </a>
<% else %>
<div style="margin: 2.2rem 0;">
<a class="btn btn-lg btn-outline-secondary blurred-location-input" submit_to="/profile/tags/create/<%= current_user.uid %>"><i class="fa fa-map-marker" style="color:#c40;"></i> <%= translation('dashboard_v2.sidebar.add_location') %></a>
<p><small class="form-grey">
<%= translation('dashboard_v2.sidebar.location_work') %> |
<a class="form-grey" style="text-decoration: underline;" href="https://publiclab.org/location-privacy" target="_blank"><%= translation('dashboard_v2.sidebar.location_privacy') %></a>
</p></small>
</div>
<%= render partial: 'tag/location' %>
<% end %>
14 changes: 2 additions & 12 deletions app/views/dashboard_v2/_sidebar.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
<%= javascript_include_tag('asyncTagSubscriptions.js') %>
<%# TODO Location not working, will be fixed after working on https://github.com/publiclab/plots2/issues/8566 %>
<% if current_user %>
<div style="margin: 2.2rem 0;">
<a class="btn btn-lg btn-outline-secondary blurred-location-input" submit_to="/profile/tags/create/<%= current_user.uid %>"><i class="fa fa-map-marker" style="color:#c40;"></i> <%= translation('dashboard_v2.sidebar.add_location') %></a>
<p><small class="form-grey">
<%= translation('dashboard_v2.sidebar.location_work') %> |
<a class="form-grey" style="text-decoration: underline;" href="https://publiclab.org/location-privacy" target="_blank"><%= translation('dashboard_v2.sidebar.location_privacy') %></a>
</p></small>
</div>
<% end %>
<%= render partial: 'tag/location' %>

<%= render partial: 'dashboard_v2/location'%>
<%# More Topics %>
<div id="accordion">
<div class="card">
Expand Down Expand Up @@ -72,7 +62,7 @@
position: absolute;
right: 0;
padding-right: 9px;
padding-top: 1px;
padding-top: 9px;
}

a[aria-expanded=true] .fa-angle-up {
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ en:
more_topics: "To improve your feed, follow the trending and featured topics linked below."
new_comment: "new comment"
sidebar:
nearby_activity: "Nearby Activity"
add_location: "Add your location"
location_work: "Add your location to see work near you"
location_privacy: "About location privacy"
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
get 'feed/liked' => 'notes#liked_rss'

get 'dashboard' => 'home#dashboard'
get 'v2/dashboard' => 'home#dashboard_v2'
get '/v2/dashboard' => 'home#dashboard_v2'
get 'comments' => 'comment#index'
get 'profile/comments/:id' => 'users#comments'
get 'profile/comments/:id/tag/:tagname' => 'users#comments_by_tagname'
Expand Down
11 changes: 11 additions & 0 deletions test/functional/home_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,15 @@ def setup
# Checking the latest_activity_node ensures that the most recent activity was bumped up.
assert_equal expected_first_topic.latest_activity_nid, new_first_topic.latest_activity_nid
end

test 'subscribed topics do not appear in trending topics' do
current_user = users(:bob)
UserSession.create(current_user)
get :dashboard_v2
# Sort both the subscribed tags and the trending tags alphabetically and compare the names
subscribed_tags = TagSelection.where(user_id: current_user.id).pluck(:tid)
tag_names = Tag.where(tid: subscribed_tags).pluck(:name).sort
trending_tags = assigns[:trending_tags].pluck(:name).sort
assert_not_equal tag_names , trending_tags
end
end
35 changes: 18 additions & 17 deletions test/system/dashboard_v2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,6 @@
class DashboardV2Test < ApplicationSystemTestCase
Capybara.default_max_wait_time = 60

test 'view trending topics' do
user = users(:bob)
subscribed_tags = TagSelection.where(user_id: user.id).pluck(:tid)
# Return the name of a subscribed tag at random
tag_name = Tag.where(tid: subscribed_tags).pluck(:name).sample

visit '/'
click_on 'Login'
fill_in("username-login", with: "Bob")
fill_in("password-signup", with: "secretive")
click_on 'Log in'
visit '/v2/dashboard'
# Ensure that a subscribed tag is not present on the trending and follow section
assert_selector("div > div.other-topics > span a[href='/tag/#{tag_name}']", count: 0)
assert_selector("div#moreTopics div > div > div a[href='/tag/#{tag_name}']", count: 0)
end

test 'trending tags are returned when a user has not subscribed to any topics' do
visit '/'
click_on 'Login'
Expand All @@ -31,4 +14,22 @@ class DashboardV2Test < ApplicationSystemTestCase
assert_selector("div > div.other-topics > span a")
assert_selector("div#moreTopics div > div > div a")
end

test 'view trending topics' do
user = users(:bob)
subscribed_tags = TagSelection.where(user_id: user.id).pluck(:tid)
# Return the name of a subscribed tag at random
tag_name = Tag.where(tid: subscribed_tags).pluck(:name).sample

visit '/'
click_on 'Login'
fill_in("username-login", with: "Bob")
fill_in("password-signup", with: "secretive")
click_on 'Log in'
visit '/v2/dashboard'
# Ensure that a subscribed tag is not present on the trending and follow section
assert_selector("div > div.other-topics > span a[href='/tag/#{tag_name}']", count: 0)
assert_selector("div#moreTopics div > div > div a[href='/tag/#{tag_name}']", count: 0)
end

end