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

Tag logins #6326

Merged
merged 6 commits into from
Sep 24, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions app/assets/javascripts/graph.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function graphUrl(url, el) {
console.log('graphUrl');
$.get(url, function onGetGraphData(response) {
graphCsv(response, el);
});
Expand All @@ -8,7 +7,13 @@ console.log('graphUrl');
function graphCsv(csv, el) {

var data = [];
var rows = csv.split('\n').slice(1);
var rows = csv.split('\n');
var labels = false;

if (parseFloat(rows[0][0]) != rows[0][0]) { // if it's not a number
labels = rows[0].split(',');
rows = rows.slice(1);
}

for (var i = 0; i < rows[0].split(',').length; i++) {
data.push([]);
Expand All @@ -23,10 +28,10 @@ function graphCsv(csv, el) {
}
});

return graph(data, el);
return graph(data, el, labels);
}

function dataToDatasets(data) {
function dataToDatasets(data, labels) {

var colors = {
"blue":"rgb(54, 162, 235)",
Expand All @@ -41,7 +46,7 @@ function dataToDatasets(data) {
var datasets = [];
data.forEach(function(data, i) {
datasets.push({
label: "Dataset " + i,
label: labels ? labels[i] : "Dataset " + i,
backgroundColor: colors[colorNames[i]],
borderColor: colors[colorNames[i]],
legendPosition: 'right',
Expand All @@ -53,17 +58,17 @@ function dataToDatasets(data) {
return datasets;
}

function graph(data, el) {
function graph(data, el, labels) {

el = el || "graph-canvas";
data = data || [1, 2, 4, 1, 5];

var datasets = dataToDatasets(data);
var datasets = dataToDatasets(data, labels);

var config = {
type: 'line',
data: {
labels: Array.from(Array(data[0].length).keys()),
labels: labels,
datasets: datasets
},
options: {
Expand Down
12 changes: 10 additions & 2 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,18 @@ def power_tag_objects(tagname = nil)
end

# return whole community_tag objects but no powertags or "event"
def normal_tags
def normal_tags(order = :none)
all_tags = tags.select { |tag| !tag.name.include?(':') }
tids = all_tags.collect(&:tid)
NodeTag.where('nid = ? AND tid IN (?)', id, tids)
if order == :followers
tags = NodeTag.where('nid = ? AND community_tags.tid IN (?)', id, tids)
.left_outer_joins(:tag, :tag_selections)
.order(Arel.sql('count(tag_selections.user_id) DESC'))
.group(:tid)
else
tags = NodeTag.where('nid = ? AND tid IN (?)', id, tids)
end
tags
end

def location_tags
Expand Down
1 change: 1 addition & 0 deletions app/models/node_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class NodeTag < ApplicationRecord
belongs_to :node, foreign_key: 'nid'
belongs_to :tag, foreign_key: 'tid'
belongs_to :users, foreign_key: 'uid'
has_many :tag_selections, foreign_key: 'tid'
accepts_nested_attributes_for :tag

after_create :increment_count
Expand Down
13 changes: 8 additions & 5 deletions app/views/comments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
<div class="card-body">
<form class="comment-form" id="comment-form" data-remote="true" action="/comment/create/<%= @node.nid %><%= "?type=question" if local_assigns[:type]=="question" %>" <% if local_assigns[:aid].blank? %>method="post"<% end %>>

<h4 style="margin-top:0;"><%= title %><% if current_user && current_user.id == @node.uid %> <small><a target="_blank" href="https://publiclab.org/comment-templates">Add a response template</a></small><% end %></h4>
<% if current_user && current_user.id == @node.uid %>
<span class="pull-right" style="color:#ccc;"><a target="_blank" href="https://publiclab.org/comment-templates">Add a template</a></span>
<% end %>

<h4 style="margin-top:0;"><%= title %></h4>

<style>
#imagebar {
Expand Down Expand Up @@ -101,10 +105,9 @@
<% end %>

<span style="color:#888;"> &nbsp;
<br class="d-md-none" /><%= raw t('comments._form.logged_in', :username => current_user.username) %> |
<a target="_blank" href="/wiki/authoring-help#Formatting"><%= t('comments._form.formatting') %></a> |
<a onClick="$('#who-is-notified-form').toggle()"><%= t('comments._form.notifications') %></a> |
<a onClick = "insertTitleSuggestionTemplate()">Propose Title</a>
<br class="d-md-none" /><%= raw t('comments._form.logged_in', :username => current_user.username) %> &nbsp;
<a target="_blank" href="/wiki/authoring-help#Formatting"><i class="fa fa-question-circle"></i></a> &nbsp;
<a onClick="$('#who-is-notified-form').toggle()"><i class="fa fa-bell-o"></i></a>
</span>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/home/_social.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="social">
<div id="social" style="margin-top:10px;">
<% if Rails.env == "production" %>
<div class="fb-like" data-send="false" data-layout="button_count" data-width="50" data-show-faces="false" style="vertical-align: middle; bottom: 6px;margin-right:10px" ></div>

Expand Down
12 changes: 9 additions & 3 deletions app/views/tag/_miniCard.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
<a class="ellipsis pull-right" data-toggle="dropdown"><i class="fa fa-ellipsis-h" style="color:#666;font-size:18px;margin-right:10px;"></i></a>
<div class="dropdown-menu" style = "font-size:13px;">
<div class="dropdown-item"><a href='/tag/<%= tag.name %>' style="color:black; text-decoration: underline;"><%= Tag.tagged_node_count(tag.name) || 0 %> notes</a></div>
<div class="dropdown-item">created by <a href='/profile/<%= tag.try(:author).try(:username) %>' style="color:black; text-decoration: underline;"><%= tag.try(:author).try(:username) %></a></div>
<div class="dropdown-item">created <%= time_ago_in_words(Time.at(tag.date)) %> ago</div>
<div class="dropdown-item">created by <a href='/profile/<%= tag.try(:author).try(:username) %>' style="color:black; text-decoration: underline;"><%= tag.try(:author).try(:username) %></a> <%= time_ago_in_words(Time.at(tag.date)) %> ago</div>
<% if current_user && !current_user.following(tag.name) %>
<div class="dropdown-item"><a class="pull-right btn btn-primary" href='/unsubscribe/tag/<%= tag.name %>'>Unfollow</a></div>
<% end %>
<% if logged_in_as(['admin', 'moderator']) || (current_user && ( current_user.uid == @node.uid || current_user.uid == tag.uid)) %>
<% if tag.name.include? ':' %>
<div class="dropdown-item"><a data-confirm="This is a power tag (see https://publiclab.org/wiki/power-tags) -- and may drive a specific function on this page. Are you sure you want to delete it?" class="tag-delete" href="/tag/delete/<%= @node.id %>/<%= tag.tid %>" data-tag-id="<%= tag.tid %>" data-method="delete" style="color:black; text-decoration: underline;">delete tag</a></div>
Expand All @@ -22,7 +24,11 @@
<a style="color:#808080;" href="/tag/<%= tag.name %>"><%= Tag.follower_count(tag.name) %> following</a>
</p>

<a class="pull-right btn btn-primary" href='/subscribe/tag/<%= tag.name %>'>Follow</a>
<% if current_user && current_user.following(tag.name) %>
<a class="pull-right btn btn-primary requireLogin" href="/post?tags=<%= tag.name %>">Post <i class="fa fa-plus fa-white"></i></a>
<% else %>
<a class="pull-right btn btn-primary requireLogin" href='/subscribe/tag/<%= tag.name %>'>Follow</a>
<% end %>
</div>
</div>
<br />
2 changes: 1 addition & 1 deletion app/views/tag/_tagging.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<% end %>
</p>
<div id="tags" class="node-tags">
<%= render partial: 'tag/tags', locals: { power_tag: false, badge_name: 'badge-secondary', tags: @node.normal_tags } %>
<%= render partial: 'tag/tags', locals: { power_tag: false, badge_name: 'badge-secondary', tags: @node.normal_tags(:followers) } %>
<%= render partial: 'tag/tags', locals: { power_tag: true, badge_name: 'badge-primary', tags: @node.power_tag_objects } %>
</div>
<% else %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/tag/_tags_popover.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="pop_content subscribe-btn">
<p class="small_heading"> Follow related tags: </p>
<p> Follow related tags: </p>
<%= form_with remote: true, url: '/subscribe/multiple/tag' do |f| %>
<% tags&.each_with_index do |tag, i| %>
<div class="form-check">
Expand All @@ -11,7 +11,7 @@
<% if current_user %>
<%= f.submit 'Subscribe', id: "subscribe", class: "btn btn-primary btn-sm" %>
<% else %>
<a class="btn btn-primary btn-sm" onClick="require_login_and_redirect_to('/subscribe/multiple/tag/' + getCheckedTags())">Subscribe</a>
<a class="btn btn-primary btn-sm btn-white" onClick="require_login_and_redirect_to('/subscribe/multiple/tag/' + getCheckedTags())">Subscribe</a>
<% end %>
<% end %>
</div>
Expand Down
18 changes: 9 additions & 9 deletions app/views/tag/_topicCard.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

<div class="card-view">
<% @tags.each do |tag| %>
<div class="card shadow-sm p-2 mb-3 bg-white rounded" >
<div class="card-header mt-2" style=" padding:0.8em; background-color: inherit; border:none;">
<h4 style="display: inline-block;"><%= tag.name %></h4>
<p style="display: inline-block; color: #808080;"><a style="text-decoration: underline; color: #808080;" href="/tag/<%= tag.name %>"><%= Tag.follower_count(tag.name) %> people</a> discussing</p>
<p style="display: inline-block; color: #808080;"><a style="text-decoration: underline; color: #808080;" href="/tag/<%= tag.name %>"><%= Tag.follower_count(tag.name) %> following</a></p>
</div>
<div class="card-body" style="padding:0.8em;">
<div class="node-list">
Expand All @@ -17,14 +16,16 @@
<% else %>
<div class="circle"></div>
<% end %>
<p style="display: inline-block; margin-left: 10px;"><a style="color: inherit;" <% if @widget %>target="_blank"<% end %> href="<%= node.path %>"><%= (node.type == 'note') ? node.title : node.latest.title %></a></p>
<p style="display: inline-block; margin-left: 10px;color: #808080;">by <a style="color: #808080;" <% if @widget %>target="_blank"<% end %> href="/profile/<%= node.author.name %>">@<%= node.author.name %></a></p>
<p style="margin-left: 10px;">
<a style="color: inherit;" <% if @widget %>target="_blank"<% end %> href="<%= node.path %>"><%= (node.type == 'note') ? node.title : node.latest.title %></a>
<span style="color: #808080;">by <a style="color: #808080;" <% if @widget %>target="_blank"<% end %> href="/profile/<%= node.author.name %>">@<%= node.author.name %></a>
</p>
</div>
<% end %>
</div>
</div>
<div class="card-footer" style="background-color: inherit; border:none;">
<a style="text-decoration: underline; color: #808080; display: inline-block;" href="/tag/<%= tag.name %>"><%= tag.count %> <%= t('tag.index.more_posts') %> <i class="fa fa-angle-double-right"></i></a>
<a style="text-decoration: underline; color: #808080; display: inline-block;" href="/tag/<%= tag.name %>"><%= tag.count %> <%= t('tag.index.more_posts') %> &raquo;</a>

<a style="float: right; width: 100px;" rel="tooltip" title="<%= t('sidebar._post_button.share_your_work') %>" data-placement="bottom" href="/post?tags=<%= tag.name %>" class="btn btn-primary btn-sm">New post <i class="fa fa-plus fa-white"></i></a>
<% if current_user %>
Expand All @@ -47,12 +48,11 @@
display: grid;
}

.node-body {
display: flex;
}

.circle {
background-color: gray;
display: block;
margin-right: 8px;
float: left;
height: 20px;
width: 20px;
border-radius: 100%;
Expand Down
2 changes: 1 addition & 1 deletion app/views/tag/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<%= javascript_include_tag('async_tag_subscriptions.js') %>
<div class="col-md-6">
<h1 style="font-family:Junction Light;"><%= t('tag.index.popular_tags') %></h1>
<h1 style="padding-top:40px;font-family:Junction Light;"><%= t('tag.index.popular_tags') %></h1>

<% cache('feature_tags-header', skip_digest: true) do %>
<%= feature('tags-header') %>
Expand Down
15 changes: 3 additions & 12 deletions app/views/tag/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,22 @@
</div>
<% if @wiki %>
<p class = "wiki-sub"><%= @wiki.latest.body %></p>
<% else %>
<p class = "wiki-sub">This topic has no wiki</p>
<% end %>
<div class = "tag-buttons">
<div class="btn-group" role="group">
<% if current_user && current_user.following(@title) %>
<a style="float: right; width: 100px;" rel="tooltip" title="<%= t('sidebar._post_button.share_your_work') %>" data-placement="bottom" href="/post?tags=<%= tag.name %>" class="btn btn-primary requireLogin">New post <i class="fa fa-plus fa-white"></i></a>
<% elsif current_user %>
<a class="btn btn-primary" target="_blank" href="/subscribe/tag/<%= @title %>"> Subscribe</a>
<% else %>
<a class="btn btn-primary requireLogin" target="_blank" href="/subscribe/tag/<%= @title %>"> Follow</a>
<% if @related_tags %>
<a><%= render partial: 'tag/dropdown_subscribe', locals: { tags: @related_tags, buttonStyle: "btn-primary"} %></a>
<% end %>
<% else %>
<a class="btn btn-primary" data-toggle="tooltip" data-placement="top" title="Login to Subscribe" style="color:white;">Subscribe</a>
<a class="btn rounded-right btn-primary btn-md"><i class="fa fa-caret-down" style="color:white;" data-toggle="tooltip" data-placement="top" title="Login to Subscribe to related-tags"></i></a>
<% end %>
</div>
<% if @wiki %>
<a><%= link_to("Learn more &raquo;".html_safe, "/wiki/#{params[:id]}", :class=> "btn btn-outline-secondary")%></a>
<% else %>
<a class="btn btn-outline-secondary" href="/wiki/new?title=<%= params[:id] %>">Add a wiki page <span class="fa fa-plus"></span></a>
<a class="btn btn-outline-secondary" href="/wiki/new?title=<%= params[:id] %>">Add a description <span class="fa fa-plus"></span></a>
<% end %>
</div>
</div>
Expand Down Expand Up @@ -65,10 +60,6 @@
</div>
</div>
<div class="col-md-3">
<!-- <div class="people-map">
<%= render :partial => "map/peopleLeaflet" , locals: {people: true , lat:23 , lon: 4} %>
</div> -->
<a href="/people" style="color:#666;"><u>See more people near here</u></a><br>
<%= render partial: "tag/show/related_tags" %>
</div>
</div>
Expand Down
3 changes: 0 additions & 3 deletions app/views/tag/show/_header.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<% else %>

<div class="im d-none d-md-block" id="wiki-empty1">
<h5 class="line">This topic's wiki page doesn't have an image. </h5>
<div class="bottom-right">
<a href="/contributors/<%= params[:id] %>">
<%= Tag.follower_count(params[:id]) %> people discussing
Expand Down Expand Up @@ -54,11 +53,9 @@
<% else %>

<div class="im d-none d-md-block" id="wiki-empty1">
<!-- <h5 class="line">This topic has no lead wiki page. </h5> -->
<div class="bottom-right"><%= Tag.follower_count(params[:id]) %> people discussing</div>
</div>
<div class="im d-sm-none" id="wiki-empty2">
<!-- <h5 style="margin: 5px; color: #777;">This topic has no lead wiki page. </h5> -->
<div class="bottom-right"><%= Tag.follower_count(params[:id]) %> people discussing</div>
</div>
<% end %>
Expand Down