Skip to content

Commit

Permalink
Maps added to profile page #1940 (#1965)
Browse files Browse the repository at this point in the history
* Added maps

* Created _userLeaflet.html.erb

* Maps added

* Maps added

* Share Location button added

* Changed local variable to meaningful name

* Static image for sharing location .

* Uploaded static image of map

* Small change

* Static image deleted

* Changes done +code indentation done
  • Loading branch information
sagarpreet-chadha authored and jywarren committed Jan 22, 2018
1 parent 06d481a commit 5087a3e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 5 deletions.
12 changes: 12 additions & 0 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ def profile
@facebook = @profile_user.social_link("facebook")
@instagram = @profile_user.social_link("instagram")


@map_lat = nil
@map_lon = nil
@map_blurred = nil
if(@profile_user.has_power_tag("lat") && @profile_user.has_power_tag("lon"))
@map_lat = @profile_user.get_value_of_power_tag("lat").to_f
@map_lon = @profile_user.get_value_of_power_tag("lon").to_f
if(@profile_user.has_power_tag("blurred"))
@map_blurred = @profile_user.get_value_of_power_tag("blurred")
end
end

if @user.status == 0
if current_user && (current_user.role == "admin" || current_user.role == "moderator")
flash.now[:error] = I18n.t('users_controller.user_has_been_banned')
Expand Down
24 changes: 24 additions & 0 deletions app/views/map/_userLeaflet.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<% if haslocation == true %>
<% unique_id = rand(100) %>
<style>
#map<%= unique_id %> { height:300px; margin: 0; position: relative;}
</style>
<div class="leaflet-map" id="map<%= unique_id %>"></div>
<script>
var map = L.map('map<%= unique_id %>').setView([<%= @map_lat %>,<%= @map_lon %>], 7);
L.tileLayer("//a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/{z}/{x}/{y}.png").addTo(map);
<% if !(@map_blurred == "true") %>
L.marker([<%= @map_lat %>, <%= @map_lon %>]).addTo(map).bindPopup("<a href='https://publiclab.org/profile/<%= @profile_user.username %>'><%= @profile_user.username %> </a>");
<% end %>
</script>
<% else %>
<div id="map_template" style="position: relative; display: inline-block;">
<img src="https://a.tiles.mapbox.com/v3/jywarren.map-lmrwb2em/0/0/0.png" style="height:300px; margin: 0; position: relative; margin-right: -10px;">
<button type='button' class='btn btn-default btn-lg' onclick='addLocation()' style="position: absolute; position: absolute;top: 41% ; left: 15% ;"> <strong> Share your Location </strong> </button>
</div>
<script>
function addLocation() {
$('.blurred-location-input').click() ;
}
</script>
<% end %>
14 changes: 9 additions & 5 deletions app/views/users/profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<ul class="nav bullet">
<% @wikis.each do |wiki| %>
<% unless (!@node.nil? && wiki.nid == @node.nid) %>
<li><a href="<%= wiki.path %>"><i class="fa fa-<%= wiki.icon %>"></i> <%= wiki.latest.title %></a> <small style="color:#888;"><%= t('users.profile.updated') %> <%= distance_of_time_in_words(wiki.updated_at, Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= t('users.profile.by') %> <a href="/profile/<%= wiki.latest.author.name %>"><%= wiki.latest.author.name %></a></small></li>
<li><a href="<%= wiki.path %>"><i class="fa fa-<%= wiki.icon %>"></i> <%= wiki.latest.title %></a> <small style="color:#888;"><%= t('users.profile.updated') %> <%= distance_of_time_in_words(wiki.updated_at, Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' }) %> <%= t('users.profile.by') %> <a href="/profile/<%= wiki.latest.author.name %>"><%= wiki.latest.author.name %></a></small></li>
<% end %>
<% end %>
<% if params[:controller] == "search" %>
Expand Down Expand Up @@ -158,14 +158,18 @@

<hr />
<div class="row" id="highlight" style=" text-align: center;">
<h3 class="col-md-4 col-xs-12 col-sm-4"><%= Node.questions.where(status: 1, uid: @user.id).length %> questions asked</h3>
<h3 class="col-md-4 col-xs-12 col-sm-4"><%= Answer.where(uid: @profile_user.id).count %> answers posted</h3>
<h3 class="col-md-4 col-xs-12 col-sm-4"><%= Node.questions.where(status: 1, uid: @user.id).length %> questions asked <br><br> <%= Answer.where(uid: @profile_user.id).count %> answers posted</h3>
<h3 class="col-md-4 col-xs-12 col-sm-4"><%= Comment.where(uid: @profile_user.id).count %> comments posted</h3>
<% if !@map_lat.nil? && !@map_lon.nil? %>
<%= render :partial => "map/userLeaflet" , locals: {haslocation: true} %>
<% elsif !current_user.nil? && current_user.id == @user.id %>
<%= render :partial => "map/userLeaflet" , locals: {haslocation: false} %>
<% end %>
</div>
<hr />

<ul class="nav nav-tabs">
<span style="float:right;"><small><%= raw t('users.profile.joined_time_ago', :time_ago => distance_of_time_in_words(@user.created_at, Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' })) %></small></span>
<span style="float:right;"><small><%= raw t('users.profile.joined_time_ago', :time_ago => distance_of_time_in_words(@user.created_at, Time.current, { include_seconds: false, scope: 'datetime.time_ago_in_words' })) %></small></span>
<li class="active"><a href="#research" data-toggle="tab"><%= t('users.profile.research') %></a></li>
<li><a href="#coauthored" data-toggle="tab"><span class="hidden-sm hidden-xs"> <%= t('users.profile.Coauthored') %> (<%= @coauthored.size %>)</span></a></li>
<li><a href="#questions" data-toggle="tab"><i class="fa fa-comments"></i><span class="hidden-sm hidden-xs"> <%= t('users.profile.questions') %> (<%= Node.questions.where(status: 1, uid: @user.id).length %>)</span></a></li>
Expand Down Expand Up @@ -231,7 +235,7 @@
<hr />

<% if current_user && (current_user.id == @user.id || current_user.role == "admin") %>
<%= render :partial => "tag/tagging", locals: { url: "/profile/tags/create/#{ @user.id }" } %>
<%= render :partial => "tag/tagging", locals: { url: "/profile/tags/create/#{ @user.id }" } %>
<% end %>

<hr />
Expand Down

0 comments on commit 5087a3e

Please sign in to comment.