Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/publiclab/plots2 into main
Browse files Browse the repository at this point in the history
  • Loading branch information
avats-dev committed Sep 24, 2020
2 parents 62d4986 + e4a0bbf commit 4a8c93e
Show file tree
Hide file tree
Showing 15 changed files with 181 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ gem 'rb-readline'
gem 'rdiscount', '~> 2.2'
gem "recaptcha", require: "recaptcha/rails"
gem 'responders', '~> 3.0'
gem 'rubocop', '~> 0.90.0', require: false
gem 'rubocop', '~> 0.91.0', require: false
gem "ruby-openid", :require => "openid"
gem 'sanitize'
gem 'sentry-raven'
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -459,16 +459,16 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.0)
rubocop (0.90.0)
rubocop (0.91.0)
parallel (~> 1.10)
parser (>= 2.7.1.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.3.0, < 1.0)
rubocop-ast (>= 0.4.0, < 1.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
rubocop-ast (0.4.2)
parser (>= 2.7.1.4)
ruby-openid (2.9.2)
ruby-progressbar (1.10.1)
Expand Down Expand Up @@ -666,7 +666,7 @@ DEPENDENCIES
rest-client
reverse_markdown
rspec
rubocop (~> 0.90.0)
rubocop (~> 0.91.0)
ruby-openid
sanitize
sassc-rails
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/print_new.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ svg {
break-before: avoid-page;
}

img {
img, .card {
page-break-before: avoid; /* 'always,' 'avoid,' 'left,' 'inherit,' or 'right' */
page-break-after: avoid; /* 'always,' 'avoid,' 'left,' 'inherit,' or 'right' */
page-break-inside: avoid; /* or 'auto' */
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def print

if @node
impressionist(@node, 'print', unique: [:ip_address])
render layout: false
render layout: "print"

else
page_not_found
Expand Down
21 changes: 10 additions & 11 deletions app/controllers/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,22 +83,11 @@ def show
@node = @wiki # expose the wiki node in the @node variable so we get open graph meta tags in the layout

default_type = params[:id].match?('question:') ? 'questions' : 'note'
if params[:order].nil?
params[:order] = 'last_updated' # default ordering set
end

@node_type = params[:node_type] || default_type
@start = Time.parse(params[:start]) if params[:start]
@end = Time.parse(params[:end]) if params[:end]

order_by = if params[:order] == 'views'
'node.views DESC'
elsif params[:order] == 'likes'
'node.cached_likes DESC'
elsif params[:order] == 'last_updated'
'node_revisions.timestamp DESC'
end

node_type = if %w(questions note).include?(@node_type)
'note'
elsif @node_type == 'wiki'
Expand Down Expand Up @@ -127,6 +116,16 @@ def show
end
end

order_by = if params[:order] == 'views'
'node.views DESC'
elsif params[:order] == 'likes'
'node.cached_likes DESC'
elsif @node_type == 'wiki' # wiki sorting by timestamp isn't working; https://github.com/publiclab/plots2/issues/7334#issuecomment-696938352
'node.nid DESC'
else # params[:order] == 'last_updated'
'node_revisions.timestamp DESC'
end

@pagy, nodes = pagy(nodes.order(order_by), items: 24)
@paginated = true

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/wiki_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def print

if @node
impressionist(@node, 'print', unique: [:ip_address])
render layout: false
render layout: "print"

else
page_not_found
Expand Down
2 changes: 1 addition & 1 deletion app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ def self.new_note(params)
img.save
end
node.save!
if node.status != 3
if node.status == 1
node.notify
end
else
Expand Down
1 change: 1 addition & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def self.contributors(tagname)
end
uids = uids.uniq
User.where(id: uids)
.where(status: [1, 4])
end

def self.contributor_count(tagname)
Expand Down
121 changes: 121 additions & 0 deletions app/views/layouts/print.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!DOCTYPE html>
<html lang="<%= I18n.locale || 'en' %>">
<head>
<meta charset="utf-8" />
<title>&#127880; Public Lab<%= ": "+(@title || params[:action].capitalize) %></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<% if @node && @node.body %>
<meta name="description" content="<%= raw strip_tags(sanitize(RDiscount.new(@node.body).to_html)).truncate(100) %>" />
<% else %>
<meta name="description" content="Public Lab is an open community which collaboratively develops accessible, open source, Do-It-Yourself technologies for investigating local environmental health and justice issues." />
<% end %>
<%= action_cable_meta_tag %>
<meta name="author" content="Public Lab contributors" />
<link href="https://<%= request.host %>/feed.rss" rel="alternate" type="application/rss+xml" title="Public Lab research" />

<link rel="stylesheet preload prefetch" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0-2/css/all.min.css" as="style" type="text/css" />
<!-- Loading critical css and rest asynchronously #7996 -->
<%= javascript_include_tag "application" %>
<style>
<%= CriticalPathCss.fetch(request.path) %>
</style>
<script>
loadCSS("<%= stylesheet_path('application') %>");
</script>
<link rel="preload" href="<%= stylesheet_path('application') %>" as="style" onload="this.onload=null;this.rel='stylesheet'">
<noscript>
<link rel="stylesheet" href="<%= stylesheet_path('application') %>">
</noscript>
<% if @node && @node.has_tag('style:fancy') %>
<%= stylesheet_link_tag "fancy", :media => "all" %>
<% end %>
<%= stylesheet_link_tag "print", :media => "print" %>

<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->

<%= csrf_meta_tags %>
<meta name="google-translate-customization" content="4ce4c7c384354172-5179499fc244f592-g2b333d0d29f59663-d" />

<% if current_user %>
<%= javascript_include_tag "cable" %>
<% end %>

<% if @node && @node.body %>
<meta property="og:title" content="<%= @title %>" />
<meta property="og:site_name" content="Public Lab" />
<meta property="og:url" content="https://<%= request.host %>/n/<%= @node.id %>" />
<meta property="og:description" content="<%= raw strip_tags(sanitize(RDiscount.new(@node.body).to_html)).truncate(100) %>" />
<meta property="og:type" content="article" />
<meta property="fb:app_id" content="644692375883090" />
<% if @node.main_image %>
<meta property="og:image" content="https://<%= request.host %><%= @node.main_image.path(:default) %>" />
<meta name="twitter:image" content="https://<%= request.host %><%= @node.main_image.path(:default) %>">
<% elsif scraped_image = @node.scraped_image %>
<meta property="og:image" content="<%= scraped_image %>" />
<meta name="twitter:image" content="<%= scraped_image %>">
<% end %>
<p class="facebook-summary" style="display:none;">
<%= raw strip_tags(sanitize(RDiscount.new(@node.body).to_html)).truncate(100) %>
</p>
<% end %>
<p class="facebook-summary" style="display:none;"><%= translation('layout._header.summary') %></p>

<!-- facebook needs this apparently -->
<div id="fb-root"></div>

<%= yield(:head) %>

<script type="text/javascript">
I18n.defaultLocale = "<%= I18n.default_locale %>";
I18n.locale = "<%= I18n.locale %>";
I18n.fallbacks = true;
$(function () {
$("[data-toggle=popover]").popover({
html: true,
content: function() {
return $('#popover-content').html();
}
});
});
</script>

<% cache('feature_header', skip_digest: true) do %>
<%= feature("header") %>
<% end %>

<%= yield(:head) %>

<style type="text/css">
.pac-container { z-index: 100000; }

#ex1Slider .slider-selection {
background: #BABABA;
}

</style>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.2.0/bootstrap-slider.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.2.0/css/bootstrap-slider.min.css" />

</head>

<body>
<div id="top_map"> </div>
<div class="container">
<div class="row">

<%= yield %>

</div><!--/row-->
</div><!--/container-->

</body>
<script>
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
</script>
</html>
4 changes: 2 additions & 2 deletions app/views/sidebar/_question.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<% end %>

<% if params[:controller] == 'questions' %>
<% if @users.length > 0 %>
<% if @users.size > 0 %>
<h4>Top Answerers</h4>
<% @users.each do |author| %>
<% count = @node.answers.where(uid: author.uid).length %>
<% count = @node.answers.where(uid: author.uid).size %>
<%if !(author.banned?)%>
<p><i class="fa fa-user" style="margin-right: 5px;"></i><a rel="tooltip" title="<%= count %> answers" data-placement="right" href="/profile/<%= author.name %>"><%= author.name %></a></p>
<% end %>
Expand Down
15 changes: 8 additions & 7 deletions app/views/tag/_tagging.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<script>
$(function () {
$('#tags [data-toggle="tooltip"]').tooltip()
$('#tags [data-toggle="tooltip"]').tooltip();
var pops = $("[data-toggle=popover]");
$(".label").on("click", function(e){
Expand All @@ -46,14 +46,15 @@ $(function () {
<% parent ||= nil %>
<% if current_user && (parent != :profile || (current_user.id == user.id || logged_in_as(['admin']))) %>
<a data-toggle="tooltip" title="Add tags/View all" aria-label="Add tags/View all" id="tags-open" class="btn btn-circle btn-circle-sm tags-open" style="float:left;">
<i class="fa fa-plus" style="color:#808080;"></i>
</a>
<a aria-label="Add tags" id="tags-open" class="btn btn-circle btn-circle-sm" style="float:left;"><i class="fa fa-plus" style="color:#808080;"></i></a>
<% if @node && @node.tags.count == 0 %>
<span style="float:left;color:#666;margin-top:14px;margin-left:5px;">Add tags</a>
<% end %>
<%= render partial: 'tag/form', locals: { node: @node ||= nil, user: user ||= nil, url: url ||= nil } %>
<% if @node && @node.tags.count == 0 %>
<span style="float:left;color:#666;margin-top:14px;margin-left:5px;">Add tags</span>
<% end %>
<%= render partial: 'tag/form', locals: { node: @node ||= nil, user: user ||= nil, url: url ||= nil } %>
<% end %>
<script>
Expand Down
15 changes: 0 additions & 15 deletions app/views/tag/_tags.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<% user = user || @user # allow overriding w/ local variable %>
<div class="tags-list">
<% if tags.length > 0 && power_tag %>
<a aria-label="Show more tags" class="btn btn-circle btn-circle-sm show-more-tags" href="javascript:void(0);" style="float:left;"><i class="fa fa-ellipsis-h" style="color:#808080;"></i></a>
<% end %>
<% tags.each_with_index do |tag, i| %>
<% if tag.class == NodeTag %>
Expand All @@ -27,18 +24,6 @@
<% end %>
<script>
(function() {
$('.show-more-tags').click(function showMoreTags() {
$('.more-tags').show();
$('.show-more-tags').hide();
$("#tagform").show();
$("#tags-open").hide();
$(".tag-input").focus();
});
})();
</script>
<% elsif tag.class == UserTag && (tag.name[0..4] != "oauth" || (logged_in_as(['admin', 'moderator']) || (current_user && current_user.uid == tag.uid))) %>
<li style="width: 100%;">
Expand Down
16 changes: 13 additions & 3 deletions app/views/tag/show/_sort.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@
<button class="btn btn-outline-secondary dropdown-toggle" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="margin-left:14px;">Sort by</button>
<div class="dropdown-menu dropdown-menu-right mt-1" aria-labelledby="dropdownMenuButton">
<% if params[:action] == "show" %>
<a class="dropdown-item <% if params[:order] == 'last_updated' %> active<% end %>" href="/tag/<%= params[:id] %>"><i class="fa fa-clock-o"></i> <span class="d-lg-inline">by last updated</span></a>
<a class="dropdown-item <% if params[:order] == 'views' %> active<% end %>" href="?order=views"><i class="fa fa-eye"></i> <span class="d-lg-inline">by views</span></a>
<a class="dropdown-item <% if params[:order] == 'likes' %> active<% end %>" href="?order=likes"><i class="fa fa-star"></i> <span class="d-lg-inline">by likes</span></a>
<a class="dropdown-item <% if params[:order] == 'last_updated' %> active<% end %>" href="/tag/<%= params[:id] %>">
<% if @node_type == 'wiki' %>
<i class="fa fa-clock-o"></i> <span class="d-lg-inline">by created date</span>
<% else %>
<i class="fa fa-clock-o"></i> <span class="d-lg-inline">by last updated</span>
<% end %>
</a>
<a class="dropdown-item <% if params[:order] == 'views' %> active<% end %>" href="?order=views">
<i class="fa fa-eye"></i> <span class="d-lg-inline">by views</span>
</a>
<a class="dropdown-item <% if params[:order] == 'likes' %> active<% end %>" href="?order=likes">
<i class="fa fa-star"></i> <span class="d-lg-inline">by likes</span>
</a>
<% end %>
</div>
</div>
22 changes: 14 additions & 8 deletions test/functional/notes_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,9 @@ def teardown
test 'should redirect to questions show page after creating a new question' do
title = 'How to use Spectrometer'
perform_enqueued_jobs do
assert_emails 1 do
# no emails sent for first-time posters, as it's held in moderation
assert users(:bob).first_time_poster
assert_emails 0 do
user = UserSession.create(users(:bob))
post :create,
params: {
Expand All @@ -540,13 +542,17 @@ def teardown
test 'non-first-timer posts a question' do
UserSession.create(users(:jeff))
title = 'My first question to Public Lab'
post :create,
params: {
title: title,
body: 'Spectrometer question',
tags: 'question:spectrometer',
redirect: 'question'
}
perform_enqueued_jobs do
assert_emails 1 do
post :create,
params: {
title: title,
body: 'Spectrometer question',
tags: 'question:spectrometer',
redirect: 'question'
}
end
end

assert_redirected_to '/questions/' + users(:jeff).username + '/' + Time.now.strftime('%m-%d-%Y') + '/' + title.parameterize
assert_equal flash[:notice], 'Question published. In the meantime, if you have more to contribute, feel free to do so.'
Expand Down
4 changes: 3 additions & 1 deletion test/system/post_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ def assert_page_does_not_reload(message = "page should not reload")

# Wait for the location to be added
wait_for_ajax
find('.tags-list a.show-more-tags').click()

# there should also be a page reload now, because we want to reload to see the sidebar mini-map
find('a#tags-open').click()

# Make sure proper latitude and longitude tags are added
assert_selector('.tags-list .badge a[href="/tag/lat:22"]', text: "lat:22")
Expand Down

0 comments on commit 4a8c93e

Please sign in to comment.